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

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

Issue 11298006: Browser-wide audio mirroring for TabCapture API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix more nits, disable for ios Created 8 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/audio/virtual_audio_output_stream.h"
6
7 #include "base/message_loop.h"
8 #include "media/audio/audio_manager_base.h"
9 #include "media/audio/virtual_audio_input_stream.h"
10
11 namespace media {
12
13 // static
14 VirtualAudioOutputStream* VirtualAudioOutputStream::MakeStream(
15 AudioManagerBase* manager, const AudioParameters& params,
16 VirtualAudioInputStream* target) {
17 return new VirtualAudioOutputStream(manager, params, target);
18 }
19
20 VirtualAudioOutputStream::VirtualAudioOutputStream(
21 AudioManagerBase* manager, const AudioParameters& params,
22 VirtualAudioInputStream* target)
23 : audio_manager_(manager), callback_(NULL), params_(params),
24 target_input_stream_(target), volume_(1.0f), attached_(false) {
25 }
26
27 VirtualAudioOutputStream::~VirtualAudioOutputStream() {
28 DCHECK(!callback_);
29 DCHECK(!attached_);
30 }
31
32 bool VirtualAudioOutputStream::Open() {
33 DCHECK(CalledOnAudioThread());
34 return true;
35 }
36
37 void VirtualAudioOutputStream::Start(AudioSourceCallback* callback) {
38 DCHECK(CalledOnAudioThread());
39 DCHECK(!attached_);
40 callback_ = callback;
41 target_input_stream_->AddOutputStream(this, params_);
42 attached_ = true;
43 }
44
45 void VirtualAudioOutputStream::Stop() {
46 DCHECK(CalledOnAudioThread());
47 DCHECK(attached_);
48 callback_ = NULL;
49 target_input_stream_->RemoveOutputStream(this, params_);
50 attached_ = false;
51 }
52
53 void VirtualAudioOutputStream::Close() {
54 DCHECK(CalledOnAudioThread());
55 audio_manager_->ReleaseOutputStream(this);
56 }
57
58 void VirtualAudioOutputStream::SetVolume(double volume) {
59 volume_ = static_cast<float>(volume);
DaleCurtis 2012/12/03 19:27:28 Change class variable to double instead?
justinlin 2012/12/03 21:18:42 Done.
60 }
61
62 void VirtualAudioOutputStream::GetVolume(double* volume) {
63 *volume = volume_;
64 }
65
66 double VirtualAudioOutputStream::ProvideInput(
67 AudioBus* audio_bus, base::TimeDelta buffer_delay) {
68 DCHECK(CalledOnAudioThread());
69 if (!callback_)
DaleCurtis 2012/12/03 19:27:28 I'd just DCHECK(callback_) or CHECK() here since y
justinlin 2012/12/03 21:18:42 Done. This was previously needed I think when we a
70 return 0;
71
72 int frames = callback_->OnMoreData(audio_bus, AudioBuffersState());
73 if (frames < audio_bus->frames())
74 audio_bus->ZeroFramesPartial(frames, audio_bus->frames() - frames);
75
76 return frames > 0 ? volume_ : 0;
77 }
78
79 bool VirtualAudioOutputStream::CalledOnAudioThread() {
80 return audio_manager_->GetMessageLoop()->BelongsToCurrentThread();
81 }
82
83 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698