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