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

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

Issue 922663002: Moved the fake input stream's processing onto the audio worker thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updating GN files Created 5 years, 10 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
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_input_stream.h" 5 #include "media/audio/virtual_audio_input_stream.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 const AudioParameters& params, 51 const AudioParameters& params,
52 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner, 52 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner,
53 const AfterCloseCallback& after_close_cb) 53 const AfterCloseCallback& after_close_cb)
54 : worker_task_runner_(worker_task_runner), 54 : worker_task_runner_(worker_task_runner),
55 after_close_cb_(after_close_cb), 55 after_close_cb_(after_close_cb),
56 callback_(NULL), 56 callback_(NULL),
57 buffer_(new uint8[params.GetBytesPerBuffer()]), 57 buffer_(new uint8[params.GetBytesPerBuffer()]),
58 params_(params), 58 params_(params),
59 mixer_(params_, params_, false), 59 mixer_(params_, params_, false),
60 num_attached_output_streams_(0), 60 num_attached_output_streams_(0),
61 fake_consumer_(worker_task_runner_, params_) { 61 fake_worker_(worker_task_runner_, params_),
62 audio_bus_(AudioBus::Create(params)) {
62 DCHECK(params_.IsValid()); 63 DCHECK(params_.IsValid());
63 DCHECK(worker_task_runner_.get()); 64 DCHECK(worker_task_runner_.get());
64 65
65 // VAIS can be constructed on any thread, but will DCHECK that all 66 // VAIS can be constructed on any thread, but will DCHECK that all
66 // AudioInputStream methods are called from the same thread. 67 // AudioInputStream methods are called from the same thread.
67 thread_checker_.DetachFromThread(); 68 thread_checker_.DetachFromThread();
68 } 69 }
69 70
70 VirtualAudioInputStream::~VirtualAudioInputStream() { 71 VirtualAudioInputStream::~VirtualAudioInputStream() {
71 DCHECK(!callback_); 72 DCHECK(!callback_);
(...skipping 10 matching lines...) Expand all
82 83
83 bool VirtualAudioInputStream::Open() { 84 bool VirtualAudioInputStream::Open() {
84 DCHECK(thread_checker_.CalledOnValidThread()); 85 DCHECK(thread_checker_.CalledOnValidThread());
85 memset(buffer_.get(), 0, params_.GetBytesPerBuffer()); 86 memset(buffer_.get(), 0, params_.GetBytesPerBuffer());
86 return true; 87 return true;
87 } 88 }
88 89
89 void VirtualAudioInputStream::Start(AudioInputCallback* callback) { 90 void VirtualAudioInputStream::Start(AudioInputCallback* callback) {
90 DCHECK(thread_checker_.CalledOnValidThread()); 91 DCHECK(thread_checker_.CalledOnValidThread());
91 callback_ = callback; 92 callback_ = callback;
92 fake_consumer_.Start(base::Bind( 93 fake_worker_.Start(base::Bind(
93 &VirtualAudioInputStream::PumpAudio, base::Unretained(this))); 94 &VirtualAudioInputStream::PumpAudio, base::Unretained(this)));
94 } 95 }
95 96
96 void VirtualAudioInputStream::Stop() { 97 void VirtualAudioInputStream::Stop() {
97 DCHECK(thread_checker_.CalledOnValidThread()); 98 DCHECK(thread_checker_.CalledOnValidThread());
98 fake_consumer_.Stop(); 99 fake_worker_.Stop();
99 callback_ = NULL; 100 callback_ = NULL;
100 } 101 }
101 102
102 void VirtualAudioInputStream::AddOutputStream( 103 void VirtualAudioInputStream::AddOutputStream(
103 VirtualAudioOutputStream* stream, const AudioParameters& output_params) { 104 VirtualAudioOutputStream* stream, const AudioParameters& output_params) {
104 DCHECK(thread_checker_.CalledOnValidThread()); 105 DCHECK(thread_checker_.CalledOnValidThread());
105 106
106 base::AutoLock scoped_lock(converter_network_lock_); 107 base::AutoLock scoped_lock(converter_network_lock_);
107 108
108 AudioConvertersMap::iterator converter = converters_.find(output_params); 109 AudioConvertersMap::iterator converter = converters_.find(output_params);
(...skipping 16 matching lines...) Expand all
125 126
126 base::AutoLock scoped_lock(converter_network_lock_); 127 base::AutoLock scoped_lock(converter_network_lock_);
127 128
128 DCHECK(converters_.find(output_params) != converters_.end()); 129 DCHECK(converters_.find(output_params) != converters_.end());
129 converters_[output_params]->RemoveInput(stream); 130 converters_[output_params]->RemoveInput(stream);
130 131
131 --num_attached_output_streams_; 132 --num_attached_output_streams_;
132 DCHECK_LE(0, num_attached_output_streams_); 133 DCHECK_LE(0, num_attached_output_streams_);
133 } 134 }
134 135
135 void VirtualAudioInputStream::PumpAudio(AudioBus* audio_bus) { 136 void VirtualAudioInputStream::PumpAudio() {
136 DCHECK(worker_task_runner_->BelongsToCurrentThread()); 137 DCHECK(worker_task_runner_->BelongsToCurrentThread());
137 138
138 { 139 {
139 base::AutoLock scoped_lock(converter_network_lock_); 140 base::AutoLock scoped_lock(converter_network_lock_);
140 // Because the audio is being looped-back, the delay until it will be played 141 // Because the audio is being looped-back, the delay until it will be played
141 // out is zero. 142 // out is zero.
142 mixer_.ConvertWithDelay(base::TimeDelta(), audio_bus); 143 mixer_.ConvertWithDelay(base::TimeDelta(), audio_bus_.get());
143 } 144 }
144 // Because the audio is being looped-back, the delay since since it was 145 // Because the audio is being looped-back, the delay since since it was
145 // recorded is zero. 146 // recorded is zero.
146 callback_->OnData(this, audio_bus, 0, 1.0); 147 callback_->OnData(this, audio_bus_.get(), 0, 1.0);
147 } 148 }
148 149
149 void VirtualAudioInputStream::Close() { 150 void VirtualAudioInputStream::Close() {
150 DCHECK(thread_checker_.CalledOnValidThread()); 151 DCHECK(thread_checker_.CalledOnValidThread());
151 152
152 Stop(); // Make sure callback_ is no longer being used. 153 Stop(); // Make sure callback_ is no longer being used.
153 154
154 // If a non-null AfterCloseCallback was provided to the constructor, invoke it 155 // If a non-null AfterCloseCallback was provided to the constructor, invoke it
155 // here. The callback is moved to a stack-local first since |this| could be 156 // here. The callback is moved to a stack-local first since |this| could be
156 // destroyed during Run(). 157 // destroyed during Run().
(...skipping 20 matching lines...) Expand all
177 178
178 bool VirtualAudioInputStream::GetAutomaticGainControl() { 179 bool VirtualAudioInputStream::GetAutomaticGainControl() {
179 return false; 180 return false;
180 } 181 }
181 182
182 bool VirtualAudioInputStream::IsMuted() { 183 bool VirtualAudioInputStream::IsMuted() {
183 return false; 184 return false;
184 } 185 }
185 186
186 } // namespace media 187 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698