Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: media/base/audio_buffer_converter_unittest.cc

Issue 245523002: Merge 264918 "Fix the output request size for AudioBufferConvert..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1916/src/
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/audio_buffer_converter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 18 matching lines...) Expand all
29 0, 29 0,
30 1, 30 1,
31 frames, 31 frames,
32 base::TimeDelta::FromSeconds(0), 32 base::TimeDelta::FromSeconds(0),
33 base::TimeDelta::FromSeconds(0)); 33 base::TimeDelta::FromSeconds(0));
34 } 34 }
35 35
36 class AudioBufferConverterTest : public ::testing::Test { 36 class AudioBufferConverterTest : public ::testing::Test {
37 public: 37 public:
38 AudioBufferConverterTest() 38 AudioBufferConverterTest()
39 : input_frames_(0), expected_output_frames_(0.0), output_frames_(0) { 39 : input_frames_(0),
40 AudioParameters output_params(AudioParameters::AUDIO_PCM_LOW_LATENCY, 40 expected_output_frames_(0.0),
41 kOutChannelLayout, 41 output_frames_(0),
42 kOutSampleRate, 42 output_params_(AudioParameters::AUDIO_PCM_LOW_LATENCY,
43 16, 43 kOutChannelLayout,
44 kOutFrameSize); 44 kOutSampleRate,
45 ResetConverter(output_params); 45 16,
46 kOutFrameSize) {
47 audio_buffer_converter_.reset(new AudioBufferConverter(output_params_));
46 } 48 }
47 49
48 void Reset() { 50 void Reset() {
49 audio_buffer_converter_->Reset(); 51 audio_buffer_converter_->Reset();
50 output_frames_ = expected_output_frames_ = input_frames_ = 0; 52 output_frames_ = expected_output_frames_ = input_frames_ = 0;
51 } 53 }
52 54
53 void AddInput(const scoped_refptr<AudioBuffer>& in) { 55 void AddInput(const scoped_refptr<AudioBuffer>& in) {
54 if (!in->end_of_stream()) { 56 if (!in->end_of_stream()) {
55 input_frames_ += in->frame_count(); 57 input_frames_ += in->frame_count();
56 expected_output_frames_ += 58 expected_output_frames_ +=
57 in->frame_count() * 59 in->frame_count() *
58 (static_cast<double>(kOutSampleRate) / in->sample_rate()); 60 (static_cast<double>(output_params_.sample_rate()) /
61 in->sample_rate());
59 } 62 }
60 audio_buffer_converter_->AddInput(in); 63 audio_buffer_converter_->AddInput(in);
61 } 64 }
62 65
66 void ConsumeOutput() {
67 ASSERT_TRUE(audio_buffer_converter_->HasNextBuffer());
68 scoped_refptr<AudioBuffer> out = audio_buffer_converter_->GetNextBuffer();
69 if (!out->end_of_stream()) {
70 output_frames_ += out->frame_count();
71 EXPECT_EQ(out->sample_rate(), output_params_.sample_rate());
72 EXPECT_EQ(out->channel_layout(), output_params_.channel_layout());
73 EXPECT_EQ(out->channel_count(), output_params_.channels());
74 } else {
75 EXPECT_FALSE(audio_buffer_converter_->HasNextBuffer());
76 }
77 }
78
63 void ConsumeAllOutput() { 79 void ConsumeAllOutput() {
64 AddInput(AudioBuffer::CreateEOSBuffer()); 80 AddInput(AudioBuffer::CreateEOSBuffer());
65 while (audio_buffer_converter_->HasNextBuffer()) { 81 while (audio_buffer_converter_->HasNextBuffer())
66 scoped_refptr<AudioBuffer> out = audio_buffer_converter_->GetNextBuffer(); 82 ConsumeOutput();
67 if (!out->end_of_stream()) {
68 output_frames_ += out->frame_count();
69 EXPECT_EQ(out->sample_rate(), out_sample_rate_);
70 EXPECT_EQ(out->channel_layout(), out_channel_layout_);
71 EXPECT_EQ(out->channel_count(), out_channel_count_);
72 } else {
73 EXPECT_FALSE(audio_buffer_converter_->HasNextBuffer());
74 }
75 }
76 EXPECT_EQ(output_frames_, ceil(expected_output_frames_)); 83 EXPECT_EQ(output_frames_, ceil(expected_output_frames_));
77 } 84 }
78 85
79 void ResetConverter(AudioParameters out_params) { 86 protected:
80 audio_buffer_converter_.reset(new AudioBufferConverter(out_params));
81 out_channel_layout_ = out_params.channel_layout();
82 out_channel_count_ = out_params.channels();
83 out_sample_rate_ = out_params.sample_rate();
84 }
85
86 private:
87 scoped_ptr<AudioBufferConverter> audio_buffer_converter_; 87 scoped_ptr<AudioBufferConverter> audio_buffer_converter_;
88 88
89 int input_frames_; 89 int input_frames_;
90 double expected_output_frames_; 90 double expected_output_frames_;
91 int output_frames_; 91 int output_frames_;
92 92 int input_buffers_;
93 int out_sample_rate_; 93 AudioParameters output_params_;
94 ChannelLayout out_channel_layout_;
95 int out_channel_count_;
96 }; 94 };
97 95
98 TEST_F(AudioBufferConverterTest, PassThrough) { 96 TEST_F(AudioBufferConverterTest, PassThrough) {
99 scoped_refptr<AudioBuffer> in = 97 scoped_refptr<AudioBuffer> in =
100 MakeTestBuffer(kOutSampleRate, kOutChannelLayout, kOutChannelCount, 512); 98 MakeTestBuffer(kOutSampleRate, kOutChannelLayout, kOutChannelCount, 512);
101 AddInput(in); 99 AddInput(in);
102 ConsumeAllOutput(); 100 ConsumeAllOutput();
103 } 101 }
104 102
105 TEST_F(AudioBufferConverterTest, Downsample) { 103 TEST_F(AudioBufferConverterTest, Downsample) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 AddInput( 201 AddInput(
204 MakeTestBuffer(kOutSampleRate, kOutChannelLayout, kOutChannelCount, 512)); 202 MakeTestBuffer(kOutSampleRate, kOutChannelLayout, kOutChannelCount, 512));
205 Reset(); 203 Reset();
206 // Make sure we can keep using the AudioBufferConverter after we've Reset(). 204 // Make sure we can keep using the AudioBufferConverter after we've Reset().
207 AddInput( 205 AddInput(
208 MakeTestBuffer(kOutSampleRate, kOutChannelLayout, kOutChannelCount, 512)); 206 MakeTestBuffer(kOutSampleRate, kOutChannelLayout, kOutChannelCount, 512));
209 ConsumeAllOutput(); 207 ConsumeAllOutput();
210 } 208 }
211 209
212 TEST_F(AudioBufferConverterTest, DiscreteChannelLayout) { 210 TEST_F(AudioBufferConverterTest, DiscreteChannelLayout) {
213 AudioParameters output_params(AudioParameters::AUDIO_PCM_LOW_LATENCY, 211 output_params_ = AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
214 CHANNEL_LAYOUT_DISCRETE, 212 CHANNEL_LAYOUT_DISCRETE,
215 2, 213 2,
216 0, 214 0,
217 kOutSampleRate, 215 kOutSampleRate,
218 16, 216 16,
219 512, 217 512,
220 0); 218 0);
221 ResetConverter(output_params); 219 audio_buffer_converter_.reset(new AudioBufferConverter(output_params_));
222 AddInput(MakeTestBuffer(kOutSampleRate, CHANNEL_LAYOUT_STEREO, 2, 512)); 220 AddInput(MakeTestBuffer(kOutSampleRate, CHANNEL_LAYOUT_STEREO, 2, 512));
223 ConsumeAllOutput(); 221 ConsumeAllOutput();
224 } 222 }
225 223
224 TEST_F(AudioBufferConverterTest, LargeBuffersResampling) {
225 output_params_ = AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
226 kOutChannelLayout,
227 kOutSampleRate,
228 16,
229 2048);
230
231 audio_buffer_converter_.reset(new AudioBufferConverter(output_params_));
232 const int kInputSampleRate = 48000;
233 const int kInputFrameSize = 8192;
234 ASSERT_NE(kInputSampleRate, kOutSampleRate);
235
236 const int kInputBuffers = 3;
237 for (int i = 0; i < kInputBuffers; ++i) {
238 AddInput(MakeTestBuffer(kInputSampleRate,
239 kOutChannelLayout,
240 kOutChannelCount,
241 kInputFrameSize));
242 }
243
244 // Do not add an EOS packet here, as it will invoke flushing.
245 while (audio_buffer_converter_->HasNextBuffer())
246 ConsumeOutput();
247
248 // Since the input buffer size is a multiple of the input request size there
249 // should never be any frames remaining at this point.
250 ASSERT_EQ(kInputFrameSize %
251 audio_buffer_converter_->input_buffer_size_for_testing(),
252 0);
253 EXPECT_EQ(0, audio_buffer_converter_->input_frames_left_for_testing());
254 }
255
226 } // namespace media 256 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_buffer_converter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698