OLD | NEW |
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 Loading... |
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, | |
34 PeerConnectionDependencyFactory* factory) | 32 PeerConnectionDependencyFactory* factory) |
35 : MediaStreamAudioSource(true /* is_local_source */), | 33 : MediaStreamAudioSource(true /* is_local_source */), |
36 consumer_render_frame_id_(consumer_render_frame_id), | 34 consumer_render_frame_id_(consumer_render_frame_id), |
37 pc_factory_(factory), | 35 pc_factory_(factory), |
38 constraints_(constraints), | |
39 started_callback_(started_callback), | |
40 volume_(0), | 36 volume_(0), |
41 allow_invalid_render_frame_id_for_testing_(false) { | 37 allow_invalid_render_frame_id_for_testing_(false) { |
42 DCHECK(pc_factory_); | 38 DCHECK(pc_factory_); |
43 DVLOG(1) << "ProcessedLocalAudioSource::ProcessedLocalAudioSource()"; | 39 DVLOG(1) << "ProcessedLocalAudioSource::ProcessedLocalAudioSource()"; |
44 MediaStreamSource::SetDeviceInfo(device_info); | 40 MediaStreamSource::SetDeviceInfo(device_info); |
45 } | 41 } |
46 | 42 |
47 ProcessedLocalAudioSource::~ProcessedLocalAudioSource() { | 43 ProcessedLocalAudioSource::~ProcessedLocalAudioSource() { |
48 DVLOG(1) << "ProcessedLocalAudioSource::~ProcessedLocalAudioSource()"; | 44 DVLOG(1) << "ProcessedLocalAudioSource::~ProcessedLocalAudioSource()"; |
49 EnsureSourceIsStopped(); | 45 EnsureSourceIsStopped(); |
50 } | 46 } |
51 | 47 |
52 // static | 48 // static |
53 ProcessedLocalAudioSource* ProcessedLocalAudioSource::From( | 49 ProcessedLocalAudioSource* ProcessedLocalAudioSource::From( |
54 MediaStreamAudioSource* source) { | 50 MediaStreamAudioSource* source) { |
55 if (source && source->GetClassIdentifier() == kClassIdentifier) | 51 if (source && source->GetClassIdentifier() == kClassIdentifier) |
56 return static_cast<ProcessedLocalAudioSource*>(source); | 52 return static_cast<ProcessedLocalAudioSource*>(source); |
57 return nullptr; | 53 return nullptr; |
58 } | 54 } |
59 | 55 |
| 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 |
60 void* ProcessedLocalAudioSource::GetClassIdentifier() const { | 64 void* ProcessedLocalAudioSource::GetClassIdentifier() const { |
61 return kClassIdentifier; | 65 return kClassIdentifier; |
62 } | 66 } |
63 | 67 |
64 bool ProcessedLocalAudioSource::EnsureSourceIsStarted() { | 68 bool ProcessedLocalAudioSource::EnsureSourceIsStarted() { |
65 DCHECK(thread_checker_.CalledOnValidThread()); | 69 DCHECK(thread_checker_.CalledOnValidThread()); |
66 | 70 |
67 { | 71 { |
68 base::AutoLock auto_lock(source_lock_); | 72 base::AutoLock auto_lock(source_lock_); |
69 if (source_) | 73 if (source_) |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 int ProcessedLocalAudioSource::Volume() const { | 256 int ProcessedLocalAudioSource::Volume() const { |
253 // Note: Using NoBarrier_Load() because the timing of visibility of the | 257 // Note: Using NoBarrier_Load() because the timing of visibility of the |
254 // updated volume information on other threads can be relaxed. | 258 // updated volume information on other threads can be relaxed. |
255 return base::subtle::NoBarrier_Load(&volume_); | 259 return base::subtle::NoBarrier_Load(&volume_); |
256 } | 260 } |
257 | 261 |
258 int ProcessedLocalAudioSource::MaxVolume() const { | 262 int ProcessedLocalAudioSource::MaxVolume() const { |
259 return WebRtcAudioDeviceImpl::kMaxVolumeLevel; | 263 return WebRtcAudioDeviceImpl::kMaxVolumeLevel; |
260 } | 264 } |
261 | 265 |
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 Loading... |
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 |
OLD | NEW |