Simplify dispatch_slice().
[paraslash.git] / afh.h
1 /*
2  * Copyright (C) 2005-2009 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 /** Audio format dependent information. */
27 struct afh_info {
28         /** The number of chunks this audio file contains. */
29         long unsigned chunks_total;
30         /** The length of the audio file in seconds. */
31         long unsigned seconds_total;
32         /** A string that gets filled in by the audio format handler. */
33         char *info_string;
34         /**
35          * The table that specifies the offset of the individual pieces in
36          * the current audio file.
37          */
38         uint32_t *chunk_table;
39         /** Period of time between sending data chunks. */
40         struct timeval chunk_tv;
41         /** End of file timeout - Do not load new audio file until this time. */
42         struct timeval eof_tv;
43         /**
44          * The position of the header within the audio file. Ignored if \a
45          * header_len equals zero.
46          */
47         uint32_t header_offset;
48         /**
49          * The header is needed by senders in case a new client connects in the
50          * middle of the stream. The length of the header defaults to zero
51          * which means that this audio format does not need any special header
52          * treatment. The audio format handler does not need to set this to
53          * zero in this case.
54          */
55         uint32_t header_len;
56         /** The number of channels. */
57         uint8_t channels;
58         /** Frequency in Hz. */
59         uint16_t frequency;
60         /** Exact meaning depends on audio format. */
61         uint16_t bitrate;
62 };
63
64 /**
65  *  Structure for audio format handling.
66  *
67  *  There's one such struct for each supported audio format. Initially, only \a
68  *  name and \a init are defined. During the startup process, para_server calls
69  *  the \a init function of each audio format handler which is expected to fill
70  *  in the other part of this struct.
71  */
72 struct audio_format_handler {
73         /** Name of the audio format. */
74         const char *name;
75         /**
76          * Pointer to the audio format handler's init function.
77          *
78          * Must initialize all function pointers and is assumed to succeed.
79          */
80         void (*init)(struct audio_format_handler*);
81         /** Typical file endings for files that can be handled by this afh. */
82         const char **suffixes;
83         /**
84          * Check if this audio format handler can handle the file.
85          *
86          * This is a  pointer to a function returning whether a given file is
87          * valid for this audio format. A negative return value indicates that
88          * this audio format handler is unable to decode the given file. On
89          * success, the function must return a positive value and fill in the
90          * given struct afh_info.
91          *
92          * \sa struct afh_info
93          */
94         int (*get_file_info)(char *map, size_t numbytes, int fd,
95                 struct afh_info *afi);
96 };
97
98 void afh_init(void);
99 int guess_audio_format(const char *name);
100 int compute_afhi(const char *path, char *data, size_t size,
101         int fd, struct afh_info *afhi);
102 const char *audio_format_name(int);
103 void afh_get_chunk(long unsigned chunk_num, struct afh_info *afhi,
104                 void *map, const char **buf, size_t *len);
105 void afh_get_header(struct afh_info *afhi, void *map, const char **buf, size_t *len);
106 char *make_taginfo(char *title, char *artist, char *album, char *year,
107                 char *comment);