Add ICU message format support
[chromium-blink-merge.git] / content / renderer / media / renderer_webaudiodevice_impl.h
blob3f4e20e6d3449e7019c24c44e05555db23456f23
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_RENDERER_WEBAUDIODEVICE_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_
8 #include "base/cancelable_callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/threading/thread_checker.h"
11 #include "media/audio/audio_parameters.h"
12 #include "media/base/audio_renderer_sink.h"
13 #include "third_party/WebKit/public/platform/WebAudioDevice.h"
14 #include "third_party/WebKit/public/platform/WebVector.h"
16 namespace base {
17 class SingleThreadTaskRunner;
20 namespace media {
21 class AudioOutputDevice;
22 class NullAudioSink;
25 namespace content {
27 class RendererWebAudioDeviceImpl
28 : public blink::WebAudioDevice,
29 public media::AudioRendererSink::RenderCallback {
30 public:
31 RendererWebAudioDeviceImpl(const media::AudioParameters& params,
32 blink::WebAudioDevice::RenderCallback* callback,
33 int session_id);
34 virtual ~RendererWebAudioDeviceImpl();
36 // blink::WebAudioDevice implementation.
37 virtual void start();
38 virtual void stop();
39 virtual double sampleRate();
41 // AudioRendererSink::RenderCallback implementation.
42 int Render(media::AudioBus* dest, int audio_delay_milliseconds) override;
44 void OnRenderError() override;
46 private:
47 const media::AudioParameters params_;
49 // Weak reference to the callback into WebKit code.
50 blink::WebAudioDevice::RenderCallback* const client_callback_;
52 // To avoid the need for locking, ensure the control methods of the
53 // blink::WebAudioDevice implementation are called on the same thread.
54 base::ThreadChecker thread_checker_;
56 // When non-NULL, we are started. When NULL, we are stopped.
57 scoped_refptr<media::AudioOutputDevice> output_device_;
59 // ID to allow browser to select the correct input device for unified IO.
60 int session_id_;
62 // Timeticks when the silence starts.
63 base::TimeTicks first_silence_time_ ;
65 // TaskRunner to post callbacks to the render thread.
66 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
68 // A fake audio sink object that consumes data when long period of silence
69 // audio is detected. This object lives on the render thread.
70 scoped_refptr<media::NullAudioSink> null_audio_sink_;
72 // Whether audio output is directed to |null_audio_sink_|.
73 bool is_using_null_audio_sink_;
75 // First audio buffer after silence finishes. We store this buffer so that
76 // it can be sent to the |output_device_| later after switching from
77 // |null_audio_sink_|.
78 scoped_ptr<media::AudioBus> first_buffer_after_silence_;
80 bool is_first_buffer_after_silence_;
82 // A cancelable task that is posted to start the |null_audio_sink_| after a
83 // period of silence. We do this on android to save battery consumption.
84 base::CancelableClosure start_null_audio_sink_callback_;
86 DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl);
89 } // namespace content
91 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_