summaryrefslogtreecommitdiff
path: root/lib/rbcodec/metadata
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2022-03-13 10:55:47 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2022-03-13 10:55:47 -0400
commit77e4dd81f5abedda802b8b6e895849995907b484 (patch)
tree750656ede0dac091aa1512ccd81660ec40ddbb58 /lib/rbcodec/metadata
parenteb86ee296a40249c33d1969087f98108735beaa9 (diff)
downloadrockbox-77e4dd81f5abedda802b8b6e895849995907b484.tar.gz
rockbox-77e4dd81f5abedda802b8b6e895849995907b484.zip
option_string clean-up and consolidate with metadata_common
Change-Id: I2649f6af37bd871fb8f181ae2f716ff0bcf1f65c
Diffstat (limited to 'lib/rbcodec/metadata')
-rw-r--r--lib/rbcodec/metadata/metadata_common.c36
-rw-r--r--lib/rbcodec/metadata/metadata_common.h1
-rw-r--r--lib/rbcodec/metadata/mp4.c13
-rw-r--r--lib/rbcodec/metadata/replaygain.c31
4 files changed, 54 insertions, 27 deletions
diff --git a/lib/rbcodec/metadata/metadata_common.c b/lib/rbcodec/metadata/metadata_common.c
index 3677599c30..2586b2b65e 100644
--- a/lib/rbcodec/metadata/metadata_common.c
+++ b/lib/rbcodec/metadata/metadata_common.c
@@ -252,22 +252,42 @@ bool skip_id3v2(int fd, struct mp3entry *id3)
252 return success; 252 return success;
253} 253}
254 254
255static int get_tag_option(const char *option, const char *const oplist[]) 255#ifndef ROCKBOX /*codecs can be built without rockbox */
256/* returns match index from option list
257 * returns -1 if option was not found
258 * option list is array of char pointers with the final item set to null
259 * ex - const char *option[] = { "op_a", "op_b", "op_c", NULL}
260 */
261int string_option(const char *option, const char *const oplist[], bool ignore_case)
256{ 262{
257 int i; 263 int i;
258 int ifound = -1; 264 int ifound = -1;
259 const char *op; 265 const char *op;
260 for (i=0; (op=oplist[i]) != NULL; i++) 266 if (ignore_case)
261 { 267 {
262 if (strcasecmp(op, option) == 0) 268 for (i=0; (op=oplist[i]) != NULL; i++)
263 { 269 {
264 ifound = i; 270 if (strcasecmp(op, option) == 0)
265 break; 271 {
272 ifound = i;
273 break;
274 }
275 }
276 }
277 else
278 {
279 for (i=0; (op=oplist[i]) != NULL; i++)
280 {
281 if (strcmp(op, option) == 0)
282 {
283 ifound = i;
284 break;
285 }
266 } 286 }
267 } 287 }
268 return ifound; 288 return ifound;
269} 289}
270 290#endif
271/* Parse the tag (the name-value pair) and fill id3 and buffer accordingly. 291/* Parse the tag (the name-value pair) and fill id3 and buffer accordingly.
272 * String values to keep are written to buf. Returns number of bytes written 292 * String values to keep are written to buf. Returns number of bytes written
273 * to buf (including end nil). 293 * to buf (including end nil).
@@ -287,7 +307,7 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3,
287 eMUSICBRAINZ1, eMUSICBRAINZ2 307 eMUSICBRAINZ1, eMUSICBRAINZ2
288 }; 308 };
289 309
290 const char *tagops[] = 310 static const char *tagops[] =
291 { "track", "tracknumber", "discnumber", "disc", 311 { "track", "tracknumber", "discnumber", "disc",
292 "year","date","title", "artist", "album", "genre" 312 "year","date","title", "artist", "album", "genre"
293 "composer","comment","albumartist","album artist", 313 "composer","comment","albumartist","album artist",
@@ -295,7 +315,7 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3,
295 "musicbrainz_trackid", "http://musicbrainz.org", NULL 315 "musicbrainz_trackid", "http://musicbrainz.org", NULL
296 }; 316 };
297 317
298 int item = get_tag_option(name, tagops); 318 int item = string_option(name, tagops, true);
299 319
300 if (((item == eTRACK && (type == TAGTYPE_APE))) 320 if (((item == eTRACK && (type == TAGTYPE_APE)))
301 || (item == eTRACKNUMBER && (type == TAGTYPE_VORBIS))) 321 || (item == eTRACKNUMBER && (type == TAGTYPE_VORBIS)))
diff --git a/lib/rbcodec/metadata/metadata_common.h b/lib/rbcodec/metadata/metadata_common.h
index db91729de4..14115b745a 100644
--- a/lib/rbcodec/metadata/metadata_common.h
+++ b/lib/rbcodec/metadata/metadata_common.h
@@ -38,6 +38,7 @@ bool read_ape_tags(int fd, struct mp3entry* id3);
38long read_vorbis_tags(int fd, struct mp3entry *id3, 38long read_vorbis_tags(int fd, struct mp3entry *id3,
39 long tag_remaining); 39 long tag_remaining);
40 40
41int string_option(const char *option, const char *const oplist[], bool ignore_case);
41bool skip_id3v2(int fd, struct mp3entry *id3); 42bool skip_id3v2(int fd, struct mp3entry *id3);
42long read_string(int fd, char* buf, long buf_size, int eos, long size); 43long read_string(int fd, char* buf, long buf_size, int eos, long size);
43 44
diff --git a/lib/rbcodec/metadata/mp4.c b/lib/rbcodec/metadata/mp4.c
index 41f38480b1..accc5cd662 100644
--- a/lib/rbcodec/metadata/mp4.c
+++ b/lib/rbcodec/metadata/mp4.c
@@ -533,13 +533,18 @@ static bool read_mp4_tags(int fd, struct mp3entry* id3,
533 rd_ret = 0; 533 rd_ret = 0;
534 tag_name[rd_ret] = 0; 534 tag_name[rd_ret] = 0;
535 535
536 static const char *tn_options[] = {"composer", "iTunSMPB",
537 "musicbrainz track id", "album artist", NULL};
536 538
537 if ((strcasecmp(tag_name, "composer") == 0) && !cwrt) 539 int tn_op = string_option(tag_name, tn_options, true);
540
541
542 if (tn_op == 0 && !cwrt) /*composer*/
538 { 543 {
539 read_mp4_tag_string(fd, size, &buffer, &buffer_left, 544 read_mp4_tag_string(fd, size, &buffer, &buffer_left,
540 &id3->composer); 545 &id3->composer);
541 } 546 }
542 else if (strcasecmp(tag_name, "iTunSMPB") == 0) 547 else if (tn_op == 1) /*iTunSMPB*/
543 { 548 {
544 char value[TAG_VALUE_LENGTH]; 549 char value[TAG_VALUE_LENGTH];
545 char* value_p = value; 550 char* value_p = value;
@@ -552,12 +557,12 @@ static bool read_mp4_tags(int fd, struct mp3entry* id3,
552 DEBUGF("AAC: lead_trim %d, tail_trim %d\n", 557 DEBUGF("AAC: lead_trim %d, tail_trim %d\n",
553 id3->lead_trim, id3->tail_trim); 558 id3->lead_trim, id3->tail_trim);
554 } 559 }
555 else if (strcasecmp(tag_name, "musicbrainz track id") == 0) 560 else if (tn_op == 2) /*musicbrainz track id*/
556 { 561 {
557 read_mp4_tag_string(fd, size, &buffer, &buffer_left, 562 read_mp4_tag_string(fd, size, &buffer, &buffer_left,
558 &id3->mb_track_id); 563 &id3->mb_track_id);
559 } 564 }
560 else if ((strcasecmp(tag_name, "album artist") == 0)) 565 else if (tn_op == 3) /*album artist*/
561 { 566 {
562 read_mp4_tag_string(fd, size, &buffer, &buffer_left, 567 read_mp4_tag_string(fd, size, &buffer, &buffer_left,
563 &id3->albumartist); 568 &id3->albumartist);
diff --git a/lib/rbcodec/metadata/replaygain.c b/lib/rbcodec/metadata/replaygain.c
index 7aa77cfedd..eb98bbc342 100644
--- a/lib/rbcodec/metadata/replaygain.c
+++ b/lib/rbcodec/metadata/replaygain.c
@@ -32,6 +32,7 @@
32#include "debug.h" 32#include "debug.h"
33#include "replaygain.h" 33#include "replaygain.h"
34#include "fixedpoint.h" 34#include "fixedpoint.h"
35#include "metadata_common.h"
35 36
36#define FP_BITS (12) 37#define FP_BITS (12)
37#define FP_ONE (1 << FP_BITS) 38#define FP_ONE (1 << FP_BITS)
@@ -167,29 +168,29 @@ long get_replaygain_int(long int_gain)
167void parse_replaygain(const char* key, const char* value, 168void parse_replaygain(const char* key, const char* value,
168 struct mp3entry* entry) 169 struct mp3entry* entry)
169{ 170{
170 if (((strcasecmp(key, "replaygain_track_gain") == 0) || 171 static const char *rg_options[] = {"replaygain_track_gain", "rg_radio",
171 (strcasecmp(key, "rg_radio") == 0)) && 172 "replaygain_album_gain", "rg_audiophile",
172 !entry->track_gain) 173 "replaygain_track_peak", "rg_peak",
173 { 174 "replaygain_album_peak", NULL};
175
176 int rg_op = string_option(key, rg_options, true);
177
178 if ((rg_op == 0 || rg_op == 1) && !entry->track_gain)
179 { /*replaygain_track_gain||rg_radio*/
174 entry->track_level = get_replaygain(value); 180 entry->track_level = get_replaygain(value);
175 entry->track_gain = convert_gain(entry->track_level); 181 entry->track_gain = convert_gain(entry->track_level);
176 } 182 }
177 else if (((strcasecmp(key, "replaygain_album_gain") == 0) || 183 else if ((rg_op == 2 || rg_op == 3) && !entry->album_gain)
178 (strcasecmp(key, "rg_audiophile") == 0)) && 184 { /*replaygain_album_gain||rg_audiophile*/
179 !entry->album_gain)
180 {
181 entry->album_level = get_replaygain(value); 185 entry->album_level = get_replaygain(value);
182 entry->album_gain = convert_gain(entry->album_level); 186 entry->album_gain = convert_gain(entry->album_level);
183 } 187 }
184 else if (((strcasecmp(key, "replaygain_track_peak") == 0) || 188 else if ((rg_op == 4 || rg_op == 5) && !entry->track_peak)
185 (strcasecmp(key, "rg_peak") == 0)) && 189 { /*replaygain_track_peak||rg_peak*/
186 !entry->track_peak)
187 {
188 entry->track_peak = get_replaypeak(value); 190 entry->track_peak = get_replaypeak(value);
189 } 191 }
190 else if ((strcasecmp(key, "replaygain_album_peak") == 0) && 192 else if ((rg_op == 6) && !entry->album_peak)
191 !entry->album_peak) 193 { /*replaygain_album_peak*/
192 {
193 entry->album_peak = get_replaypeak(value); 194 entry->album_peak = get_replaypeak(value);
194 } 195 }
195} 196}