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_local_audio_track.h" | 5 #include "content/renderer/media/webrtc_local_audio_track.h" |
6 | 6 |
7 #include "content/renderer/media/webrtc_audio_capturer.h" | 7 #include "content/renderer/media/webrtc_audio_capturer.h" |
8 #include "content/renderer/media/webrtc_audio_capturer_sink_owner.h" | 8 #include "content/renderer/media/webrtc_audio_capturer_sink_owner.h" |
9 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h" | 9 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 static const char kAudioTrackKind[] = "audio"; | 13 static const char kAudioTrackKind[] = "audio"; |
14 | 14 |
| 15 namespace { |
| 16 |
| 17 using webrtc::MediaConstraintsInterface; |
| 18 |
| 19 // This helper function checks if any audio constraints are set that require |
| 20 // audio processing to be applied. Right now this is a big, single switch for |
| 21 // all of the properties, but in the future they'll be handled one by one. |
| 22 bool NeedsAudioProcessing( |
| 23 const webrtc::MediaConstraintsInterface* constraints) { |
| 24 if (!constraints) |
| 25 return false; |
| 26 |
| 27 static const char* kAudioProcessingProperties[] = { |
| 28 MediaConstraintsInterface::kEchoCancellation, |
| 29 MediaConstraintsInterface::kExperimentalEchoCancellation, |
| 30 MediaConstraintsInterface::kAutoGainControl, |
| 31 MediaConstraintsInterface::kExperimentalAutoGainControl, |
| 32 MediaConstraintsInterface::kNoiseSuppression, |
| 33 MediaConstraintsInterface::kHighpassFilter, |
| 34 }; |
| 35 |
| 36 for (size_t i = 0; i < arraysize(kAudioProcessingProperties); ++i) { |
| 37 bool value = false; |
| 38 if (webrtc::FindConstraint(constraints, kAudioProcessingProperties[i], |
| 39 &value, NULL) && |
| 40 value) { |
| 41 return true; |
| 42 } |
| 43 } |
| 44 |
| 45 return false; |
| 46 } |
| 47 |
| 48 } // namespace. |
| 49 |
15 scoped_refptr<WebRtcLocalAudioTrack> WebRtcLocalAudioTrack::Create( | 50 scoped_refptr<WebRtcLocalAudioTrack> WebRtcLocalAudioTrack::Create( |
16 const std::string& id, | 51 const std::string& id, |
17 const scoped_refptr<WebRtcAudioCapturer>& capturer, | 52 const scoped_refptr<WebRtcAudioCapturer>& capturer, |
18 webrtc::AudioSourceInterface* track_source) { | 53 webrtc::AudioSourceInterface* track_source, |
| 54 const webrtc::MediaConstraintsInterface* constraints) { |
19 talk_base::RefCountedObject<WebRtcLocalAudioTrack>* track = | 55 talk_base::RefCountedObject<WebRtcLocalAudioTrack>* track = |
20 new talk_base::RefCountedObject<WebRtcLocalAudioTrack>( | 56 new talk_base::RefCountedObject<WebRtcLocalAudioTrack>( |
21 id, capturer, track_source); | 57 id, capturer, track_source, constraints); |
22 return track; | 58 return track; |
23 } | 59 } |
24 | 60 |
25 WebRtcLocalAudioTrack::WebRtcLocalAudioTrack( | 61 WebRtcLocalAudioTrack::WebRtcLocalAudioTrack( |
26 const std::string& label, | 62 const std::string& label, |
27 const scoped_refptr<WebRtcAudioCapturer>& capturer, | 63 const scoped_refptr<WebRtcAudioCapturer>& capturer, |
28 webrtc::AudioSourceInterface* track_source) | 64 webrtc::AudioSourceInterface* track_source, |
| 65 const webrtc::MediaConstraintsInterface* constraints) |
29 : webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>(label), | 66 : webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>(label), |
30 capturer_(capturer), | 67 capturer_(capturer), |
31 track_source_(track_source), | 68 track_source_(track_source), |
32 need_audio_processing_(!capturer->device_id().empty()) { | 69 need_audio_processing_(NeedsAudioProcessing(constraints)) { |
33 // The capturer with a valid device id is using microphone as source, | 70 // The capturer with a valid device id is using microphone as source, |
34 // and APM (AudioProcessingModule) is turned on only for microphone data. | 71 // and APM (AudioProcessingModule) is turned on only for microphone data. |
35 DCHECK(capturer.get()); | 72 DCHECK(capturer.get()); |
36 DVLOG(1) << "WebRtcLocalAudioTrack::WebRtcLocalAudioTrack()"; | 73 DVLOG(1) << "WebRtcLocalAudioTrack::WebRtcLocalAudioTrack()"; |
37 | |
38 // TODO(tommi): Remove this, feed audio constraints to WebRtcLocalAudioTrack | |
39 // and check the constraints. This is here to fix a recent regression whereby | |
40 // audio processing is not enabled for WebAudio regardless of the hard coded | |
41 // audio constraints. For more info: http://crbug.com/277134 | |
42 need_audio_processing_ = true; | |
43 } | 74 } |
44 | 75 |
45 WebRtcLocalAudioTrack::~WebRtcLocalAudioTrack() { | 76 WebRtcLocalAudioTrack::~WebRtcLocalAudioTrack() { |
46 DCHECK(thread_checker_.CalledOnValidThread()); | 77 DCHECK(thread_checker_.CalledOnValidThread()); |
47 DVLOG(1) << "WebRtcLocalAudioTrack::~WebRtcLocalAudioTrack()"; | 78 DVLOG(1) << "WebRtcLocalAudioTrack::~WebRtcLocalAudioTrack()"; |
48 // Users might not call Stop() on the track. | 79 // Users might not call Stop() on the track. |
49 Stop(); | 80 Stop(); |
50 } | 81 } |
51 | 82 |
52 void WebRtcLocalAudioTrack::CaptureData(const int16* audio_data, | 83 void WebRtcLocalAudioTrack::CaptureData(const int16* audio_data, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 base::AutoLock auto_lock(lock_); | 226 base::AutoLock auto_lock(lock_); |
196 sinks = sinks_; | 227 sinks = sinks_; |
197 capturer_ = NULL; | 228 capturer_ = NULL; |
198 } | 229 } |
199 | 230 |
200 for (SinkList::const_iterator it = sinks.begin(); it != sinks.end(); ++it) | 231 for (SinkList::const_iterator it = sinks.begin(); it != sinks.end(); ++it) |
201 (*it)->Reset(); | 232 (*it)->Reset(); |
202 } | 233 } |
203 | 234 |
204 } // namespace content | 235 } // namespace content |
OLD | NEW |