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 (int 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)) { |
tommi (sloooow) - chröme
2013/08/26 08:18:36
Henrik: Take a look at this line, see how it was a
henrika (OOO until Aug 14)
2013/08/26 11:34:55
Thanks for pointing out this key change.
| |
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()"; |
74 | |
75 // TODO(xians): Remove this workaround. It is currently here to maintain | |
76 // backwards compatibility with the previous implementations and apps where | |
77 // no constraints are specified for audio but we've still enabled audio | |
78 // processing. | |
79 if (!need_audio_processing_ && !capturer->device_id().empty()) { | |
henrika (OOO until Aug 14)
2013/08/26 08:04:55
What is a typical case when we can hit this part?
tommi (sloooow) - chröme
2013/08/26 08:18:36
apprtc.appspot.com for instance. No audio process
henrika (OOO until Aug 14)
2013/08/26 11:34:55
OK.
| |
80 DLOG(WARNING) << "Enabling audio processing despite lack of constraints."; | |
81 need_audio_processing_ = true; | |
82 } | |
37 } | 83 } |
38 | 84 |
39 WebRtcLocalAudioTrack::~WebRtcLocalAudioTrack() { | 85 WebRtcLocalAudioTrack::~WebRtcLocalAudioTrack() { |
40 DCHECK(thread_checker_.CalledOnValidThread()); | 86 DCHECK(thread_checker_.CalledOnValidThread()); |
41 DVLOG(1) << "WebRtcLocalAudioTrack::~WebRtcLocalAudioTrack()"; | 87 DVLOG(1) << "WebRtcLocalAudioTrack::~WebRtcLocalAudioTrack()"; |
42 // Users might not call Stop() on the track. | 88 // Users might not call Stop() on the track. |
43 Stop(); | 89 Stop(); |
44 } | 90 } |
45 | 91 |
46 void WebRtcLocalAudioTrack::CaptureData(const int16* audio_data, | 92 void WebRtcLocalAudioTrack::CaptureData(const int16* audio_data, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 base::AutoLock auto_lock(lock_); | 235 base::AutoLock auto_lock(lock_); |
190 sinks = sinks_; | 236 sinks = sinks_; |
191 capturer_ = NULL; | 237 capturer_ = NULL; |
192 } | 238 } |
193 | 239 |
194 for (SinkList::const_iterator it = sinks.begin(); it != sinks.end(); ++it) | 240 for (SinkList::const_iterator it = sinks.begin(); it != sinks.end(); ++it) |
195 (*it)->Reset(); | 241 (*it)->Reset(); |
196 } | 242 } |
197 | 243 |
198 } // namespace content | 244 } // namespace content |
OLD | NEW |