Merge /fml/ag-raetsch/home/maan/scm/paraslash_meins/paraslash
[paraslash.git] / afh.h
1 /*
2  * Copyright (C) 2005-2007 Andre Noll <maan@systemlinux.org>
3  *
4  *     This program is free software; you can redistribute it and/or modify
5  *     it under the terms of the GNU General Public License as published by
6  *     the Free Software Foundation; either version 2 of the License, or
7  *     (at your option) any later version.
8  *
9  *     This program is distributed in the hope that it will be useful,
10  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *     GNU General Public License for more details.
13  *
14  *     You should have received a copy of the GNU General Public License
15  *     along with this program; if not, write to the Free Software
16  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
17  */
18
19 /** \file afh.h structures for audio format handling (para_server) */
20
21 /** \cond */
22 #ifdef HAVE_OGGVORBIS
23 #define OV_AUDIO_FORMAT " ogg"
24 #define OV_AUDIO_FORMAT_ARRAY , "ogg"
25 #else
26 #define OV_AUDIO_FORMAT ""
27 #define OV_AUDIO_FORMAT_ARRAY
28 #endif
29
30 #ifdef HAVE_FAAD
31 #define AAC_AUDIO_FORMAT " aac"
32 #define AAC_AUDIO_FORMAT_ARRAY , "aac"
33 #else
34 #define AAC_AUDIO_FORMAT ""
35 #define AAC_AUDIO_FORMAT_ARRAY
36 #endif
37
38 #define SUPPORTED_AUDIO_FORMATS "mp3" OV_AUDIO_FORMAT AAC_AUDIO_FORMAT
39 #define SUPPORTED_AUDIO_FORMATS_ARRAY "mp3" OV_AUDIO_FORMAT_ARRAY \
40         AAC_AUDIO_FORMAT_ARRAY, NULL
41
42 /** \endcond */
43
44 /** size of the  audio_file info string */
45 #define AUDIO_FILE_INFO_SIZE 16384
46
47 struct audio_format_info {
48         /** the number of chunks this audio file contains */
49         long unsigned chunks_total;
50         /** the length of the audio file in seconds */
51         long unsigned seconds_total;
52         /** a string that gets filled in by the audio format handler */
53         char info_string[AUDIO_FILE_INFO_SIZE];
54         /**
55          * the table that specifies the offset of the individual pieces in
56          * the current audio file.
57          */
58         size_t *chunk_table;
59         /** period of time between sending data chunks */
60         struct timeval chunk_tv;
61         /** end of file timeout - do not load new audio file until this time */
62         struct timeval eof_tv;
63         /**
64          * The header is needed by senders in case a new client connects in the
65          * middle of the stream. The length of the header defaults to zero
66          * which means that this audio format does not need any special header
67          * treatment. The audio format handler does not need to set this to
68          * zero in this case.
69          */
70         unsigned header_len;
71         /**
72          * The position of the header within the audio file. Ignored if \a
73          * header_len equals zero.
74          */
75         unsigned header_offset;
76         uint8_t channels;
77         uint16_t frequency;
78         uint16_t bitrate;
79 };
80
81 /**
82  * structure for audio format handling
83  *
84  * There's exactly one such struct for each supported audio format. Initially,
85  * only \a name and \a init are defined. During the startup process,
86  * para_server calls the \a init function of each audio format handler which is
87  * expected to fill in all the other function pointers.
88  */
89 struct audio_format_handler {
90         /**
91          * name of the audio format
92          */
93         const char *name;
94         /**
95          * typical file endings for files that can be handled by this afh.
96          */
97         const char **suffixes;
98         /**
99          * pointer to the audio format handler's init function
100          *
101          * Must initialize all function pointers and is assumed to succeed.
102          */
103         void (*init)(struct audio_format_handler*);
104         /**
105          * check if this audio format handler can handle the file
106          *
107          * This is a  pointer to a function returning whether a given file is
108          * valid for this audio format. A negative return value indicates that
109          * this audio format handler did not recognize the given file. On
110          * success, the function must return a positive value and fill in the
111          * given struct audio_format_info.
112          *
113          * \sa struct audio_format_info
114         */
115         int (*get_file_info)(char *map, size_t numbytes,
116                 struct audio_format_info *afi);
117 };
118