• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "media/audio/fake_audio_manager.h"
6 
7 namespace media {
8 
9 namespace {
10 
11 const int kDefaultInputBufferSize = 1024;
12 const int kDefaultSampleRate = 48000;
13 
14 }  // namespace
15 
FakeAudioManager(AudioLogFactory * audio_log_factory)16 FakeAudioManager::FakeAudioManager(AudioLogFactory* audio_log_factory)
17     : AudioManagerBase(audio_log_factory) {}
18 
~FakeAudioManager()19 FakeAudioManager::~FakeAudioManager() {
20   Shutdown();
21 }
22 
23 // Implementation of AudioManager.
HasAudioOutputDevices()24 bool FakeAudioManager::HasAudioOutputDevices() { return false; }
25 
HasAudioInputDevices()26 bool FakeAudioManager::HasAudioInputDevices() { return false; }
27 
28 // Implementation of AudioManagerBase.
MakeLinearOutputStream(const AudioParameters & params)29 AudioOutputStream* FakeAudioManager::MakeLinearOutputStream(
30     const AudioParameters& params) {
31   return FakeAudioOutputStream::MakeFakeStream(this, params);
32 }
33 
MakeLowLatencyOutputStream(const AudioParameters & params,const std::string & device_id,const std::string & input_device_id)34 AudioOutputStream* FakeAudioManager::MakeLowLatencyOutputStream(
35     const AudioParameters& params,
36     const std::string& device_id,
37     const std::string& input_device_id) {
38   return FakeAudioOutputStream::MakeFakeStream(this, params);
39 }
40 
MakeLinearInputStream(const AudioParameters & params,const std::string & device_id)41 AudioInputStream* FakeAudioManager::MakeLinearInputStream(
42     const AudioParameters& params,
43     const std::string& device_id) {
44   return FakeAudioInputStream::MakeFakeStream(this, params);
45 }
46 
MakeLowLatencyInputStream(const AudioParameters & params,const std::string & device_id)47 AudioInputStream* FakeAudioManager::MakeLowLatencyInputStream(
48     const AudioParameters& params,
49     const std::string& device_id) {
50   return FakeAudioInputStream::MakeFakeStream(this, params);
51 }
52 
GetPreferredOutputStreamParameters(const std::string & output_device_id,const AudioParameters & input_params)53 AudioParameters FakeAudioManager::GetPreferredOutputStreamParameters(
54     const std::string& output_device_id,
55     const AudioParameters& input_params) {
56   static const int kDefaultOutputBufferSize = 2048;
57   static const int kDefaultSampleRate = 48000;
58   ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
59   int sample_rate = kDefaultSampleRate;
60   int buffer_size = kDefaultOutputBufferSize;
61   int bits_per_sample = 16;
62   int input_channels = 0;
63   if (input_params.IsValid()) {
64     sample_rate = input_params.sample_rate();
65     bits_per_sample = input_params.bits_per_sample();
66     channel_layout = input_params.channel_layout();
67     input_channels = input_params.input_channels();
68     buffer_size = std::min(input_params.frames_per_buffer(), buffer_size);
69   }
70 
71   return AudioParameters(
72       AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels,
73       sample_rate, bits_per_sample, buffer_size, AudioParameters::NO_EFFECTS);
74 }
75 
GetInputStreamParameters(const std::string & device_id)76 AudioParameters FakeAudioManager::GetInputStreamParameters(
77     const std::string& device_id) {
78   return AudioParameters(
79       AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
80       kDefaultSampleRate, 16, kDefaultInputBufferSize);
81 }
82 
83 }  // namespace media
84