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

Side by Side Diff: media/audio/virtual_audio_output_stream.cc

Issue 11416350: Tab Audio Mirroring: WebContentsAudioInputStream is a new implementation which represents the lifet… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replace RunAfterClosed() scheme with 'after close callback' passed to ctor. Created 7 years, 11 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 "media/audio/virtual_audio_output_stream.h" 5 #include "media/audio/virtual_audio_output_stream.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop_proxy.h"
8 #include "media/audio/audio_manager_base.h"
9 #include "media/audio/virtual_audio_input_stream.h" 8 #include "media/audio/virtual_audio_input_stream.h"
10 9
11 namespace media { 10 namespace media {
12 11
13 // static
14 VirtualAudioOutputStream* VirtualAudioOutputStream::MakeStream(
15 AudioManagerBase* manager, const AudioParameters& params,
16 base::MessageLoopProxy* message_loop, VirtualAudioInputStream* target) {
17 return new VirtualAudioOutputStream(manager, params, message_loop, target);
18 }
19
20 VirtualAudioOutputStream::VirtualAudioOutputStream( 12 VirtualAudioOutputStream::VirtualAudioOutputStream(
21 AudioManagerBase* manager, const AudioParameters& params, 13 const AudioParameters& params, base::MessageLoopProxy* message_loop,
22 base::MessageLoopProxy* message_loop, VirtualAudioInputStream* target) 14 VirtualAudioInputStream* target, const AfterCloseCallback& after_close_cb)
23 : audio_manager_(manager), message_loop_(message_loop), callback_(NULL), 15 : params_(params), message_loop_(message_loop),
24 params_(params), target_input_stream_(target), volume_(1.0f), 16 target_input_stream_(target), after_close_cb_(after_close_cb),
25 attached_(false) { 17 callback_(NULL), volume_(1.0f) {
18 DCHECK(params_.IsValid());
19 DCHECK(message_loop_);
20 DCHECK(target);
26 } 21 }
27 22
28 VirtualAudioOutputStream::~VirtualAudioOutputStream() { 23 VirtualAudioOutputStream::~VirtualAudioOutputStream() {
29 DCHECK(!callback_); 24 DCHECK(!callback_);
30 DCHECK(!attached_);
31 } 25 }
32 26
33 bool VirtualAudioOutputStream::Open() { 27 bool VirtualAudioOutputStream::Open() {
34 DCHECK(message_loop_->BelongsToCurrentThread()); 28 DCHECK(message_loop_->BelongsToCurrentThread());
35 return true; 29 return true;
36 } 30 }
37 31
38 void VirtualAudioOutputStream::Start(AudioSourceCallback* callback) { 32 void VirtualAudioOutputStream::Start(AudioSourceCallback* callback) {
39 DCHECK(message_loop_->BelongsToCurrentThread()); 33 DCHECK(message_loop_->BelongsToCurrentThread());
40 DCHECK(!attached_); 34 DCHECK(!callback_);
41 callback_ = callback; 35 callback_ = callback;
42 target_input_stream_->AddOutputStream(this, params_); 36 target_input_stream_->AddOutputStream(this, params_);
43 attached_ = true;
44 } 37 }
45 38
46 void VirtualAudioOutputStream::Stop() { 39 void VirtualAudioOutputStream::Stop() {
47 DCHECK(message_loop_->BelongsToCurrentThread()); 40 DCHECK(message_loop_->BelongsToCurrentThread());
48 DCHECK(attached_); 41 if (callback_) {
49 callback_ = NULL; 42 callback_ = NULL;
50 target_input_stream_->RemoveOutputStream(this, params_); 43 target_input_stream_->RemoveOutputStream(this, params_);
51 attached_ = false; 44 }
52 } 45 }
53 46
54 void VirtualAudioOutputStream::Close() { 47 void VirtualAudioOutputStream::Close() {
55 DCHECK(message_loop_->BelongsToCurrentThread()); 48 DCHECK(message_loop_->BelongsToCurrentThread());
56 audio_manager_->ReleaseOutputStream(this); 49 Stop();
50 if (!after_close_cb_.is_null()) {
DaleCurtis 2013/01/17 01:15:52 Ditto.
miu 2013/01/17 05:33:55 Added the comments here as well.
51 const AfterCloseCallback cb = after_close_cb_;
52 after_close_cb_.Reset();
53 cb.Run(this);
54 }
57 } 55 }
58 56
59 void VirtualAudioOutputStream::SetVolume(double volume) { 57 void VirtualAudioOutputStream::SetVolume(double volume) {
58 DCHECK(message_loop_->BelongsToCurrentThread());
60 volume_ = volume; 59 volume_ = volume;
61 } 60 }
62 61
63 void VirtualAudioOutputStream::GetVolume(double* volume) { 62 void VirtualAudioOutputStream::GetVolume(double* volume) {
63 DCHECK(message_loop_->BelongsToCurrentThread());
64 *volume = volume_; 64 *volume = volume_;
65 } 65 }
66 66
67 double VirtualAudioOutputStream::ProvideInput(AudioBus* audio_bus, 67 double VirtualAudioOutputStream::ProvideInput(AudioBus* audio_bus,
68 base::TimeDelta buffer_delay) { 68 base::TimeDelta buffer_delay) {
69 DCHECK(message_loop_->BelongsToCurrentThread()); 69 DCHECK(message_loop_->BelongsToCurrentThread());
70 DCHECK(callback_); 70 DCHECK(callback_);
71 71
72 int frames = callback_->OnMoreData(audio_bus, AudioBuffersState()); 72 int frames = callback_->OnMoreData(audio_bus, AudioBuffersState());
73 if (frames < audio_bus->frames()) 73 if (frames < audio_bus->frames())
74 audio_bus->ZeroFramesPartial(frames, audio_bus->frames() - frames); 74 audio_bus->ZeroFramesPartial(frames, audio_bus->frames() - frames);
75 75
76 return frames > 0 ? volume_ : 0; 76 return frames > 0 ? volume_ : 0;
77 } 77 }
78 78
79 } // namespace media 79 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698