Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / renderer / media / renderer_webaudiodevice_impl.h
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.
4
5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/threading/thread_checker.h"
10 #include "media/audio/audio_parameters.h"
11 #include "media/base/audio_renderer_sink.h"
12 #include "third_party/WebKit/public/platform/WebAudioDevice.h"
13 #include "third_party/WebKit/public/platform/WebVector.h"
14
15 namespace media {
16 class AudioOutputDevice;
17 }
18
19 namespace content {
20
21 class RendererWebAudioDeviceImpl
22     : public blink::WebAudioDevice,
23       public media::AudioRendererSink::RenderCallback {
24  public:
25   RendererWebAudioDeviceImpl(const media::AudioParameters& params,
26                              blink::WebAudioDevice::RenderCallback* callback,
27                              int session_id);
28   virtual ~RendererWebAudioDeviceImpl();
29
30   // blink::WebAudioDevice implementation.
31   virtual void start();
32   virtual void stop();
33   virtual double sampleRate();
34
35   // AudioRendererSink::RenderCallback implementation.
36   int Render(media::AudioBus* dest, int audio_delay_milliseconds) override;
37
38   void OnRenderError() override;
39
40  private:
41   const media::AudioParameters params_;
42
43   // Weak reference to the callback into WebKit code.
44   blink::WebAudioDevice::RenderCallback* const client_callback_;
45
46   // To avoid the need for locking, ensure the control methods of the
47   // blink::WebAudioDevice implementation are called on the same thread.
48   base::ThreadChecker thread_checker_;
49
50   // When non-NULL, we are started.  When NULL, we are stopped.
51   scoped_refptr<media::AudioOutputDevice> output_device_;
52
53   // ID to allow browser to select the correct input device for unified IO.
54   int session_id_;
55
56   DISALLOW_COPY_AND_ASSIGN(RendererWebAudioDeviceImpl);
57 };
58
59 }  // namespace content
60
61 #endif  // CONTENT_RENDERER_MEDIA_MEDIA_RENDERER_WEBAUDIODEVICE_IMPL_H_