| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "media/base/audio_pull_fifo.h" | 8 #include "media/base/audio_pull_fifo.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // Max number of audio framed the FIFO can contain. | 22 // Max number of audio framed the FIFO can contain. |
| 23 static const int kMaxFramesInFifo = 2048; | 23 static const int kMaxFramesInFifo = 2048; |
| 24 | 24 |
| 25 class AudioPullFifoTest | 25 class AudioPullFifoTest |
| 26 : public testing::TestWithParam<int> { | 26 : public testing::TestWithParam<int> { |
| 27 public: | 27 public: |
| 28 AudioPullFifoTest() | 28 AudioPullFifoTest() |
| 29 : pull_fifo_(kChannels, kMaxFramesInFifo, base::Bind( | 29 : pull_fifo_(kChannels, kMaxFramesInFifo, base::Bind( |
| 30 &AudioPullFifoTest::ProvideInput, base::Unretained(this))), | 30 &AudioPullFifoTest::ProvideInput, base::Unretained(this))), |
| 31 audio_bus_(AudioBus::Create(kChannels, kMaxFramesInFifo)), | 31 audio_bus_(AudioBus::Create(kChannels, kMaxFramesInFifo)), |
| 32 fill_value_(0) {} | 32 fill_value_(0), |
| 33 last_frame_delay_(-1) {} |
| 33 virtual ~AudioPullFifoTest() {} | 34 virtual ~AudioPullFifoTest() {} |
| 34 | 35 |
| 35 void VerifyValue(const float data[], int size, float start_value) { | 36 void VerifyValue(const float data[], int size, float start_value) { |
| 36 float value = start_value; | 37 float value = start_value; |
| 37 for (int i = 0; i < size; ++i) { | 38 for (int i = 0; i < size; ++i) { |
| 38 ASSERT_FLOAT_EQ(value++, data[i]) << "i=" << i; | 39 ASSERT_FLOAT_EQ(value++, data[i]) << "i=" << i; |
| 39 } | 40 } |
| 40 } | 41 } |
| 41 | 42 |
| 42 // Consume data using different sizes, acquire audio frames from the FIFO | 43 // Consume data using different sizes, acquire audio frames from the FIFO |
| 43 // and verify that the retrieved values matches the values written by the | 44 // and verify that the retrieved values matches the values written by the |
| 44 // producer. | 45 // producer. |
| 45 void ConsumeTest(int frames_to_consume) { | 46 void ConsumeTest(int frames_to_consume) { |
| 46 int start_value = 0; | 47 int start_value = 0; |
| 47 SCOPED_TRACE(base::StringPrintf("Checking frames_to_consume %d", | 48 SCOPED_TRACE(base::StringPrintf("Checking frames_to_consume %d", |
| 48 frames_to_consume)); | 49 frames_to_consume)); |
| 49 pull_fifo_.Consume(audio_bus_.get(), frames_to_consume); | 50 pull_fifo_.Consume(audio_bus_.get(), frames_to_consume); |
| 50 for (int j = 0; j < kChannels; ++j) { | 51 for (int j = 0; j < kChannels; ++j) { |
| 51 VerifyValue(audio_bus_->channel(j), frames_to_consume, start_value); | 52 VerifyValue(audio_bus_->channel(j), frames_to_consume, start_value); |
| 52 } | 53 } |
| 53 start_value += frames_to_consume; | 54 start_value += frames_to_consume; |
| 55 EXPECT_LT(last_frame_delay_, audio_bus_->frames()); |
| 54 } | 56 } |
| 55 | 57 |
| 56 // AudioPullFifo::ReadCB implementation where we increase a value for each | 58 // AudioPullFifo::ReadCB implementation where we increase a value for each |
| 57 // audio frame that we provide. Note that all channels are given the same | 59 // audio frame that we provide. Note that all channels are given the same |
| 58 // value to simplify the verification. | 60 // value to simplify the verification. |
| 59 virtual void ProvideInput(AudioBus* audio_bus) { | 61 virtual void ProvideInput(int frame_delay, AudioBus* audio_bus) { |
| 62 ASSERT_GT(frame_delay, last_frame_delay_); |
| 63 last_frame_delay_ = frame_delay; |
| 64 |
| 60 EXPECT_EQ(audio_bus->channels(), audio_bus_->channels()); | 65 EXPECT_EQ(audio_bus->channels(), audio_bus_->channels()); |
| 61 EXPECT_EQ(audio_bus->frames(), kMaxFramesInFifo); | 66 EXPECT_EQ(audio_bus->frames(), kMaxFramesInFifo); |
| 62 for (int i = 0; i < audio_bus->frames(); ++i) { | 67 for (int i = 0; i < audio_bus->frames(); ++i) { |
| 63 for (int j = 0; j < audio_bus->channels(); ++j) { | 68 for (int j = 0; j < audio_bus->channels(); ++j) { |
| 64 // Store same value in all channels. | 69 // Store same value in all channels. |
| 65 audio_bus->channel(j)[i] = fill_value_; | 70 audio_bus->channel(j)[i] = fill_value_; |
| 66 } | 71 } |
| 67 fill_value_++; | 72 fill_value_++; |
| 68 } | 73 } |
| 69 } | 74 } |
| 70 | 75 |
| 71 protected: | 76 protected: |
| 72 AudioPullFifo pull_fifo_; | 77 AudioPullFifo pull_fifo_; |
| 73 scoped_ptr<AudioBus> audio_bus_; | 78 scoped_ptr<AudioBus> audio_bus_; |
| 74 int fill_value_; | 79 int fill_value_; |
| 80 int last_frame_delay_; |
| 75 | 81 |
| 76 DISALLOW_COPY_AND_ASSIGN(AudioPullFifoTest); | 82 DISALLOW_COPY_AND_ASSIGN(AudioPullFifoTest); |
| 77 }; | 83 }; |
| 78 | 84 |
| 79 TEST_P(AudioPullFifoTest, Consume) { | 85 TEST_P(AudioPullFifoTest, Consume) { |
| 80 ConsumeTest(GetParam()); | 86 ConsumeTest(GetParam()); |
| 81 } | 87 } |
| 82 | 88 |
| 83 // Test common |frames_to_consume| values which will be used as input | 89 // Test common |frames_to_consume| values which will be used as input |
| 84 // parameter to AudioPullFifo::Consume() when the consumer asks for data. | 90 // parameter to AudioPullFifo::Consume() when the consumer asks for data. |
| 85 INSTANTIATE_TEST_CASE_P( | 91 INSTANTIATE_TEST_CASE_P( |
| 86 AudioPullFifoTest, AudioPullFifoTest, | 92 AudioPullFifoTest, AudioPullFifoTest, |
| 87 testing::Values(544, 512, 512, 512, 512, 2048, 544, 441, 440, 433, 500)); | 93 testing::Values(544, 512, 512, 512, 512, 2048, 544, 441, 440, 433, 500)); |
| 88 | 94 |
| 89 } // namespace media | 95 } // namespace media |
| OLD | NEW |