Fix build break
[chromium-blink-merge.git] / content / renderer / media / webrtc_audio_renderer.h
blobaf4bf38823ba369f899bb1caafa298032c76cbd1
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/synchronization/lock.h"
10 #include "base/threading/thread_checker.h"
11 #include "content/renderer/media/webrtc_audio_device_impl.h"
12 #include "media/base/audio_decoder.h"
13 #include "media/base/audio_pull_fifo.h"
14 #include "media/base/audio_renderer_sink.h"
15 #include "webkit/media/media_stream_audio_renderer.h"
17 namespace content {
19 class RendererAudioOutputDevice;
20 class WebRtcAudioRendererSource;
22 // This renderer handles calls from the pipeline and WebRtc ADM. It is used
23 // for connecting WebRtc MediaStream with the audio pipeline.
24 class CONTENT_EXPORT WebRtcAudioRenderer
25 : NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback),
26 NON_EXPORTED_BASE(public webkit_media::MediaStreamAudioRenderer) {
27 public:
28 explicit WebRtcAudioRenderer(int source_render_view_id);
30 // Initialize function called by clients like WebRtcAudioDeviceImpl.
31 // Stop() has to be called before |source| is deleted.
32 bool Initialize(WebRtcAudioRendererSource* source);
34 // Methods called by WebMediaPlayerMS and WebRtcAudioDeviceImpl.
35 // MediaStreamAudioRenderer implementation.
36 virtual void Start() OVERRIDE;
37 virtual void Play() OVERRIDE;
38 virtual void Pause() OVERRIDE;
39 virtual void Stop() OVERRIDE;
40 virtual void SetVolume(float volume) OVERRIDE;
41 virtual base::TimeDelta GetCurrentRenderTime() const OVERRIDE;
42 virtual bool IsLocalRenderer() const OVERRIDE;
44 protected:
45 virtual ~WebRtcAudioRenderer();
47 private:
48 enum State {
49 UNINITIALIZED,
50 PLAYING,
51 PAUSED,
54 // Used to DCHECK that we are called on the correct thread.
55 base::ThreadChecker thread_checker_;
57 // Flag to keep track the state of the renderer.
58 State state_;
60 // media::AudioRendererSink::RenderCallback implementation.
61 // These two methods are called on the AudioOutputDevice worker thread.
62 virtual int Render(media::AudioBus* audio_bus,
63 int audio_delay_milliseconds) OVERRIDE;
64 virtual void OnRenderError() OVERRIDE;
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);
70 // The render view in which the audio is rendered into |sink_|.
71 const int source_render_view_id_;
73 // The sink (destination) for rendered audio.
74 scoped_refptr<RendererAudioOutputDevice> sink_;
76 // Audio data source from the browser process.
77 WebRtcAudioRendererSource* source_;
79 // Buffers used for temporary storage during render callbacks.
80 // Allocated during initialization.
81 scoped_ptr<int16[]> buffer_;
83 // Protects access to |state_|, |source_| and |sink_|.
84 base::Lock lock_;
86 // Ref count for the MediaPlayers which are playing audio.
87 int play_ref_count_;
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_;
93 // Contains the accumulated delay estimate which is provided to the WebRTC
94 // AEC.
95 int audio_delay_milliseconds_;
97 // Lengh of an audio frame in milliseconds.
98 double frame_duration_milliseconds_;
100 double fifo_io_ratio_;
102 DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioRenderer);
105 } // namespace content
107 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_