Ignore fake MPEG frame headers when seeking them.

This commit is contained in:
Tsuda Kageyu
2017-01-20 22:38:25 +09:00
parent d2e0e55223
commit 6bb92c34fa
4 changed files with 56 additions and 63 deletions

BIN
tests/data/garbage.mp3 Normal file

Binary file not shown.

View File

@ -64,6 +64,7 @@ class TestMPEG : public CppUnit::TestFixture
CPPUNIT_TEST(testEmptyID3v2);
CPPUNIT_TEST(testEmptyID3v1);
CPPUNIT_TEST(testEmptyAPE);
CPPUNIT_TEST(testIgnoreGarbage);
CPPUNIT_TEST_SUITE_END();
public:
@ -119,13 +120,8 @@ public:
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT(!f.audioProperties()->xingHeader());
long last = f.lastFrameOffset();
MPEG::Header lastHeader(&f, last, false);
while(!lastHeader.isValid()) {
last = f.previousFrameOffset(last);
lastHeader = MPEG::Header(&f, last, false);
}
const long last = f.lastFrameOffset();
const MPEG::Header lastHeader(&f, last, false);
CPPUNIT_ASSERT_EQUAL(28213L, last);
CPPUNIT_ASSERT_EQUAL(209, lastHeader.frameLength());
@ -163,7 +159,7 @@ public:
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(176, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(183, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(320, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
@ -421,6 +417,27 @@ public:
}
}
void testIgnoreGarbage()
{
const ScopedFileCopy copy("garbage", ".mp3");
{
MPEG::File f(copy.fileName().c_str());
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT(f.hasID3v2Tag());
CPPUNIT_ASSERT_EQUAL(2255L, f.firstFrameOffset());
CPPUNIT_ASSERT_EQUAL(6015L, f.lastFrameOffset());
CPPUNIT_ASSERT_EQUAL(String("Title A"), f.ID3v2Tag()->title());
f.ID3v2Tag()->setTitle("Title B");
f.save();
}
{
MPEG::File f(copy.fileName().c_str());
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT(f.hasID3v2Tag());
CPPUNIT_ASSERT_EQUAL(String("Title B"), f.ID3v2Tag()->title());
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestMPEG);