com_lsblob: Print an error message if no blob matched.
[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)/ author(spx) */
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 header is needed by senders in case a new client connects in the
47 * middle of the stream. The length of the header defaults to zero
48 * which means that this audio format does not need any special header
49 * treatment. The audio format handler does not need to set this to
50 * zero in this case.
51 */
52 uint32_t header_len;
53 /** The number of channels. */
54 uint8_t channels;
55 /** Frequency in Hz. */
56 uint16_t frequency;
57 /** Exact meaning depends on audio format. */
58 uint16_t bitrate;
59 };
60
61 /**
62 * Structure for audio format handling.
63 *
64 * There's one such struct for each supported audio format. Initially, only \a
65 * name and \a init are defined. During the startup process, para_server calls
66 * the \a init function of each audio format handler which is expected to fill
67 * in the other part of this struct.
68 */
69 struct audio_format_handler {
70 /** Name of the audio format. */
71 const char *name;
72 /**
73 * Pointer to the audio format handler's init function.
74 *
75 * Must initialize all function pointers and is assumed to succeed.
76 */
77 void (*init)(struct audio_format_handler*);
78 /** Typical file endings for files that can be handled by this afh. */
79 const char **suffixes;
80 /**
81 * Check if this audio format handler can handle the file.
82 *
83 * This is a pointer to a function returning whether a given file is
84 * valid for this audio format. A negative return value indicates that
85 * this audio format handler is unable to decode the given file. On
86 * success, the function must return a positive value and fill in the
87 * given struct afh_info.
88 *
89 * \sa struct afh_info
90 */
91 int (*get_file_info)(char *map, size_t numbytes, int fd,
92 struct afh_info *afi);
93 /** Optional, used for header-rewriting. See \ref afh_get_header(). */
94 void (*get_header)(void *map, size_t mapsize, char **buf, size_t *len);
95 };
96
97 void afh_init(void);
98 int guess_audio_format(const char *name);
99 int compute_afhi(const char *path, char *data, size_t size,
100 int fd, struct afh_info *afhi);
101 const char *audio_format_name(int);
102 void afh_get_chunk(long unsigned chunk_num, struct afh_info *afhi,
103 void *map, const char **buf, size_t *len);
104 void afh_get_header(struct afh_info *afhi, uint8_t audio_format_id,
105 void *map, size_t mapsize, char **buf, size_t *len);
106 void afh_free_header(char *header_buf, uint8_t audio_format_id);