| 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/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 10 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 11 #include "content/common/child_process.h" | 12 #include "content/common/child_process.h" |
| 12 #include "content/common/media/audio_messages.h" | 13 #include "content/common/media/audio_messages.h" |
| 13 #include "content/renderer/media/audio_hardware.h" | 14 #include "content/renderer/media/audio_hardware.h" |
| 14 #include "content/renderer/media/audio_message_filter.h" | 15 #include "content/renderer/media/audio_message_filter.h" |
| 15 #include "content/renderer/render_thread_impl.h" | 16 #include "content/renderer/render_thread_impl.h" |
| 17 #include "media/base/media_switches.h" |
| 16 | 18 |
| 17 namespace content { | 19 namespace content { |
| 18 | 20 |
| 19 // static | 21 // static |
| 20 PepperPlatformAudioOutputImpl* PepperPlatformAudioOutputImpl::Create( | 22 PepperPlatformAudioOutputImpl* PepperPlatformAudioOutputImpl::Create( |
| 21 int sample_rate, | 23 int sample_rate, |
| 22 int frames_per_buffer, | 24 int frames_per_buffer, |
| 23 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { | 25 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { |
| 24 scoped_refptr<PepperPlatformAudioOutputImpl> audio_output( | 26 scoped_refptr<PepperPlatformAudioOutputImpl> audio_output( |
| 25 new PepperPlatformAudioOutputImpl()); | 27 new PepperPlatformAudioOutputImpl()); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 int frames_per_buffer, | 116 int frames_per_buffer, |
| 115 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { | 117 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { |
| 116 DCHECK(client); | 118 DCHECK(client); |
| 117 // Make sure we don't call init more than once. | 119 // Make sure we don't call init more than once. |
| 118 DCHECK_EQ(0, stream_id_); | 120 DCHECK_EQ(0, stream_id_); |
| 119 | 121 |
| 120 client_ = client; | 122 client_ = client; |
| 121 | 123 |
| 122 media::AudioParameters::Format format; | 124 media::AudioParameters::Format format; |
| 123 const int kMaxFramesForLowLatency = 2047; | 125 const int kMaxFramesForLowLatency = 2047; |
| 124 // Use the low latency back end if the client request is compatible, and | 126 |
| 125 // the sample count is low enough to justify using AUDIO_PCM_LOW_LATENCY. | 127 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 126 if (sample_rate == audio_hardware::GetOutputSampleRate() && | 128 if (cmd_line->HasSwitch(switches::kEnableAudioOutputResampler)) { |
| 127 frames_per_buffer <= kMaxFramesForLowLatency && | 129 // Rely on AudioOutputResampler to handle any inconsistencies between the |
| 128 frames_per_buffer % audio_hardware::GetOutputBufferSize() == 0) { | 130 // hardware params required for low latency and the requested params. |
| 131 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY; |
| 132 } else if (sample_rate == audio_hardware::GetOutputSampleRate() && |
| 133 frames_per_buffer <= kMaxFramesForLowLatency && |
| 134 frames_per_buffer % audio_hardware::GetOutputBufferSize() == 0) { |
| 135 // Use the low latency back end if the client request is compatible, and |
| 136 // the sample count is low enough to justify using AUDIO_PCM_LOW_LATENCY. |
| 129 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY; | 137 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY; |
| 130 } else { | 138 } else { |
| 131 format = media::AudioParameters::AUDIO_PCM_LINEAR; | 139 format = media::AudioParameters::AUDIO_PCM_LINEAR; |
| 132 } | 140 } |
| 133 | 141 |
| 134 media::AudioParameters params(format, CHANNEL_LAYOUT_STEREO, sample_rate, 16, | 142 media::AudioParameters params(format, CHANNEL_LAYOUT_STEREO, sample_rate, 16, |
| 135 frames_per_buffer); | 143 frames_per_buffer); |
| 136 | 144 |
| 137 ChildProcess::current()->io_message_loop()->PostTask( | 145 ChildProcess::current()->io_message_loop()->PostTask( |
| 138 FROM_HERE, | 146 FROM_HERE, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 164 | 172 |
| 165 ipc_->CloseStream(stream_id_); | 173 ipc_->CloseStream(stream_id_); |
| 166 ipc_->RemoveDelegate(stream_id_); | 174 ipc_->RemoveDelegate(stream_id_); |
| 167 stream_id_ = 0; | 175 stream_id_ = 0; |
| 168 | 176 |
| 169 Release(); // Release for the delegate, balances out the reference taken in | 177 Release(); // Release for the delegate, balances out the reference taken in |
| 170 // PepperPluginDelegateImpl::CreateAudio. | 178 // PepperPluginDelegateImpl::CreateAudio. |
| 171 } | 179 } |
| 172 | 180 |
| 173 } // namespace content | 181 } // namespace content |
| OLD | NEW |