kill close_audio_file handler from struct audio format.
[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 /** 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 int 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 * optional audio file header
65 *
66 * This is read from a sender in case a new client connects in the
67 * middle of the stream. The audio format handler does not need to set
68 * this if the audio format does not need any special header treatment.
69 * If non-NULL, it must point to a buffer holding the current audio
70 * file header.
71 */
72 char *header;
73 /* the length of the header, ignored if \a header is \p NULL */
74 unsigned header_len;
75 };
76
77 /**
78 * structure for audio format handling
79 *
80 * There's exactly one such struct for each supported audio format. Initially,
81 * only \a name and \a init are defined. During the startup process,
82 * para_server calls the \a init function of each audio format handler which is
83 * expected to fill in all the other function pointers.
84 */
85 struct audio_format_handler {
86 /**
87 * name of the audio format
88 */
89 const char *name;
90 /**
91 * typical file endings for files that can be handled by this afh.
92 */
93 const char **suffixes;
94 /**
95 * pointer to the audio format handler's init function
96 *
97 * Must initialize all function pointers and is assumed to succeed.
98 */
99 void (*init)(struct audio_format_handler*);
100 /**
101 * check if this audio format handler can handle the file
102 *
103 * This is a pointer to a function returning whether a given file is
104 * valid for this audio format. A negative return value indicates that
105 * this audio format handler did not recognize the given file. On
106 * success, the function must return a positive value and fill in the
107 * given struct audio_format_info.
108 *
109 * \sa struct audio_format_info
110 */
111 int (*get_file_info)(FILE *audio_file, struct audio_format_info *afi);
112 };
113