-// Copyright 2016 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
namespace media {
// Constants to specify the type of audio data used.
-static const AudioCodec kCodec = kCodecVorbis;
+static const AudioCodec kCodec = AudioCodec::kVorbis;
static const SampleFormat kSampleFormat = kSampleFormatPlanarF32;
static const base::TimeDelta kSeekPreroll;
static const int kSamplesPerSecond = 10000;
-static const base::TimeDelta kBufferDuration =
- base::TimeDelta::FromMilliseconds(20);
+static const base::TimeDelta kBufferDuration = base::Milliseconds(20);
static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO;
static const int kChannelCount = 2;
static const int kChannels = ChannelLayoutToChannelCount(kChannelLayout);
TEST_P(AudioTimestampValidatorTest, WarnForEraticTimes) {
AudioDecoderConfig decoder_config;
decoder_config.Initialize(kCodec, kSampleFormat, kChannelLayout,
- kSamplesPerSecond, EmptyExtraData(), Unencrypted(),
- kSeekPreroll, codec_delay_);
+ kSamplesPerSecond, EmptyExtraData(),
+ EncryptionScheme::kUnencrypted, kSeekPreroll,
+ codec_delay_);
// Validator should fail to stabilize pattern for timestamp expectations.
EXPECT_MEDIA_LOG(
AudioTimestampValidator validator(decoder_config, &media_log_);
- const base::TimeDelta kRandomOffsets[] = {
- base::TimeDelta::FromMilliseconds(100),
- base::TimeDelta::FromMilliseconds(350)};
+ const base::TimeDelta kRandomOffsets[] = {base::Milliseconds(100),
+ base::Milliseconds(350)};
for (int i = 0; i < 100; ++i) {
// Each buffer's timestamp is kBufferDuration from the previous buffer.
- scoped_refptr<DecoderBuffer> encoded_buffer = new DecoderBuffer(0);
+ auto encoded_buffer = base::MakeRefCounted<DecoderBuffer>(0);
// Ping-pong between two random offsets to prevent validator from
// stabilizing timestamp pattern.
base::TimeDelta randomOffset =
- kRandomOffsets[i % arraysize(kRandomOffsets)];
+ kRandomOffsets[i % std::size(kRandomOffsets)];
encoded_buffer->set_timestamp(i * kBufferDuration + randomOffset);
if (i == 0) {
scoped_refptr<AudioBuffer> decoded_buffer = MakeAudioBuffer<float>(
kSampleFormat, kChannelLayout, kChannelCount, kSamplesPerSecond, 1.0f,
0.0f, kFramesPerBuffer, i * kBufferDuration);
- validator.RecordOutputDuration(decoded_buffer.get());
+ validator.RecordOutputDuration(*decoded_buffer);
}
}
}
TEST_P(AudioTimestampValidatorTest, NoWarningForValidTimes) {
AudioDecoderConfig decoder_config;
decoder_config.Initialize(kCodec, kSampleFormat, kChannelLayout,
- kSamplesPerSecond, EmptyExtraData(), Unencrypted(),
- kSeekPreroll, codec_delay_);
+ kSamplesPerSecond, EmptyExtraData(),
+ EncryptionScheme::kUnencrypted, kSeekPreroll,
+ codec_delay_);
// Validator should quickly stabilize pattern for timestamp expectations.
EXPECT_MEDIA_LOG(HasSubstr("Failed to reconcile encoded audio times "
for (int i = 0; i < 100; ++i) {
// Each buffer's timestamp is kBufferDuration from the previous buffer.
- scoped_refptr<DecoderBuffer> encoded_buffer = new DecoderBuffer(0);
+ auto encoded_buffer = base::MakeRefCounted<DecoderBuffer>(0);
encoded_buffer->set_timestamp(i * kBufferDuration);
if (i == 0) {
scoped_refptr<AudioBuffer> decoded_buffer = MakeAudioBuffer<float>(
kSampleFormat, kChannelLayout, kChannelCount, kSamplesPerSecond, 1.0f,
0.0f, kFramesPerBuffer, i * kBufferDuration);
- validator.RecordOutputDuration(decoded_buffer.get());
+ validator.RecordOutputDuration(*decoded_buffer);
}
}
}
TEST_P(AudioTimestampValidatorTest, SingleWarnForSingleLargeGap) {
AudioDecoderConfig decoder_config;
decoder_config.Initialize(kCodec, kSampleFormat, kChannelLayout,
- kSamplesPerSecond, EmptyExtraData(), Unencrypted(),
- kSeekPreroll, codec_delay_);
+ kSamplesPerSecond, EmptyExtraData(),
+ EncryptionScheme::kUnencrypted, kSeekPreroll,
+ codec_delay_);
AudioTimestampValidator validator(decoder_config, &media_log_);
// Halfway through the stream, introduce sudden gap of 50 milliseconds.
base::TimeDelta offset;
if (i >= 50)
- offset = base::TimeDelta::FromMilliseconds(100);
+ offset = base::Milliseconds(100);
// This gap never widens, so expect only a single warning when its first
// introduced.
if (i == 50)
EXPECT_MEDIA_LOG(HasSubstr("timestamp gap detected"));
- scoped_refptr<DecoderBuffer> encoded_buffer = new DecoderBuffer(0);
+ auto encoded_buffer = base::MakeRefCounted<DecoderBuffer>(0);
encoded_buffer->set_timestamp(i * kBufferDuration + offset);
if (i == 0) {
scoped_refptr<AudioBuffer> decoded_buffer = MakeAudioBuffer<float>(
kSampleFormat, kChannelLayout, kChannelCount, kSamplesPerSecond, 1.0f,
0.0f, kFramesPerBuffer, i * kBufferDuration);
- validator.RecordOutputDuration(decoded_buffer.get());
+ validator.RecordOutputDuration(*decoded_buffer);
}
}
}
TEST_P(AudioTimestampValidatorTest, RepeatedWarnForSlowAccumulatingDrift) {
AudioDecoderConfig decoder_config;
decoder_config.Initialize(kCodec, kSampleFormat, kChannelLayout,
- kSamplesPerSecond, EmptyExtraData(), Unencrypted(),
- kSeekPreroll, codec_delay_);
+ kSamplesPerSecond, EmptyExtraData(),
+ EncryptionScheme::kUnencrypted, kSeekPreroll,
+ codec_delay_);
AudioTimestampValidator validator(decoder_config, &media_log_);
"with decoded output."))
.Times(0);
+ int num_timestamp_gap_warnings = 0;
+ const int kMaxTimestampGapWarnings = 10; // Must be the same as in .cc
+
for (int i = 0; i < 100; ++i) {
// Wait for delayed output to begin plus an additional two iterations to
// start using drift offset. The the two iterations without offset will
// iteration.
base::TimeDelta offset;
if (i >= output_delay_ + 2)
- offset = i * base::TimeDelta::FromMilliseconds(1);
+ offset = i * base::Milliseconds(1);
- scoped_refptr<DecoderBuffer> encoded_buffer = new DecoderBuffer(0);
+ auto encoded_buffer = base::MakeRefCounted<DecoderBuffer>(0);
encoded_buffer->set_timestamp((i * kBufferDuration) + offset);
// Expect gap warnings to start when drift hits 50 milliseconds. Warnings
- // should continue as the gap widens.
- if (offset > base::TimeDelta::FromMilliseconds(50)) {
- EXPECT_MEDIA_LOG(HasSubstr("timestamp gap detected"));
+ // should continue as the gap widens until log limit is hit.
+
+ if (offset > base::Milliseconds(50)) {
+ EXPECT_LIMITED_MEDIA_LOG(HasSubstr("timestamp gap detected"),
+ num_timestamp_gap_warnings,
+ kMaxTimestampGapWarnings);
}
validator.CheckForTimestampGap(*encoded_buffer);
scoped_refptr<AudioBuffer> decoded_buffer = MakeAudioBuffer<float>(
kSampleFormat, kChannelLayout, kChannelCount, kSamplesPerSecond, 1.0f,
0.0f, kFramesPerBuffer, i * kBufferDuration);
- validator.RecordOutputDuration(decoded_buffer.get());
+ validator.RecordOutputDuration(*decoded_buffer);
}
}
}
// Test with cartesian product of various output delay, codec delay, and front
// discard values. These simulate configurations for different containers/codecs
// which present different challenges when building timestamp expectations.
-INSTANTIATE_TEST_CASE_P(
- ,
+INSTANTIATE_TEST_SUITE_P(
+ All,
AudioTimestampValidatorTest,
- ::testing::Combine(
- ::testing::Values(0, 10), // output delay
- ::testing::Values(0, 512), // codec delay
- ::testing::Values(base::TimeDelta(), // front discard
- base::TimeDelta::FromMilliseconds(65))));
+ ::testing::Combine(::testing::Values(0, 10), // output delay
+ ::testing::Values(0, 512), // codec delay
+ ::testing::Values(base::TimeDelta(), // front discard
+ base::Milliseconds(65))));
-} // namespace media
\ No newline at end of file
+} // namespace media