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 "base/threading/thread_checker.h" |
11 #include "content/renderer/media/media_stream_audio_renderer.h" | 11 #include "content/renderer/media/media_stream_audio_renderer.h" |
12 #include "content/renderer/media/webrtc_audio_device_impl.h" | 12 #include "content/renderer/media/webrtc_audio_device_impl.h" |
13 #include "media/base/audio_decoder.h" | 13 #include "media/base/audio_decoder.h" |
14 #include "media/base/audio_pull_fifo.h" | 14 #include "media/base/audio_pull_fifo.h" |
15 #include "media/base/audio_renderer_sink.h" | 15 #include "media/base/audio_renderer_sink.h" |
| 16 #include "media/base/channel_layout.h" |
16 | 17 |
17 namespace media { | 18 namespace media { |
18 class AudioOutputDevice; | 19 class AudioOutputDevice; |
19 } | 20 } |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 | 23 |
23 class WebRtcAudioRendererSource; | 24 class WebRtcAudioRendererSource; |
24 | 25 |
25 // This renderer handles calls from the pipeline and WebRtc ADM. It is used | 26 // This renderer handles calls from the pipeline and WebRtc ADM. It is used |
26 // for connecting WebRtc MediaStream with the audio pipeline. | 27 // for connecting WebRtc MediaStream with the audio pipeline. |
27 class CONTENT_EXPORT WebRtcAudioRenderer | 28 class CONTENT_EXPORT WebRtcAudioRenderer |
28 : NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback), | 29 : NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback), |
29 NON_EXPORTED_BASE(public MediaStreamAudioRenderer) { | 30 NON_EXPORTED_BASE(public MediaStreamAudioRenderer) { |
30 public: | 31 public: |
31 explicit WebRtcAudioRenderer(int source_render_view_id); | 32 WebRtcAudioRenderer(int source_render_view_id, |
| 33 int session_id, |
| 34 int sample_rate, |
| 35 int frames_per_buffer); |
32 | 36 |
33 // Initialize function called by clients like WebRtcAudioDeviceImpl. | 37 // Initialize function called by clients like WebRtcAudioDeviceImpl. |
34 // Stop() has to be called before |source| is deleted. | 38 // Stop() has to be called before |source| is deleted. |
35 bool Initialize(WebRtcAudioRendererSource* source); | 39 bool Initialize(WebRtcAudioRendererSource* source); |
36 | 40 |
37 // Methods called by WebMediaPlayerMS and WebRtcAudioDeviceImpl. | 41 // Methods called by WebMediaPlayerMS and WebRtcAudioDeviceImpl. |
38 // MediaStreamAudioRenderer implementation. | 42 // MediaStreamAudioRenderer implementation. |
39 virtual void Start() OVERRIDE; | 43 virtual void Start() OVERRIDE; |
40 virtual void Play() OVERRIDE; | 44 virtual void Play() OVERRIDE; |
41 virtual void Pause() OVERRIDE; | 45 virtual void Pause() OVERRIDE; |
(...skipping 23 matching lines...) Expand all Loading... |
65 virtual int Render(media::AudioBus* audio_bus, | 69 virtual int Render(media::AudioBus* audio_bus, |
66 int audio_delay_milliseconds) OVERRIDE; | 70 int audio_delay_milliseconds) OVERRIDE; |
67 virtual void OnRenderError() OVERRIDE; | 71 virtual void OnRenderError() OVERRIDE; |
68 | 72 |
69 // Called by AudioPullFifo when more data is necessary. | 73 // Called by AudioPullFifo when more data is necessary. |
70 // This method is called on the AudioOutputDevice worker thread. | 74 // This method is called on the AudioOutputDevice worker thread. |
71 void SourceCallback(int fifo_frame_delay, media::AudioBus* audio_bus); | 75 void SourceCallback(int fifo_frame_delay, media::AudioBus* audio_bus); |
72 | 76 |
73 // The render view in which the audio is rendered into |sink_|. | 77 // The render view in which the audio is rendered into |sink_|. |
74 const int source_render_view_id_; | 78 const int source_render_view_id_; |
| 79 const int session_id_; |
75 | 80 |
76 // The sink (destination) for rendered audio. | 81 // The sink (destination) for rendered audio. |
77 scoped_refptr<media::AudioOutputDevice> sink_; | 82 scoped_refptr<media::AudioOutputDevice> sink_; |
78 | 83 |
79 // Audio data source from the browser process. | 84 // Audio data source from the browser process. |
80 WebRtcAudioRendererSource* source_; | 85 WebRtcAudioRendererSource* source_; |
81 | 86 |
82 // Buffers used for temporary storage during render callbacks. | 87 // Buffers used for temporary storage during render callbacks. |
83 // Allocated during initialization. | 88 // Allocated during initialization. |
84 scoped_ptr<int16[]> buffer_; | 89 scoped_ptr<int16[]> buffer_; |
85 | 90 |
86 // Protects access to |state_|, |source_| and |sink_|. | 91 // Protects access to |state_|, |source_| and |sink_|. |
87 base::Lock lock_; | 92 base::Lock lock_; |
88 | 93 |
89 // Ref count for the MediaPlayers which are playing audio. | 94 // Ref count for the MediaPlayers which are playing audio. |
90 int play_ref_count_; | 95 int play_ref_count_; |
91 | 96 |
92 // Used to buffer data between the client and the output device in cases where | 97 // Used to buffer data between the client and the output device in cases where |
93 // the client buffer size is not the same as the output device buffer size. | 98 // the client buffer size is not the same as the output device buffer size. |
94 scoped_ptr<media::AudioPullFifo> audio_fifo_; | 99 scoped_ptr<media::AudioPullFifo> audio_fifo_; |
95 | 100 |
96 // Contains the accumulated delay estimate which is provided to the WebRTC | 101 // Contains the accumulated delay estimate which is provided to the WebRTC |
97 // AEC. | 102 // AEC. |
98 int audio_delay_milliseconds_; | 103 int audio_delay_milliseconds_; |
99 | 104 |
100 // Delay due to the FIFO in milliseconds. | 105 // Delay due to the FIFO in milliseconds. |
101 int fifo_delay_milliseconds_; | 106 int fifo_delay_milliseconds_; |
102 | 107 |
| 108 // The preferred sample rate and buffer sizes provided via the ctor. |
| 109 const int sample_rate_; |
| 110 const int frames_per_buffer_; |
| 111 |
103 DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioRenderer); | 112 DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioRenderer); |
104 }; | 113 }; |
105 | 114 |
106 } // namespace content | 115 } // namespace content |
107 | 116 |
108 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_ | 117 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_ |
OLD | NEW |