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

Side by Side Diff: content/renderer/media/webrtc/processed_local_audio_source.cc

Issue 2623443002: Fix getUserMedia so that failure is reported for invalid audio sources. (Closed)
Patch Set: Address comments Created 3 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
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 "content/renderer/media/webrtc/processed_local_audio_source.h" 5 #include "content/renderer/media/webrtc/processed_local_audio_source.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "content/renderer/media/audio_device_factory.h" 10 #include "content/renderer/media/audio_device_factory.h"
(...skipping 11 matching lines...) Expand all
22 namespace content { 22 namespace content {
23 23
24 namespace { 24 namespace {
25 // Used as an identifier for ProcessedLocalAudioSource::From(). 25 // Used as an identifier for ProcessedLocalAudioSource::From().
26 void* const kClassIdentifier = const_cast<void**>(&kClassIdentifier); 26 void* const kClassIdentifier = const_cast<void**>(&kClassIdentifier);
27 } // namespace 27 } // namespace
28 28
29 ProcessedLocalAudioSource::ProcessedLocalAudioSource( 29 ProcessedLocalAudioSource::ProcessedLocalAudioSource(
30 int consumer_render_frame_id, 30 int consumer_render_frame_id,
31 const StreamDeviceInfo& device_info, 31 const StreamDeviceInfo& device_info,
32 const blink::WebMediaConstraints& constraints,
33 const ConstraintsCallback& started_callback,
32 PeerConnectionDependencyFactory* factory) 34 PeerConnectionDependencyFactory* factory)
33 : MediaStreamAudioSource(true /* is_local_source */), 35 : MediaStreamAudioSource(true /* is_local_source */),
34 consumer_render_frame_id_(consumer_render_frame_id), 36 consumer_render_frame_id_(consumer_render_frame_id),
35 pc_factory_(factory), 37 pc_factory_(factory),
38 constraints_(constraints),
39 started_callback_(started_callback),
36 volume_(0), 40 volume_(0),
37 allow_invalid_render_frame_id_for_testing_(false) { 41 allow_invalid_render_frame_id_for_testing_(false) {
38 DCHECK(pc_factory_); 42 DCHECK(pc_factory_);
39 DVLOG(1) << "ProcessedLocalAudioSource::ProcessedLocalAudioSource()"; 43 DVLOG(1) << "ProcessedLocalAudioSource::ProcessedLocalAudioSource()";
40 MediaStreamSource::SetDeviceInfo(device_info); 44 MediaStreamSource::SetDeviceInfo(device_info);
41 } 45 }
42 46
43 ProcessedLocalAudioSource::~ProcessedLocalAudioSource() { 47 ProcessedLocalAudioSource::~ProcessedLocalAudioSource() {
44 DVLOG(1) << "ProcessedLocalAudioSource::~ProcessedLocalAudioSource()"; 48 DVLOG(1) << "ProcessedLocalAudioSource::~ProcessedLocalAudioSource()";
45 EnsureSourceIsStopped(); 49 EnsureSourceIsStopped();
46 } 50 }
47 51
48 // static 52 // static
49 ProcessedLocalAudioSource* ProcessedLocalAudioSource::From( 53 ProcessedLocalAudioSource* ProcessedLocalAudioSource::From(
50 MediaStreamAudioSource* source) { 54 MediaStreamAudioSource* source) {
51 if (source && source->GetClassIdentifier() == kClassIdentifier) 55 if (source && source->GetClassIdentifier() == kClassIdentifier)
52 return static_cast<ProcessedLocalAudioSource*>(source); 56 return static_cast<ProcessedLocalAudioSource*>(source);
53 return nullptr; 57 return nullptr;
54 } 58 }
55 59
56 void ProcessedLocalAudioSource::SetSourceConstraints(
57 const blink::WebMediaConstraints& constraints) {
58 DCHECK(thread_checker_.CalledOnValidThread());
59 DCHECK(!constraints.isNull());
60 DCHECK(!source_);
61 constraints_ = constraints;
62 }
63
64 void* ProcessedLocalAudioSource::GetClassIdentifier() const { 60 void* ProcessedLocalAudioSource::GetClassIdentifier() const {
65 return kClassIdentifier; 61 return kClassIdentifier;
66 } 62 }
67 63
68 bool ProcessedLocalAudioSource::EnsureSourceIsStarted() { 64 bool ProcessedLocalAudioSource::EnsureSourceIsStarted() {
69 DCHECK(thread_checker_.CalledOnValidThread()); 65 DCHECK(thread_checker_.CalledOnValidThread());
70 66
71 { 67 {
72 base::AutoLock auto_lock(source_lock_); 68 base::AutoLock auto_lock(source_lock_);
73 if (source_) 69 if (source_)
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 int ProcessedLocalAudioSource::Volume() const { 252 int ProcessedLocalAudioSource::Volume() const {
257 // Note: Using NoBarrier_Load() because the timing of visibility of the 253 // Note: Using NoBarrier_Load() because the timing of visibility of the
258 // updated volume information on other threads can be relaxed. 254 // updated volume information on other threads can be relaxed.
259 return base::subtle::NoBarrier_Load(&volume_); 255 return base::subtle::NoBarrier_Load(&volume_);
260 } 256 }
261 257
262 int ProcessedLocalAudioSource::MaxVolume() const { 258 int ProcessedLocalAudioSource::MaxVolume() const {
263 return WebRtcAudioDeviceImpl::kMaxVolumeLevel; 259 return WebRtcAudioDeviceImpl::kMaxVolumeLevel;
264 } 260 }
265 261
262 void ProcessedLocalAudioSource::OnCaptureStarted() {
263 started_callback_.Run(this, MEDIA_DEVICE_OK, "");
264 }
265
266 void ProcessedLocalAudioSource::Capture(const media::AudioBus* audio_bus, 266 void ProcessedLocalAudioSource::Capture(const media::AudioBus* audio_bus,
267 int audio_delay_milliseconds, 267 int audio_delay_milliseconds,
268 double volume, 268 double volume,
269 bool key_pressed) { 269 bool key_pressed) {
270 #if defined(OS_WIN) || defined(OS_MACOSX) 270 #if defined(OS_WIN) || defined(OS_MACOSX)
271 DCHECK_LE(volume, 1.0); 271 DCHECK_LE(volume, 1.0);
272 #elif (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_OPENBSD) 272 #elif (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_OPENBSD)
273 // We have a special situation on Linux where the microphone volume can be 273 // We have a special situation on Linux where the microphone volume can be
274 // "higher than maximum". The input volume slider in the sound preference 274 // "higher than maximum". The input volume slider in the sound preference
275 // allows the user to set a scaling that is higher than 100%. It means that 275 // allows the user to set a scaling that is higher than 100%. It means that
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 367
368 // If the buffer size is missing from the StreamDeviceInfo, provide 10ms as a 368 // If the buffer size is missing from the StreamDeviceInfo, provide 10ms as a
369 // fall-back. 369 // fall-back.
370 // 370 //
371 // TODO(miu): Identify where/why the buffer size might be missing, fix the 371 // TODO(miu): Identify where/why the buffer size might be missing, fix the
372 // code, and then require it here. http://crbug.com/638081 372 // code, and then require it here. http://crbug.com/638081
373 return (sample_rate / 100); 373 return (sample_rate / 100);
374 } 374 }
375 375
376 } // namespace content 376 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698