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

Side by Side Diff: content/browser/renderer_host/media/audio_renderer_host.cc

Issue 10836025: Part 1: Plumb render view ID to render host (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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/browser/renderer_host/media/audio_renderer_host.h" 5 #include "content/browser/renderer_host/media/audio_renderer_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/process.h" 9 #include "base/process.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 IPC_MESSAGE_HANDLER(AudioHostMsg_FlushStream, OnFlushStream) 185 IPC_MESSAGE_HANDLER(AudioHostMsg_FlushStream, OnFlushStream)
186 IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, OnCloseStream) 186 IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, OnCloseStream)
187 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume) 187 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume)
188 IPC_MESSAGE_UNHANDLED(handled = false) 188 IPC_MESSAGE_UNHANDLED(handled = false)
189 IPC_END_MESSAGE_MAP_EX() 189 IPC_END_MESSAGE_MAP_EX()
190 190
191 return handled; 191 return handled;
192 } 192 }
193 193
194 void AudioRendererHost::OnCreateStream( 194 void AudioRendererHost::OnCreateStream(
195 int stream_id, const media::AudioParameters& params) { 195 int render_view_id,
196 int stream_id,
197 const media::AudioParameters& params) {
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
197 DCHECK(LookupById(stream_id) == NULL); 199 DCHECK(LookupById(stream_id) == NULL);
198 200
199 media::AudioParameters audio_params(params); 201 media::AudioParameters audio_params(params);
200 DCHECK_GT(audio_params.frames_per_buffer(), 0); 202 DCHECK_GT(audio_params.frames_per_buffer(), 0);
201 203
202 uint32 buffer_size = audio_params.GetBytesPerBuffer(); 204 uint32 buffer_size = audio_params.GetBytesPerBuffer();
203 205
204 scoped_ptr<AudioEntry> entry(new AudioEntry()); 206 scoped_ptr<AudioEntry> entry(new AudioEntry());
205 207
(...skipping 27 matching lines...) Expand all
233 } 235 }
234 236
235 // If we have created the controller successfully, create an entry and add it 237 // If we have created the controller successfully, create an entry and add it
236 // to the map. 238 // to the map.
237 entry->stream_id = stream_id; 239 entry->stream_id = stream_id;
238 audio_entries_.insert(std::make_pair(stream_id, entry.release())); 240 audio_entries_.insert(std::make_pair(stream_id, entry.release()));
239 if (media_observer_) 241 if (media_observer_)
240 media_observer_->OnSetAudioStreamStatus(this, stream_id, "created"); 242 media_observer_->OnSetAudioStreamStatus(this, stream_id, "created");
241 } 243 }
242 244
243 void AudioRendererHost::OnPlayStream(int stream_id) { 245 void AudioRendererHost::OnPlayStream(int render_view_id, int stream_id) {
244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
245 247
246 AudioEntry* entry = LookupById(stream_id); 248 AudioEntry* entry = LookupById(stream_id);
247 if (!entry) { 249 if (!entry) {
248 SendErrorMessage(stream_id); 250 SendErrorMessage(stream_id);
249 return; 251 return;
250 } 252 }
251 253
252 entry->controller->Play(); 254 entry->controller->Play();
253 if (media_observer_) 255 if (media_observer_)
254 media_observer_->OnSetAudioStreamPlaying(this, stream_id, true); 256 media_observer_->OnSetAudioStreamPlaying(this, stream_id, true);
255 } 257 }
256 258
257 void AudioRendererHost::OnPauseStream(int stream_id) { 259 void AudioRendererHost::OnPauseStream(int render_view_id, int stream_id) {
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
259 261
260 AudioEntry* entry = LookupById(stream_id); 262 AudioEntry* entry = LookupById(stream_id);
261 if (!entry) { 263 if (!entry) {
262 SendErrorMessage(stream_id); 264 SendErrorMessage(stream_id);
263 return; 265 return;
264 } 266 }
265 267
266 entry->controller->Pause(); 268 entry->controller->Pause();
267 if (media_observer_) 269 if (media_observer_)
268 media_observer_->OnSetAudioStreamPlaying(this, stream_id, false); 270 media_observer_->OnSetAudioStreamPlaying(this, stream_id, false);
269 } 271 }
270 272
271 void AudioRendererHost::OnFlushStream(int stream_id) { 273 void AudioRendererHost::OnFlushStream(int render_view_id, int stream_id) {
272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
273 275
274 AudioEntry* entry = LookupById(stream_id); 276 AudioEntry* entry = LookupById(stream_id);
275 if (!entry) { 277 if (!entry) {
276 SendErrorMessage(stream_id); 278 SendErrorMessage(stream_id);
277 return; 279 return;
278 } 280 }
279 281
280 entry->controller->Flush(); 282 entry->controller->Flush();
281 if (media_observer_) 283 if (media_observer_)
282 media_observer_->OnSetAudioStreamStatus(this, stream_id, "flushed"); 284 media_observer_->OnSetAudioStreamStatus(this, stream_id, "flushed");
283 } 285 }
284 286
285 void AudioRendererHost::OnCloseStream(int stream_id) { 287 void AudioRendererHost::OnCloseStream(int render_view_id, int stream_id) {
286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
287 289
288 if (media_observer_) 290 if (media_observer_)
289 media_observer_->OnSetAudioStreamStatus(this, stream_id, "closed"); 291 media_observer_->OnSetAudioStreamStatus(this, stream_id, "closed");
290 292
291 AudioEntry* entry = LookupById(stream_id); 293 AudioEntry* entry = LookupById(stream_id);
292 294
293 if (entry) 295 if (entry)
294 CloseAndDeleteStream(entry); 296 CloseAndDeleteStream(entry);
295 } 297 }
296 298
297 void AudioRendererHost::OnSetVolume(int stream_id, double volume) { 299 void AudioRendererHost::OnSetVolume(int render_view_id,
300 int stream_id,
301 double volume) {
298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
299 303
300 AudioEntry* entry = LookupById(stream_id); 304 AudioEntry* entry = LookupById(stream_id);
301 if (!entry) { 305 if (!entry) {
302 SendErrorMessage(stream_id); 306 SendErrorMessage(stream_id);
303 return; 307 return;
304 } 308 }
305 309
306 // Make sure the volume is valid. 310 // Make sure the volume is valid.
307 if (volume < 0 || volume > 1.0) 311 if (volume < 0 || volume > 1.0)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 380
377 // Iterate the map of entries. 381 // Iterate the map of entries.
378 // TODO(hclam): Implement a faster look up method. 382 // TODO(hclam): Implement a faster look up method.
379 for (AudioEntryMap::iterator i = audio_entries_.begin(); 383 for (AudioEntryMap::iterator i = audio_entries_.begin();
380 i != audio_entries_.end(); ++i) { 384 i != audio_entries_.end(); ++i) {
381 if (!i->second->pending_close && controller == i->second->controller.get()) 385 if (!i->second->pending_close && controller == i->second->controller.get())
382 return i->second; 386 return i->second;
383 } 387 }
384 return NULL; 388 return NULL;
385 } 389 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698