Skip to content

Commit 7306a38

Browse files
committed
Move COM tag parsing to constructor
Change-Id: Icfcf05655ca98ccccad4f94834770c2f4098a764
1 parent 2ed7770 commit 7306a38

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

media/libstagefright/MP3Extractor.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,37 @@ MP3Extractor::MP3Extractor(
348348
}
349349

350350
mInitCheck = OK;
351+
352+
// get iTunes-style gapless info if present
353+
ID3 id3(mDataSource);
354+
if (id3.isValid()) {
355+
ID3::Iterator *com = new ID3::Iterator(id3, "COM");
356+
if (com->done()) {
357+
delete com;
358+
com = new ID3::Iterator(id3, "COMM");
359+
}
360+
while(!com->done()) {
361+
String8 commentdesc;
362+
String8 commentvalue;
363+
com->getString(&commentdesc, &commentvalue);
364+
const char * desc = commentdesc.string();
365+
const char * value = commentvalue.string();
366+
367+
// first 3 characters are the language, which we don't care about
368+
if(strlen(desc) > 3 && strcmp(desc + 3, "iTunSMPB") == 0) {
369+
370+
int32_t delay, padding;
371+
if (sscanf(value, " %*x %x %x %*x", &delay, &padding) == 2) {
372+
mMeta->setInt32(kKeyEncoderDelay, delay);
373+
mMeta->setInt32(kKeyEncoderPadding, padding);
374+
}
375+
break;
376+
}
377+
com->next();
378+
}
379+
delete com;
380+
com = NULL;
381+
}
351382
}
352383

353384
size_t MP3Extractor::countTracks() {
@@ -555,33 +586,6 @@ sp<MetaData> MP3Extractor::getMetaData() {
555586
return meta;
556587
}
557588

558-
ID3::Iterator *com = new ID3::Iterator(id3, "COM");
559-
if (com->done()) {
560-
delete com;
561-
com = new ID3::Iterator(id3, "COMM");
562-
}
563-
while(!com->done()) {
564-
String8 commentdesc;
565-
String8 commentvalue;
566-
com->getString(&commentdesc, &commentvalue);
567-
const char * desc = commentdesc.string();
568-
const char * value = commentvalue.string();
569-
570-
// first 3 characters are the language, which we don't care about
571-
if(strlen(desc) > 3 && strcmp(desc + 3, "iTunSMPB") == 0) {
572-
573-
int32_t delay, padding;
574-
if (sscanf(value, " %*x %x %x %*x", &delay, &padding) == 2) {
575-
mMeta->setInt32(kKeyEncoderDelay, delay);
576-
mMeta->setInt32(kKeyEncoderPadding, padding);
577-
}
578-
break;
579-
}
580-
com->next();
581-
}
582-
delete com;
583-
com = NULL;
584-
585589
struct Map {
586590
int key;
587591
const char *tag1;

0 commit comments

Comments
 (0)