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 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "third_party/libjingle/source/talk/app/webrtc/mediastreamtrack.h" | 14 #include "third_party/libjingle/source/talk/app/webrtc/mediastreamtrack.h" |
15 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h" | 15 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h" |
16 | 16 |
17 namespace cricket { | 17 namespace cricket { |
18 class AudioRenderer; | 18 class AudioRenderer; |
19 } | 19 } |
20 | 20 |
21 namespace webrtc { | 21 namespace webrtc { |
22 class AudioSourceInterface; | 22 class AudioSourceInterface; |
| 23 class AudioProcessorInterface; |
23 } | 24 } |
24 | 25 |
25 namespace content { | 26 namespace content { |
26 | 27 |
27 class WebRtcAudioSinkAdapter; | 28 class WebRtcAudioSinkAdapter; |
28 class WebRtcLocalAudioTrack; | 29 class WebRtcLocalAudioTrack; |
29 | 30 |
30 class CONTENT_EXPORT WebRtcLocalAudioTrackAdapter | 31 class CONTENT_EXPORT WebRtcLocalAudioTrackAdapter |
31 : NON_EXPORTED_BASE(public cricket::AudioRenderer), | 32 : NON_EXPORTED_BASE(public cricket::AudioRenderer), |
32 NON_EXPORTED_BASE( | 33 NON_EXPORTED_BASE( |
33 public webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>) { | 34 public webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>) { |
34 public: | 35 public: |
35 static scoped_refptr<WebRtcLocalAudioTrackAdapter> Create( | 36 static scoped_refptr<WebRtcLocalAudioTrackAdapter> Create( |
36 const std::string& label, | 37 const std::string& label, |
37 webrtc::AudioSourceInterface* track_source); | 38 webrtc::AudioSourceInterface* track_source); |
38 | 39 |
39 WebRtcLocalAudioTrackAdapter( | 40 WebRtcLocalAudioTrackAdapter( |
40 const std::string& label, | 41 const std::string& label, |
41 webrtc::AudioSourceInterface* track_source); | 42 webrtc::AudioSourceInterface* track_source); |
42 | 43 |
43 virtual ~WebRtcLocalAudioTrackAdapter(); | 44 virtual ~WebRtcLocalAudioTrackAdapter(); |
44 | 45 |
45 void Initialize(WebRtcLocalAudioTrack* owner); | 46 void Initialize(WebRtcLocalAudioTrack* owner); |
46 | 47 |
47 std::vector<int> VoeChannels() const; | 48 std::vector<int> VoeChannels() const; |
48 | 49 |
| 50 // Method called by the WebRtcLocalAudioTrack to set the processor that |
| 51 // applies signal processing on the data of the track. |
| 52 // This class will keep a reference of the |processor|. |
| 53 // Called on the main render thread. |
| 54 void SetAudioProcessor(webrtc::AudioProcessorInterface* processor); |
| 55 |
49 private: | 56 private: |
50 // webrtc::MediaStreamTrack implementation. | 57 // webrtc::MediaStreamTrack implementation. |
51 virtual std::string kind() const OVERRIDE; | 58 virtual std::string kind() const OVERRIDE; |
52 | 59 |
53 // webrtc::AudioTrackInterface implementation. | 60 // webrtc::AudioTrackInterface implementation. |
54 virtual void AddSink(webrtc::AudioTrackSinkInterface* sink) OVERRIDE; | 61 virtual void AddSink(webrtc::AudioTrackSinkInterface* sink) OVERRIDE; |
55 virtual void RemoveSink(webrtc::AudioTrackSinkInterface* sink) OVERRIDE; | 62 virtual void RemoveSink(webrtc::AudioTrackSinkInterface* sink) OVERRIDE; |
| 63 virtual bool GetSignalLevel(int* level) OVERRIDE; |
| 64 virtual webrtc::AudioProcessorInterface* GetAudioProcessor() OVERRIDE; |
56 | 65 |
57 // cricket::AudioCapturer implementation. | 66 // cricket::AudioCapturer implementation. |
58 virtual void AddChannel(int channel_id) OVERRIDE; | 67 virtual void AddChannel(int channel_id) OVERRIDE; |
59 virtual void RemoveChannel(int channel_id) OVERRIDE; | 68 virtual void RemoveChannel(int channel_id) OVERRIDE; |
60 | 69 |
61 // webrtc::AudioTrackInterface implementation. | 70 // webrtc::AudioTrackInterface implementation. |
62 virtual webrtc::AudioSourceInterface* GetSource() const OVERRIDE; | 71 virtual webrtc::AudioSourceInterface* GetSource() const OVERRIDE; |
63 virtual cricket::AudioRenderer* GetRenderer() OVERRIDE; | 72 virtual cricket::AudioRenderer* GetRenderer() OVERRIDE; |
64 | 73 |
65 // Weak reference. | 74 // Weak reference. |
66 WebRtcLocalAudioTrack* owner_; | 75 WebRtcLocalAudioTrack* owner_; |
67 | 76 |
68 // The source of the audio track which handles the audio constraints. | 77 // The source of the audio track which handles the audio constraints. |
69 // TODO(xians): merge |track_source_| to |capturer_| in WebRtcLocalAudioTrack. | 78 // TODO(xians): merge |track_source_| to |capturer_| in WebRtcLocalAudioTrack. |
70 talk_base::scoped_refptr<webrtc::AudioSourceInterface> track_source_; | 79 talk_base::scoped_refptr<webrtc::AudioSourceInterface> track_source_; |
71 | 80 |
| 81 // The audio processsor that applies audio processing on the data of audio |
| 82 // track. |
| 83 talk_base::scoped_refptr<webrtc::AudioProcessorInterface> audio_processor_; |
| 84 |
72 // A vector of WebRtc VoE channels that the capturer sends data to. | 85 // A vector of WebRtc VoE channels that the capturer sends data to. |
73 std::vector<int> voe_channels_; | 86 std::vector<int> voe_channels_; |
74 | 87 |
75 // A vector of the peer connection sink adapters which receive the audio data | 88 // A vector of the peer connection sink adapters which receive the audio data |
76 // from the audio track. | 89 // from the audio track. |
77 ScopedVector<WebRtcAudioSinkAdapter> sink_adapters_; | 90 ScopedVector<WebRtcAudioSinkAdapter> sink_adapters_; |
78 | 91 |
79 // Protects |voe_channels_|. | 92 // The amplitude of the signal. |
| 93 int signal_level_; |
| 94 |
| 95 // Protects |voe_channels_|, |audio_processor_| and |signal_level_|. |
80 mutable base::Lock lock_; | 96 mutable base::Lock lock_; |
81 }; | 97 }; |
82 | 98 |
83 } // namespace content | 99 } // namespace content |
84 | 100 |
85 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_ | 101 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_ |
OLD | NEW |