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_AUDIO_RENDERER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "base/threading/thread_checker.h" | |
10 #include "content/renderer/media/webrtc_audio_device_impl.h" | 11 #include "content/renderer/media/webrtc_audio_device_impl.h" |
11 #include "media/base/audio_decoder.h" | 12 #include "media/base/audio_decoder.h" |
13 #include "media/base/audio_pull_fifo.h" | |
12 #include "media/base/audio_renderer_sink.h" | 14 #include "media/base/audio_renderer_sink.h" |
13 #include "webkit/media/media_stream_audio_renderer.h" | 15 #include "webkit/media/media_stream_audio_renderer.h" |
14 | 16 |
15 namespace content { | 17 namespace content { |
16 | 18 |
17 class RendererAudioOutputDevice; | 19 class RendererAudioOutputDevice; |
18 class WebRtcAudioRendererSource; | 20 class WebRtcAudioRendererSource; |
19 | 21 |
20 // This renderer handles calls from the pipeline and WebRtc ADM. It is used | 22 // This renderer handles calls from the pipeline and WebRtc ADM. It is used |
21 // for connecting WebRtc MediaStream with pipeline. | 23 // for connecting WebRtc MediaStream with the audio pipeline. |
22 class CONTENT_EXPORT WebRtcAudioRenderer | 24 class CONTENT_EXPORT WebRtcAudioRenderer |
23 : NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback), | 25 : NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback), |
24 NON_EXPORTED_BASE(public webkit_media::MediaStreamAudioRenderer) { | 26 NON_EXPORTED_BASE(public webkit_media::MediaStreamAudioRenderer) { |
25 public: | 27 public: |
26 explicit WebRtcAudioRenderer(int source_render_view_id); | 28 explicit WebRtcAudioRenderer(int source_render_view_id); |
27 | 29 |
28 // Initialize function called by clients like WebRtcAudioDeviceImpl. Note, | 30 // Initialize function called by clients like WebRtcAudioDeviceImpl. |
29 // Stop() has to be called before |source| is deleted. | 31 // Stop() has to be called before |source| is deleted. |
30 // Returns false if Initialize() fails. | |
31 bool Initialize(WebRtcAudioRendererSource* source); | 32 bool Initialize(WebRtcAudioRendererSource* source); |
32 | 33 |
33 // Methods called by WebMediaPlayerMS and WebRtcAudioDeviceImpl. | 34 // Methods called by WebMediaPlayerMS and WebRtcAudioDeviceImpl. |
34 // MediaStreamAudioRenderer implementation. | 35 // MediaStreamAudioRenderer implementation. |
35 virtual void Start() OVERRIDE; | 36 virtual void Start() OVERRIDE; |
36 virtual void Play() OVERRIDE; | 37 virtual void Play() OVERRIDE; |
37 virtual void Pause() OVERRIDE; | 38 virtual void Pause() OVERRIDE; |
38 virtual void Stop() OVERRIDE; | 39 virtual void Stop() OVERRIDE; |
39 virtual void SetVolume(float volume) OVERRIDE; | 40 virtual void SetVolume(float volume) OVERRIDE; |
40 virtual base::TimeDelta GetCurrentRenderTime() const OVERRIDE; | 41 virtual base::TimeDelta GetCurrentRenderTime() const OVERRIDE; |
41 virtual bool IsLocalRenderer() const OVERRIDE; | 42 virtual bool IsLocalRenderer() const OVERRIDE; |
42 | 43 |
43 protected: | 44 protected: |
44 virtual ~WebRtcAudioRenderer(); | 45 virtual ~WebRtcAudioRenderer(); |
45 | 46 |
46 private: | 47 private: |
47 enum State { | 48 enum State { |
48 UNINITIALIZED, | 49 UNINITIALIZED, |
49 PLAYING, | 50 PLAYING, |
50 PAUSED, | 51 PAUSED, |
51 }; | 52 }; |
53 | |
54 // Used to DCHECK that we are called on the correct thread. | |
55 base::ThreadChecker thread_checker_; | |
56 | |
52 // Flag to keep track the state of the renderer. | 57 // Flag to keep track the state of the renderer. |
53 State state_; | 58 State state_; |
54 | 59 |
55 // media::AudioRendererSink::RenderCallback implementation. | 60 // media::AudioRendererSink::RenderCallback implementation. |
61 // These two methods are called on the AudioOutputDevice worker thread. | |
56 virtual int Render(media::AudioBus* audio_bus, | 62 virtual int Render(media::AudioBus* audio_bus, |
57 int audio_delay_milliseconds) OVERRIDE; | 63 int audio_delay_milliseconds) OVERRIDE; |
58 virtual void OnRenderError() OVERRIDE; | 64 virtual void OnRenderError() OVERRIDE; |
59 | 65 |
66 // Called by AudioPullFifo when more data is necessary. | |
67 // This method is called on the AudioOutputDevice worker thread. | |
68 void SourceCallback(int fifo_frame_delay, media::AudioBus* audio_bus); | |
69 | |
60 // The render view in which the audio is rendered into |sink_|. | 70 // The render view in which the audio is rendered into |sink_|. |
61 const int source_render_view_id_; | 71 const int source_render_view_id_; |
62 | 72 |
63 // The sink (destination) for rendered audio. | 73 // The sink (destination) for rendered audio. |
64 scoped_refptr<RendererAudioOutputDevice> sink_; | 74 scoped_refptr<RendererAudioOutputDevice> sink_; |
65 | 75 |
66 // Audio data source from the browser process. | 76 // Audio data source from the browser process. |
67 WebRtcAudioRendererSource* source_; | 77 WebRtcAudioRendererSource* source_; |
68 | 78 |
69 // Cached values of utilized audio parameters. Platform dependent. | |
70 media::AudioParameters params_; | |
71 | |
72 // Buffers used for temporary storage during render callbacks. | 79 // Buffers used for temporary storage during render callbacks. |
73 // Allocated during initialization. | 80 // Allocated during initialization. |
74 scoped_array<int16> buffer_; | 81 scoped_array<int16> buffer_; |
75 | 82 |
76 // Protect access to |state_|. | 83 // Protects access to |state_|, |source_| and |sink_|. |
77 base::Lock lock_; | 84 base::Lock lock_; |
78 | 85 |
79 // Ref count for the MediaPlayers which are playing audio. | 86 // Ref count for the MediaPlayers which are playing audio. |
80 int play_ref_count_; | 87 int play_ref_count_; |
81 | 88 |
89 // Used to buffer data between the client and the output device in cases where | |
90 // the client buffer size is not the same as the output device buffer size. | |
91 scoped_ptr<media::AudioPullFifo> audio_fifo_; | |
92 | |
93 double frame_duration_milliseconds_; | |
tommi (sloooow) - chröme
2013/01/31 13:42:08
why is this a double and audio_delay_milliseconds_
henrika (OOO until Aug 14)
2013/01/31 14:29:38
I want to maintain precision. For fs=48kHz, we hav
| |
94 | |
95 int audio_delay_milliseconds_; | |
96 | |
82 DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioRenderer); | 97 DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioRenderer); |
83 }; | 98 }; |
84 | 99 |
85 } // namespace content | 100 } // namespace content |
86 | 101 |
87 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_ | 102 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_ |
OLD | NEW |