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/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 bool PepperPlatformAudioOutputImpl::Initialize( | 76 bool PepperPlatformAudioOutputImpl::Initialize( |
77 int sample_rate, | 77 int sample_rate, |
78 int frames_per_buffer, | 78 int frames_per_buffer, |
79 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { | 79 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { |
80 DCHECK(client); | 80 DCHECK(client); |
81 // Make sure we don't call init more than once. | 81 // Make sure we don't call init more than once. |
82 DCHECK_EQ(0, stream_id_); | 82 DCHECK_EQ(0, stream_id_); |
83 | 83 |
84 client_ = client; | 84 client_ = client; |
85 | 85 |
86 AudioParameters::Format format; | 86 media::AudioParameters::Format format; |
87 const int kMaxFramesForLowLatency = 2048; | 87 const int kMaxFramesForLowLatency = 2048; |
88 // Use the low latency back end if the client request is compatible, and | 88 // Use the low latency back end if the client request is compatible, and |
89 // the sample count is low enough to justify using AUDIO_PCM_LOW_LATENCY. | 89 // the sample count is low enough to justify using AUDIO_PCM_LOW_LATENCY. |
90 if (sample_rate == audio_hardware::GetOutputSampleRate() && | 90 if (sample_rate == audio_hardware::GetOutputSampleRate() && |
91 frames_per_buffer <= kMaxFramesForLowLatency && | 91 frames_per_buffer <= kMaxFramesForLowLatency && |
92 frames_per_buffer % audio_hardware::GetOutputBufferSize() == 0) { | 92 frames_per_buffer % audio_hardware::GetOutputBufferSize() == 0) { |
93 format = AudioParameters::AUDIO_PCM_LOW_LATENCY; | 93 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY; |
94 } else { | 94 } else { |
95 format = AudioParameters::AUDIO_PCM_LINEAR; | 95 format = media::AudioParameters::AUDIO_PCM_LINEAR; |
96 } | 96 } |
97 | 97 |
98 AudioParameters params(format, CHANNEL_LAYOUT_STEREO, sample_rate, | 98 media::AudioParameters params(format, CHANNEL_LAYOUT_STEREO, sample_rate, 16, |
99 16, frames_per_buffer); | 99 frames_per_buffer); |
100 | 100 |
101 ChildProcess::current()->io_message_loop()->PostTask( | 101 ChildProcess::current()->io_message_loop()->PostTask( |
102 FROM_HERE, | 102 FROM_HERE, |
103 base::Bind(&PepperPlatformAudioOutputImpl::InitializeOnIOThread, | 103 base::Bind(&PepperPlatformAudioOutputImpl::InitializeOnIOThread, |
104 this, params)); | 104 this, params)); |
105 return true; | 105 return true; |
106 } | 106 } |
107 | 107 |
108 void PepperPlatformAudioOutputImpl::InitializeOnIOThread( | 108 void PepperPlatformAudioOutputImpl::InitializeOnIOThread( |
109 const AudioParameters& params) { | 109 const media::AudioParameters& params) { |
110 stream_id_ = filter_->AddDelegate(this); | 110 stream_id_ = filter_->AddDelegate(this); |
111 filter_->Send(new AudioHostMsg_CreateStream(stream_id_, params)); | 111 filter_->Send(new AudioHostMsg_CreateStream(stream_id_, params)); |
112 } | 112 } |
113 | 113 |
114 void PepperPlatformAudioOutputImpl::StartPlaybackOnIOThread() { | 114 void PepperPlatformAudioOutputImpl::StartPlaybackOnIOThread() { |
115 if (stream_id_) | 115 if (stream_id_) |
116 filter_->Send(new AudioHostMsg_PlayStream(stream_id_)); | 116 filter_->Send(new AudioHostMsg_PlayStream(stream_id_)); |
117 } | 117 } |
118 | 118 |
119 void PepperPlatformAudioOutputImpl::StopPlaybackOnIOThread() { | 119 void PepperPlatformAudioOutputImpl::StopPlaybackOnIOThread() { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // Must dereference the client only on the main thread. Shutdown may have | 154 // Must dereference the client only on the main thread. Shutdown may have |
155 // occurred while the request was in-flight, so we need to NULL check. | 155 // occurred while the request was in-flight, so we need to NULL check. |
156 if (client_) | 156 if (client_) |
157 client_->StreamCreated(handle, length, socket_handle); | 157 client_->StreamCreated(handle, length, socket_handle); |
158 } else { | 158 } else { |
159 main_message_loop_proxy_->PostTask(FROM_HERE, | 159 main_message_loop_proxy_->PostTask(FROM_HERE, |
160 base::Bind(&PepperPlatformAudioOutputImpl::OnStreamCreated, this, | 160 base::Bind(&PepperPlatformAudioOutputImpl::OnStreamCreated, this, |
161 handle, socket_handle, length)); | 161 handle, socket_handle, length)); |
162 } | 162 } |
163 } | 163 } |
OLD | NEW |