Fix c&p error from r25853 that should've fixed some snprintf warnings.
[kugel-rb.git] / apps / metadata.h
blob0d0f6c5aacb88d215afdc41756d8055260102d38
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 "file.h"
27 #include "config.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, /* Musepack */
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_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 #endif
87 /* add new formats at any index above this line to have a sensible order -
88 specified array index inits are used */
89 /* format arrays defined in id3.c */
91 AFMT_NUM_CODECS,
93 #if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING)
94 /* masks to decompose parts */
95 CODEC_AFMT_MASK = 0x0fff,
96 CODEC_TYPE_MASK = 0x7000,
98 /* switch for specifying codec type when requesting a filename */
99 CODEC_TYPE_DECODER = (0 << 12), /* default */
100 CODEC_TYPE_ENCODER = (1 << 12),
101 #endif /* CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) */
104 #if CONFIG_CODEC == SWCODEC
105 #define CODEC_EXTENSION "codec"
107 #ifdef HAVE_RECORDING
108 #define ENCODER_SUFFIX "_enc"
109 enum rec_format_indexes
111 __REC_FORMAT_START_INDEX = -1,
113 /* start formats */
115 REC_FORMAT_PCM_WAV,
116 REC_FORMAT_AIFF,
117 REC_FORMAT_WAVPACK,
118 REC_FORMAT_MPA_L3,
120 /* add new formats at any index above this line to have a sensible order -
121 specified array index inits are used
122 REC_FORMAT_CFG_NUM_BITS should allocate enough bits to hold the range
123 REC_FORMAT_CFG_VALUE_LIST should be in same order as indexes
126 REC_NUM_FORMATS,
128 REC_FORMAT_DEFAULT = REC_FORMAT_PCM_WAV,
129 REC_FORMAT_CFG_NUM_BITS = 2
132 #define REC_FORMAT_CFG_VAL_LIST "wave,aiff,wvpk,mpa3"
134 /* get REC_FORMAT_* corresponding AFMT_* */
135 extern const int rec_format_afmt[REC_NUM_FORMATS];
136 /* get AFMT_* corresponding REC_FORMAT_* */
137 extern const int afmt_rec_format[AFMT_NUM_CODECS];
139 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
140 { label, root_fname, enc_root_fname, ext_list }
141 #else /* !HAVE_RECORDING */
142 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
143 { label, root_fname, ext_list }
144 #endif /* HAVE_RECORDING */
146 #else /* !SWCODEC */
148 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
149 { label, ext_list }
150 #endif /* CONFIG_CODEC == SWCODEC */
152 /** Database of audio formats **/
153 /* record describing the audio format */
154 struct afmt_entry
156 const char *label; /* format label */
157 #if CONFIG_CODEC == SWCODEC
158 const char *codec_root_fn; /* root codec filename (sans _enc and .codec) */
159 #ifdef HAVE_RECORDING
160 const char *codec_enc_root_fn; /* filename of encoder codec */
161 #endif
162 #endif
163 const char *ext_list; /* double NULL terminated extension
164 list for type with the first as
165 the default for recording */
168 /* database of labels and codecs. add formats per above enum */
169 extern const struct afmt_entry audio_formats[AFMT_NUM_CODECS];
171 #if MEMORYSIZE > 2
172 #define ID3V2_BUF_SIZE 900
173 #else
174 #define ID3V2_BUF_SIZE 300
175 #endif
177 enum {
178 ID3_VER_1_0 = 1,
179 ID3_VER_1_1,
180 ID3_VER_2_2,
181 ID3_VER_2_3,
182 ID3_VER_2_4
185 struct mp3entry {
186 char path[MAX_PATH];
187 char* title;
188 char* artist;
189 char* album;
190 char* genre_string;
191 char* disc_string;
192 char* track_string;
193 char* year_string;
194 char* composer;
195 char* comment;
196 char* albumartist;
197 char* grouping;
198 int discnum;
199 int tracknum;
200 int version;
201 int layer;
202 int year;
203 unsigned char id3version;
204 unsigned int codectype;
205 unsigned int bitrate;
206 unsigned long frequency;
207 unsigned long id3v2len;
208 unsigned long id3v1len;
209 unsigned long first_frame_offset; /* Byte offset to first real MP3 frame.
210 Used for skipping leading garbage to
211 avoid gaps between tracks. */
212 unsigned long vbr_header_pos;
213 unsigned long filesize; /* without headers; in bytes */
214 unsigned long length; /* song length in ms */
215 unsigned long elapsed; /* ms played */
217 int lead_trim; /* Number of samples to skip at the beginning */
218 int tail_trim; /* Number of samples to remove from the end */
220 /* Added for Vorbis */
221 unsigned long samples; /* number of samples in track */
223 /* MP3 stream specific info */
224 unsigned long frame_count; /* number of frames in the file (if VBR) */
226 /* Used for A52/AC3 */
227 unsigned long bytesperframe; /* number of bytes per frame (if CBR) */
229 /* Xing VBR fields */
230 bool vbr;
231 bool has_toc; /* True if there is a VBR header in the file */
232 unsigned char toc[100]; /* table of contents */
234 /* Added for ATRAC3 */
235 unsigned int channels; /* Number of channels in the stream */
236 unsigned int extradata_size; /* Size (in bytes) of the codec's extradata from the container */
237 /* these following two fields are used for local buffering */
238 char id3v2buf[ID3V2_BUF_SIZE];
239 char id3v1buf[4][92];
241 /* resume related */
242 unsigned long offset; /* bytes played */
243 int index; /* playlist index */
245 /* runtime database fields */
246 long tagcache_idx; /* 0=invalid, otherwise idx+1 */
247 int rating;
248 int score;
249 long playcount;
250 long lastplayed;
251 long playtime;
253 /* replaygain support */
255 #if CONFIG_CODEC == SWCODEC
256 char* track_gain_string;
257 char* album_gain_string;
258 long track_gain; /* 7.24 signed fixed point. 0 for no gain. */
259 long album_gain;
260 long track_peak; /* 7.24 signed fixed point. 0 for no peak. */
261 long album_peak;
262 #endif
264 /* Cuesheet support */
265 struct cuesheet *cuesheet;
267 /* Musicbrainz Track ID */
268 char* mb_track_id;
271 unsigned int probe_file_format(const char *filename);
272 bool get_metadata(struct mp3entry* id3, int fd, const char* trackname);
273 bool mp3info(struct mp3entry *entry, const char *filename);
274 void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig);
275 void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig);
276 #if CONFIG_CODEC == SWCODEC
277 void strip_tags(int handle_id);
278 #endif
280 #endif