FS#11968 by Peter Lecky - Slovak language update
[maemo-rb.git] / apps / metadata.h
blob5662c2e84034f1ab40dc870bfd1657a3f1355d21
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 */
40 AFMT_MPA_L1, /* MPEG Audio layer 1 */
41 AFMT_MPA_L2, /* MPEG Audio layer 2 */
42 AFMT_MPA_L3, /* MPEG Audio layer 3 */
44 #if CONFIG_CODEC == SWCODEC
45 AFMT_AIFF, /* Audio Interchange File Format */
46 AFMT_PCM_WAV, /* Uncompressed PCM in a WAV file */
47 AFMT_OGG_VORBIS, /* Ogg Vorbis */
48 AFMT_FLAC, /* FLAC */
49 AFMT_MPC_SV7, /* Musepack SV7 */
50 AFMT_A52, /* A/52 (aka AC3) audio */
51 AFMT_WAVPACK, /* WavPack */
52 AFMT_MP4_ALAC, /* Apple Lossless Audio Codec */
53 AFMT_MP4_AAC, /* Advanced Audio Coding (AAC) in M4A container */
54 AFMT_SHN, /* Shorten */
55 AFMT_SID, /* SID File Format */
56 AFMT_ADX, /* ADX File Format */
57 AFMT_NSF, /* NESM (NES Sound Format) */
58 AFMT_SPEEX, /* Ogg Speex speech */
59 AFMT_SPC, /* SPC700 save state */
60 AFMT_APE, /* Monkey's Audio (APE) */
61 AFMT_WMA, /* WMAV1/V2 in ASF */
62 AFMT_WMAPRO, /* WMA Professional in ASF */
63 AFMT_MOD, /* Amiga MOD File Format */
64 AFMT_SAP, /* Atari 8Bit SAP Format */
65 AFMT_RM_COOK, /* Cook in RM/RA */
66 AFMT_RM_AAC, /* AAC in RM/RA */
67 AFMT_RM_AC3, /* AC3 in RM/RA */
68 AFMT_RM_ATRAC3, /* ATRAC3 in RM/RA */
69 AFMT_CMC, /* Atari 8bit cmc format */
70 AFMT_CM3, /* Atari 8bit cm3 format */
71 AFMT_CMR, /* Atari 8bit cmr format */
72 AFMT_CMS, /* Atari 8bit cms format */
73 AFMT_DMC, /* Atari 8bit dmc format */
74 AFMT_DLT, /* Atari 8bit dlt format */
75 AFMT_MPT, /* Atari 8bit mpt format */
76 AFMT_MPD, /* Atari 8bit mpd format */
77 AFMT_RMT, /* Atari 8bit rmt format */
78 AFMT_TMC, /* Atari 8bit tmc format */
79 AFMT_TM8, /* Atari 8bit tm8 format */
80 AFMT_TM2, /* Atari 8bit tm2 format */
81 AFMT_OMA_ATRAC3, /* Atrac3 in Sony OMA container */
82 AFMT_SMAF, /* SMAF */
83 AFMT_AU, /* Sun Audio file */
84 AFMT_VOX, /* VOX */
85 AFMT_WAVE64, /* Wave64 */
86 AFMT_TTA, /* True Audio */
87 AFMT_WMAVOICE, /* WMA Voice in ASF */
88 AFMT_MPC_SV8, /* Musepack SV8 */
89 AFMT_MP4_AAC_HE, /* Advanced Audio Coding (AAC-HE) in M4A container */
90 #endif
92 /* add new formats at any index above this line to have a sensible order -
93 specified array index inits are used */
94 /* format arrays defined in id3.c */
96 AFMT_NUM_CODECS,
98 #if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING)
99 /* masks to decompose parts */
100 CODEC_AFMT_MASK = 0x0fff,
101 CODEC_TYPE_MASK = 0x7000,
103 /* switch for specifying codec type when requesting a filename */
104 CODEC_TYPE_DECODER = (0 << 12), /* default */
105 CODEC_TYPE_ENCODER = (1 << 12),
106 #endif /* CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) */
109 #if CONFIG_CODEC == SWCODEC
110 #define CODEC_EXTENSION "codec"
112 #ifdef HAVE_RECORDING
113 enum rec_format_indexes
115 __REC_FORMAT_START_INDEX = -1,
117 /* start formats */
119 REC_FORMAT_PCM_WAV,
120 REC_FORMAT_AIFF,
121 REC_FORMAT_WAVPACK,
122 REC_FORMAT_MPA_L3,
124 /* add new formats at any index above this line to have a sensible order -
125 specified array index inits are used
126 REC_FORMAT_CFG_NUM_BITS should allocate enough bits to hold the range
127 REC_FORMAT_CFG_VALUE_LIST should be in same order as indexes
130 REC_NUM_FORMATS,
132 REC_FORMAT_DEFAULT = REC_FORMAT_PCM_WAV,
133 REC_FORMAT_CFG_NUM_BITS = 2
136 #define REC_FORMAT_CFG_VAL_LIST "wave,aiff,wvpk,mpa3"
138 /* get REC_FORMAT_* corresponding AFMT_* */
139 extern const int rec_format_afmt[REC_NUM_FORMATS];
140 /* get AFMT_* corresponding REC_FORMAT_* */
141 extern const int afmt_rec_format[AFMT_NUM_CODECS];
143 #define AFMT_ENTRY(label, root_fname, enc_root_fname, func, ext_list) \
144 { label, root_fname, enc_root_fname, func, ext_list }
145 #else /* !HAVE_RECORDING */
146 #define AFMT_ENTRY(label, root_fname, enc_root_fname, func, ext_list) \
147 { label, root_fname, func, ext_list }
148 #endif /* HAVE_RECORDING */
150 #else /* !SWCODEC */
152 #define AFMT_ENTRY(label, root_fname, enc_root_fname, func, ext_list) \
153 { label, func, ext_list }
154 #endif /* CONFIG_CODEC == SWCODEC */
156 /** Database of audio formats **/
157 /* record describing the audio format */
158 struct mp3entry;
159 struct afmt_entry
161 const char *label; /* format label */
162 #if CONFIG_CODEC == SWCODEC
163 const char *codec_root_fn; /* root codec filename (sans _enc and .codec) */
164 #ifdef HAVE_RECORDING
165 const char *codec_enc_root_fn; /* filename of encoder codec */
166 #endif
167 #endif
168 bool (*parse_func)(int fd, struct mp3entry *id3); /* return true on success */
169 const char *ext_list; /* NULL terminated extension
170 list for type with the first as
171 the default for recording */
174 /* database of labels and codecs. add formats per above enum */
175 extern const struct afmt_entry audio_formats[AFMT_NUM_CODECS];
177 #if MEMORYSIZE > 2
178 #define ID3V2_BUF_SIZE 900
179 #define ID3V2_MAX_ITEM_SIZE 120
180 #else
181 #define ID3V2_BUF_SIZE 300
182 #define ID3V2_MAX_ITEM_SIZE 60
183 #endif
185 enum {
186 ID3_VER_1_0 = 1,
187 ID3_VER_1_1,
188 ID3_VER_2_2,
189 ID3_VER_2_3,
190 ID3_VER_2_4
193 #ifdef HAVE_ALBUMART
194 enum mp3_aa_type {
195 AA_TYPE_UNSYNC = -1,
196 AA_TYPE_UNKNOWN,
197 AA_TYPE_BMP,
198 AA_TYPE_PNG,
199 AA_TYPE_JPG,
202 struct mp3_albumart {
203 enum mp3_aa_type type;
204 int size;
205 off_t pos;
207 #endif
209 struct mp3entry {
210 char path[MAX_PATH];
211 char* title;
212 char* artist;
213 char* album;
214 char* genre_string;
215 char* disc_string;
216 char* track_string;
217 char* year_string;
218 char* composer;
219 char* comment;
220 char* albumartist;
221 char* grouping;
222 int discnum;
223 int tracknum;
224 int version;
225 int layer;
226 int year;
227 unsigned char id3version;
228 unsigned int codectype;
229 unsigned int bitrate;
230 unsigned long frequency;
231 unsigned long id3v2len;
232 unsigned long id3v1len;
233 unsigned long first_frame_offset; /* Byte offset to first real MP3 frame.
234 Used for skipping leading garbage to
235 avoid gaps between tracks. */
236 unsigned long vbr_header_pos;
237 unsigned long filesize; /* without headers; in bytes */
238 unsigned long length; /* song length in ms */
239 unsigned long elapsed; /* ms played */
241 int lead_trim; /* Number of samples to skip at the beginning */
242 int tail_trim; /* Number of samples to remove from the end */
244 /* Added for Vorbis */
245 unsigned long samples; /* number of samples in track */
247 /* MP3 stream specific info */
248 unsigned long frame_count; /* number of frames in the file (if VBR) */
250 /* Used for A52/AC3 */
251 unsigned long bytesperframe; /* number of bytes per frame (if CBR) */
253 /* Xing VBR fields */
254 bool vbr;
255 bool has_toc; /* True if there is a VBR header in the file */
256 unsigned char toc[100]; /* table of contents */
258 /* Added for ATRAC3 */
259 unsigned int channels; /* Number of channels in the stream */
260 unsigned int extradata_size; /* Size (in bytes) of the codec's extradata from the container */
262 /* Added for AAC HE SBR */
263 bool needs_upsampling_correction; /* flag used by aac codec */
265 /* these following two fields are used for local buffering */
266 char id3v2buf[ID3V2_BUF_SIZE];
267 char id3v1buf[4][92];
269 /* resume related */
270 unsigned long offset; /* bytes played */
271 int index; /* playlist index */
273 #ifdef HAVE_TAGCACHE
274 unsigned char autoresumable; /* caches result of autoresumable() */
276 /* runtime database fields */
277 long tagcache_idx; /* 0=invalid, otherwise idx+1 */
278 int rating;
279 int score;
280 long playcount;
281 long lastplayed;
282 long playtime;
283 #endif
285 /* replaygain support */
286 #if CONFIG_CODEC == SWCODEC
287 long track_gain; /* s19.12 signed fixed point. 0 for no gain. */
288 long album_gain;
289 long track_peak; /* s19.12 signed fixed point. 0 for no peak. */
290 long album_peak;
291 #endif
293 #ifdef HAVE_ALBUMART
294 bool embed_albumart;
295 struct mp3_albumart albumart;
296 #endif
298 /* Cuesheet support */
299 struct cuesheet *cuesheet;
301 /* Musicbrainz Track ID */
302 char* mb_track_id;
305 unsigned int probe_file_format(const char *filename);
306 bool get_metadata(struct mp3entry* id3, int fd, const char* trackname);
307 bool mp3info(struct mp3entry *entry, const char *filename);
308 void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig);
309 void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig);
311 #if CONFIG_CODEC == SWCODEC
312 void strip_tags(int handle_id);
313 #endif
315 #ifdef HAVE_TAGCACHE
316 bool autoresumable(struct mp3entry *id3);
317 #endif
319 #endif