summaryrefslogtreecommitdiff
path: root/lib/rbcodec/metadata/metadata.h
diff options
context:
space:
mode:
authorSean Bartell <wingedtachikoma@gmail.com>2011-06-24 01:25:21 -0400
committerNils Wallménius <nils@rockbox.org>2012-03-18 12:00:39 +0100
commitb5716df4cb2837bbbc42195cf1aefcf03e21d6a6 (patch)
tree130cd712e2e00893b6df9959a375a8d9523a1aca /lib/rbcodec/metadata/metadata.h
parent24bd9d5393dbe39a5c6194877bc00ede669b1d5d (diff)
downloadrockbox-b5716df4cb2837bbbc42195cf1aefcf03e21d6a6.tar.gz
rockbox-b5716df4cb2837bbbc42195cf1aefcf03e21d6a6.zip
Build librbcodec with DSP and metadata.
All associated files are moved to /lib/rbcodec. Change-Id: I572ddd2b8a996aae1e98c081d06b1ed356dce222
Diffstat (limited to 'lib/rbcodec/metadata/metadata.h')
-rw-r--r--lib/rbcodec/metadata/metadata.h353
1 files changed, 353 insertions, 0 deletions
diff --git a/lib/rbcodec/metadata/metadata.h b/lib/rbcodec/metadata/metadata.h
new file mode 100644
index 0000000000..55e4d76f25
--- /dev/null
+++ b/lib/rbcodec/metadata/metadata.h
@@ -0,0 +1,353 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 Dave Chapman
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef _METADATA_H
23#define _METADATA_H
24
25#include <stdbool.h>
26#include "config.h"
27#include "file.h"
28
29
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.
33 */
34enum
35{
36 AFMT_UNKNOWN = 0, /* Unknown file format */
37
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 */
42
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
96
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 */
100
101 AFMT_NUM_CODECS,
102
103#if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING)
104 /* masks to decompose parts */
105 CODEC_AFMT_MASK = 0x0fff,
106 CODEC_TYPE_MASK = 0x7000,
107
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) */
112};
113
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
122
123#ifdef HAVE_RECORDING
124enum rec_format_indexes
125{
126 __REC_FORMAT_START_INDEX = -1,
127
128 /* start formats */
129
130 REC_FORMAT_PCM_WAV,
131 REC_FORMAT_AIFF,
132 REC_FORMAT_WAVPACK,
133 REC_FORMAT_MPA_L3,
134
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
139 */
140
141 REC_NUM_FORMATS,
142
143 REC_FORMAT_DEFAULT = REC_FORMAT_PCM_WAV,
144 REC_FORMAT_CFG_NUM_BITS = 2
145};
146
147#define REC_FORMAT_CFG_VAL_LIST "wave,aiff,wvpk,mpa3"
148
149/* get REC_FORMAT_* corresponding AFMT_* */
150extern const int rec_format_afmt[REC_NUM_FORMATS];
151/* get AFMT_* corresponding REC_FORMAT_* */
152/* unused: extern const int afmt_rec_format[AFMT_NUM_CODECS]; */
153
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 */
160
161#else /* !SWCODEC */
162
163#define AFMT_ENTRY(label, root_fname, enc_root_fname, func, ext_list) \
164 { label, func, ext_list }
165#endif /* CONFIG_CODEC == SWCODEC */
166
167/** Database of audio formats **/
168/* record describing the audio format */
169struct mp3entry;
170struct afmt_entry
171{
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 */
183};
184
185/* database of labels and codecs. add formats per above enum */
186extern const struct afmt_entry audio_formats[AFMT_NUM_CODECS];
187
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
195
196enum {
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
202};
203
204#ifdef HAVE_ALBUMART
205enum mp3_aa_type {
206 AA_TYPE_UNSYNC = -1,
207 AA_TYPE_UNKNOWN,
208 AA_TYPE_BMP,
209 AA_TYPE_PNG,
210 AA_TYPE_JPG,
211};
212
213struct mp3_albumart {
214 enum mp3_aa_type type;
215 int size;
216 off_t pos;
217};
218#endif
219
220enum character_encoding {
221 CHAR_ENC_ISO_8859_1 = 1,
222 CHAR_ENC_UTF_8,
223 CHAR_ENC_UTF_16_LE,
224 CHAR_ENC_UTF_16_BE,
225};
226
227/* cache embedded cuesheet details */
228struct embedded_cuesheet {
229 int size;
230 off_t pos;
231 enum character_encoding encoding;
232};
233
234struct mp3entry {
235 char path[MAX_PATH];
236 char* title;
237 char* artist;
238 char* album;
239 char* genre_string;
240 char* disc_string;
241 char* track_string;
242 char* year_string;
243 char* composer;
244 char* comment;
245 char* albumartist;
246 char* grouping;
247 int discnum;
248 int tracknum;
249 int layer;
250 int year;
251 unsigned char id3version;
252 unsigned int codectype;
253 unsigned int bitrate;
254 unsigned long frequency;
255 unsigned long id3v2len;
256 unsigned long id3v1len;
257 unsigned long first_frame_offset; /* Byte offset to first real MP3 frame.
258 Used for skipping leading garbage to
259 avoid gaps between tracks. */
260 unsigned long filesize; /* without headers; in bytes */
261 unsigned long length; /* song length in ms */
262 unsigned long elapsed; /* ms played */
263
264 int lead_trim; /* Number of samples to skip at the beginning */
265 int tail_trim; /* Number of samples to remove from the end */
266
267 /* Added for Vorbis, used by mp4 parser as well. */
268 unsigned long samples; /* number of samples in track */
269
270 /* MP3 stream specific info */
271 unsigned long frame_count; /* number of frames in the file (if VBR) */
272
273 /* Used for A52/AC3 */
274 unsigned long bytesperframe; /* number of bytes per frame (if CBR) */
275
276 /* Xing VBR fields */
277 bool vbr;
278 bool has_toc; /* True if there is a VBR header in the file */
279 unsigned char toc[100]; /* table of contents */
280
281 /* Added for ATRAC3 */
282 unsigned int channels; /* Number of channels in the stream */
283 unsigned int extradata_size; /* Size (in bytes) of the codec's extradata from the container */
284
285 /* Added for AAC HE SBR */
286 bool needs_upsampling_correction; /* flag used by aac codec */
287
288 /* these following two fields are used for local buffering */
289 char id3v2buf[ID3V2_BUF_SIZE];
290 char id3v1buf[4][92];
291
292 /* resume related */
293 unsigned long offset; /* bytes played */
294 int index; /* playlist index */
295
296#ifdef HAVE_TAGCACHE
297 unsigned char autoresumable; /* caches result of autoresumable() */
298
299 /* runtime database fields */
300 long tagcache_idx; /* 0=invalid, otherwise idx+1 */
301 int rating;
302 int score;
303 long playcount;
304 long lastplayed;
305 long playtime;
306#endif
307
308 /* replaygain support */
309#if CONFIG_CODEC == SWCODEC
310 long track_level; /* holds the level in dB * (1<<FP_BITS) */
311 long album_level;
312 long track_gain; /* s19.12 signed fixed point. 0 for no gain. */
313 long album_gain;
314 long track_peak; /* s19.12 signed fixed point. 0 for no peak. */
315 long album_peak;
316#endif
317
318#ifdef HAVE_ALBUMART
319 bool has_embedded_albumart;
320 struct mp3_albumart albumart;
321#endif
322
323 /* Cuesheet support */
324 bool has_embedded_cuesheet;
325 struct embedded_cuesheet embedded_cuesheet;
326 struct cuesheet *cuesheet;
327
328 /* Musicbrainz Track ID */
329 char* mb_track_id;
330};
331
332unsigned int probe_file_format(const char *filename);
333bool get_metadata(struct mp3entry* id3, int fd, const char* trackname);
334bool mp3info(struct mp3entry *entry, const char *filename);
335void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig);
336void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig);
337void wipe_mp3entry(struct mp3entry *id3);
338
339#if CONFIG_CODEC == SWCODEC
340void fill_metadata_from_path(struct mp3entry *id3, const char *trackname);
341int get_audio_base_codec_type(int type);
342void strip_tags(int handle_id);
343enum data_type get_audio_base_data_type(int afmt);
344bool format_buffers_with_offset(int afmt);
345#endif
346
347#ifdef HAVE_TAGCACHE
348bool autoresumable(struct mp3entry *id3);
349#endif
350
351#endif
352
353