Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: content/renderer/pepper/pepper_platform_audio_output_impl.cc

Issue 9655018: Make AudioParameters a class instead of a struct (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix copyright years Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 11 matching lines...) Expand all
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 // static 30 // static
31 PepperPlatformAudioOutputImpl* PepperPlatformAudioOutputImpl::Create( 31 PepperPlatformAudioOutputImpl* PepperPlatformAudioOutputImpl::Create(
32 uint32_t sample_rate, 32 int sample_rate,
33 uint32_t sample_count, 33 int frames_per_buffer,
34 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) { 34 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) {
35 scoped_refptr<PepperPlatformAudioOutputImpl> audio_output( 35 scoped_refptr<PepperPlatformAudioOutputImpl> audio_output(
36 new PepperPlatformAudioOutputImpl); 36 new PepperPlatformAudioOutputImpl);
37 if (audio_output->Initialize(sample_rate, sample_count, client)) { 37 if (audio_output->Initialize(sample_rate, frames_per_buffer, client)) {
38 // Balanced by Release invoked in 38 // Balanced by Release invoked in
39 // PepperPlatformAudioOutputImpl::ShutDownOnIOThread(). 39 // PepperPlatformAudioOutputImpl::ShutDownOnIOThread().
40 return audio_output.release(); 40 return audio_output.release();
41 } 41 }
42 return NULL; 42 return NULL;
43 } 43 }
44 44
45 bool PepperPlatformAudioOutputImpl::StartPlayback() { 45 bool PepperPlatformAudioOutputImpl::StartPlayback() {
46 if (filter_) { 46 if (filter_) {
47 ChildProcess::current()->io_message_loop()->PostTask( 47 ChildProcess::current()->io_message_loop()->PostTask(
(...skipping 19 matching lines...) Expand all
67 void PepperPlatformAudioOutputImpl::ShutDown() { 67 void PepperPlatformAudioOutputImpl::ShutDown() {
68 // Called on the main thread to stop all audio callbacks. We must only change 68 // Called on the main thread to stop all audio callbacks. We must only change
69 // the client on the main thread, and the delegates from the I/O thread. 69 // the client on the main thread, and the delegates from the I/O thread.
70 client_ = NULL; 70 client_ = NULL;
71 ChildProcess::current()->io_message_loop()->PostTask( 71 ChildProcess::current()->io_message_loop()->PostTask(
72 FROM_HERE, 72 FROM_HERE,
73 base::Bind(&PepperPlatformAudioOutputImpl::ShutDownOnIOThread, this)); 73 base::Bind(&PepperPlatformAudioOutputImpl::ShutDownOnIOThread, this));
74 } 74 }
75 75
76 bool PepperPlatformAudioOutputImpl::Initialize( 76 bool PepperPlatformAudioOutputImpl::Initialize(
77 uint32_t sample_rate, 77 int sample_rate,
78 uint32_t sample_count, 78 int frames_per_buffer,
79 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) { 79 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* 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 params; 86 AudioParameters::Format format;
87 const uint32_t kMaxSampleCountForLowLatency = 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 sample_count <= kMaxSampleCountForLowLatency && 91 frames_per_buffer <= kMaxFramesForLowLatency &&
92 sample_count % audio_hardware::GetOutputBufferSize() == 0) 92 frames_per_buffer % audio_hardware::GetOutputBufferSize() == 0) {
93 params.format = AudioParameters::AUDIO_PCM_LOW_LATENCY; 93 format = AudioParameters::AUDIO_PCM_LOW_LATENCY;
94 else 94 } else {
95 params.format = AudioParameters::AUDIO_PCM_LINEAR; 95 format = AudioParameters::AUDIO_PCM_LINEAR;
96 params.channels = 2; 96 }
97 params.sample_rate = sample_rate; 97
98 params.bits_per_sample = 16; 98 AudioParameters params(format, CHANNEL_LAYOUT_STEREO, sample_rate,
99 params.samples_per_packet = sample_count; 99 16, 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 AudioParameters& params) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_platform_audio_output_impl.h ('k') | content/renderer/pepper/pepper_plugin_delegate_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698