OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_LOCAL_AUDIO_TRACK_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
13 #include "content/renderer/media/webrtc_audio_device_impl.h" | 13 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 14 #include "content/renderer/media/webrtc_local_audio_source_provider.h" |
14 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" | 15 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" |
15 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 16 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
16 #include "third_party/libjingle/source/talk/app/webrtc/mediastreamtrack.h" | 17 #include "third_party/libjingle/source/talk/app/webrtc/mediastreamtrack.h" |
17 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h" | 18 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h" |
18 | 19 |
19 namespace cricket { | 20 namespace cricket { |
20 class AudioRenderer; | 21 class AudioRenderer; |
21 } // namespace cricket | 22 } // namespace cricket |
22 | 23 |
23 namespace media { | 24 namespace media { |
24 class AudioBus; | 25 class AudioBus; |
25 } // namespace media | 26 } // namespace media |
26 | 27 |
27 namespace content { | 28 namespace content { |
28 | 29 |
29 class WebAudioCapturerSource; | 30 class WebAudioCapturerSource; |
30 class WebRtcAudioCapturer; | 31 class WebRtcAudioCapturer; |
31 class WebRtcAudioCapturerSinkOwner; | 32 class WebRtcAudioCapturerSinkOwner; |
| 33 class WebRtcAudioProcessor; |
32 | 34 |
33 // A WebRtcLocalAudioTrack instance contains the implementations of | 35 // A WebRtcLocalAudioTrack instance contains the implementations of |
34 // MediaStreamTrack and WebRtcAudioCapturerSink. | 36 // MediaStreamTrack and WebRtcAudioCapturerSink. |
35 // When an instance is created, it will register itself as a track to the | 37 // When an instance is created, it will register itself as a track to the |
36 // WebRtcAudioCapturer to get the captured data, and forward the data to | 38 // WebRtcAudioCapturer to get the captured data, and forward the data to |
37 // its |sinks_|. The data flow can be stopped by disabling the audio track. | 39 // its |sinks_|. The data flow can be stopped by disabling the audio track. |
38 class CONTENT_EXPORT WebRtcLocalAudioTrack | 40 class CONTENT_EXPORT WebRtcLocalAudioTrack |
39 : NON_EXPORTED_BASE(public cricket::AudioRenderer), | 41 : NON_EXPORTED_BASE(public cricket::AudioRenderer), |
40 NON_EXPORTED_BASE( | 42 NON_EXPORTED_BASE( |
41 public webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>) { | 43 public webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>), |
| 44 NON_EXPORTED_BASE(public WebRtcAudioRenderDataObserver) { |
42 public: | 45 public: |
43 static scoped_refptr<WebRtcLocalAudioTrack> Create( | 46 static scoped_refptr<WebRtcLocalAudioTrack> Create( |
44 const std::string& id, | 47 const std::string& id, |
45 const scoped_refptr<WebRtcAudioCapturer>& capturer, | 48 const scoped_refptr<WebRtcAudioCapturer>& capturer, |
46 WebAudioCapturerSource* webaudio_source, | 49 WebAudioCapturerSource* webaudio_source, |
47 webrtc::AudioSourceInterface* track_source, | 50 webrtc::AudioSourceInterface* track_source, |
48 const webrtc::MediaConstraintsInterface* constraints); | 51 const webrtc::MediaConstraintsInterface* constraints, |
| 52 WebRtcAudioDeviceImpl* audio_device); |
49 | 53 |
50 // Add a sink to the track. This function will trigger a SetCaptureFormat() | 54 // Add a sink to the track. This function will trigger a SetCaptureFormat() |
51 // call on the |sink|. | 55 // call on the |sink|. |
52 // Called on the main render thread. | 56 // Called on the main render thread. |
53 void AddSink(WebRtcAudioCapturerSink* sink); | 57 void AddSink(WebRtcAudioCapturerSink* sink); |
54 | 58 |
55 // Remove a sink from the track. | 59 // Remove a sink from the track. |
56 // Called on the main render thread. | 60 // Called on the main render thread. |
57 void RemoveSink(WebRtcAudioCapturerSink* sink); | 61 void RemoveSink(WebRtcAudioCapturerSink* sink); |
58 | 62 |
59 // Starts the local audio track. Called on the main render thread and | 63 // Starts the local audio track. Called on the main render thread and |
60 // should be called only once when audio track is created. | 64 // should be called only once when audio track is created. |
61 void Start(); | 65 void Start(); |
62 | 66 |
63 // Stops the local audio track. Called on the main render thread and | 67 // Stops the local audio track. Called on the main render thread by the |
64 // should be called only once when audio track going away. | 68 // capturer and should be called only once when audio track going away. |
65 void Stop(); | 69 void Stop(); |
66 | 70 |
67 // Method called by the capturer to deliver the capture data. | 71 // Method called by the capturer to deliver the capture data. |
68 void Capture(media::AudioBus* audio_source, | 72 void Capture(media::AudioBus* audio_source, |
69 int audio_delay_milliseconds, | 73 int audio_delay_milliseconds, |
70 int volume, | 74 int volume, |
71 bool key_pressed); | 75 bool key_pressed); |
72 | 76 |
73 // Method called by the capturer to set the audio parameters used by source | 77 // Method called by the capturer to set the audio parameters used by source |
74 // of the capture data.. | 78 // of the capture data.. |
75 // Can be called on different user threads. | 79 // Can be called on different user threads. |
76 void SetCaptureFormat(const media::AudioParameters& params); | 80 void SetCaptureFormat(const media::AudioParameters& params); |
77 | 81 |
| 82 WebKit::WebAudioSourceProvider* audio_source_provider() const { |
| 83 return source_provider_.get(); |
| 84 } |
| 85 |
78 protected: | 86 protected: |
79 WebRtcLocalAudioTrack( | 87 WebRtcLocalAudioTrack( |
80 const std::string& label, | 88 const std::string& label, |
81 const scoped_refptr<WebRtcAudioCapturer>& capturer, | 89 const scoped_refptr<WebRtcAudioCapturer>& capturer, |
82 WebAudioCapturerSource* webaudio_source, | 90 WebAudioCapturerSource* webaudio_source, |
83 webrtc::AudioSourceInterface* track_source, | 91 webrtc::AudioSourceInterface* track_source, |
84 const webrtc::MediaConstraintsInterface* constraints); | 92 const webrtc::MediaConstraintsInterface* constraints, |
| 93 WebRtcAudioDeviceImpl* audio_device); |
85 | 94 |
86 virtual ~WebRtcLocalAudioTrack(); | 95 virtual ~WebRtcLocalAudioTrack(); |
87 | 96 |
88 private: | 97 private: |
89 typedef std::list<scoped_refptr<WebRtcAudioCapturerSinkOwner> > SinkList; | 98 typedef std::list<scoped_refptr<WebRtcAudioCapturerSinkOwner> > SinkList; |
90 | 99 |
91 // cricket::AudioCapturer implementation. | 100 // cricket::AudioCapturer implementation. |
92 virtual void AddChannel(int channel_id) OVERRIDE; | 101 virtual void AddChannel(int channel_id) OVERRIDE; |
93 virtual void RemoveChannel(int channel_id) OVERRIDE; | 102 virtual void RemoveChannel(int channel_id) OVERRIDE; |
94 | 103 |
95 // webrtc::AudioTrackInterface implementation. | 104 // webrtc::AudioTrackInterface implementation. |
96 virtual webrtc::AudioSourceInterface* GetSource() const OVERRIDE; | 105 virtual webrtc::AudioSourceInterface* GetSource() const OVERRIDE; |
97 virtual cricket::AudioRenderer* GetRenderer() OVERRIDE; | 106 virtual cricket::AudioRenderer* GetRenderer() OVERRIDE; |
98 | 107 |
99 // webrtc::MediaStreamTrack implementation. | 108 // webrtc::MediaStreamTrack implementation. |
100 virtual std::string kind() const OVERRIDE; | 109 virtual std::string kind() const OVERRIDE; |
101 | 110 |
| 111 // WebRtcAudioRenderDataObserver implementation. |
| 112 virtual void OnRenderData(const int16* render_audio, |
| 113 int sample_rate, |
| 114 int number_of_channels, |
| 115 int number_of_frames, |
| 116 int render_delay_ms) OVERRIDE; |
| 117 virtual void OnRenderClosing() OVERRIDE; |
| 118 |
102 // The provider of captured data to render. | 119 // The provider of captured data to render. |
103 // The WebRtcAudioCapturer is today created by WebRtcAudioDeviceImpl. | 120 // The WebRtcAudioCapturer is today created by WebRtcAudioDeviceImpl. |
104 scoped_refptr<WebRtcAudioCapturer> capturer_; | 121 scoped_refptr<WebRtcAudioCapturer> capturer_; |
105 | 122 |
106 // The source of the audio track which is used by WebAudio, which provides | 123 // The source of the audio track which is used by WebAudio, which provides |
107 // data to the audio track when hooking up with WebAudio. | 124 // data to the audio track when hooking up with WebAudio. |
108 scoped_refptr<WebAudioCapturerSource> webaudio_source_; | 125 scoped_refptr<WebAudioCapturerSource> webaudio_source_; |
109 | 126 |
110 // The source of the audio track which handles the audio constraints. | 127 // The source of the audio track which handles the audio constraints. |
111 // TODO(xians): merge |track_source_| to |capturer_|. | 128 // TODO(xians): merge |track_source_| to |capturer_|. |
112 talk_base::scoped_refptr<webrtc::AudioSourceInterface> track_source_; | 129 talk_base::scoped_refptr<webrtc::AudioSourceInterface> track_source_; |
113 | 130 |
114 // A list of sinks that the audio data is fed to. | 131 // A list of sinks that the audio data is fed to. |
115 SinkList sinks_; | 132 SinkList sinks_; |
116 | 133 |
117 // Used to DCHECK that we are called on the correct thread. | 134 // Used to DCHECK that we are called on the correct thread. |
118 base::ThreadChecker thread_checker_; | 135 base::ThreadChecker thread_checker_; |
119 | 136 |
120 // Protects |params_| and |sinks_|. | 137 // Protects |params_| and |sinks_|. |
121 mutable base::Lock lock_; | 138 mutable base::Lock lock_; |
122 | 139 |
123 // A vector of WebRtc VoE channels that the capturer sends datat to. | 140 // A vector of WebRtc VoE channels that the capturer sends datat to. |
124 std::vector<int> voe_channels_; | 141 std::vector<int> voe_channels_; |
125 | 142 |
126 bool need_audio_processing_; | 143 bool need_audio_processing_; |
127 | 144 |
128 // Buffers used for temporary storage during capture callbacks. | 145 // Cached audio parameters for the source. |
129 // Allocated during initialization. | 146 media::AudioParameters source_params_; |
130 class ConfiguredBuffer; | 147 |
131 scoped_refptr<ConfiguredBuffer> buffer_; | 148 // Cached audio parameters for the sinks. |
| 149 media::AudioParameters sink_params_; |
| 150 |
| 151 scoped_ptr<WebRtcAudioProcessor> audio_processor_; |
| 152 |
| 153 // The source provider to feed the track data to other clients like |
| 154 // WebAudio. |
| 155 const scoped_ptr<WebRtcLocalAudioSourceProvider> source_provider_; |
| 156 |
| 157 WebRtcAudioDeviceImpl* audio_device_; |
132 | 158 |
133 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioTrack); | 159 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioTrack); |
134 }; | 160 }; |
135 | 161 |
136 } // namespace content | 162 } // namespace content |
137 | 163 |
138 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ | 164 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ |
OLD | NEW |