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