Bug 1296531 - Add gtest for encoding audio data. r=jesup

MozReview-Commit-ID: 9hAecL1VG7B

--HG--
extra : rebase_source : 87e362296629ef77d34ef95de4a36f8966d7ad97
This commit is contained in:
Andreas Pehrson 2017-02-17 12:15:48 +01:00
Родитель ed7be2f6af
Коммит 339115c0f8
1 изменённых файлов: 29 добавлений и 0 удалений

Просмотреть файл

@ -221,3 +221,32 @@ TEST(OpusAudioTrackEncoder, FetchMetadata)
EXPECT_EQ(channels, opusMeta->mChannels);
EXPECT_EQ(sampleRate, opusMeta->mSamplingFrequency);
}
TEST(OpusAudioTrackEncoder, FrameEncode)
{
const int32_t channels = 1;
const int32_t sampleRate = 44100;
TestOpusTrackEncoder encoder;
EXPECT_TRUE(encoder.TestOpusCreation(channels, sampleRate));
// Generate five seconds of raw audio data.
AudioGenerator generator(channels, sampleRate);
AudioSegment segment;
const int32_t samples = sampleRate * 5;
generator.Generate(segment, samples);
encoder.AppendAudioSegment(Move(segment));
encoder.NotifyCurrentTime(samples);
EncodedFrameContainer container;
EXPECT_TRUE(NS_SUCCEEDED(encoder.GetEncodedTrack(container)));
// Verify that encoded data is 5 seconds long.
uint64_t totalDuration = 0;
for (auto& frame : container.GetEncodedFrames()) {
totalDuration += frame->GetDuration();
}
// 44100 as used above gets resampled to 48000 for opus.
const uint64_t five = 48000 * 5;
EXPECT_EQ(five, totalDuration);
}