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