GSoC/Buflib: Enable compaction in buflib.
[kugel-rb.git] / apps / metadata.h
blobe1f30c170df5d25561f6bc0b1f03badf5f23bda9
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Dave Chapman
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef _METADATA_H
23 #define _METADATA_H
25 #include <stdbool.h>
26 #include "config.h"
27 #include "file.h"
30 /* Audio file types. */
31 /* NOTE: The values of the AFMT_* items are used for the %fc tag in the WPS
32 - so new entries MUST be added to the end to maintain compatibility.
34 enum
36 AFMT_UNKNOWN = 0, /* Unknown file format */
38 /* start formats */
39 AFMT_MPA_L1, /* MPEG Audio layer 1 */
40 AFMT_MPA_L2, /* MPEG Audio layer 2 */
41 AFMT_MPA_L3, /* MPEG Audio layer 3 */
43 #if CONFIG_CODEC == SWCODEC
44 AFMT_AIFF, /* Audio Interchange File Format */
45 AFMT_PCM_WAV, /* Uncompressed PCM in a WAV file */
46 AFMT_OGG_VORBIS, /* Ogg Vorbis */
47 AFMT_FLAC, /* FLAC */
48 AFMT_MPC_SV7, /* Musepack SV7 */
49 AFMT_A52, /* A/52 (aka AC3) audio */
50 AFMT_WAVPACK, /* WavPack */
51 AFMT_MP4_ALAC, /* Apple Lossless Audio Codec */
52 AFMT_MP4_AAC, /* Advanced Audio Coding (AAC) in M4A container */
53 AFMT_SHN, /* Shorten */
54 AFMT_SID, /* SID File Format */
55 AFMT_ADX, /* ADX File Format */
56 AFMT_NSF, /* NESM (NES Sound Format) */
57 AFMT_SPEEX, /* Ogg Speex speech */
58 AFMT_SPC, /* SPC700 save state */
59 AFMT_APE, /* Monkey's Audio (APE) */
60 AFMT_WMA, /* WMAV1/V2 in ASF */
61 AFMT_WMAPRO, /* WMA Professional in ASF */
62 AFMT_MOD, /* Amiga MOD File Format */
63 AFMT_SAP, /* Atari 8Bit SAP Format */
64 AFMT_RM_COOK, /* Cook in RM/RA */
65 AFMT_RM_AAC, /* AAC in RM/RA */
66 AFMT_RM_AC3, /* AC3 in RM/RA */
67 AFMT_RM_ATRAC3, /* ATRAC3 in RM/RA */
68 AFMT_CMC, /* Atari 8bit cmc format */
69 AFMT_CM3, /* Atari 8bit cm3 format */
70 AFMT_CMR, /* Atari 8bit cmr format */
71 AFMT_CMS, /* Atari 8bit cms format */
72 AFMT_DMC, /* Atari 8bit dmc format */
73 AFMT_DLT, /* Atari 8bit dlt format */
74 AFMT_MPT, /* Atari 8bit mpt format */
75 AFMT_MPD, /* Atari 8bit mpd format */
76 AFMT_RMT, /* Atari 8bit rmt format */
77 AFMT_TMC, /* Atari 8bit tmc format */
78 AFMT_TM8, /* Atari 8bit tm8 format */
79 AFMT_TM2, /* Atari 8bit tm2 format */
80 AFMT_OMA_ATRAC3, /* Atrac3 in Sony OMA container */
81 AFMT_SMAF, /* SMAF */
82 AFMT_AU, /* Sun Audio file */
83 AFMT_VOX, /* VOX */
84 AFMT_WAVE64, /* Wave64 */
85 AFMT_TTA, /* True Audio */
86 AFMT_WMAVOICE, /* WMA Voice in ASF */
87 AFMT_MPC_SV8, /* Musepack SV8 */
88 AFMT_MP4_AAC_HE, /* Advanced Audio Coding (AAC-HE) in M4A container */
89 AFMT_AY, /* AY (ZX Spectrum, Amstrad CPC Sound Format) */
90 AFMT_GBS, /* GBS (Game Boy Sound Format) */
91 AFMT_HES, /* HES (Hudson Entertainment System Sound Format) */
92 AFMT_SGC, /* SGC (Sega Master System, Game Gear, Coleco Vision Sound Format) */
93 AFMT_VGM, /* VGM (Video Game Music Format) */
94 AFMT_KSS, /* KSS (MSX computer KSS Music File) */
95 #endif
97 /* add new formats at any index above this line to have a sensible order -
98 specified array index inits are used */
99 /* format arrays defined in id3.c */
101 AFMT_NUM_CODECS,
103 #if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING)
104 /* masks to decompose parts */
105 CODEC_AFMT_MASK = 0x0fff,
106 CODEC_TYPE_MASK = 0x7000,
108 /* switch for specifying codec type when requesting a filename */
109 CODEC_TYPE_DECODER = (0 << 12), /* default */
110 CODEC_TYPE_ENCODER = (1 << 12),
111 #endif /* CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) */
114 #if CONFIG_CODEC == SWCODEC
115 #if (CONFIG_PLATFORM & PLATFORM_ANDROID)
116 #define CODEC_EXTENSION "so"
117 #define CODEC_PREFIX "lib"
118 #else
119 #define CODEC_EXTENSION "codec"
120 #define CODEC_PREFIX ""
121 #endif
123 #ifdef HAVE_RECORDING
124 enum rec_format_indexes
126 __REC_FORMAT_START_INDEX = -1,
128 /* start formats */
130 REC_FORMAT_PCM_WAV,
131 REC_FORMAT_AIFF,
132 REC_FORMAT_WAVPACK,
133 REC_FORMAT_MPA_L3,
135 /* add new formats at any index above this line to have a sensible order -
136 specified array index inits are used
137 REC_FORMAT_CFG_NUM_BITS should allocate enough bits to hold the range
138 REC_FORMAT_CFG_VALUE_LIST should be in same order as indexes
141 REC_NUM_FORMATS,
143 REC_FORMAT_DEFAULT = REC_FORMAT_PCM_WAV,
144 REC_FORMAT_CFG_NUM_BITS = 2
147 #define REC_FORMAT_CFG_VAL_LIST "wave,aiff,wvpk,mpa3"
149 /* get REC_FORMAT_* corresponding AFMT_* */
150 extern const int rec_format_afmt[REC_NUM_FORMATS];
151 /* get AFMT_* corresponding REC_FORMAT_* */
152 extern const int afmt_rec_format[AFMT_NUM_CODECS];
154 #define AFMT_ENTRY(label, root_fname, enc_root_fname, func, ext_list) \
155 { label, root_fname, enc_root_fname, func, ext_list }
156 #else /* !HAVE_RECORDING */
157 #define AFMT_ENTRY(label, root_fname, enc_root_fname, func, ext_list) \
158 { label, root_fname, func, ext_list }
159 #endif /* HAVE_RECORDING */
161 #else /* !SWCODEC */
163 #define AFMT_ENTRY(label, root_fname, enc_root_fname, func, ext_list) \
164 { label, func, ext_list }
165 #endif /* CONFIG_CODEC == SWCODEC */
167 /** Database of audio formats **/
168 /* record describing the audio format */
169 struct mp3entry;
170 struct afmt_entry
172 const char *label; /* format label */
173 #if CONFIG_CODEC == SWCODEC
174 const char *codec_root_fn; /* root codec filename (sans _enc and .codec) */
175 #ifdef HAVE_RECORDING
176 const char *codec_enc_root_fn; /* filename of encoder codec */
177 #endif
178 #endif
179 bool (*parse_func)(int fd, struct mp3entry *id3); /* return true on success */
180 const char *ext_list; /* NULL terminated extension
181 list for type with the first as
182 the default for recording */
185 /* database of labels and codecs. add formats per above enum */
186 extern const struct afmt_entry audio_formats[AFMT_NUM_CODECS];
188 #if MEMORYSIZE > 2
189 #define ID3V2_BUF_SIZE 900
190 #define ID3V2_MAX_ITEM_SIZE 240
191 #else
192 #define ID3V2_BUF_SIZE 300
193 #define ID3V2_MAX_ITEM_SIZE 90
194 #endif
196 enum {
197 ID3_VER_1_0 = 1,
198 ID3_VER_1_1,
199 ID3_VER_2_2,
200 ID3_VER_2_3,
201 ID3_VER_2_4
204 #ifdef HAVE_ALBUMART
205 enum mp3_aa_type {
206 AA_TYPE_UNSYNC = -1,
207 AA_TYPE_UNKNOWN,
208 AA_TYPE_BMP,
209 AA_TYPE_PNG,
210 AA_TYPE_JPG,
213 struct mp3_albumart {
214 enum mp3_aa_type type;
215 int size;
216 off_t pos;
218 #endif
220 struct mp3entry {
221 char path[MAX_PATH];
222 char* title;
223 char* artist;
224 char* album;
225 char* genre_string;
226 char* disc_string;
227 char* track_string;
228 char* year_string;
229 char* composer;
230 char* comment;
231 char* albumartist;
232 char* grouping;
233 int discnum;
234 int tracknum;
235 int layer;
236 int year;
237 unsigned char id3version;
238 unsigned int codectype;
239 unsigned int bitrate;
240 unsigned long frequency;
241 unsigned long id3v2len;
242 unsigned long id3v1len;
243 unsigned long first_frame_offset; /* Byte offset to first real MP3 frame.
244 Used for skipping leading garbage to
245 avoid gaps between tracks. */
246 unsigned long filesize; /* without headers; in bytes */
247 unsigned long length; /* song length in ms */
248 unsigned long elapsed; /* ms played */
250 int lead_trim; /* Number of samples to skip at the beginning */
251 int tail_trim; /* Number of samples to remove from the end */
253 /* Added for Vorbis, used by mp4 parser as well. */
254 unsigned long samples; /* number of samples in track */
256 /* MP3 stream specific info */
257 unsigned long frame_count; /* number of frames in the file (if VBR) */
259 /* Used for A52/AC3 */
260 unsigned long bytesperframe; /* number of bytes per frame (if CBR) */
262 /* Xing VBR fields */
263 bool vbr;
264 bool has_toc; /* True if there is a VBR header in the file */
265 unsigned char toc[100]; /* table of contents */
267 /* Added for ATRAC3 */
268 unsigned int channels; /* Number of channels in the stream */
269 unsigned int extradata_size; /* Size (in bytes) of the codec's extradata from the container */
271 /* Added for AAC HE SBR */
272 bool needs_upsampling_correction; /* flag used by aac codec */
274 /* these following two fields are used for local buffering */
275 char id3v2buf[ID3V2_BUF_SIZE];
276 char id3v1buf[4][92];
278 /* resume related */
279 unsigned long offset; /* bytes played */
280 int index; /* playlist index */
282 #ifdef HAVE_TAGCACHE
283 unsigned char autoresumable; /* caches result of autoresumable() */
285 /* runtime database fields */
286 long tagcache_idx; /* 0=invalid, otherwise idx+1 */
287 int rating;
288 int score;
289 long playcount;
290 long lastplayed;
291 long playtime;
292 #endif
294 /* replaygain support */
295 #if CONFIG_CODEC == SWCODEC
296 long track_level; /* holds the level in dB * (1<<FP_BITS) */
297 long album_level;
298 long track_gain; /* s19.12 signed fixed point. 0 for no gain. */
299 long album_gain;
300 long track_peak; /* s19.12 signed fixed point. 0 for no peak. */
301 long album_peak;
302 #endif
304 #ifdef HAVE_ALBUMART
305 bool embed_albumart;
306 struct mp3_albumart albumart;
307 #endif
309 /* Cuesheet support */
310 struct cuesheet *cuesheet;
312 /* Musicbrainz Track ID */
313 char* mb_track_id;
316 unsigned int probe_file_format(const char *filename);
317 bool get_metadata(struct mp3entry* id3, int fd, const char* trackname);
318 bool mp3info(struct mp3entry *entry, const char *filename);
319 void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig);
320 void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig);
321 void wipe_mp3entry(struct mp3entry *id3);
323 #if CONFIG_CODEC == SWCODEC
324 void fill_metadata_from_path(struct mp3entry *id3, const char *trackname);
325 int get_audio_base_codec_type(int type);
326 void strip_tags(int handle_id);
327 enum data_type get_audio_base_data_type(int afmt);
328 bool format_buffers_with_offset(int afmt);
329 #endif
331 #ifdef HAVE_TAGCACHE
332 bool autoresumable(struct mp3entry *id3);
333 #endif
335 #endif