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" |
19 | 20 |
20 namespace media { | 21 namespace media { |
21 class AudioBus; | 22 class AudioBus; |
22 class AudioFifo; | 23 class AudioFifo; |
23 class AudioOutputDevice; | 24 class AudioOutputDevice; |
24 class AudioParameters; | 25 class AudioParameters; |
25 } | 26 } |
26 | 27 |
27 namespace content { | 28 namespace content { |
28 | 29 |
29 class WebRtcAudioCapturer; | 30 class WebRtcAudioCapturer; |
30 | 31 |
31 // WebRtcLocalAudioRenderer is a MediaStreamAudioRenderer designed for rendering | 32 // WebRtcLocalAudioRenderer is a MediaStreamAudioRenderer designed for rendering |
32 // local audio media stream tracks, | 33 // local audio media stream tracks, |
33 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediastreamtrack | 34 // http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediastreamtrack |
34 // It also implements media::AudioRendererSink::RenderCallback to render audio | 35 // It also implements media::AudioRendererSink::RenderCallback to render audio |
35 // data provided from a WebRtcLocalAudioTrack source. | 36 // data provided from a WebRtcLocalAudioTrack source. |
36 // When the audio layer in the browser process asks for data to render, this | 37 // When the audio layer in the browser process asks for data to render, this |
37 // class provides the data by implementing the WebRtcAudioCapturerSink | 38 // class provides the data by implementing the MediaStreamAudioSink |
38 // interface, i.e., we are a sink seen from the WebRtcAudioCapturer perspective. | 39 // interface, i.e., we are a sink seen from the WebRtcAudioCapturer perspective. |
39 // TODO(henrika): improve by using similar principles as in RTCVideoRenderer | 40 // TODO(henrika): improve by using similar principles as in RTCVideoRenderer |
40 // which register itself to the video track when the provider is started and | 41 // which register itself to the video track when the provider is started and |
41 // deregisters itself when it is stopped. | 42 // deregisters itself when it is stopped. |
42 // Tracking this at http://crbug.com/164813. | 43 // Tracking this at http://crbug.com/164813. |
43 class CONTENT_EXPORT WebRtcLocalAudioRenderer | 44 class CONTENT_EXPORT WebRtcLocalAudioRenderer |
44 : NON_EXPORTED_BASE(public MediaStreamAudioRenderer), | 45 : NON_EXPORTED_BASE(public MediaStreamAudioRenderer), |
45 NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback), | 46 NON_EXPORTED_BASE(public MediaStreamAudioSink), |
46 NON_EXPORTED_BASE(public WebRtcAudioCapturerSink) { | 47 NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback) { |
47 public: | 48 public: |
48 // Creates a local renderer and registers a capturing |source| object. | 49 // Creates a local renderer and registers a capturing |source| object. |
49 // The |source| is owned by the WebRtcAudioDeviceImpl. | 50 // The |source| is owned by the WebRtcAudioDeviceImpl. |
50 // Called on the main thread. | 51 // Called on the main thread. |
51 WebRtcLocalAudioRenderer(WebRtcLocalAudioTrack* audio_track, | 52 WebRtcLocalAudioRenderer(WebRtcLocalAudioTrack* audio_track, |
52 int source_render_view_id, | 53 int source_render_view_id, |
53 int session_id, | 54 int session_id, |
54 int frames_per_buffer); | 55 int frames_per_buffer); |
55 | 56 |
56 // MediaStreamAudioRenderer implementation. | 57 // MediaStreamAudioRenderer implementation. |
57 // Called on the main thread. | 58 // Called on the main thread. |
58 virtual void Start() OVERRIDE; | 59 virtual void Start() OVERRIDE; |
59 virtual void Stop() OVERRIDE; | 60 virtual void Stop() OVERRIDE; |
60 virtual void Play() OVERRIDE; | 61 virtual void Play() OVERRIDE; |
61 virtual void Pause() OVERRIDE; | 62 virtual void Pause() OVERRIDE; |
62 virtual void SetVolume(float volume) OVERRIDE; | 63 virtual void SetVolume(float volume) OVERRIDE; |
63 virtual base::TimeDelta GetCurrentRenderTime() const OVERRIDE; | 64 virtual base::TimeDelta GetCurrentRenderTime() const OVERRIDE; |
64 virtual bool IsLocalRenderer() const OVERRIDE; | 65 virtual bool IsLocalRenderer() const OVERRIDE; |
65 | 66 |
66 const base::TimeDelta& total_render_time() const { | 67 const base::TimeDelta& total_render_time() const { |
67 return total_render_time_; | 68 return total_render_time_; |
68 } | 69 } |
69 | 70 |
70 protected: | 71 protected: |
71 virtual ~WebRtcLocalAudioRenderer(); | 72 virtual ~WebRtcLocalAudioRenderer(); |
72 | 73 |
73 private: | 74 private: |
74 // WebRtcAudioCapturerSink implementation. | 75 // MediaStreamAudioSink implementation. |
75 | 76 |
76 // Called on the AudioInputDevice worker thread. | 77 // Called on the AudioInputDevice worker thread. |
77 virtual int CaptureData(const std::vector<int>& channels, | 78 virtual void OnData(const int16* audio_data, |
78 const int16* audio_data, | 79 int sample_rate, |
79 int sample_rate, | 80 int number_of_channels, |
80 int number_of_channels, | 81 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 | 82 |
87 // Can be called on different user thread. | 83 // Called on the AudioInputDevice worker thread. |
88 virtual void SetCaptureFormat(const media::AudioParameters& params) OVERRIDE; | 84 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; |
89 | 85 |
90 // media::AudioRendererSink::RenderCallback implementation. | 86 // media::AudioRendererSink::RenderCallback implementation. |
91 // Render() is called on the AudioOutputDevice thread and OnRenderError() | 87 // Render() is called on the AudioOutputDevice thread and OnRenderError() |
92 // on the IO thread. | 88 // on the IO thread. |
93 virtual int Render(media::AudioBus* audio_bus, | 89 virtual int Render(media::AudioBus* audio_bus, |
94 int audio_delay_milliseconds) OVERRIDE; | 90 int audio_delay_milliseconds) OVERRIDE; |
95 virtual void OnRenderError() OVERRIDE; | 91 virtual void OnRenderError() OVERRIDE; |
96 | 92 |
97 // Initializes and starts the |sink_| if | 93 // Initializes and starts the |sink_| if |
98 // we have received valid |source_params_| && | 94 // we have received valid |source_params_| && |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 156 |
161 // Used to DCHECK that some methods are called on the capture audio thread. | 157 // Used to DCHECK that some methods are called on the capture audio thread. |
162 base::ThreadChecker capture_thread_checker_; | 158 base::ThreadChecker capture_thread_checker_; |
163 | 159 |
164 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioRenderer); | 160 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioRenderer); |
165 }; | 161 }; |
166 | 162 |
167 } // namespace content | 163 } // namespace content |
168 | 164 |
169 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_RENDERER_H_ | 165 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_RENDERER_H_ |
OLD | NEW |