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

Side by Side Diff: media/audio/audio_low_latency_input_output_unittest.cc

Issue 12316131: Moved AudioUtil static functions to AudioManager interfaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: made the GetPreferredOutputStreamParameters protected Created 7 years, 9 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/audio/audio_input_volume_unittest.cc ('k') | media/audio/audio_manager.h » ('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 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/environment.h" 6 #include "base/environment.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
12 #include "base/test/test_timeouts.h" 12 #include "base/test/test_timeouts.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "media/audio/audio_io.h" 15 #include "media/audio/audio_io.h"
16 #include "media/audio/audio_manager_base.h" 16 #include "media/audio/audio_manager_base.h"
17 #include "media/audio/audio_util.h"
18 #include "media/base/seekable_buffer.h" 17 #include "media/base/seekable_buffer.h"
19 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 20
22 #if defined(OS_LINUX) || defined(OS_OPENBSD) 21 #if defined(OS_LINUX) || defined(OS_OPENBSD)
23 #include "media/audio/linux/audio_manager_linux.h" 22 #include "media/audio/linux/audio_manager_linux.h"
24 #elif defined(OS_MACOSX) 23 #elif defined(OS_MACOSX)
25 #include "media/audio/mac/audio_manager_mac.h" 24 #include "media/audio/mac/audio_manager_mac.h"
26 #elif defined(OS_WIN) 25 #elif defined(OS_WIN)
27 #include "media/audio/win/audio_manager_win.h" 26 #include "media/audio/win/audio_manager_win.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 scoped_array<AudioDelayState> delay_states_; 278 scoped_array<AudioDelayState> delay_states_;
280 size_t input_elements_to_write_; 279 size_t input_elements_to_write_;
281 size_t output_elements_to_write_; 280 size_t output_elements_to_write_;
282 base::Time previous_write_time_; 281 base::Time previous_write_time_;
283 }; 282 };
284 283
285 class AudioInputStreamTraits { 284 class AudioInputStreamTraits {
286 public: 285 public:
287 typedef AudioInputStream StreamType; 286 typedef AudioInputStream StreamType;
288 287
289 static int HardwareSampleRate() { 288 static AudioParameters GetDefaultAudioStreamParameters(
290 return static_cast<int>(media::GetAudioInputHardwareSampleRate( 289 AudioManager* audio_manager) {
291 AudioManagerBase::kDefaultDeviceId)); 290 return audio_manager->GetInputStreamParameters(
292 } 291 AudioManagerBase::kDefaultDeviceId);
293
294 // TODO(henrika): add support for GetAudioInputHardwareBufferSize in media.
295 static int HardwareBufferSize() {
296 return static_cast<int>(media::GetAudioHardwareBufferSize());
297 } 292 }
298 293
299 static StreamType* CreateStream(AudioManager* audio_manager, 294 static StreamType* CreateStream(AudioManager* audio_manager,
300 const AudioParameters& params) { 295 const AudioParameters& params) {
301 return audio_manager->MakeAudioInputStream(params, 296 return audio_manager->MakeAudioInputStream(params,
302 AudioManagerBase::kDefaultDeviceId); 297 AudioManagerBase::kDefaultDeviceId);
303 } 298 }
304 }; 299 };
305 300
306 class AudioOutputStreamTraits { 301 class AudioOutputStreamTraits {
307 public: 302 public:
308 typedef AudioOutputStream StreamType; 303 typedef AudioOutputStream StreamType;
309 304
310 static int HardwareSampleRate() { 305 static AudioParameters GetDefaultAudioStreamParameters(
311 return static_cast<int>(media::GetAudioHardwareSampleRate()); 306 AudioManager* audio_manager) {
312 } 307 return audio_manager->GetDefaultOutputStreamParameters();
313
314 static int HardwareBufferSize() {
315 return static_cast<int>(media::GetAudioHardwareBufferSize());
316 } 308 }
317 309
318 static StreamType* CreateStream(AudioManager* audio_manager, 310 static StreamType* CreateStream(AudioManager* audio_manager,
319 const AudioParameters& params) { 311 const AudioParameters& params) {
320 return audio_manager->MakeAudioOutputStream(params); 312 return audio_manager->MakeAudioOutputStream(params);
321 } 313 }
322 }; 314 };
323 315
324 // Traits template holding a trait of StreamType. It encapsulates 316 // Traits template holding a trait of StreamType. It encapsulates
325 // AudioInputStream and AudioOutputStream stream types. 317 // AudioInputStream and AudioOutputStream stream types.
326 template <typename StreamTraits> 318 template <typename StreamTraits>
327 class StreamWrapper { 319 class StreamWrapper {
328 public: 320 public:
329 typedef typename StreamTraits::StreamType StreamType; 321 typedef typename StreamTraits::StreamType StreamType;
330 322
331 explicit StreamWrapper(AudioManager* audio_manager) 323 explicit StreamWrapper(AudioManager* audio_manager)
332 : 324 :
333 audio_manager_(audio_manager), 325 audio_manager_(audio_manager),
334 format_(AudioParameters::AUDIO_PCM_LOW_LATENCY), 326 format_(AudioParameters::AUDIO_PCM_LOW_LATENCY),
335 #if defined(OS_ANDROID) 327 #if defined(OS_ANDROID)
336 channel_layout_(CHANNEL_LAYOUT_MONO), 328 channel_layout_(CHANNEL_LAYOUT_MONO),
337 #else 329 #else
338 channel_layout_(CHANNEL_LAYOUT_STEREO), 330 channel_layout_(CHANNEL_LAYOUT_STEREO),
339 #endif 331 #endif
340 bits_per_sample_(16) { 332 bits_per_sample_(16) {
341 // Use the preferred sample rate. 333 // Use the preferred sample rate.
342 sample_rate_ = StreamTraits::HardwareSampleRate(); 334 const AudioParameters& params =
335 StreamTraits::GetDefaultAudioStreamParameters(audio_manager_);
336 sample_rate_ = params.sample_rate();
343 337
344 // Use the preferred buffer size. Note that the input side uses the same 338 // Use the preferred buffer size. Note that the input side uses the same
345 // size as the output side in this implementation. 339 // size as the output side in this implementation.
346 samples_per_packet_ = StreamTraits::HardwareBufferSize(); 340 samples_per_packet_ = params.frames_per_buffer();
347 } 341 }
348 342
349 virtual ~StreamWrapper() {} 343 virtual ~StreamWrapper() {}
350 344
351 // Creates an Audio[Input|Output]Stream stream object using default 345 // Creates an Audio[Input|Output]Stream stream object using default
352 // parameters. 346 // parameters.
353 StreamType* Create() { 347 StreamType* Create() {
354 return CreateStream(); 348 return CreateStream();
355 } 349 }
356 350
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 441
448 // All Close() operations that run on the mocked audio thread, 442 // All Close() operations that run on the mocked audio thread,
449 // should be synchronous and not post additional close tasks to 443 // should be synchronous and not post additional close tasks to
450 // mocked the audio thread. Hence, there is no need to call 444 // mocked the audio thread. Hence, there is no need to call
451 // message_loop()->RunUntilIdle() after the Close() methods. 445 // message_loop()->RunUntilIdle() after the Close() methods.
452 aos->Close(); 446 aos->Close();
453 ais->Close(); 447 ais->Close();
454 } 448 }
455 449
456 } // namespace media 450 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_input_volume_unittest.cc ('k') | media/audio/audio_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698