Introduce the new nonblock API.
[paraslash.git] / afh.h
1 /*
2  * Copyright (C) 2005-2010 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 " wma "
23
24 /** \endcond */
25
26 /**
27  * The tags used by all audio format handlers.
28  *
29  * Paraslash only uses the more common tags. These are recognized
30  * for all supported audio formats.
31  */
32 struct taginfo {
33         /** TPE1 (id3v2) / ARTIST (vorbis) / ©ART (aac) */
34         char *artist;
35         /** TIT2/TITLE/©nam */
36         char *title;
37         /** TDRC/YEAR/©day */
38         char *year;
39         /** TALB/ALBUM/©alb */
40         char *album;
41         /** COMM/COMMENT/©cmt */
42         char *comment;
43 };
44
45 /** Audio format dependent information. */
46 struct afh_info {
47         /** The number of chunks this audio file contains. */
48         long unsigned chunks_total;
49         /** The length of the audio file in seconds. */
50         long unsigned seconds_total;
51         /** Audio handler specific info about the file. */
52         char *techinfo;
53         /** Id3 tags, vorbis comments, aac tags. */
54         struct taginfo tags;
55         /**
56          * The table that specifies the offset of the individual pieces in
57          * the current audio file.
58          */
59         uint32_t *chunk_table;
60         /** Period of time between sending data chunks. */
61         struct timeval chunk_tv;
62         /**
63          * The position of the header within the audio file. Ignored if \a
64          * header_len equals zero.
65          */
66         uint32_t header_offset;
67         /**
68          * The header is needed by senders in case a new client connects in the
69          * middle of the stream. The length of the header defaults to zero
70          * which means that this audio format does not need any special header
71          * treatment. The audio format handler does not need to set this to
72          * zero in this case.
73          */
74         uint32_t header_len;
75         /** The number of channels. */
76         uint8_t channels;
77         /** Frequency in Hz. */
78         uint16_t frequency;
79         /** Exact meaning depends on audio format. */
80         uint16_t bitrate;
81 };
82
83 /**
84  *  Structure for audio format handling.
85  *
86  *  There's one such struct for each supported audio format. Initially, only \a
87  *  name and \a init are defined. During the startup process, para_server calls
88  *  the \a init function of each audio format handler which is expected to fill
89  *  in the other part of this struct.
90  */
91 struct audio_format_handler {
92         /** Name of the audio format. */
93         const char *name;
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         /** Typical file endings for files that can be handled by this afh. */
101         const char **suffixes;
102         /**
103          * Check if this audio format handler can handle the file.
104          *
105          * This is a  pointer to a function returning whether a given file is
106          * valid for this audio format. A negative return value indicates that
107          * this audio format handler is unable to decode the given file. On
108          * success, the function must return a positive value and fill in the
109          * given struct afh_info.
110          *
111          * \sa struct afh_info
112          */
113         int (*get_file_info)(char *map, size_t numbytes, int fd,
114                 struct afh_info *afi);
115 };
116
117 void afh_init(void);
118 int guess_audio_format(const char *name);
119 int compute_afhi(const char *path, char *data, size_t size,
120         int fd, struct afh_info *afhi);
121 const char *audio_format_name(int);
122 void afh_get_chunk(long unsigned chunk_num, struct afh_info *afhi,
123                 void *map, const char **buf, size_t *len);
124 uint32_t afh_get_largest_chunk_size(struct afh_info *afhi);
125 void afh_get_header(struct afh_info *afhi, void *map, const char **buf, size_t *len);