• 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)34 AudioOutputStream* FakeAudioManager::MakeLowLatencyOutputStream(
35     const AudioParameters& params,
36     const std::string& device_id) {
37   return FakeAudioOutputStream::MakeFakeStream(this, params);
38 }
39 
MakeLinearInputStream(const AudioParameters & params,const std::string & device_id)40 AudioInputStream* FakeAudioManager::MakeLinearInputStream(
41     const AudioParameters& params,
42     const std::string& device_id) {
43   return FakeAudioInputStream::MakeFakeStream(this, params);
44 }
45 
MakeLowLatencyInputStream(const AudioParameters & params,const std::string & device_id)46 AudioInputStream* FakeAudioManager::MakeLowLatencyInputStream(
47     const AudioParameters& params,
48     const std::string& device_id) {
49   return FakeAudioInputStream::MakeFakeStream(this, params);
50 }
51 
GetPreferredOutputStreamParameters(const std::string & output_device_id,const AudioParameters & input_params)52 AudioParameters FakeAudioManager::GetPreferredOutputStreamParameters(
53     const std::string& output_device_id,
54     const AudioParameters& input_params) {
55   static const int kDefaultOutputBufferSize = 2048;
56   static const int kDefaultSampleRate = 48000;
57   ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
58   int sample_rate = kDefaultSampleRate;
59   int buffer_size = kDefaultOutputBufferSize;
60   int bits_per_sample = 16;
61   int input_channels = 0;
62   if (input_params.IsValid()) {
63     sample_rate = input_params.sample_rate();
64     bits_per_sample = input_params.bits_per_sample();
65     channel_layout = input_params.channel_layout();
66     input_channels = input_params.input_channels();
67     buffer_size = std::min(input_params.frames_per_buffer(), buffer_size);
68   }
69 
70   return AudioParameters(
71       AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels,
72       sample_rate, bits_per_sample, buffer_size, AudioParameters::NO_EFFECTS);
73 }
74 
GetInputStreamParameters(const std::string & device_id)75 AudioParameters FakeAudioManager::GetInputStreamParameters(
76     const std::string& device_id) {
77   return AudioParameters(
78       AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
79       kDefaultSampleRate, 16, kDefaultInputBufferSize);
80 }
81 
82 }  // namespace media
83