2015-05-13 16:15:39 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <vector>
|
|
|
|
|
2015-06-05 15:34:19 +03:00
|
|
|
#include "MP3Demuxer.h"
|
2015-05-13 16:15:39 +03:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
|
|
|
#include "MockMediaResource.h"
|
|
|
|
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
class MockMP3MediaResource;
|
|
|
|
class MockMP3StreamMediaResource;
|
|
|
|
namespace mozilla {
|
|
|
|
DDLoggedTypeNameAndBase(::MockMP3MediaResource, MockMediaResource);
|
|
|
|
DDLoggedTypeNameAndBase(::MockMP3StreamMediaResource, MockMP3MediaResource);
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-08-11 01:27:41 +03:00
|
|
|
using namespace mozilla;
|
2015-11-17 20:02:41 +03:00
|
|
|
using media::TimeUnit;
|
|
|
|
|
2015-07-09 23:42:23 +03:00
|
|
|
// Regular MP3 file mock resource.
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
class MockMP3MediaResource
|
|
|
|
: public MockMediaResource
|
|
|
|
, public DecoderDoctorLifeLogger<MockMP3MediaResource>
|
|
|
|
{
|
2015-07-09 23:42:23 +03:00
|
|
|
public:
|
|
|
|
explicit MockMP3MediaResource(const char* aFileName)
|
|
|
|
: MockMediaResource(aFileName)
|
|
|
|
{}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~MockMP3MediaResource() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// MP3 stream mock resource.
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
class MockMP3StreamMediaResource
|
|
|
|
: public MockMP3MediaResource
|
|
|
|
, public DecoderDoctorLifeLogger<MockMP3StreamMediaResource>
|
|
|
|
{
|
2015-07-09 23:42:23 +03:00
|
|
|
public:
|
|
|
|
explicit MockMP3StreamMediaResource(const char* aFileName)
|
|
|
|
: MockMP3MediaResource(aFileName)
|
|
|
|
{}
|
|
|
|
|
|
|
|
int64_t GetLength() override { return -1; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~MockMP3StreamMediaResource() {}
|
|
|
|
};
|
|
|
|
|
2015-05-13 16:15:39 +03:00
|
|
|
struct MP3Resource {
|
|
|
|
const char* mFilePath;
|
|
|
|
bool mIsVBR;
|
2015-07-09 23:42:23 +03:00
|
|
|
int64_t mFileSize;
|
2015-05-13 16:15:39 +03:00
|
|
|
int32_t mMPEGLayer;
|
|
|
|
int32_t mMPEGVersion;
|
|
|
|
uint8_t mID3MajorVersion;
|
|
|
|
uint8_t mID3MinorVersion;
|
|
|
|
uint8_t mID3Flags;
|
|
|
|
uint32_t mID3Size;
|
|
|
|
|
|
|
|
int64_t mDuration;
|
|
|
|
float mDurationError;
|
2015-08-03 21:45:35 +03:00
|
|
|
float mSeekError;
|
2015-05-13 16:15:39 +03:00
|
|
|
int32_t mSampleRate;
|
|
|
|
int32_t mSamplesPerFrame;
|
|
|
|
uint32_t mNumSamples;
|
|
|
|
// TODO: temp solution, we could parse them instead or account for them
|
|
|
|
// otherwise.
|
|
|
|
int32_t mNumTrailingFrames;
|
|
|
|
int32_t mBitrate;
|
|
|
|
int32_t mSlotSize;
|
|
|
|
int32_t mPrivate;
|
|
|
|
|
|
|
|
// The first n frame offsets.
|
|
|
|
std::vector<int32_t> mSyncOffsets;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MockMP3MediaResource> mResource;
|
|
|
|
RefPtr<MP3TrackDemuxer> mDemuxer;
|
2015-05-13 16:15:39 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class MP3DemuxerTest : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
void SetUp() override {
|
|
|
|
{
|
|
|
|
MP3Resource res;
|
|
|
|
res.mFilePath = "noise.mp3";
|
|
|
|
res.mIsVBR = false;
|
|
|
|
res.mFileSize = 965257;
|
|
|
|
res.mMPEGLayer = 3;
|
|
|
|
res.mMPEGVersion = 1;
|
|
|
|
res.mID3MajorVersion = 3;
|
|
|
|
res.mID3MinorVersion = 0;
|
|
|
|
res.mID3Flags = 0;
|
|
|
|
res.mID3Size = 2141;
|
|
|
|
res.mDuration = 30067000;
|
|
|
|
res.mDurationError = 0.001f;
|
2015-08-03 21:45:35 +03:00
|
|
|
res.mSeekError = 0.02f;
|
2015-05-13 16:15:39 +03:00
|
|
|
res.mSampleRate = 44100;
|
|
|
|
res.mSamplesPerFrame = 1152;
|
|
|
|
res.mNumSamples = 1325952;
|
|
|
|
res.mNumTrailingFrames = 2;
|
|
|
|
res.mBitrate = 256000;
|
|
|
|
res.mSlotSize = 1;
|
|
|
|
res.mPrivate = 0;
|
|
|
|
const int syncs[] = { 2151, 2987, 3823, 4659, 5495, 6331 };
|
|
|
|
res.mSyncOffsets.insert(res.mSyncOffsets.begin(), syncs, syncs + 6);
|
2015-07-09 23:42:23 +03:00
|
|
|
|
|
|
|
// No content length can be estimated for CBR stream resources.
|
|
|
|
MP3Resource streamRes = res;
|
|
|
|
streamRes.mFileSize = -1;
|
|
|
|
streamRes.mDuration = -1;
|
|
|
|
streamRes.mDurationError = 0.0f;
|
|
|
|
|
|
|
|
res.mResource = new MockMP3MediaResource(res.mFilePath);
|
|
|
|
res.mDemuxer = new MP3TrackDemuxer(res.mResource);
|
2015-05-13 16:15:39 +03:00
|
|
|
mTargets.push_back(res);
|
2015-07-09 23:42:23 +03:00
|
|
|
|
|
|
|
streamRes.mResource = new MockMP3StreamMediaResource(streamRes.mFilePath);
|
|
|
|
streamRes.mDemuxer = new MP3TrackDemuxer(streamRes.mResource);
|
|
|
|
mTargets.push_back(streamRes);
|
2015-05-13 16:15:39 +03:00
|
|
|
}
|
|
|
|
|
2015-09-13 17:12:20 +03:00
|
|
|
{
|
|
|
|
MP3Resource res;
|
|
|
|
// This file trips up the MP3 demuxer if ID3v2 tags aren't properly skipped. If skipping is
|
|
|
|
// not properly implemented, depending on the strictness of the MPEG frame parser a false
|
|
|
|
// sync will be detected somewhere within the metadata at or after 112087, or failing
|
|
|
|
// that, at the artificially added extraneous header at 114532.
|
|
|
|
res.mFilePath = "id3v2header.mp3";
|
|
|
|
res.mIsVBR = false;
|
|
|
|
res.mFileSize = 191302;
|
|
|
|
res.mMPEGLayer = 3;
|
|
|
|
res.mMPEGVersion = 1;
|
|
|
|
res.mID3MajorVersion = 3;
|
|
|
|
res.mID3MinorVersion = 0;
|
|
|
|
res.mID3Flags = 0;
|
|
|
|
res.mID3Size = 115304;
|
2017-12-19 10:14:57 +03:00
|
|
|
res.mDuration = 3166167;
|
2015-09-13 17:12:20 +03:00
|
|
|
res.mDurationError = 0.001f;
|
|
|
|
res.mSeekError = 0.02f;
|
|
|
|
res.mSampleRate = 44100;
|
|
|
|
res.mSamplesPerFrame = 1152;
|
|
|
|
res.mNumSamples = 139392;
|
|
|
|
res.mNumTrailingFrames = 0;
|
|
|
|
res.mBitrate = 192000;
|
|
|
|
res.mSlotSize = 1;
|
|
|
|
res.mPrivate = 1;
|
|
|
|
const int syncs[] = { 115314, 115941, 116568, 117195, 117822, 118449 };
|
|
|
|
res.mSyncOffsets.insert(res.mSyncOffsets.begin(), syncs, syncs + 6);
|
|
|
|
|
|
|
|
// No content length can be estimated for CBR stream resources.
|
|
|
|
MP3Resource streamRes = res;
|
|
|
|
streamRes.mFileSize = -1;
|
|
|
|
streamRes.mDuration = -1;
|
|
|
|
streamRes.mDurationError = 0.0f;
|
|
|
|
|
|
|
|
res.mResource = new MockMP3MediaResource(res.mFilePath);
|
|
|
|
res.mDemuxer = new MP3TrackDemuxer(res.mResource);
|
|
|
|
mTargets.push_back(res);
|
|
|
|
|
|
|
|
streamRes.mResource = new MockMP3StreamMediaResource(streamRes.mFilePath);
|
|
|
|
streamRes.mDemuxer = new MP3TrackDemuxer(streamRes.mResource);
|
|
|
|
mTargets.push_back(streamRes);
|
|
|
|
}
|
|
|
|
|
2015-05-13 16:15:39 +03:00
|
|
|
{
|
|
|
|
MP3Resource res;
|
|
|
|
res.mFilePath = "noise_vbr.mp3";
|
|
|
|
res.mIsVBR = true;
|
|
|
|
res.mFileSize = 583679;
|
|
|
|
res.mMPEGLayer = 3;
|
|
|
|
res.mMPEGVersion = 1;
|
|
|
|
res.mID3MajorVersion = 3;
|
|
|
|
res.mID3MinorVersion = 0;
|
|
|
|
res.mID3Flags = 0;
|
|
|
|
res.mID3Size = 2221;
|
|
|
|
res.mDuration = 30081000;
|
|
|
|
res.mDurationError = 0.005f;
|
2015-08-03 21:45:35 +03:00
|
|
|
res.mSeekError = 0.02f;
|
2015-05-13 16:15:39 +03:00
|
|
|
res.mSampleRate = 44100;
|
|
|
|
res.mSamplesPerFrame = 1152;
|
|
|
|
res.mNumSamples = 1326575;
|
|
|
|
res.mNumTrailingFrames = 3;
|
|
|
|
res.mBitrate = 154000;
|
|
|
|
res.mSlotSize = 1;
|
|
|
|
res.mPrivate = 0;
|
|
|
|
const int syncs[] = { 2231, 2648, 2752, 3796, 4318, 4735 };
|
|
|
|
res.mSyncOffsets.insert(res.mSyncOffsets.begin(), syncs, syncs + 6);
|
2015-07-09 23:42:23 +03:00
|
|
|
|
|
|
|
// VBR stream resources contain header info on total frames numbers, which
|
|
|
|
// is used to estimate the total duration.
|
|
|
|
MP3Resource streamRes = res;
|
|
|
|
streamRes.mFileSize = -1;
|
|
|
|
|
|
|
|
res.mResource = new MockMP3MediaResource(res.mFilePath);
|
|
|
|
res.mDemuxer = new MP3TrackDemuxer(res.mResource);
|
2015-05-13 16:15:39 +03:00
|
|
|
mTargets.push_back(res);
|
2015-07-09 23:42:23 +03:00
|
|
|
|
|
|
|
streamRes.mResource = new MockMP3StreamMediaResource(streamRes.mFilePath);
|
|
|
|
streamRes.mDemuxer = new MP3TrackDemuxer(streamRes.mResource);
|
2015-11-17 17:22:36 +03:00
|
|
|
mTargets.push_back(streamRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
MP3Resource res;
|
|
|
|
res.mFilePath = "small-shot.mp3";
|
|
|
|
res.mIsVBR = true;
|
|
|
|
res.mFileSize = 6825;
|
|
|
|
res.mMPEGLayer = 3;
|
|
|
|
res.mMPEGVersion = 1;
|
|
|
|
res.mID3MajorVersion = 4;
|
|
|
|
res.mID3MinorVersion = 0;
|
|
|
|
res.mID3Flags = 0;
|
|
|
|
res.mID3Size = 24;
|
|
|
|
res.mDuration = 336686;
|
|
|
|
res.mDurationError = 0.01f;
|
|
|
|
res.mSeekError = 0.2f;
|
|
|
|
res.mSampleRate = 44100;
|
|
|
|
res.mSamplesPerFrame = 1152;
|
|
|
|
res.mNumSamples = 12;
|
|
|
|
res.mNumTrailingFrames = 0;
|
|
|
|
res.mBitrate = 256000;
|
|
|
|
res.mSlotSize = 1;
|
|
|
|
res.mPrivate = 0;
|
|
|
|
const int syncs[] = { 34, 556, 1078, 1601, 2123, 2646, 3168, 3691, 4213,
|
|
|
|
4736, 5258, 5781, 6303 };
|
|
|
|
res.mSyncOffsets.insert(res.mSyncOffsets.begin(), syncs, syncs + 13);
|
|
|
|
|
|
|
|
// No content length can be estimated for CBR stream resources.
|
|
|
|
MP3Resource streamRes = res;
|
|
|
|
streamRes.mFileSize = -1;
|
|
|
|
|
|
|
|
res.mResource = new MockMP3MediaResource(res.mFilePath);
|
|
|
|
res.mDemuxer = new MP3TrackDemuxer(res.mResource);
|
2016-03-21 00:08:45 +03:00
|
|
|
mTargets.push_back(res);
|
|
|
|
|
|
|
|
streamRes.mResource = new MockMP3StreamMediaResource(streamRes.mFilePath);
|
|
|
|
streamRes.mDemuxer = new MP3TrackDemuxer(streamRes.mResource);
|
|
|
|
mTargets.push_back(streamRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
MP3Resource res;
|
|
|
|
// This file contains a false frame sync at 34, just after the ID3 tag,
|
|
|
|
// which should be identified as a false positive and skipped.
|
|
|
|
res.mFilePath = "small-shot-false-positive.mp3";
|
|
|
|
res.mIsVBR = true;
|
|
|
|
res.mFileSize = 6845;
|
|
|
|
res.mMPEGLayer = 3;
|
|
|
|
res.mMPEGVersion = 1;
|
|
|
|
res.mID3MajorVersion = 4;
|
|
|
|
res.mID3MinorVersion = 0;
|
|
|
|
res.mID3Flags = 0;
|
|
|
|
res.mID3Size = 24;
|
|
|
|
res.mDuration = 336686;
|
|
|
|
res.mDurationError = 0.01f;
|
|
|
|
res.mSeekError = 0.2f;
|
|
|
|
res.mSampleRate = 44100;
|
|
|
|
res.mSamplesPerFrame = 1152;
|
|
|
|
res.mNumSamples = 12;
|
|
|
|
res.mNumTrailingFrames = 0;
|
|
|
|
res.mBitrate = 256000;
|
|
|
|
res.mSlotSize = 1;
|
|
|
|
res.mPrivate = 0;
|
|
|
|
const int syncs[] = { 54, 576, 1098, 1621, 2143, 2666, 3188, 3711, 4233,
|
|
|
|
4756, 5278, 5801, 6323 };
|
|
|
|
res.mSyncOffsets.insert(res.mSyncOffsets.begin(), syncs, syncs + 13);
|
|
|
|
|
|
|
|
// No content length can be estimated for CBR stream resources.
|
|
|
|
MP3Resource streamRes = res;
|
|
|
|
streamRes.mFileSize = -1;
|
|
|
|
|
|
|
|
res.mResource = new MockMP3MediaResource(res.mFilePath);
|
|
|
|
res.mDemuxer = new MP3TrackDemuxer(res.mResource);
|
2016-12-21 00:15:48 +03:00
|
|
|
mTargets.push_back(res);
|
|
|
|
|
|
|
|
streamRes.mResource = new MockMP3StreamMediaResource(streamRes.mFilePath);
|
|
|
|
streamRes.mDemuxer = new MP3TrackDemuxer(streamRes.mResource);
|
|
|
|
mTargets.push_back(streamRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
MP3Resource res;
|
|
|
|
res.mFilePath = "small-shot-partial-xing.mp3";
|
|
|
|
res.mIsVBR = true;
|
|
|
|
res.mFileSize = 6825;
|
|
|
|
res.mMPEGLayer = 3;
|
|
|
|
res.mMPEGVersion = 1;
|
|
|
|
res.mID3MajorVersion = 4;
|
|
|
|
res.mID3MinorVersion = 0;
|
|
|
|
res.mID3Flags = 0;
|
|
|
|
res.mID3Size = 24;
|
|
|
|
res.mDuration = 336686;
|
|
|
|
res.mDurationError = 0.01f;
|
|
|
|
res.mSeekError = 0.2f;
|
|
|
|
res.mSampleRate = 44100;
|
|
|
|
res.mSamplesPerFrame = 1152;
|
|
|
|
res.mNumSamples = 12;
|
|
|
|
res.mNumTrailingFrames = 0;
|
|
|
|
res.mBitrate = 256000;
|
|
|
|
res.mSlotSize = 1;
|
|
|
|
res.mPrivate = 0;
|
|
|
|
const int syncs[] = { 34, 556, 1078, 1601, 2123, 2646, 3168, 3691, 4213,
|
|
|
|
4736, 5258, 5781, 6303 };
|
|
|
|
res.mSyncOffsets.insert(res.mSyncOffsets.begin(), syncs, syncs + 13);
|
|
|
|
|
|
|
|
// No content length can be estimated for CBR stream resources.
|
|
|
|
MP3Resource streamRes = res;
|
|
|
|
streamRes.mFileSize = -1;
|
|
|
|
|
|
|
|
res.mResource = new MockMP3MediaResource(res.mFilePath);
|
|
|
|
res.mDemuxer = new MP3TrackDemuxer(res.mResource);
|
2015-11-17 17:22:36 +03:00
|
|
|
mTargets.push_back(res);
|
|
|
|
|
|
|
|
streamRes.mResource = new MockMP3StreamMediaResource(streamRes.mFilePath);
|
|
|
|
streamRes.mDemuxer = new MP3TrackDemuxer(streamRes.mResource);
|
2015-07-09 23:42:23 +03:00
|
|
|
mTargets.push_back(streamRes);
|
2015-05-13 16:15:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& target: mTargets) {
|
2017-08-07 13:09:56 +03:00
|
|
|
ASSERT_EQ(NS_OK, target.mResource->Open());
|
2015-05-13 16:15:39 +03:00
|
|
|
ASSERT_TRUE(target.mDemuxer->Init());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<MP3Resource> mTargets;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(MP3DemuxerTest, ID3Tags) {
|
|
|
|
for (const auto& target: mTargets) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaRawData> frame(target.mDemuxer->DemuxSample());
|
2015-05-13 16:15:39 +03:00
|
|
|
ASSERT_TRUE(frame);
|
|
|
|
|
|
|
|
const auto& id3 = target.mDemuxer->ID3Header();
|
|
|
|
ASSERT_TRUE(id3.IsValid());
|
|
|
|
|
|
|
|
EXPECT_EQ(target.mID3MajorVersion, id3.MajorVersion());
|
|
|
|
EXPECT_EQ(target.mID3MinorVersion, id3.MinorVersion());
|
|
|
|
EXPECT_EQ(target.mID3Flags, id3.Flags());
|
|
|
|
EXPECT_EQ(target.mID3Size, id3.Size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(MP3DemuxerTest, VBRHeader) {
|
|
|
|
for (const auto& target: mTargets) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaRawData> frame(target.mDemuxer->DemuxSample());
|
2015-05-13 16:15:39 +03:00
|
|
|
ASSERT_TRUE(frame);
|
|
|
|
|
|
|
|
const auto& vbr = target.mDemuxer->VBRInfo();
|
|
|
|
|
|
|
|
if (target.mIsVBR) {
|
|
|
|
EXPECT_EQ(FrameParser::VBRHeader::XING, vbr.Type());
|
|
|
|
// TODO: find reference number which accounts for trailing headers.
|
2015-10-15 20:58:02 +03:00
|
|
|
// EXPECT_EQ(target.mNumSamples / target.mSamplesPerFrame, vbr.NumAudioFrames().value());
|
2015-05-13 16:15:39 +03:00
|
|
|
} else {
|
|
|
|
EXPECT_EQ(FrameParser::VBRHeader::NONE, vbr.Type());
|
2015-10-15 20:58:02 +03:00
|
|
|
EXPECT_FALSE(vbr.NumAudioFrames());
|
2015-05-13 16:15:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(MP3DemuxerTest, FrameParsing) {
|
|
|
|
for (const auto& target: mTargets) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaRawData> frameData(target.mDemuxer->DemuxSample());
|
2015-05-13 16:15:39 +03:00
|
|
|
ASSERT_TRUE(frameData);
|
2015-07-09 23:42:23 +03:00
|
|
|
EXPECT_EQ(target.mFileSize, target.mDemuxer->StreamLength());
|
2015-05-13 16:15:39 +03:00
|
|
|
|
|
|
|
const auto& id3 = target.mDemuxer->ID3Header();
|
|
|
|
ASSERT_TRUE(id3.IsValid());
|
|
|
|
|
2015-07-09 23:42:23 +03:00
|
|
|
int64_t parsedLength = id3.Size();
|
|
|
|
int64_t bitrateSum = 0;
|
|
|
|
int32_t numFrames = 0;
|
|
|
|
int32_t numSamples = 0;
|
2015-05-13 16:15:39 +03:00
|
|
|
|
|
|
|
while (frameData) {
|
2015-07-09 23:42:23 +03:00
|
|
|
if (static_cast<int64_t>(target.mSyncOffsets.size()) > numFrames) {
|
2015-05-13 16:15:39 +03:00
|
|
|
// Test sync offsets.
|
|
|
|
EXPECT_EQ(target.mSyncOffsets[numFrames], frameData->mOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
++numFrames;
|
2015-08-06 03:58:35 +03:00
|
|
|
parsedLength += frameData->Size();
|
2015-05-13 16:15:39 +03:00
|
|
|
|
|
|
|
const auto& frame = target.mDemuxer->LastFrame();
|
|
|
|
const auto& header = frame.Header();
|
|
|
|
ASSERT_TRUE(header.IsValid());
|
|
|
|
|
|
|
|
numSamples += header.SamplesPerFrame();
|
|
|
|
|
|
|
|
EXPECT_EQ(target.mMPEGLayer, header.Layer());
|
|
|
|
EXPECT_EQ(target.mSampleRate, header.SampleRate());
|
|
|
|
EXPECT_EQ(target.mSamplesPerFrame, header.SamplesPerFrame());
|
|
|
|
EXPECT_EQ(target.mSlotSize, header.SlotSize());
|
|
|
|
EXPECT_EQ(target.mPrivate, header.Private());
|
|
|
|
|
|
|
|
if (target.mIsVBR) {
|
|
|
|
// Used to compute the average bitrate for VBR streams.
|
|
|
|
bitrateSum += target.mBitrate;
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(target.mBitrate, header.Bitrate());
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// There may be trailing headers which we don't parse, so the stream length
|
|
|
|
// is the upper bound.
|
2015-07-09 23:42:23 +03:00
|
|
|
if (target.mFileSize > 0) {
|
|
|
|
EXPECT_GE(target.mFileSize, parsedLength);
|
|
|
|
}
|
2015-05-13 16:15:39 +03:00
|
|
|
|
|
|
|
if (target.mIsVBR) {
|
|
|
|
ASSERT_TRUE(numFrames);
|
|
|
|
EXPECT_EQ(target.mBitrate, static_cast<int32_t>(bitrateSum / numFrames));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(MP3DemuxerTest, Duration) {
|
|
|
|
for (const auto& target: mTargets) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaRawData> frameData(target.mDemuxer->DemuxSample());
|
2015-05-13 16:15:39 +03:00
|
|
|
ASSERT_TRUE(frameData);
|
2015-07-09 23:42:23 +03:00
|
|
|
EXPECT_EQ(target.mFileSize, target.mDemuxer->StreamLength());
|
2015-05-13 16:15:39 +03:00
|
|
|
|
|
|
|
while (frameData) {
|
2015-06-05 15:34:19 +03:00
|
|
|
EXPECT_NEAR(target.mDuration, target.mDemuxer->Duration().ToMicroseconds(),
|
2015-05-13 16:15:39 +03:00
|
|
|
target.mDurationError * target.mDuration);
|
|
|
|
|
|
|
|
frameData = target.mDemuxer->DemuxSample();
|
|
|
|
}
|
|
|
|
}
|
2015-11-17 20:02:41 +03:00
|
|
|
|
|
|
|
// Seek out of range tests.
|
|
|
|
for (const auto& target: mTargets) {
|
|
|
|
// Skip tests for stream media resources because of lacking duration.
|
|
|
|
if (target.mFileSize <= 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
target.mDemuxer->Reset();
|
|
|
|
RefPtr<MediaRawData> frameData(target.mDemuxer->DemuxSample());
|
|
|
|
ASSERT_TRUE(frameData);
|
|
|
|
|
2017-04-17 11:35:04 +03:00
|
|
|
const auto duration = target.mDemuxer->Duration();
|
|
|
|
const auto pos = duration + TimeUnit::FromMicroseconds(1e6);
|
2015-11-17 20:02:41 +03:00
|
|
|
|
|
|
|
// Attempt to seek 1 second past the end of stream.
|
2017-04-17 11:35:04 +03:00
|
|
|
target.mDemuxer->Seek(pos);
|
2015-11-17 20:02:41 +03:00
|
|
|
// The seek should bring us to the end of the stream.
|
2017-04-17 11:35:04 +03:00
|
|
|
EXPECT_NEAR(duration.ToMicroseconds(),
|
|
|
|
target.mDemuxer->SeekPosition().ToMicroseconds(),
|
|
|
|
target.mSeekError * duration.ToMicroseconds());
|
2015-11-17 20:02:41 +03:00
|
|
|
|
|
|
|
// Since we're at the end of the stream, there should be no frames left.
|
|
|
|
frameData = target.mDemuxer->DemuxSample();
|
|
|
|
ASSERT_FALSE(frameData);
|
|
|
|
}
|
2015-05-13 16:15:39 +03:00
|
|
|
}
|
2015-08-03 21:45:35 +03:00
|
|
|
|
|
|
|
TEST_F(MP3DemuxerTest, Seek) {
|
|
|
|
for (const auto& target: mTargets) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaRawData> frameData(target.mDemuxer->DemuxSample());
|
2015-08-03 21:45:35 +03:00
|
|
|
ASSERT_TRUE(frameData);
|
|
|
|
|
2017-04-17 11:35:04 +03:00
|
|
|
const auto seekTime = TimeUnit::FromSeconds(1);
|
|
|
|
auto pos = target.mDemuxer->SeekPosition();
|
2015-08-03 21:45:35 +03:00
|
|
|
|
|
|
|
while (frameData) {
|
2017-04-17 11:35:04 +03:00
|
|
|
EXPECT_NEAR(pos.ToMicroseconds(),
|
|
|
|
target.mDemuxer->SeekPosition().ToMicroseconds(),
|
|
|
|
target.mSeekError * pos.ToMicroseconds());
|
2015-08-03 21:45:35 +03:00
|
|
|
|
|
|
|
pos += seekTime;
|
2017-04-17 11:35:04 +03:00
|
|
|
target.mDemuxer->Seek(pos);
|
2015-08-03 21:45:35 +03:00
|
|
|
frameData = target.mDemuxer->DemuxSample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Seeking should work with in-between resets, too.
|
|
|
|
for (const auto& target: mTargets) {
|
|
|
|
target.mDemuxer->Reset();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaRawData> frameData(target.mDemuxer->DemuxSample());
|
2015-08-03 21:45:35 +03:00
|
|
|
ASSERT_TRUE(frameData);
|
|
|
|
|
2017-04-17 11:35:04 +03:00
|
|
|
const auto seekTime = TimeUnit::FromSeconds(1);
|
|
|
|
auto pos = target.mDemuxer->SeekPosition();
|
2015-08-03 21:45:35 +03:00
|
|
|
|
|
|
|
while (frameData) {
|
2017-04-17 11:35:04 +03:00
|
|
|
EXPECT_NEAR(pos.ToMicroseconds(),
|
|
|
|
target.mDemuxer->SeekPosition().ToMicroseconds(),
|
|
|
|
target.mSeekError * pos.ToMicroseconds());
|
2015-08-03 21:45:35 +03:00
|
|
|
|
|
|
|
pos += seekTime;
|
|
|
|
target.mDemuxer->Reset();
|
2017-04-17 11:35:04 +03:00
|
|
|
target.mDemuxer->Seek(pos);
|
2015-08-03 21:45:35 +03:00
|
|
|
frameData = target.mDemuxer->DemuxSample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|