OLD | NEW |
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 "content/renderer/pepper/pepper_platform_audio_output_impl.h" | 5 #include "content/renderer/pepper/pepper_platform_audio_output_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "content/common/child_process.h" | 12 #include "content/common/child_process.h" |
13 #include "content/common/media/audio_messages.h" | 13 #include "content/common/media/audio_messages.h" |
14 #include "content/renderer/media/audio_hardware.h" | |
15 #include "content/renderer/media/audio_message_filter.h" | 14 #include "content/renderer/media/audio_message_filter.h" |
16 #include "content/renderer/render_thread_impl.h" | 15 #include "content/renderer/render_thread_impl.h" |
| 16 #include "media/base/audio_hardware_config.h" |
17 #include "media/base/media_switches.h" | 17 #include "media/base/media_switches.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 // static | 21 // static |
22 PepperPlatformAudioOutputImpl* PepperPlatformAudioOutputImpl::Create( | 22 PepperPlatformAudioOutputImpl* PepperPlatformAudioOutputImpl::Create( |
23 int sample_rate, | 23 int sample_rate, |
24 int frames_per_buffer, | 24 int frames_per_buffer, |
25 int source_render_view_id, | 25 int source_render_view_id, |
26 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { | 26 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 int sample_rate, | 118 int sample_rate, |
119 int frames_per_buffer, | 119 int frames_per_buffer, |
120 int source_render_view_id, | 120 int source_render_view_id, |
121 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { | 121 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { |
122 DCHECK(client); | 122 DCHECK(client); |
123 client_ = client; | 123 client_ = client; |
124 | 124 |
125 media::AudioParameters::Format format; | 125 media::AudioParameters::Format format; |
126 const int kMaxFramesForLowLatency = 2047; | 126 const int kMaxFramesForLowLatency = 2047; |
127 | 127 |
| 128 media::AudioHardwareConfig* hardware_config = |
| 129 RenderThreadImpl::current()->GetAudioHardwareConfig(); |
| 130 |
128 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 131 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
129 if (!cmd_line->HasSwitch(switches::kDisableAudioOutputResampler)) { | 132 if (!cmd_line->HasSwitch(switches::kDisableAudioOutputResampler)) { |
130 // Rely on AudioOutputResampler to handle any inconsistencies between the | 133 // Rely on AudioOutputResampler to handle any inconsistencies between the |
131 // hardware params required for low latency and the requested params. | 134 // hardware params required for low latency and the requested params. |
132 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY; | 135 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY; |
133 } else if (sample_rate == GetAudioOutputSampleRate() && | 136 } else if (sample_rate == hardware_config->GetOutputSampleRate() && |
134 frames_per_buffer <= kMaxFramesForLowLatency && | 137 frames_per_buffer <= kMaxFramesForLowLatency && |
135 frames_per_buffer % content::GetAudioOutputBufferSize() == 0) { | 138 frames_per_buffer % hardware_config->GetOutputBufferSize() == 0) { |
136 // Use the low latency back end if the client request is compatible, and | 139 // Use the low latency back end if the client request is compatible, and |
137 // the sample count is low enough to justify using AUDIO_PCM_LOW_LATENCY. | 140 // the sample count is low enough to justify using AUDIO_PCM_LOW_LATENCY. |
138 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY; | 141 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY; |
139 } else { | 142 } else { |
140 format = media::AudioParameters::AUDIO_PCM_LINEAR; | 143 format = media::AudioParameters::AUDIO_PCM_LINEAR; |
141 } | 144 } |
142 | 145 |
143 media::AudioParameters params(format, media::CHANNEL_LAYOUT_STEREO, | 146 media::AudioParameters params(format, media::CHANNEL_LAYOUT_STEREO, |
144 sample_rate, 16, frames_per_buffer); | 147 sample_rate, 16, frames_per_buffer); |
145 | 148 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 181 |
179 ipc_->CloseStream(stream_id_); | 182 ipc_->CloseStream(stream_id_); |
180 ipc_->RemoveDelegate(stream_id_); | 183 ipc_->RemoveDelegate(stream_id_); |
181 stream_id_ = 0; | 184 stream_id_ = 0; |
182 | 185 |
183 Release(); // Release for the delegate, balances out the reference taken in | 186 Release(); // Release for the delegate, balances out the reference taken in |
184 // PepperPluginDelegateImpl::CreateAudio. | 187 // PepperPluginDelegateImpl::CreateAudio. |
185 } | 188 } |
186 | 189 |
187 } // namespace content | 190 } // namespace content |
OLD | NEW |