| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "media/base/audio_buffer.h" | 6 #include "media/base/audio_buffer.h" |
| 7 #include "media/base/audio_buffer_converter.h" | 7 #include "media/base/audio_buffer_converter.h" |
| 8 #include "media/base/sinc_resampler.h" | 8 #include "media/base/sinc_resampler.h" |
| 9 #include "media/base/test_helpers.h" | 9 #include "media/base/test_helpers.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace media { | 13 namespace media { |
| 14 | 14 |
| 15 // Important: Use an odd buffer size here so SIMD issues are caught. |
| 16 const int kOutFrameSize = 441; |
| 15 const int kOutSampleRate = 44100; | 17 const int kOutSampleRate = 44100; |
| 16 const ChannelLayout kOutChannelLayout = CHANNEL_LAYOUT_STEREO; | 18 const ChannelLayout kOutChannelLayout = CHANNEL_LAYOUT_STEREO; |
| 17 | 19 |
| 18 static scoped_refptr<AudioBuffer> MakeTestBuffer(int sample_rate, | 20 static scoped_refptr<AudioBuffer> MakeTestBuffer(int sample_rate, |
| 19 ChannelLayout channel_layout, | 21 ChannelLayout channel_layout, |
| 20 int frames) { | 22 int frames) { |
| 21 return MakeAudioBuffer<uint8>(kSampleFormatU8, | 23 return MakeAudioBuffer<uint8>(kSampleFormatU8, |
| 22 channel_layout, | 24 channel_layout, |
| 23 sample_rate, | 25 sample_rate, |
| 24 0, | 26 0, |
| 25 1, | 27 1, |
| 26 frames, | 28 frames, |
| 27 base::TimeDelta::FromSeconds(0), | 29 base::TimeDelta::FromSeconds(0), |
| 28 base::TimeDelta::FromSeconds(0)); | 30 base::TimeDelta::FromSeconds(0)); |
| 29 } | 31 } |
| 30 | 32 |
| 31 class AudioBufferConverterTest : public ::testing::Test { | 33 class AudioBufferConverterTest : public ::testing::Test { |
| 32 public: | 34 public: |
| 33 AudioBufferConverterTest() | 35 AudioBufferConverterTest() |
| 34 : input_frames_(0), expected_output_frames_(0.0), output_frames_(0) { | 36 : input_frames_(0), expected_output_frames_(0.0), output_frames_(0) { |
| 35 AudioParameters output_params(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 37 AudioParameters output_params(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 36 kOutChannelLayout, | 38 kOutChannelLayout, |
| 37 kOutSampleRate, | 39 kOutSampleRate, |
| 38 16, | 40 16, |
| 39 512); | 41 kOutFrameSize); |
| 40 audio_buffer_converter_.reset(new AudioBufferConverter(output_params)); | 42 audio_buffer_converter_.reset(new AudioBufferConverter(output_params)); |
| 41 } | 43 } |
| 42 | 44 |
| 43 void Reset() { | 45 void Reset() { |
| 44 audio_buffer_converter_->Reset(); | 46 audio_buffer_converter_->Reset(); |
| 45 output_frames_ = expected_output_frames_ = input_frames_ = 0; | 47 output_frames_ = expected_output_frames_ = input_frames_ = 0; |
| 46 } | 48 } |
| 47 | 49 |
| 48 void AddInput(const scoped_refptr<AudioBuffer>& in) { | 50 void AddInput(const scoped_refptr<AudioBuffer>& in) { |
| 49 if (!in->end_of_stream()) { | 51 if (!in->end_of_stream()) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 179 |
| 178 TEST_F(AudioBufferConverterTest, ResetThenConvert) { | 180 TEST_F(AudioBufferConverterTest, ResetThenConvert) { |
| 179 AddInput(MakeTestBuffer(kOutSampleRate, kOutChannelLayout, 512)); | 181 AddInput(MakeTestBuffer(kOutSampleRate, kOutChannelLayout, 512)); |
| 180 Reset(); | 182 Reset(); |
| 181 // Make sure we can keep using the AudioBufferConverter after we've Reset(). | 183 // Make sure we can keep using the AudioBufferConverter after we've Reset(). |
| 182 AddInput(MakeTestBuffer(kOutSampleRate, kOutChannelLayout, 512)); | 184 AddInput(MakeTestBuffer(kOutSampleRate, kOutChannelLayout, 512)); |
| 183 ConsumeAllOutput(); | 185 ConsumeAllOutput(); |
| 184 } | 186 } |
| 185 | 187 |
| 186 } // namespace media | 188 } // namespace media |
| OLD | NEW |