aac_afh.c: Fix serious memory leak.
[paraslash.git] / afh.h
1 /*
2 * Copyright (C) 2005-2007 Andre Noll <maan@systemlinux.org>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 /** \file afh.h structures for audio format handling (para_server) */
8
9 /** \cond */
10 #ifdef HAVE_OGGVORBIS
11 #define OV_AUDIO_FORMAT " ogg"
12 #define OV_AUDIO_FORMAT_ARRAY , "ogg"
13 #else
14 #define OV_AUDIO_FORMAT ""
15 #define OV_AUDIO_FORMAT_ARRAY
16 #endif
17
18 #ifdef HAVE_FAAD
19 #define AAC_AUDIO_FORMAT " aac"
20 #define AAC_AUDIO_FORMAT_ARRAY , "aac"
21 #else
22 #define AAC_AUDIO_FORMAT ""
23 #define AAC_AUDIO_FORMAT_ARRAY
24 #endif
25
26 #define SUPPORTED_AUDIO_FORMATS "mp3" OV_AUDIO_FORMAT AAC_AUDIO_FORMAT
27 #define SUPPORTED_AUDIO_FORMATS_ARRAY "mp3" OV_AUDIO_FORMAT_ARRAY \
28 AAC_AUDIO_FORMAT_ARRAY, NULL
29
30 /** \endcond */
31
32 /** size of the audio_file info string */
33 #define AUDIO_FILE_INFO_SIZE 256
34
35 /**
36 * Audio format dependent information. Details vary between each audio format
37 * handler.
38 */
39 struct audio_format_info {
40 /** The number of chunks this audio file contains. */
41 long unsigned chunks_total;
42 /** The length of the audio file in seconds. */
43 long unsigned seconds_total;
44 /** A string that gets filled in by the audio format handler. */
45 char info_string[AUDIO_FILE_INFO_SIZE];
46 /**
47 * The table that specifies the offset of the individual pieces in
48 * the current audio file.
49 */
50 size_t *chunk_table;
51 /** Period of time between sending data chunks. */
52 struct timeval chunk_tv;
53 /** End of file timeout - Do not load new audio file until this time. */
54 struct timeval eof_tv;
55 /**
56 * The header is needed by senders in case a new client connects in the
57 * middle of the stream. The length of the header defaults to zero
58 * which means that this audio format does not need any special header
59 * treatment. The audio format handler does not need to set this to
60 * zero in this case.
61 */
62 unsigned header_len;
63 /**
64 * The position of the header within the audio file. Ignored if \a
65 * header_len equals zero.
66 */
67 unsigned header_offset;
68 /** The number of channels. */
69 uint8_t channels;
70 /** Frquency on Hz. */
71 uint16_t frequency;
72 /** Exact meaning depends on audio format. */
73 uint16_t bitrate;
74 };
75
76 /**
77 * Structure for audio format handling.
78 *
79 * There's one such struct for each supported audio format. Initially, only \a
80 * name and \a init are defined. During the startup process, para_server calls
81 * the \a init function of each audio format handler which is expected to fill
82 * in the other part of this struct.
83 */
84 struct audio_format_handler {
85 /** Name of the audio format. */
86 const char *name;
87 /**
88 * Pointer to the audio format handler's init function.
89 *
90 * Must initialize all function pointers and is assumed to succeed.
91 */
92 void (*init)(struct audio_format_handler*);
93 /** Typical file endings for files that can be handled by this afh. */
94 const char **suffixes;
95 /**
96 * Check if this audio format handler can handle the file.
97 *
98 * This is a pointer to a function returning whether a given file is
99 * valid for this audio format. A negative return value indicates that
100 * this audio format handler is unable to decode the given file. On
101 * success, the function must return a positive value and fill in the
102 * given struct audio_format_info.
103 *
104 * \sa struct audio_format_info
105 */
106 int (*get_file_info)(char *map, size_t numbytes,
107 struct audio_format_info *afi);
108 };
109