2 * Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file afh.h Structures for audio format handling (para_server). */
10 * The tags used by all audio format handlers.
12 * Paraslash only uses the more common tags. These are recognized
13 * for all supported audio formats.
16 /** TPE1 (id3v2) / ARTIST (vorbis) / ART (aac)/ author(spx) */
24 /** COMM/COMMENT/cmt */
28 /** Audio format dependent information. */
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. */
36 /** Id3 tags, vorbis comments, aac tags. */
39 * The table that specifies the offset of the individual pieces in
40 * the current audio file.
42 uint32_t *chunk_table
;
43 /** Period of time between sending data chunks. */
44 struct timeval chunk_tv
;
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
53 /** The number of channels. */
55 /** Frequency in Hz. */
57 /** Exact meaning depends on audio format. */
61 /** Data about the current audio file, passed from afs to server. */
62 struct audio_file_data
{
63 /** The open file descriptor to the current audio file. */
65 /** Vss needs this for streaming. */
67 /** Size of the largest chunk. */
68 uint32_t max_chunk_size
;
69 /** Needed to get the audio file header. */
70 uint8_t audio_format_id
;
74 * Structure for audio format handling.
76 * There's one such struct for each supported audio format. Initially, only \a
77 * name and \a init are defined. During the startup process, para_server calls
78 * the \a init function of each audio format handler which is expected to fill
79 * in the other part of this struct.
81 struct audio_format_handler
{
82 /** Name of the audio format. */
85 * Pointer to the audio format handler's init function.
87 * Must initialize all function pointers and is assumed to succeed.
89 void (*init
)(struct audio_format_handler
*);
90 /** Typical file endings for files that can be handled by this afh. */
91 const char **suffixes
;
93 * Check if this audio format handler can handle the file.
95 * This is a pointer to a function returning whether a given file is
96 * valid for this audio format. A negative return value indicates that
97 * this audio format handler is unable to decode the given file. On
98 * success, the function must return a positive value and fill in the
99 * given struct afh_info.
101 * \sa struct afh_info
103 int (*get_file_info
)(char *map
, size_t numbytes
, int fd
,
104 struct afh_info
*afi
);
105 /** Optional, used for header-rewriting. See \ref afh_get_header(). */
106 void (*get_header
)(void *map
, size_t mapsize
, char **buf
, size_t *len
);
108 * Write audio file with altered tags, optional.
110 * The output file descriptor has been opened by the caller and must not
111 * be closed in this function.
113 int (*rewrite_tags
)(const char *map
, size_t mapsize
, struct taginfo
*tags
,
114 int output_fd
, const char *filename
);
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 int32_t afh_get_start_chunk(int32_t approx_chunk_num
,
125 const struct afh_info
*afhi
);
126 void afh_get_header(struct afh_info
*afhi
, uint8_t audio_format_id
,
127 void *map
, size_t mapsize
, char **buf
, size_t *len
);
128 void afh_free_header(char *header_buf
, uint8_t audio_format_id
);
129 void clear_afhi(struct afh_info
*afhi
);
130 unsigned afh_get_afhi_txt(int audio_format_num
, struct afh_info
*afhi
, char **result
);
131 int afh_rewrite_tags(int audio_format_id
, void *map
, size_t mapsize
,
132 struct taginfo
*tags
, int output_fd
, const char *filename
);