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

Side by Side Diff: content/browser/media/capture/web_contents_audio_input_stream.cc

Issue 2460033003: Increment/Decrement capturer count when starts/stops audio capturing. (Closed)
Patch Set: Fix. Created 4 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/media/capture/web_contents_audio_input_stream.h" 5 #include "content/browser/media/capture/web_contents_audio_input_stream.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 ~Impl() override; 71 ~Impl() override;
72 72
73 // Notifies the consumer callback that the stream is now dead. 73 // Notifies the consumer callback that the stream is now dead.
74 void ReportError(); 74 void ReportError();
75 75
76 // (Re-)Start/Stop mirroring by posting a call to AudioMirroringManager on the 76 // (Re-)Start/Stop mirroring by posting a call to AudioMirroringManager on the
77 // IO BrowserThread. 77 // IO BrowserThread.
78 void StartMirroring(); 78 void StartMirroring();
79 void StopMirroring(); 79 void StopMirroring();
80 80
81 // Increment/decrement the capturer count on the UI BrowserThread.
82 void IncrementCapturerCount();
83 void DecrementCapturerCount();
84
81 // Invoked on the UI thread to make sure WebContents muting is turned off for 85 // Invoked on the UI thread to make sure WebContents muting is turned off for
82 // successful audio capture. 86 // successful audio capture.
83 void UnmuteWebContentsAudio(); 87 void UnmuteWebContentsAudio();
84 88
85 // AudioMirroringManager::MirroringDestination implementation 89 // AudioMirroringManager::MirroringDestination implementation
86 void QueryForMatches(const std::set<SourceFrameRef>& candidates, 90 void QueryForMatches(const std::set<SourceFrameRef>& candidates,
87 const MatchesCallback& results_callback) override; 91 const MatchesCallback& results_callback) override;
88 void QueryForMatchesOnUIThread(const std::set<SourceFrameRef>& candidates, 92 void QueryForMatchesOnUIThread(const std::set<SourceFrameRef>& candidates,
89 const MatchesCallback& results_callback); 93 const MatchesCallback& results_callback);
90 media::AudioOutputStream* AddInput( 94 media::AudioOutputStream* AddInput(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 162
159 bool WebContentsAudioInputStream::Impl::Open() { 163 bool WebContentsAudioInputStream::Impl::Open() {
160 DCHECK(thread_checker_.CalledOnValidThread()); 164 DCHECK(thread_checker_.CalledOnValidThread());
161 165
162 DCHECK_EQ(CONSTRUCTED, state_) << "Illegal to Open more than once."; 166 DCHECK_EQ(CONSTRUCTED, state_) << "Illegal to Open more than once.";
163 167
164 if (!mixer_stream_->Open()) 168 if (!mixer_stream_->Open())
165 return false; 169 return false;
166 170
167 state_ = OPENED; 171 state_ = OPENED;
168
169 tracker_->Start( 172 tracker_->Start(
170 initial_render_process_id_, initial_main_render_frame_id_, 173 initial_render_process_id_, initial_main_render_frame_id_,
171 base::Bind(&Impl::OnTargetChanged, this)); 174 base::Bind(&Impl::OnTargetChanged, this));
175 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
176 base::Bind(&Impl::IncrementCapturerCount, this));
172 177
173 return true; 178 return true;
174 } 179 }
175 180
181 void WebContentsAudioInputStream::Impl::IncrementCapturerCount() {
182 DCHECK_CURRENTLY_ON(BrowserThread::UI);
183
184 if (WebContents* contents = tracker_->web_contents())
185 contents->IncrementCapturerCount(gfx::Size());
186 }
187
176 void WebContentsAudioInputStream::Impl::Start(AudioInputCallback* callback) { 188 void WebContentsAudioInputStream::Impl::Start(AudioInputCallback* callback) {
177 DCHECK(thread_checker_.CalledOnValidThread()); 189 DCHECK(thread_checker_.CalledOnValidThread());
178 DCHECK(callback); 190 DCHECK(callback);
179 191
180 if (state_ != OPENED) 192 if (state_ != OPENED)
181 return; 193 return;
182 194
183 callback_ = callback; 195 callback_ = callback;
184 if (is_target_lost_) { 196 if (is_target_lost_) {
185 ReportError(); 197 ReportError();
(...skipping 29 matching lines...) Expand all
215 StopMirroring(); 227 StopMirroring();
216 } 228 }
217 229
218 void WebContentsAudioInputStream::Impl::Close() { 230 void WebContentsAudioInputStream::Impl::Close() {
219 DCHECK(thread_checker_.CalledOnValidThread()); 231 DCHECK(thread_checker_.CalledOnValidThread());
220 232
221 Stop(); 233 Stop();
222 234
223 if (state_ == OPENED) { 235 if (state_ == OPENED) {
224 state_ = CONSTRUCTED; 236 state_ = CONSTRUCTED;
237 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
238 base::Bind(&Impl::DecrementCapturerCount, this));
225 tracker_->Stop(); 239 tracker_->Stop();
226 mixer_stream_->Close(); 240 mixer_stream_->Close();
227 } 241 }
228 242
229 DCHECK_EQ(CONSTRUCTED, state_); 243 DCHECK_EQ(CONSTRUCTED, state_);
230 state_ = CLOSED; 244 state_ = CLOSED;
231 } 245 }
232 246
247 void WebContentsAudioInputStream::Impl::DecrementCapturerCount() {
248 DCHECK_CURRENTLY_ON(BrowserThread::UI);
249
250 if (WebContents* contents = tracker_->web_contents())
251 contents->DecrementCapturerCount();
252 }
253
233 void WebContentsAudioInputStream::Impl::ReportError() { 254 void WebContentsAudioInputStream::Impl::ReportError() {
234 DCHECK(thread_checker_.CalledOnValidThread()); 255 DCHECK(thread_checker_.CalledOnValidThread());
235 256
236 // TODO(miu): Need clean-up of AudioInputCallback interface in a future 257 // TODO(miu): Need clean-up of AudioInputCallback interface in a future
237 // change, since its only implementation ignores the first argument entirely 258 // change, since its only implementation ignores the first argument entirely
238 callback_->OnError(NULL); 259 callback_->OnError(NULL);
239 } 260 }
240 261
241 void WebContentsAudioInputStream::Impl::StartMirroring() { 262 void WebContentsAudioInputStream::Impl::StartMirroring() {
242 DCHECK(thread_checker_.CalledOnValidThread()); 263 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 436
416 bool WebContentsAudioInputStream::GetAutomaticGainControl() { 437 bool WebContentsAudioInputStream::GetAutomaticGainControl() {
417 return impl_->mixer_stream()->GetAutomaticGainControl(); 438 return impl_->mixer_stream()->GetAutomaticGainControl();
418 } 439 }
419 440
420 bool WebContentsAudioInputStream::IsMuted() { 441 bool WebContentsAudioInputStream::IsMuted() {
421 return false; 442 return false;
422 } 443 }
423 444
424 } // namespace content 445 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698