| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/base/audio_discard_helper.h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 | 8 |
| 7 #include "base/memory/scoped_ptr.h" | 9 #include <memory> |
| 10 |
| 8 #include "media/base/audio_buffer.h" | 11 #include "media/base/audio_buffer.h" |
| 9 #include "media/base/audio_bus.h" | 12 #include "media/base/audio_bus.h" |
| 10 #include "media/base/audio_discard_helper.h" | |
| 11 #include "media/base/decoder_buffer.h" | 13 #include "media/base/decoder_buffer.h" |
| 12 #include "media/base/test_helpers.h" | 14 #include "media/base/test_helpers.h" |
| 13 #include "media/base/timestamp_constants.h" | 15 #include "media/base/timestamp_constants.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 17 |
| 16 namespace media { | 18 namespace media { |
| 17 | 19 |
| 18 static const float kDataStep = 0.01f; | 20 static const float kDataStep = 0.01f; |
| 19 static const size_t kSampleRate = 48000; | 21 static const size_t kSampleRate = 48000; |
| 20 | 22 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 35 0.0f, | 37 0.0f, |
| 36 kDataStep, | 38 kDataStep, |
| 37 frames, | 39 frames, |
| 38 kNoTimestamp()); | 40 kNoTimestamp()); |
| 39 } | 41 } |
| 40 | 42 |
| 41 static float ExtractDecodedData(const scoped_refptr<AudioBuffer>& buffer, | 43 static float ExtractDecodedData(const scoped_refptr<AudioBuffer>& buffer, |
| 42 int index) { | 44 int index) { |
| 43 // This is really inefficient, but we can't access the raw AudioBuffer if any | 45 // This is really inefficient, but we can't access the raw AudioBuffer if any |
| 44 // start trimming has been applied. | 46 // start trimming has been applied. |
| 45 scoped_ptr<AudioBus> temp_bus = AudioBus::Create(buffer->channel_count(), 1); | 47 std::unique_ptr<AudioBus> temp_bus = |
| 48 AudioBus::Create(buffer->channel_count(), 1); |
| 46 buffer->ReadFrames(1, index, 0, temp_bus.get()); | 49 buffer->ReadFrames(1, index, 0, temp_bus.get()); |
| 47 return temp_bus->channel(0)[0]; | 50 return temp_bus->channel(0)[0]; |
| 48 } | 51 } |
| 49 | 52 |
| 50 TEST(AudioDiscardHelperTest, TimeDeltaToFrames) { | 53 TEST(AudioDiscardHelperTest, TimeDeltaToFrames) { |
| 51 AudioDiscardHelper discard_helper(kSampleRate, 0); | 54 AudioDiscardHelper discard_helper(kSampleRate, 0); |
| 52 | 55 |
| 53 EXPECT_EQ(0u, discard_helper.TimeDeltaToFrames(base::TimeDelta())); | 56 EXPECT_EQ(0u, discard_helper.TimeDeltaToFrames(base::TimeDelta())); |
| 54 EXPECT_EQ( | 57 EXPECT_EQ( |
| 55 kSampleRate / 100, | 58 kSampleRate / 100, |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 decoded_buffer = CreateDecodedBuffer(kTestFrames * 2); | 547 decoded_buffer = CreateDecodedBuffer(kTestFrames * 2); |
| 545 ASSERT_TRUE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); | 548 ASSERT_TRUE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); |
| 546 EXPECT_EQ(kTimestamp, decoded_buffer->timestamp()); | 549 EXPECT_EQ(kTimestamp, decoded_buffer->timestamp()); |
| 547 EXPECT_EQ(kDuration * 2 - kDuration / 2, decoded_buffer->duration()); | 550 EXPECT_EQ(kDuration * 2 - kDuration / 2, decoded_buffer->duration()); |
| 548 EXPECT_EQ(kTestFrames * 2 - kDecoderDelay, decoded_buffer->frame_count()); | 551 EXPECT_EQ(kTestFrames * 2 - kDecoderDelay, decoded_buffer->frame_count()); |
| 549 ASSERT_FLOAT_EQ(kDecoderDelay * kDataStep, | 552 ASSERT_FLOAT_EQ(kDecoderDelay * kDataStep, |
| 550 ExtractDecodedData(decoded_buffer, 0)); | 553 ExtractDecodedData(decoded_buffer, 0)); |
| 551 } | 554 } |
| 552 | 555 |
| 553 } // namespace media | 556 } // namespace media |
| OLD | NEW |