Revert "[M120 Migration]Fix for crash during chrome exit"
[platform/framework/web/chromium-efl.git] / media / filters / audio_timestamp_validator_unittest.cc
index af1833c..862ed55 100644 (file)
@@ -1,4 +1,4 @@
-// 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.
 
@@ -18,12 +18,11 @@ using ::testing::HasSubstr;
 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);
@@ -62,8 +61,9 @@ class AudioTimestampValidatorTest
 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(
@@ -76,18 +76,17 @@ TEST_P(AudioTimestampValidatorTest, WarnForEraticTimes) {
 
   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) {
@@ -103,7 +102,7 @@ TEST_P(AudioTimestampValidatorTest, WarnForEraticTimes) {
       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);
     }
   }
 }
@@ -111,8 +110,9 @@ TEST_P(AudioTimestampValidatorTest, WarnForEraticTimes) {
 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 "
@@ -126,7 +126,7 @@ TEST_P(AudioTimestampValidatorTest, NoWarningForValidTimes) {
 
   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) {
@@ -142,7 +142,7 @@ TEST_P(AudioTimestampValidatorTest, NoWarningForValidTimes) {
       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);
     }
   }
 }
@@ -150,8 +150,9 @@ TEST_P(AudioTimestampValidatorTest, NoWarningForValidTimes) {
 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_);
 
@@ -164,14 +165,14 @@ TEST_P(AudioTimestampValidatorTest, SingleWarnForSingleLargeGap) {
     // 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) {
@@ -187,7 +188,7 @@ TEST_P(AudioTimestampValidatorTest, SingleWarnForSingleLargeGap) {
       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);
     }
   }
 }
@@ -195,8 +196,9 @@ TEST_P(AudioTimestampValidatorTest, SingleWarnForSingleLargeGap) {
 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_);
 
@@ -204,6 +206,9 @@ TEST_P(AudioTimestampValidatorTest, RepeatedWarnForSlowAccumulatingDrift) {
                              "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
@@ -212,15 +217,18 @@ TEST_P(AudioTimestampValidatorTest, RepeatedWarnForSlowAccumulatingDrift) {
     // 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);
@@ -231,7 +239,7 @@ TEST_P(AudioTimestampValidatorTest, RepeatedWarnForSlowAccumulatingDrift) {
       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);
     }
   }
 }
@@ -239,13 +247,12 @@ TEST_P(AudioTimestampValidatorTest, RepeatedWarnForSlowAccumulatingDrift) {
 // 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