Rename instances of struct afh_info from "afi" to "afhi".
[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 #else
13 #define OV_AUDIO_FORMAT ""
14 #endif
15
16 #ifdef HAVE_FAAD
17 #define AAC_AUDIO_FORMAT " aac"
18 #else
19 #define AAC_AUDIO_FORMAT ""
20 #endif
21
22 #define SUPPORTED_AUDIO_FORMATS "mp3" OV_AUDIO_FORMAT AAC_AUDIO_FORMAT
23
24 /** \endcond */
25
26 /** size of the  audio_file info string */
27 #define AUDIO_FILE_INFO_SIZE 256
28
29 /** Audio format dependent information. */
30 struct afh_info {
31         /** The number of chunks this audio file contains. */
32         long unsigned chunks_total;
33         /** The length of the audio file in seconds. */
34         long unsigned seconds_total;
35         /** A string that gets filled in by the audio format handler. */
36         char info_string[AUDIO_FILE_INFO_SIZE];
37         /**
38          * The table that specifies the offset of the individual pieces in
39          * the current audio file.
40          */
41         uint32_t *chunk_table;
42         /** Period of time between sending data chunks. */
43         struct timeval chunk_tv;
44         /** End of file timeout - Do not load new audio file until this time. */
45         struct timeval eof_tv;
46         /**
47          * The header is needed by senders in case a new client connects in the
48          * middle of the stream. The length of the header defaults to zero
49          * which means that this audio format does not need any special header
50          * treatment. The audio format handler does not need to set this to
51          * zero in this case.
52          */
53         unsigned header_len;
54         /**
55          * The position of the header within the audio file. Ignored if \a
56          * header_len equals zero.
57          */
58         unsigned header_offset;
59         /** The number of channels. */
60         uint8_t channels;
61         /** Frquency on Hz. */
62         uint16_t frequency;
63         /** Exact meaning depends on audio format. */
64         uint16_t bitrate;
65 };
66
67 /**
68  *  Structure for audio format handling.
69  *
70  *  There's one such struct for each supported audio format. Initially, only \a
71  *  name and \a init are defined. During the startup process, para_server calls
72  *  the \a init function of each audio format handler which is expected to fill
73  *  in the other part of this struct.
74  */
75 struct audio_format_handler {
76         /** Name of the audio format. */
77         const char *name;
78         /**
79          * Pointer to the audio format handler's init function.
80          *
81          * Must initialize all function pointers and is assumed to succeed.
82          */
83         void (*init)(struct audio_format_handler*);
84         /** Typical file endings for files that can be handled by this afh. */
85         const char **suffixes;
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
90          * valid for this audio format. A negative return value indicates that
91          * this audio format handler is unable to decode the given file. On
92          * success, the function must return a positive value and fill in the
93          * given struct afh_info.
94          *
95          * \sa struct afh_info
96          */
97         int (*get_file_info)(char *map, size_t numbytes,
98                 struct afh_info *afi);
99 };
100
101 void afh_init(void);
102 int guess_audio_format(const char *name);
103 int compute_afhi(const char *path, char *data, size_t size,
104         struct afh_info *afhi);
105 const char *audio_format_name(int);