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

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

Issue 1906423005: Replace scoped_ptr with std::unique_ptr in //media/base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-media-base: android Created 4 years, 7 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
« no previous file with comments | « media/base/audio_converter_perftest.cc ('k') | media/base/audio_discard_helper_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // MSVC++ requires this to be set before any other includes to get M_PI. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include "media/base/audio_converter.h"
9
8 #include <stddef.h> 10 #include <stddef.h>
9 11
10 #include <cmath> 12 #include <cmath>
13 #include <memory>
11 14
12 #include "base/macros.h" 15 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
15 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
16 #include "media/base/audio_converter.h"
17 #include "media/base/fake_audio_render_callback.h" 18 #include "media/base/fake_audio_render_callback.h"
18 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace media { 22 namespace media {
22 23
23 // Parameters which control the many input case tests. 24 // Parameters which control the many input case tests.
24 static const int kConvertInputs = 8; 25 static const int kConvertInputs = 8;
25 static const int kConvertCycles = 3; 26 static const int kConvertCycles = 3;
26 27
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 SetVolume(1); 165 SetVolume(1);
165 float scale = inputs > 1 ? inputs / 2.0f : inputs; 166 float scale = inputs > 1 ? inputs / 2.0f : inputs;
166 for (int i = 0; i < kConvertCycles; ++i) 167 for (int i = 0; i < kConvertCycles; ++i)
167 ASSERT_TRUE(RenderAndValidateAudioData(scale)); 168 ASSERT_TRUE(RenderAndValidateAudioData(scale));
168 } 169 }
169 170
170 protected: 171 protected:
171 virtual ~AudioConverterTest() {} 172 virtual ~AudioConverterTest() {}
172 173
173 // Converter under test. 174 // Converter under test.
174 scoped_ptr<AudioConverter> converter_; 175 std::unique_ptr<AudioConverter> converter_;
175 176
176 // Input and output parameters used for AudioConverter construction. 177 // Input and output parameters used for AudioConverter construction.
177 AudioParameters input_parameters_; 178 AudioParameters input_parameters_;
178 AudioParameters output_parameters_; 179 AudioParameters output_parameters_;
179 180
180 // Destination AudioBus for AudioConverter output. 181 // Destination AudioBus for AudioConverter output.
181 scoped_ptr<AudioBus> audio_bus_; 182 std::unique_ptr<AudioBus> audio_bus_;
182 183
183 // AudioBus containing expected results for comparison with |audio_bus_|. 184 // AudioBus containing expected results for comparison with |audio_bus_|.
184 scoped_ptr<AudioBus> expected_audio_bus_; 185 std::unique_ptr<AudioBus> expected_audio_bus_;
185 186
186 // Vector of all input callbacks used to drive AudioConverter::Convert(). 187 // Vector of all input callbacks used to drive AudioConverter::Convert().
187 ScopedVector<FakeAudioRenderCallback> fake_callbacks_; 188 ScopedVector<FakeAudioRenderCallback> fake_callbacks_;
188 189
189 // Parallel input callback which generates the expected output. 190 // Parallel input callback which generates the expected output.
190 scoped_ptr<FakeAudioRenderCallback> expected_callback_; 191 std::unique_ptr<FakeAudioRenderCallback> expected_callback_;
191 192
192 // Epsilon value with which to perform comparisons between |audio_bus_| and 193 // Epsilon value with which to perform comparisons between |audio_bus_| and
193 // |expected_audio_bus_|. 194 // |expected_audio_bus_|.
194 double epsilon_; 195 double epsilon_;
195 196
196 DISALLOW_COPY_AND_ASSIGN(AudioConverterTest); 197 DISALLOW_COPY_AND_ASSIGN(AudioConverterTest);
197 }; 198 };
198 199
199 // Ensure the buffer delay provided by AudioConverter is accurate. 200 // Ensure the buffer delay provided by AudioConverter is accurate.
200 TEST(AudioConverterTest, AudioDelayAndDiscreteChannelCount) { 201 TEST(AudioConverterTest, AudioDelayAndDiscreteChannelCount) {
201 // Choose input and output parameters such that the transform must make 202 // Choose input and output parameters such that the transform must make
202 // multiple calls to fill the buffer. 203 // multiple calls to fill the buffer.
203 AudioParameters input_parameters(AudioParameters::AUDIO_PCM_LINEAR, 204 AudioParameters input_parameters(AudioParameters::AUDIO_PCM_LINEAR,
204 CHANNEL_LAYOUT_DISCRETE, kSampleRate, 205 CHANNEL_LAYOUT_DISCRETE, kSampleRate,
205 kBitsPerChannel, kLowLatencyBufferSize); 206 kBitsPerChannel, kLowLatencyBufferSize);
206 input_parameters.set_channels_for_discrete(10); 207 input_parameters.set_channels_for_discrete(10);
207 AudioParameters output_parameters(AudioParameters::AUDIO_PCM_LINEAR, 208 AudioParameters output_parameters(AudioParameters::AUDIO_PCM_LINEAR,
208 CHANNEL_LAYOUT_DISCRETE, kSampleRate * 2, 209 CHANNEL_LAYOUT_DISCRETE, kSampleRate * 2,
209 kBitsPerChannel, kHighLatencyBufferSize); 210 kBitsPerChannel, kHighLatencyBufferSize);
210 output_parameters.set_channels_for_discrete(5); 211 output_parameters.set_channels_for_discrete(5);
211 212
212 AudioConverter converter(input_parameters, output_parameters, false); 213 AudioConverter converter(input_parameters, output_parameters, false);
213 FakeAudioRenderCallback callback(0.2); 214 FakeAudioRenderCallback callback(0.2);
214 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(output_parameters); 215 std::unique_ptr<AudioBus> audio_bus = AudioBus::Create(output_parameters);
215 converter.AddInput(&callback); 216 converter.AddInput(&callback);
216 converter.Convert(audio_bus.get()); 217 converter.Convert(audio_bus.get());
217 218
218 // Calculate the expected buffer delay for given AudioParameters. 219 // Calculate the expected buffer delay for given AudioParameters.
219 double input_sample_rate = input_parameters.sample_rate(); 220 double input_sample_rate = input_parameters.sample_rate();
220 int fill_count = 221 int fill_count =
221 (output_parameters.frames_per_buffer() * input_sample_rate / 222 (output_parameters.frames_per_buffer() * input_sample_rate /
222 output_parameters.sample_rate()) / input_parameters.frames_per_buffer(); 223 output_parameters.sample_rate()) / input_parameters.frames_per_buffer();
223 224
224 base::TimeDelta input_frame_duration = base::TimeDelta::FromMicroseconds( 225 base::TimeDelta input_frame_duration = base::TimeDelta::FromMicroseconds(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 // No resampling. No channel mixing. 259 // No resampling. No channel mixing.
259 std::tr1::make_tuple(44100, 44100, CHANNEL_LAYOUT_STEREO, 0.00000048), 260 std::tr1::make_tuple(44100, 44100, CHANNEL_LAYOUT_STEREO, 0.00000048),
260 261
261 // Upsampling. Channel upmixing. 262 // Upsampling. Channel upmixing.
262 std::tr1::make_tuple(44100, 48000, CHANNEL_LAYOUT_QUAD, 0.033), 263 std::tr1::make_tuple(44100, 48000, CHANNEL_LAYOUT_QUAD, 0.033),
263 264
264 // Downsampling. Channel downmixing. 265 // Downsampling. Channel downmixing.
265 std::tr1::make_tuple(48000, 41000, CHANNEL_LAYOUT_MONO, 0.042))); 266 std::tr1::make_tuple(48000, 41000, CHANNEL_LAYOUT_MONO, 0.042)));
266 267
267 } // namespace media 268 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_converter_perftest.cc ('k') | media/base/audio_discard_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698