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

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

Issue 225903006: PPAPI: Run clang_format.py on content/renderer/pepper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 6 years, 8 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.h" 5 #include "content/renderer/pepper/pepper_platform_audio_output.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/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "content/child/child_process.h" 11 #include "content/child/child_process.h"
12 #include "content/common/media/audio_messages.h" 12 #include "content/common/media/audio_messages.h"
13 #include "content/renderer/media/audio_message_filter.h" 13 #include "content/renderer/media/audio_message_filter.h"
14 #include "content/renderer/pepper/audio_helper.h" 14 #include "content/renderer/pepper/audio_helper.h"
15 #include "content/renderer/render_thread_impl.h" 15 #include "content/renderer/render_thread_impl.h"
16 #include "media/base/audio_hardware_config.h" 16 #include "media/base/audio_hardware_config.h"
17 #include "ppapi/shared_impl/ppb_audio_config_shared.h" 17 #include "ppapi/shared_impl/ppb_audio_config_shared.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 // static 21 // static
22 PepperPlatformAudioOutput* PepperPlatformAudioOutput::Create( 22 PepperPlatformAudioOutput* PepperPlatformAudioOutput::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 int source_render_frame_id, 26 int source_render_frame_id,
27 AudioHelper* client) { 27 AudioHelper* client) {
28 scoped_refptr<PepperPlatformAudioOutput> audio_output( 28 scoped_refptr<PepperPlatformAudioOutput> audio_output(
29 new PepperPlatformAudioOutput()); 29 new PepperPlatformAudioOutput());
30 if (audio_output->Initialize(sample_rate, frames_per_buffer, 30 if (audio_output->Initialize(sample_rate,
31 source_render_view_id, source_render_frame_id, 31 frames_per_buffer,
32 source_render_view_id,
33 source_render_frame_id,
32 client)) { 34 client)) {
33 // Balanced by Release invoked in 35 // Balanced by Release invoked in
34 // PepperPlatformAudioOutput::ShutDownOnIOThread(). 36 // PepperPlatformAudioOutput::ShutDownOnIOThread().
35 audio_output->AddRef(); 37 audio_output->AddRef();
36 return audio_output.get(); 38 return audio_output.get();
37 } 39 }
38 return NULL; 40 return NULL;
39 } 41 }
40 42
41 bool PepperPlatformAudioOutput::StartPlayback() { 43 bool PepperPlatformAudioOutput::StartPlayback() {
(...skipping 19 matching lines...) Expand all
61 void PepperPlatformAudioOutput::ShutDown() { 63 void PepperPlatformAudioOutput::ShutDown() {
62 // Called on the main thread to stop all audio callbacks. We must only change 64 // Called on the main thread to stop all audio callbacks. We must only change
63 // the client on the main thread, and the delegates from the I/O thread. 65 // the client on the main thread, and the delegates from the I/O thread.
64 client_ = NULL; 66 client_ = NULL;
65 io_message_loop_proxy_->PostTask( 67 io_message_loop_proxy_->PostTask(
66 FROM_HERE, 68 FROM_HERE,
67 base::Bind(&PepperPlatformAudioOutput::ShutDownOnIOThread, this)); 69 base::Bind(&PepperPlatformAudioOutput::ShutDownOnIOThread, this));
68 } 70 }
69 71
70 void PepperPlatformAudioOutput::OnStateChanged( 72 void PepperPlatformAudioOutput::OnStateChanged(
71 media::AudioOutputIPCDelegate::State state) { 73 media::AudioOutputIPCDelegate::State state) {}
72 }
73 74
74 void PepperPlatformAudioOutput::OnStreamCreated( 75 void PepperPlatformAudioOutput::OnStreamCreated(
75 base::SharedMemoryHandle handle, 76 base::SharedMemoryHandle handle,
76 base::SyncSocket::Handle socket_handle, 77 base::SyncSocket::Handle socket_handle,
77 int length) { 78 int length) {
78 #if defined(OS_WIN) 79 #if defined(OS_WIN)
79 DCHECK(handle); 80 DCHECK(handle);
80 DCHECK(socket_handle); 81 DCHECK(socket_handle);
81 #else 82 #else
82 DCHECK_NE(-1, handle.fd); 83 DCHECK_NE(-1, handle.fd);
83 DCHECK_NE(-1, socket_handle); 84 DCHECK_NE(-1, socket_handle);
84 #endif 85 #endif
85 DCHECK(length); 86 DCHECK(length);
86 87
87 if (base::MessageLoopProxy::current().get() == 88 if (base::MessageLoopProxy::current().get() ==
88 main_message_loop_proxy_.get()) { 89 main_message_loop_proxy_.get()) {
89 // Must dereference the client only on the main thread. Shutdown may have 90 // Must dereference the client only on the main thread. Shutdown may have
90 // occurred while the request was in-flight, so we need to NULL check. 91 // occurred while the request was in-flight, so we need to NULL check.
91 if (client_) 92 if (client_)
92 client_->StreamCreated(handle, length, socket_handle); 93 client_->StreamCreated(handle, length, socket_handle);
93 } else { 94 } else {
94 main_message_loop_proxy_->PostTask(FROM_HERE, 95 main_message_loop_proxy_->PostTask(
95 base::Bind(&PepperPlatformAudioOutput::OnStreamCreated, this, handle, 96 FROM_HERE,
96 socket_handle, length)); 97 base::Bind(&PepperPlatformAudioOutput::OnStreamCreated,
98 this,
99 handle,
100 socket_handle,
101 length));
97 } 102 }
98 } 103 }
99 104
100 void PepperPlatformAudioOutput::OnIPCClosed() { 105 void PepperPlatformAudioOutput::OnIPCClosed() { ipc_.reset(); }
101 ipc_.reset();
102 }
103 106
104 PepperPlatformAudioOutput::~PepperPlatformAudioOutput() { 107 PepperPlatformAudioOutput::~PepperPlatformAudioOutput() {
105 // Make sure we have been shut down. Warning: this will usually happen on 108 // Make sure we have been shut down. Warning: this will usually happen on
106 // the I/O thread! 109 // the I/O thread!
107 DCHECK(!ipc_); 110 DCHECK(!ipc_);
108 DCHECK(!client_); 111 DCHECK(!client_);
109 } 112 }
110 113
111 PepperPlatformAudioOutput::PepperPlatformAudioOutput() 114 PepperPlatformAudioOutput::PepperPlatformAudioOutput()
112 : client_(NULL), 115 : client_(NULL),
113 main_message_loop_proxy_(base::MessageLoopProxy::current()), 116 main_message_loop_proxy_(base::MessageLoopProxy::current()),
114 io_message_loop_proxy_(ChildProcess::current()->io_message_loop_proxy()) { 117 io_message_loop_proxy_(ChildProcess::current()->io_message_loop_proxy()) {
115 } 118 }
116 119
117 bool PepperPlatformAudioOutput::Initialize( 120 bool PepperPlatformAudioOutput::Initialize(int sample_rate,
118 int sample_rate, 121 int frames_per_buffer,
119 int frames_per_buffer, 122 int source_render_view_id,
120 int source_render_view_id, 123 int source_render_frame_id,
121 int source_render_frame_id, 124 AudioHelper* client) {
122 AudioHelper* client) {
123 DCHECK(client); 125 DCHECK(client);
124 client_ = client; 126 client_ = client;
125 127
126 RenderThreadImpl* const render_thread = RenderThreadImpl::current(); 128 RenderThreadImpl* const render_thread = RenderThreadImpl::current();
127 ipc_ = render_thread->audio_message_filter()-> 129 ipc_ = render_thread->audio_message_filter()->CreateAudioOutputIPC(
128 CreateAudioOutputIPC(source_render_view_id, source_render_frame_id); 130 source_render_view_id, source_render_frame_id);
129 CHECK(ipc_); 131 CHECK(ipc_);
130 132
131 media::AudioParameters params( 133 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
132 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 134 media::CHANNEL_LAYOUT_STEREO,
133 media::CHANNEL_LAYOUT_STEREO, sample_rate, 135 sample_rate,
134 ppapi::kBitsPerAudioOutputSample, frames_per_buffer); 136 ppapi::kBitsPerAudioOutputSample,
137 frames_per_buffer);
135 138
136 io_message_loop_proxy_->PostTask( 139 io_message_loop_proxy_->PostTask(
137 FROM_HERE, 140 FROM_HERE,
138 base::Bind(&PepperPlatformAudioOutput::InitializeOnIOThread, this, 141 base::Bind(
139 params)); 142 &PepperPlatformAudioOutput::InitializeOnIOThread, this, params));
140 return true; 143 return true;
141 } 144 }
142 145
143 void PepperPlatformAudioOutput::InitializeOnIOThread( 146 void PepperPlatformAudioOutput::InitializeOnIOThread(
144 const media::AudioParameters& params) { 147 const media::AudioParameters& params) {
145 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 148 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
146 const int kSessionId = 0; 149 const int kSessionId = 0;
147 if (ipc_) 150 if (ipc_)
148 ipc_->CreateStream(this, params, kSessionId); 151 ipc_->CreateStream(this, params, kSessionId);
149 } 152 }
(...skipping 18 matching lines...) Expand all
168 return; 171 return;
169 172
170 ipc_->CloseStream(); 173 ipc_->CloseStream();
171 ipc_.reset(); 174 ipc_.reset();
172 175
173 Release(); // Release for the delegate, balances out the reference taken in 176 Release(); // Release for the delegate, balances out the reference taken in
174 // PepperPlatformAudioOutput::Create. 177 // PepperPlatformAudioOutput::Create.
175 } 178 }
176 179
177 } // namespace content 180 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_platform_audio_output.h ('k') | content/renderer/pepper/pepper_platform_context_3d.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698