convert para_audiod to the new scheduler.
[paraslash.git] / afh.h
1 /*
2 * Copyright (C) 2005-2006 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 /**
45 * structure for audio format handling
46 *
47 * There's exactly one such struct for each supported audio format. Initially,
48 * only \a name and \a init are defined. During the startup process,
49 * para_server calls the \a init function of each audio format handler which is
50 * expected to fill in all the other function pointers.
51 */
52 struct audio_format_handler {
53 /**
54 * name of the audio format
55 */
56 const char *name;
57 /**
58 * typical file endings for files that can be handled by this afh.
59 */
60 const char **suffixes;
61 /**
62 * pointer to the audio format handler's init function
63 *
64 * Must initialize all function pointers and is assumed to succeed.
65 */
66 void (*init)(struct audio_format_handler*);
67 /**
68 * period of time between sending data chunks
69 */
70 struct timeval chunk_tv; /* length of one chunk of data */
71 /**
72 * end of file timeout - do not load new audio file until this time
73 *
74 */
75 struct timeval eof_tv; /* timeout on eof */
76 /**
77 * Pointer to the optional get-header function.
78 *
79 * This is called from a sender in case a new client connects in the middle of
80 * the stream. The audio format handler may set this to NULL to indicate that
81 * this audio format does not need any special header treatment. If non-NULL,
82 * the function it points to must return a pointer to a buffer holding the
83 * current audio file header, together with the header length.
84 */
85 char *(*get_header_info)(int *header_len);
86 /**
87 * check if this audio format handler can handle the file
88 *
89 * This is a pointer to a function returning whether a given file is valid for
90 * this audio format. A negative return value indicates that this audio format
91 * handler did not recognize the given file. On success, the function is
92 * expected to return a positive value and to fill in \arg info_str, \arg
93 * chunks and \arg seconds appropriately.
94 */
95 int (*get_file_info)(FILE *audio_file, char *info_str,
96 long unsigned *chunks, int *seconds);
97 /**
98 * cleanup function of this audio format handler
99 *
100 * This close function should deallocate any resources
101 * associated with the current audio file. In particular, it is responsible
102 * for closing the file handle. It is assumed to succeed.
103 */
104 void (*close_audio_file)(void);
105 /**
106 * jump to another position in the current audio file
107 *
108 * This is called if a client issued the ff or jmp command with \a request
109 * being the number of the next chunk that should be sent out. Must return a
110 * positive value on success and a negative value on errors.
111 */
112 int (*reposition_stream)(long unsigned request);
113 /**
114 * function responsible for reading one data chunk.
115 *
116 * \a read_chunk() must return a pointer to the next chunk of data that should
117 * be sent out, or \p NULL on errors or if the end of the file was encountered.
118 *
119 * If it returns non-NULL, \a len must contain the length of the returned
120 * buffer (which may be zero if nothing has to be sent for some reason).
121 * Otherwise, \a len is used to distinguish between the eof and the error case:
122 * It must be zero in the eof case, or negative if an error occcured.
123 */
124 char * (*read_chunk)(long unsigned chunk_num, ssize_t *len);
125 };