OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_RENDERER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_RENDERER_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_RENDERER_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_RENDERER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "content/public/renderer/media_stream_audio_sink.h" |
16 #include "content/renderer/media/media_stream_audio_renderer.h" | 17 #include "content/renderer/media/media_stream_audio_renderer.h" |
17 #include "content/renderer/media/webrtc_audio_device_impl.h" | 18 #include "content/renderer/media/webrtc_audio_device_impl.h" |
18 #include "content/renderer/media/webrtc_local_audio_track.h" | 19 #include "content/renderer/media/webrtc_local_audio_track.h" |
| 20 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
19 | 21 |
20 namespace media { | 22 namespace media { |
21 class AudioBus; | 23 class AudioBus; |
22 class AudioFifo; | 24 class AudioFifo; |
23 class AudioOutputDevice; | 25 class AudioOutputDevice; |
24 class AudioParameters; | 26 class AudioParameters; |
25 } | 27 } |
26 | 28 |
27 namespace content { | 29 namespace content { |
28 | 30 |
29 class WebRtcAudioCapturer; | 31 class WebRtcAudioCapturer; |
30 | 32 |
31 // WebRtcLocalAudioRenderer is a MediaStreamAudioRenderer designed for rendering | 33 // WebRtcLocalAudioRenderer is a MediaStreamAudioRenderer designed for rendering |
32 // local audio media stream tracks, | 34 // local audio media stream tracks, |
33 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediastreamtrack | 35 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediastreamtrack |
34 // It also implements media::AudioRendererSink::RenderCallback to render audio | 36 // It also implements media::AudioRendererSink::RenderCallback to render audio |
35 // data provided from a WebRtcLocalAudioTrack source. | 37 // data provided from a WebRtcLocalAudioTrack source. |
36 // When the audio layer in the browser process asks for data to render, this | 38 // When the audio layer in the browser process asks for data to render, this |
37 // class provides the data by implementing the WebRtcAudioCapturerSink | 39 // class provides the data by implementing the MediaStreamAudioSink |
38 // interface, i.e., we are a sink seen from the WebRtcAudioCapturer perspective. | 40 // interface, i.e., we are a sink seen from the WebRtcAudioCapturer perspective. |
39 // TODO(henrika): improve by using similar principles as in RTCVideoRenderer | 41 // TODO(henrika): improve by using similar principles as in RTCVideoRenderer |
40 // which register itself to the video track when the provider is started and | 42 // which register itself to the video track when the provider is started and |
41 // deregisters itself when it is stopped. | 43 // deregisters itself when it is stopped. |
42 // Tracking this at http://crbug.com/164813. | 44 // Tracking this at http://crbug.com/164813. |
43 class CONTENT_EXPORT WebRtcLocalAudioRenderer | 45 class CONTENT_EXPORT WebRtcLocalAudioRenderer |
44 : NON_EXPORTED_BASE(public MediaStreamAudioRenderer), | 46 : NON_EXPORTED_BASE(public MediaStreamAudioRenderer), |
45 NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback), | 47 NON_EXPORTED_BASE(public MediaStreamAudioSink), |
46 NON_EXPORTED_BASE(public WebRtcAudioCapturerSink) { | 48 NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback) { |
47 public: | 49 public: |
48 // Creates a local renderer and registers a capturing |source| object. | 50 // Creates a local renderer and registers a capturing |source| object. |
49 // The |source| is owned by the WebRtcAudioDeviceImpl. | 51 // The |source| is owned by the WebRtcAudioDeviceImpl. |
50 // Called on the main thread. | 52 // Called on the main thread. |
51 WebRtcLocalAudioRenderer(WebRtcLocalAudioTrack* audio_track, | 53 WebRtcLocalAudioRenderer(const blink::WebMediaStreamTrack& audio_track, |
52 int source_render_view_id, | 54 int source_render_view_id, |
53 int session_id, | 55 int session_id, |
54 int frames_per_buffer); | 56 int frames_per_buffer); |
55 | 57 |
56 // MediaStreamAudioRenderer implementation. | 58 // MediaStreamAudioRenderer implementation. |
57 // Called on the main thread. | 59 // Called on the main thread. |
58 virtual void Start() OVERRIDE; | 60 virtual void Start() OVERRIDE; |
59 virtual void Stop() OVERRIDE; | 61 virtual void Stop() OVERRIDE; |
60 virtual void Play() OVERRIDE; | 62 virtual void Play() OVERRIDE; |
61 virtual void Pause() OVERRIDE; | 63 virtual void Pause() OVERRIDE; |
62 virtual void SetVolume(float volume) OVERRIDE; | 64 virtual void SetVolume(float volume) OVERRIDE; |
63 virtual base::TimeDelta GetCurrentRenderTime() const OVERRIDE; | 65 virtual base::TimeDelta GetCurrentRenderTime() const OVERRIDE; |
64 virtual bool IsLocalRenderer() const OVERRIDE; | 66 virtual bool IsLocalRenderer() const OVERRIDE; |
65 | 67 |
66 const base::TimeDelta& total_render_time() const { | 68 const base::TimeDelta& total_render_time() const { |
67 return total_render_time_; | 69 return total_render_time_; |
68 } | 70 } |
69 | 71 |
70 protected: | 72 protected: |
71 virtual ~WebRtcLocalAudioRenderer(); | 73 virtual ~WebRtcLocalAudioRenderer(); |
72 | 74 |
73 private: | 75 private: |
74 // WebRtcAudioCapturerSink implementation. | 76 // MediaStreamAudioSink implementation. |
75 | 77 |
76 // Called on the AudioInputDevice worker thread. | 78 // Called on the AudioInputDevice worker thread. |
77 virtual int CaptureData(const std::vector<int>& channels, | 79 virtual void OnData(const int16* audio_data, |
78 const int16* audio_data, | 80 int sample_rate, |
79 int sample_rate, | 81 int number_of_channels, |
80 int number_of_channels, | 82 int number_of_frames) OVERRIDE; |
81 int number_of_frames, | |
82 int audio_delay_milliseconds, | |
83 int current_volume, | |
84 bool need_audio_processing, | |
85 bool key_pressed) OVERRIDE; | |
86 | 83 |
87 // Can be called on different user thread. | 84 // Called on the AudioInputDevice worker thread. |
88 virtual void SetCaptureFormat(const media::AudioParameters& params) OVERRIDE; | 85 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; |
89 | 86 |
90 // media::AudioRendererSink::RenderCallback implementation. | 87 // media::AudioRendererSink::RenderCallback implementation. |
91 // Render() is called on the AudioOutputDevice thread and OnRenderError() | 88 // Render() is called on the AudioOutputDevice thread and OnRenderError() |
92 // on the IO thread. | 89 // on the IO thread. |
93 virtual int Render(media::AudioBus* audio_bus, | 90 virtual int Render(media::AudioBus* audio_bus, |
94 int audio_delay_milliseconds) OVERRIDE; | 91 int audio_delay_milliseconds) OVERRIDE; |
95 virtual void OnRenderError() OVERRIDE; | 92 virtual void OnRenderError() OVERRIDE; |
96 | 93 |
97 // Initializes and starts the |sink_| if | 94 // Initializes and starts the |sink_| if |
98 // we have received valid |source_params_| && | 95 // we have received valid |source_params_| && |
99 // |playing_| has been set to true && | 96 // |playing_| has been set to true && |
100 // |volume_| is not zero. | 97 // |volume_| is not zero. |
101 void MaybeStartSink(); | 98 void MaybeStartSink(); |
102 | 99 |
103 // Sets new |source_params_| and then re-initializes and restarts |sink_|. | 100 // Sets new |source_params_| and then re-initializes and restarts |sink_|. |
104 void ReconfigureSink(const media::AudioParameters& params); | 101 void ReconfigureSink(const media::AudioParameters& params); |
105 | 102 |
106 // The audio track which provides data to render. Given that this class | 103 // The audio track which provides data to render. Given that this class |
107 // implements local loopback, the audio track is getting data from a capture | 104 // implements local loopback, the audio track is getting data from a capture |
108 // instance like a selected microphone and forwards the recorded data to its | 105 // instance like a selected microphone and forwards the recorded data to its |
109 // sinks. The recorded data is stored in a FIFO and consumed | 106 // sinks. The recorded data is stored in a FIFO and consumed |
110 // by this class when the sink asks for new data. | 107 // by this class when the sink asks for new data. |
111 // The WebRtcAudioCapturer is today created by WebRtcAudioDeviceImpl. | 108 // This class is calling MediaStreamAudioSink::AddToAudioTrack() and |
112 scoped_refptr<WebRtcLocalAudioTrack> audio_track_; | 109 // MediaStreamAudioSink::RemoveFromAudioTrack() to connect and disconnect |
| 110 // with the audio track. |
| 111 blink::WebMediaStreamTrack audio_track_; |
113 | 112 |
114 // The render view in which the audio is rendered into |sink_|. | 113 // The render view in which the audio is rendered into |sink_|. |
115 const int source_render_view_id_; | 114 const int source_render_view_id_; |
116 const int session_id_; | 115 const int session_id_; |
117 | 116 |
118 // MessageLoop associated with the single thread that performs all control | 117 // MessageLoop associated with the single thread that performs all control |
119 // tasks. Set to the MessageLoop that invoked the ctor. | 118 // tasks. Set to the MessageLoop that invoked the ctor. |
120 const scoped_refptr<base::MessageLoopProxy> message_loop_; | 119 const scoped_refptr<base::MessageLoopProxy> message_loop_; |
121 | 120 |
122 // The sink (destination) for rendered audio. | 121 // The sink (destination) for rendered audio. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 159 |
161 // Used to DCHECK that some methods are called on the capture audio thread. | 160 // Used to DCHECK that some methods are called on the capture audio thread. |
162 base::ThreadChecker capture_thread_checker_; | 161 base::ThreadChecker capture_thread_checker_; |
163 | 162 |
164 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioRenderer); | 163 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioRenderer); |
165 }; | 164 }; |
166 | 165 |
167 } // namespace content | 166 } // namespace content |
168 | 167 |
169 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_RENDERER_H_ | 168 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_RENDERER_H_ |
OLD | NEW |