Bug 1703812 - Part 28 - Tighten mp3 demuxing tests, removing tolerances and checking encoder delay and padding. r=alwu,geckoview-reviewers,tthibaud

This removes most fuzzing and adds checks for trim information.

Differential Revision: https://phabricator.services.mozilla.com/D170647
This commit is contained in:
Paul Adenot 2023-05-17 15:47:00 +00:00
parent bd27efb821
commit 7bbbd47c35
2 changed files with 40 additions and 25 deletions

View File

@ -73,9 +73,8 @@ struct MP3Resource {
uint32_t mSampleRate;
uint32_t mSamplesPerFrame;
uint32_t mNumSamples;
// TODO: temp solution, we could parse them instead or account for them
// otherwise.
int32_t mNumTrailingFrames;
uint32_t mPadding;
uint32_t mEncoderDelay;
uint32_t mBitrate;
uint32_t mSlotSize;
int32_t mPrivate;
@ -101,12 +100,16 @@ class MP3DemuxerTest : public ::testing::Test {
res.mID3MinorVersion = 0;
res.mID3Flags = 0;
res.mID3Size = 2141;
res.mDuration = Some(MP3Resource::Duration{30067000, 0.001f});
// The tolerance comes from the fact that this file has ID3v1 information
// at the end, this trips our CBR duration calculation. The file has
// however the correct duration when decoded / demuxed completely.
res.mDuration = Some(MP3Resource::Duration{30093062, 0.00015f});
res.mSeekError = 0.02f;
res.mSampleRate = 44100;
res.mSamplesPerFrame = 1152;
res.mNumSamples = 1325952;
res.mNumTrailingFrames = 2;
res.mNumSamples = 1327104;
res.mPadding = 0;
res.mEncoderDelay = 0;
res.mBitrate = 256000;
res.mSlotSize = 1;
res.mPrivate = 0;
@ -144,12 +147,16 @@ class MP3DemuxerTest : public ::testing::Test {
res.mID3MinorVersion = 0;
res.mID3Flags = 0;
res.mID3Size = 115304;
res.mDuration = Some(MP3Resource::Duration{3166167, 0.001f});
// The tolerance comes from the fact that this file has ID3v1 information
// at the end, this trips our CBR duration calculation. The file has
// however the correct duration when decoded / demuxed completely.
res.mDuration = Some(MP3Resource::Duration{3160833, 0.0017f});
res.mSeekError = 0.02f;
res.mSampleRate = 44100;
res.mSamplesPerFrame = 1152;
res.mNumSamples = 139392;
res.mNumTrailingFrames = 0;
res.mPadding = 0;
res.mEncoderDelay = 0;
res.mBitrate = 192000;
res.mSlotSize = 1;
res.mPrivate = 1;
@ -182,12 +189,13 @@ class MP3DemuxerTest : public ::testing::Test {
res.mID3MinorVersion = 0;
res.mID3Flags = 0;
res.mID3Size = 2221;
res.mDuration = Some(MP3Resource::Duration{30081000, 0.005f});
res.mDuration = Some(MP3Resource::Duration{30081065, 0.f});
res.mSeekError = 0.02f;
res.mSampleRate = 44100;
res.mSamplesPerFrame = 1152;
res.mNumSamples = 1326575;
res.mNumTrailingFrames = 3;
res.mPadding = 576;
res.mEncoderDelay = 2257;
res.mBitrate = 154000;
res.mSlotSize = 1;
res.mPrivate = 0;
@ -220,12 +228,13 @@ class MP3DemuxerTest : public ::testing::Test {
res.mID3MinorVersion = 0;
res.mID3Flags = 0;
res.mID3Size = 24;
res.mDuration = Some(MP3Resource::Duration{336686, 0.01f});
res.mDuration = Some(MP3Resource::Duration{301473, 0.f});
res.mSeekError = 0.2f;
res.mSampleRate = 44100;
res.mSamplesPerFrame = 1152;
res.mNumSamples = 12;
res.mNumTrailingFrames = 0;
res.mPadding = 0;
res.mEncoderDelay = 1152 + 529;
res.mBitrate = 256000;
res.mSlotSize = 1;
res.mPrivate = 0;
@ -260,12 +269,13 @@ class MP3DemuxerTest : public ::testing::Test {
res.mID3MinorVersion = 0;
res.mID3Flags = 0;
res.mID3Size = 24;
res.mDuration = Some(MP3Resource::Duration{336686, 0.01f});
res.mDuration = Some(MP3Resource::Duration{301473, 0.f});
res.mSeekError = 0.2f;
res.mSampleRate = 44100;
res.mSamplesPerFrame = 1152;
res.mNumSamples = 12;
res.mNumTrailingFrames = 0;
res.mPadding = 0;
res.mEncoderDelay = 1681;
res.mBitrate = 256000;
res.mSlotSize = 1;
res.mPrivate = 0;
@ -298,12 +308,13 @@ class MP3DemuxerTest : public ::testing::Test {
res.mID3MinorVersion = 0;
res.mID3Flags = 0;
res.mID3Size = 24;
res.mDuration = Some(MP3Resource::Duration{336686, 0.01f});
res.mDuration = Some(MP3Resource::Duration{301473, 0.f});
res.mSeekError = 0.2f;
res.mSampleRate = 44100;
res.mSamplesPerFrame = 1152;
res.mNumSamples = 12;
res.mNumTrailingFrames = 0;
res.mPadding = 0;
res.mEncoderDelay = 1681;
res.mBitrate = 256000;
res.mSlotSize = 1;
res.mPrivate = 0;
@ -336,12 +347,13 @@ class MP3DemuxerTest : public ::testing::Test {
res.mID3MinorVersion = 0;
res.mID3Flags = 0;
res.mID3Size = 4202;
res.mDuration = Some(MP3Resource::Duration{783660, 0.01f});
res.mDuration = Some(MP3Resource::Duration{731428, 0.f});
res.mSeekError = 0.02f;
res.mSampleRate = 44100;
res.mSamplesPerFrame = 1152;
res.mNumSamples = 29;
res.mNumTrailingFrames = 0;
res.mPadding = 0;
res.mEncoderDelay = 1152;
res.mBitrate = 0;
res.mSlotSize = 1;
res.mPrivate = 0;
@ -395,9 +407,6 @@ TEST_F(MP3DemuxerTest, VBRHeader) {
if (target.mHeaderType == MP3Resource::HeaderType::XING) {
EXPECT_EQ(FrameParser::VBRHeader::XING, vbr.Type());
// TODO: find reference number which accounts for trailing headers.
// EXPECT_EQ(target.mNumSamples / target.mSamplesPerFrame,
// vbr.NumAudioFrames().value());
} else if (target.mHeaderType == MP3Resource::HeaderType::VBRI) {
EXPECT_TRUE(target.mIsVBR);
EXPECT_EQ(FrameParser::VBRHeader::VBRI, vbr.Type());
@ -410,6 +419,7 @@ TEST_F(MP3DemuxerTest, VBRHeader) {
TEST_F(MP3DemuxerTest, FrameParsing) {
for (const auto& target : mTargets) {
printf("Testing: %s\n", target.mFilePath);
RefPtr<MediaRawData> frameData(target.mDemuxer->DemuxSample());
ASSERT_TRUE(frameData);
EXPECT_EQ(target.mFileSize, target.mDemuxer->StreamLength());
@ -453,9 +463,8 @@ TEST_F(MP3DemuxerTest, FrameParsing) {
frameData = target.mDemuxer->DemuxSample();
}
// TODO: find reference number which accounts for trailing headers.
// EXPECT_EQ(target.mNumSamples / target.mSamplesPerFrame, numFrames);
// EXPECT_EQ(target.mNumSamples, numSamples);
EXPECT_EQ(target.mPadding, target.mDemuxer->PaddingFrames());
EXPECT_EQ(target.mEncoderDelay, target.mDemuxer->EncoderDelayFrames());
EXPECT_GE(numSamples, 0u);
// There may be trailing headers which we don't parse, so the stream length
@ -473,6 +482,7 @@ TEST_F(MP3DemuxerTest, FrameParsing) {
TEST_F(MP3DemuxerTest, Duration) {
for (const auto& target : mTargets) {
printf("Testing: %s\n", target.mFilePath);
RefPtr<MediaRawData> frameData(target.mDemuxer->DemuxSample());
ASSERT_TRUE(frameData);
EXPECT_EQ(target.mFileSize, target.mDemuxer->StreamLength());
@ -488,6 +498,11 @@ TEST_F(MP3DemuxerTest, Duration) {
}
frameData = target.mDemuxer->DemuxSample();
}
if (target.mDuration) {
// At the end, the durations should always be exact.
EXPECT_EQ(target.mDuration->mMicroseconds,
target.mDemuxer->Duration()->ToMicroseconds());
}
}
// Seek out of range tests.

View File

@ -39,7 +39,7 @@ class MediaSessionTest : BaseSessionTest() {
const val DOM_TEST_ALBUM2 = "dahoots"
const val DOM_TEST_ALBUM3 = "mahoots"
const val DEFAULT_TEST_TITLE1 = "MediaSessionDefaultTest1"
const val TEST_DURATION1 = 3.37
const val TEST_DURATION1 = 3.34
const val WEBM_TEST_DURATION = 5.59
const val WEBM_TEST_WIDTH = 560L
const val WEBM_TEST_HEIGHT = 320L