OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/webrtc_local_audio_track_adapter.h" | 5 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/renderer/media/media_stream_audio_processor.h" |
8 #include "content/renderer/media/webrtc/webrtc_audio_sink_adapter.h" | 9 #include "content/renderer/media/webrtc/webrtc_audio_sink_adapter.h" |
9 #include "content/renderer/media/webrtc_local_audio_track.h" | 10 #include "content/renderer/media/webrtc_local_audio_track.h" |
| 11 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
10 | 12 |
11 namespace content { | 13 namespace content { |
12 | 14 |
13 static const char kAudioTrackKind[] = "audio"; | 15 static const char kAudioTrackKind[] = "audio"; |
14 | 16 |
15 scoped_refptr<WebRtcLocalAudioTrackAdapter> | 17 scoped_refptr<WebRtcLocalAudioTrackAdapter> |
16 WebRtcLocalAudioTrackAdapter::Create( | 18 WebRtcLocalAudioTrackAdapter::Create( |
17 const std::string& label, | 19 const std::string& label, |
18 webrtc::AudioSourceInterface* track_source) { | 20 webrtc::AudioSourceInterface* track_source) { |
19 talk_base::RefCountedObject<WebRtcLocalAudioTrackAdapter>* adapter = | 21 talk_base::RefCountedObject<WebRtcLocalAudioTrackAdapter>* adapter = |
20 new talk_base::RefCountedObject<WebRtcLocalAudioTrackAdapter>( | 22 new talk_base::RefCountedObject<WebRtcLocalAudioTrackAdapter>( |
21 label, track_source); | 23 label, track_source); |
22 return adapter; | 24 return adapter; |
23 } | 25 } |
24 | 26 |
25 WebRtcLocalAudioTrackAdapter::WebRtcLocalAudioTrackAdapter( | 27 WebRtcLocalAudioTrackAdapter::WebRtcLocalAudioTrackAdapter( |
26 const std::string& label, | 28 const std::string& label, |
27 webrtc::AudioSourceInterface* track_source) | 29 webrtc::AudioSourceInterface* track_source) |
28 : webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>(label), | 30 : webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>(label), |
29 owner_(NULL), | 31 owner_(NULL), |
30 track_source_(track_source) { | 32 track_source_(track_source), |
| 33 signal_level_(0) { |
31 } | 34 } |
32 | 35 |
33 WebRtcLocalAudioTrackAdapter::~WebRtcLocalAudioTrackAdapter() { | 36 WebRtcLocalAudioTrackAdapter::~WebRtcLocalAudioTrackAdapter() { |
34 } | 37 } |
35 | 38 |
36 void WebRtcLocalAudioTrackAdapter::Initialize(WebRtcLocalAudioTrack* owner) { | 39 void WebRtcLocalAudioTrackAdapter::Initialize(WebRtcLocalAudioTrack* owner) { |
37 DCHECK(!owner_); | 40 DCHECK(!owner_); |
38 DCHECK(owner); | 41 DCHECK(owner); |
39 owner_ = owner; | 42 owner_ = owner; |
40 } | 43 } |
41 | 44 |
| 45 void WebRtcLocalAudioTrackAdapter::SetAudioProcessor( |
| 46 const scoped_refptr<MediaStreamAudioProcessor>& processor) { |
| 47 base::AutoLock auto_lock(lock_); |
| 48 audio_processor_ = processor; |
| 49 } |
| 50 |
42 std::string WebRtcLocalAudioTrackAdapter::kind() const { | 51 std::string WebRtcLocalAudioTrackAdapter::kind() const { |
43 return kAudioTrackKind; | 52 return kAudioTrackKind; |
44 } | 53 } |
45 | 54 |
46 void WebRtcLocalAudioTrackAdapter::AddSink( | 55 void WebRtcLocalAudioTrackAdapter::AddSink( |
47 webrtc::AudioTrackSinkInterface* sink) { | 56 webrtc::AudioTrackSinkInterface* sink) { |
48 DCHECK(sink); | 57 DCHECK(sink); |
49 #ifndef NDEBUG | 58 #ifndef NDEBUG |
50 // Verify that |sink| has not been added. | 59 // Verify that |sink| has not been added. |
51 for (ScopedVector<WebRtcAudioSinkAdapter>::const_iterator it = | 60 for (ScopedVector<WebRtcAudioSinkAdapter>::const_iterator it = |
(...skipping 16 matching lines...) Expand all Loading... |
68 sink_adapters_.begin(); | 77 sink_adapters_.begin(); |
69 it != sink_adapters_.end(); ++it) { | 78 it != sink_adapters_.end(); ++it) { |
70 if ((*it)->IsEqual(sink)) { | 79 if ((*it)->IsEqual(sink)) { |
71 owner_->RemoveSink(*it); | 80 owner_->RemoveSink(*it); |
72 sink_adapters_.erase(it); | 81 sink_adapters_.erase(it); |
73 return; | 82 return; |
74 } | 83 } |
75 } | 84 } |
76 } | 85 } |
77 | 86 |
| 87 bool WebRtcLocalAudioTrackAdapter::GetSignalLevel(int* level) { |
| 88 base::AutoLock auto_lock(lock_); |
| 89 *level = signal_level_; |
| 90 return true; |
| 91 } |
| 92 |
| 93 talk_base::scoped_refptr<webrtc::AudioProcessorInterface> |
| 94 WebRtcLocalAudioTrackAdapter::GetAudioProcessor() { |
| 95 base::AutoLock auto_lock(lock_); |
| 96 return audio_processor_.get(); |
| 97 } |
| 98 |
78 std::vector<int> WebRtcLocalAudioTrackAdapter::VoeChannels() const { | 99 std::vector<int> WebRtcLocalAudioTrackAdapter::VoeChannels() const { |
79 base::AutoLock auto_lock(lock_); | 100 base::AutoLock auto_lock(lock_); |
80 return voe_channels_; | 101 return voe_channels_; |
81 } | 102 } |
82 | 103 |
83 void WebRtcLocalAudioTrackAdapter::SetSignalLevel(int signal_level) { | 104 void WebRtcLocalAudioTrackAdapter::SetSignalLevel(int signal_level) { |
84 // TODO(xians): Implements this. | 105 base::AutoLock auto_lock(lock_); |
| 106 signal_level_ = signal_level; |
85 } | 107 } |
86 | 108 |
87 void WebRtcLocalAudioTrackAdapter::AddChannel(int channel_id) { | 109 void WebRtcLocalAudioTrackAdapter::AddChannel(int channel_id) { |
88 DVLOG(1) << "WebRtcLocalAudioTrack::AddChannel(channel_id=" | 110 DVLOG(1) << "WebRtcLocalAudioTrack::AddChannel(channel_id=" |
89 << channel_id << ")"; | 111 << channel_id << ")"; |
90 base::AutoLock auto_lock(lock_); | 112 base::AutoLock auto_lock(lock_); |
91 if (std::find(voe_channels_.begin(), voe_channels_.end(), channel_id) != | 113 if (std::find(voe_channels_.begin(), voe_channels_.end(), channel_id) != |
92 voe_channels_.end()) { | 114 voe_channels_.end()) { |
93 // We need to handle the case when the same channel is connected to the | 115 // We need to handle the case when the same channel is connected to the |
94 // track more than once. | 116 // track more than once. |
(...skipping 15 matching lines...) Expand all Loading... |
110 | 132 |
111 webrtc::AudioSourceInterface* WebRtcLocalAudioTrackAdapter::GetSource() const { | 133 webrtc::AudioSourceInterface* WebRtcLocalAudioTrackAdapter::GetSource() const { |
112 return track_source_; | 134 return track_source_; |
113 } | 135 } |
114 | 136 |
115 cricket::AudioRenderer* WebRtcLocalAudioTrackAdapter::GetRenderer() { | 137 cricket::AudioRenderer* WebRtcLocalAudioTrackAdapter::GetRenderer() { |
116 return this; | 138 return this; |
117 } | 139 } |
118 | 140 |
119 } // namespace content | 141 } // namespace content |
OLD | NEW |