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

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: Destructors hate ASSERT() in unit tests. 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)
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), callback_(NULL), volume_(1.0f) {
25 attached_(false) { 17 DCHECK(params_.IsValid());
18 DCHECK(message_loop_);
19 DCHECK(target);
26 } 20 }
27 21
28 VirtualAudioOutputStream::~VirtualAudioOutputStream() { 22 VirtualAudioOutputStream::~VirtualAudioOutputStream() {
29 DCHECK(!callback_); 23 DCHECK(!callback_);
30 DCHECK(!attached_); 24 }
25
26 void VirtualAudioOutputStream::RunOnceClosed(const base::Closure& cb) {
27 DCHECK(on_close_cb_.is_null());
28 on_close_cb_ = cb;
31 } 29 }
32 30
33 bool VirtualAudioOutputStream::Open() { 31 bool VirtualAudioOutputStream::Open() {
34 DCHECK(message_loop_->BelongsToCurrentThread()); 32 DCHECK(message_loop_->BelongsToCurrentThread());
35 return true; 33 return true;
36 } 34 }
37 35
38 void VirtualAudioOutputStream::Start(AudioSourceCallback* callback) { 36 void VirtualAudioOutputStream::Start(AudioSourceCallback* callback) {
39 DCHECK(message_loop_->BelongsToCurrentThread()); 37 DCHECK(message_loop_->BelongsToCurrentThread());
40 DCHECK(!attached_); 38 DCHECK(!callback_);
41 callback_ = callback; 39 callback_ = callback;
42 target_input_stream_->AddOutputStream(this, params_); 40 target_input_stream_->AddOutputStream(this, params_);
43 attached_ = true;
44 } 41 }
45 42
46 void VirtualAudioOutputStream::Stop() { 43 void VirtualAudioOutputStream::Stop() {
47 DCHECK(message_loop_->BelongsToCurrentThread()); 44 DCHECK(message_loop_->BelongsToCurrentThread());
48 DCHECK(attached_); 45 if (callback_) {
49 callback_ = NULL; 46 callback_ = NULL;
50 target_input_stream_->RemoveOutputStream(this, params_); 47 target_input_stream_->RemoveOutputStream(this, params_);
51 attached_ = false; 48 }
52 } 49 }
53 50
54 void VirtualAudioOutputStream::Close() { 51 void VirtualAudioOutputStream::Close() {
55 DCHECK(message_loop_->BelongsToCurrentThread()); 52 DCHECK(message_loop_->BelongsToCurrentThread());
56 audio_manager_->ReleaseOutputStream(this); 53 Stop();
54 if (!on_close_cb_.is_null()) {
55 const base::Closure cb = on_close_cb_;
56 on_close_cb_.Reset();
57 cb.Run();
58 }
57 } 59 }
58 60
59 void VirtualAudioOutputStream::SetVolume(double volume) { 61 void VirtualAudioOutputStream::SetVolume(double volume) {
62 DCHECK(message_loop_->BelongsToCurrentThread());
60 volume_ = volume; 63 volume_ = volume;
61 } 64 }
62 65
63 void VirtualAudioOutputStream::GetVolume(double* volume) { 66 void VirtualAudioOutputStream::GetVolume(double* volume) {
67 DCHECK(message_loop_->BelongsToCurrentThread());
64 *volume = volume_; 68 *volume = volume_;
65 } 69 }
66 70
67 double VirtualAudioOutputStream::ProvideInput(AudioBus* audio_bus, 71 double VirtualAudioOutputStream::ProvideInput(AudioBus* audio_bus,
68 base::TimeDelta buffer_delay) { 72 base::TimeDelta buffer_delay) {
69 DCHECK(message_loop_->BelongsToCurrentThread()); 73 DCHECK(message_loop_->BelongsToCurrentThread());
70 DCHECK(callback_); 74 DCHECK(callback_);
71 75
72 int frames = callback_->OnMoreData(audio_bus, AudioBuffersState()); 76 int frames = callback_->OnMoreData(audio_bus, AudioBuffersState());
73 if (frames < audio_bus->frames()) 77 if (frames < audio_bus->frames())
74 audio_bus->ZeroFramesPartial(frames, audio_bus->frames() - frames); 78 audio_bus->ZeroFramesPartial(frames, audio_bus->frames() - frames);
75 79
76 return frames > 0 ? volume_ : 0; 80 return frames > 0 ? volume_ : 0;
77 } 81 }
78 82
79 } // namespace media 83 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698