Rating support for database and WPS (based on FS# 6301). A value between 0 and 10...
[Rockbox.git] / firmware / export / id3.h
blob5cc600facee7221cb8c0059a9dc8b0e4dd20d276
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Daniel Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #ifndef ID3_H
20 #define ID3_H
22 #include <stdbool.h>
23 #include "config.h"
24 #include "file.h"
26 /* Audio file types. */
27 /* NOTE: The values of the AFMT_* items are used for the %fc tag in the WPS
28 - so new entries MUST be added to the end to maintain compatibility.
30 enum
32 AFMT_UNKNOWN = 0, /* Unknown file format */
34 /* start formats */
36 AFMT_MPA_L1, /* MPEG Audio layer 1 */
37 AFMT_MPA_L2, /* MPEG Audio layer 2 */
38 AFMT_MPA_L3, /* MPEG Audio layer 3 */
40 #if CONFIG_CODEC == SWCODEC
41 AFMT_AIFF, /* Audio Interchange File Format */
42 AFMT_PCM_WAV, /* Uncompressed PCM in a WAV file */
43 AFMT_OGG_VORBIS, /* Ogg Vorbis */
44 AFMT_FLAC, /* FLAC */
45 AFMT_MPC, /* Musepack */
46 AFMT_A52, /* A/52 (aka AC3) audio */
47 AFMT_WAVPACK, /* WavPack */
48 AFMT_ALAC, /* Apple Lossless Audio Codec */
49 AFMT_AAC, /* Advanced Audio Coding (AAC) in M4A container */
50 AFMT_SHN, /* Shorten */
51 AFMT_SID, /* SID File Format */
52 AFMT_ADX, /* ADX File Format */
53 AFMT_NSF, /* NESM (NES Sound Format) */
54 AFMT_SPEEX, /* Ogg Speex speech */
55 AFMT_SPC, /* SPC700 save state */
56 #endif
58 /* add new formats at any index above this line to have a sensible order -
59 specified array index inits are used */
60 /* format arrays defined in id3.c */
62 AFMT_NUM_CODECS,
64 #if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING)
65 /* masks to decompose parts */
66 CODEC_AFMT_MASK = 0x0fff,
67 CODEC_TYPE_MASK = 0x7000,
69 /* switch for specifying codec type when requesting a filename */
70 CODEC_TYPE_DECODER = (0 << 12), /* default */
71 CODEC_TYPE_ENCODER = (1 << 12),
72 #endif /* CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) */
75 #if CONFIG_CODEC == SWCODEC
76 #define CODEC_EXTENSION "codec"
78 #ifdef HAVE_RECORDING
79 #define ENCODER_SUFFIX "_enc"
80 enum rec_format_indexes
82 __REC_FORMAT_START_INDEX = -1,
84 /* start formats */
86 REC_FORMAT_PCM_WAV,
87 REC_FORMAT_AIFF,
88 REC_FORMAT_WAVPACK,
89 REC_FORMAT_MPA_L3,
91 /* add new formats at any index above this line to have a sensible order -
92 specified array index inits are used
93 REC_FORMAT_CFG_NUM_BITS should allocate enough bits to hold the range
94 REC_FORMAT_CFG_VALUE_LIST should be in same order as indexes
97 REC_NUM_FORMATS,
99 REC_FORMAT_DEFAULT = REC_FORMAT_PCM_WAV,
100 REC_FORMAT_CFG_NUM_BITS = 2
103 #define REC_FORMAT_CFG_VAL_LIST "wave,aiff,wvpk,mpa3"
105 /* get REC_FORMAT_* corresponding AFMT_* */
106 extern const int rec_format_afmt[REC_NUM_FORMATS];
107 /* get AFMT_* corresponding REC_FORMAT_* */
108 extern const int afmt_rec_format[AFMT_NUM_CODECS];
110 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
111 { label, root_fname, enc_root_fname, ext_list }
112 #else /* !HAVE_RECORDING */
113 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
114 { label, root_fname, ext_list }
115 #endif /* HAVE_RECORDING */
116 #else /* !SWCODEC */
118 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
119 { label, ext_list }
120 #endif /* CONFIG_CODEC == SWCODEC */
122 /* record describing the audio format */
123 struct afmt_entry
125 char label[8]; /* format label */
126 #if CONFIG_CODEC == SWCODEC
127 char *codec_root_fn; /* root codec filename (sans _enc and .codec) */
128 #ifdef HAVE_RECORDING
129 char *codec_enc_root_fn; /* filename of encoder codec */
130 #endif
131 #endif
132 char *ext_list; /* double NULL terminated extension
133 list for type with the first as
134 the default for recording */
137 /* database of labels and codecs. add formats per above enum */
138 extern const struct afmt_entry audio_formats[AFMT_NUM_CODECS];
140 struct mp3entry {
141 char path[MAX_PATH];
142 char* title;
143 char* artist;
144 char* album;
145 char* genre_string;
146 char* track_string;
147 char* year_string;
148 char* composer;
149 char* comment;
150 char* albumartist;
151 int tracknum;
152 int version;
153 int layer;
154 int year;
155 unsigned char id3version;
156 unsigned int codectype;
157 unsigned int bitrate;
158 unsigned long frequency;
159 unsigned long id3v2len;
160 unsigned long id3v1len;
161 unsigned long first_frame_offset; /* Byte offset to first real MP3 frame.
162 Used for skipping leading garbage to
163 avoid gaps between tracks. */
164 unsigned long vbr_header_pos;
165 unsigned long filesize; /* without headers; in bytes */
166 unsigned long length; /* song length in ms */
167 unsigned long elapsed; /* ms played */
169 int lead_trim; /* Number of samples to skip at the beginning */
170 int tail_trim; /* Number of samples to remove from the end */
172 /* Added for Vorbis */
173 unsigned long samples; /* number of samples in track */
175 /* MP3 stream specific info */
176 unsigned long frame_count; /* number of frames in the file (if VBR) */
178 /* Used for A52/AC3 */
179 unsigned long bytesperframe; /* number of bytes per frame (if CBR) */
181 /* Xing VBR fields */
182 bool vbr;
183 bool has_toc; /* True if there is a VBR header in the file */
184 unsigned char toc[100]; /* table of contents */
186 /* these following two fields are used for local buffering */
187 char id3v2buf[300];
188 char id3v1buf[4][92];
190 /* resume related */
191 unsigned long offset; /* bytes played */
192 int index; /* playlist index */
194 /* FileEntry fields */
195 long fileentryoffset;
196 long filehash;
197 long songentryoffset;
198 long rundbentryoffset;
200 /* runtime database fields */
201 short rating;
202 short score;
203 long playcount;
204 long lastplayed;
206 /* replaygain support */
208 #if CONFIG_CODEC == SWCODEC
209 char* track_gain_string;
210 char* album_gain_string;
211 long track_gain; /* 7.24 signed fixed point. 0 for no gain. */
212 long album_gain;
213 long track_peak; /* 7.24 signed fixed point. 0 for no peak. */
214 long album_peak;
215 #endif
217 /* Cuesheet support */
218 int cuesheet_type; /* 0: none, 1: external, 2: embedded */
221 enum {
222 ID3_VER_1_0 = 1,
223 ID3_VER_1_1,
224 ID3_VER_2_2,
225 ID3_VER_2_3,
226 ID3_VER_2_4
229 bool get_mp3_metadata(int fd, struct mp3entry *entry, const char *filename, bool v1first);
230 bool mp3info(struct mp3entry *entry, const char *filename, bool v1first);
231 char* id3_get_num_genre(const unsigned int genre_num);
232 char* id3_get_codec(const struct mp3entry* id3);
233 int getid3v2len(int fd);
234 void adjust_mp3entry(struct mp3entry *entry, void *dest, void *orig);
235 void copy_mp3entry(struct mp3entry *dest, struct mp3entry *orig);
237 #endif