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 10 matching lines...) Expand all Loading... |
21 } | 21 } |
22 | 22 |
23 PepperPlatformAudioOutputImpl::~PepperPlatformAudioOutputImpl() { | 23 PepperPlatformAudioOutputImpl::~PepperPlatformAudioOutputImpl() { |
24 // Make sure we have been shut down. Warning: this will usually happen on | 24 // Make sure we have been shut down. Warning: this will usually happen on |
25 // the I/O thread! | 25 // the I/O thread! |
26 DCHECK_EQ(0, stream_id_); | 26 DCHECK_EQ(0, stream_id_); |
27 DCHECK(!client_); | 27 DCHECK(!client_); |
28 } | 28 } |
29 | 29 |
30 bool PepperPlatformAudioOutputImpl::Initialize( | 30 bool PepperPlatformAudioOutputImpl::Initialize( |
31 uint32_t sample_rate, | 31 uint32_t samples_per_second, |
32 uint32_t sample_count, | 32 uint32_t samples_per_packet, |
33 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) { | 33 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) { |
34 DCHECK(client); | 34 DCHECK(client); |
35 // Make sure we don't call init more than once. | 35 // Make sure we don't call init more than once. |
36 DCHECK_EQ(0, stream_id_); | 36 DCHECK_EQ(0, stream_id_); |
37 | 37 |
38 client_ = client; | 38 client_ = client; |
39 | 39 |
40 AudioParameters params; | 40 AudioParameters::Format format; |
41 const uint32_t kMaxSampleCountForLowLatency = 2048; | 41 const uint32_t kMaxSampleCountForLowLatency = 2048; |
42 // Use the low latency back end if the client request is compatible, and | 42 // Use the low latency back end if the client request is compatible, and |
43 // the sample count is low enough to justify using AUDIO_PCM_LOW_LATENCY. | 43 // the sample count is low enough to justify using AUDIO_PCM_LOW_LATENCY. |
44 if (sample_rate == audio_hardware::GetOutputSampleRate() && | 44 if (samples_per_second == audio_hardware::GetOutputSampleRate() && |
45 sample_count <= kMaxSampleCountForLowLatency && | 45 samples_per_packet <= kMaxSampleCountForLowLatency && |
46 sample_count % audio_hardware::GetOutputBufferSize() == 0) | 46 samples_per_packet % audio_hardware::GetOutputBufferSize() == 0) |
47 params.format = AudioParameters::AUDIO_PCM_LOW_LATENCY; | 47 format = AudioParameters::AUDIO_PCM_LOW_LATENCY; |
48 else | 48 else |
49 params.format = AudioParameters::AUDIO_PCM_LINEAR; | 49 format = AudioParameters::AUDIO_PCM_LINEAR; |
50 params.channels = 2; | 50 |
51 params.sample_rate = sample_rate; | 51 AudioParameters params(format, CHANNEL_LAYOUT_STEREO, samples_per_second, |
52 params.bits_per_sample = 16; | 52 16, samples_per_packet); |
53 params.samples_per_packet = sample_count; | |
54 | 53 |
55 ChildProcess::current()->io_message_loop()->PostTask( | 54 ChildProcess::current()->io_message_loop()->PostTask( |
56 FROM_HERE, | 55 FROM_HERE, |
57 base::Bind(&PepperPlatformAudioOutputImpl::InitializeOnIOThread, | 56 base::Bind(&PepperPlatformAudioOutputImpl::InitializeOnIOThread, |
58 this, params)); | 57 this, params)); |
59 return true; | 58 return true; |
60 } | 59 } |
61 | 60 |
62 bool PepperPlatformAudioOutputImpl::StartPlayback() { | 61 bool PepperPlatformAudioOutputImpl::StartPlayback() { |
63 if (filter_) { | 62 if (filter_) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // Must dereference the client only on the main thread. Shutdown may have | 138 // Must dereference the client only on the main thread. Shutdown may have |
140 // occurred while the request was in-flight, so we need to NULL check. | 139 // occurred while the request was in-flight, so we need to NULL check. |
141 if (client_) | 140 if (client_) |
142 client_->StreamCreated(handle, length, socket_handle); | 141 client_->StreamCreated(handle, length, socket_handle); |
143 } else { | 142 } else { |
144 main_message_loop_proxy_->PostTask(FROM_HERE, | 143 main_message_loop_proxy_->PostTask(FROM_HERE, |
145 base::Bind(&PepperPlatformAudioOutputImpl::OnStreamCreated, this, | 144 base::Bind(&PepperPlatformAudioOutputImpl::OnStreamCreated, this, |
146 handle, socket_handle, length)); | 145 handle, socket_handle, length)); |
147 } | 146 } |
148 } | 147 } |
OLD | NEW |