Fix Win8 metro startup crash from window switcher button
[chromium-blink-merge.git] / webkit / media / webaudiosourceprovider_impl.h
blob0030df548513df5ae21616a3e6c547c8a563db97
1 // Copyright (c) 2013 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 WEBKIT_MEDIA_WEBAUDIOSOURCEPROVIDER_IMPL_H_
6 #define WEBKIT_MEDIA_WEBAUDIOSOURCEPROVIDER_IMPL_H_
8 #include "base/synchronization/lock.h"
9 #include "media/base/audio_renderer_sink.h"
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAudioSourceProvider.h"
13 namespace WebKit {
14 class WebAudioSourceProviderClient;
17 namespace webkit_media {
19 // WebAudioSourceProviderImpl provides a bridge between classes:
20 // WebKit::WebAudioSourceProvider <---> media::AudioRendererSink
22 // WebAudioSourceProviderImpl wraps an existing audio sink that is used unless
23 // WebKit has set a client via setClient(). While a client is set WebKit will
24 // periodically call provideInput() to render a certain number of audio
25 // sample-frames using the sink's RenderCallback to get the data.
27 // All calls are protected by a lock.
28 class WebAudioSourceProviderImpl
29 : public WebKit::WebAudioSourceProvider,
30 public media::AudioRendererSink {
31 public:
32 explicit WebAudioSourceProviderImpl(
33 const scoped_refptr<media::AudioRendererSink>& sink);
35 // WebKit::WebAudioSourceProvider implementation.
36 virtual void setClient(WebKit::WebAudioSourceProviderClient* client);
37 virtual void provideInput(const WebKit::WebVector<float*>& audio_data,
38 size_t number_of_frames);
40 // media::AudioRendererSink implementation.
41 virtual void Start() OVERRIDE;
42 virtual void Stop() OVERRIDE;
43 virtual void Play() OVERRIDE;
44 virtual void Pause() OVERRIDE;
45 virtual bool SetVolume(double volume) OVERRIDE;
46 virtual void Initialize(const media::AudioParameters& params,
47 RenderCallback* renderer) OVERRIDE;
49 protected:
50 virtual ~WebAudioSourceProviderImpl();
52 private:
53 // Set to true when Initialize() is called.
54 int channels_;
55 int sample_rate_;
56 double volume_;
58 // Tracks the current playback state.
59 enum PlaybackState { kStopped, kStarted, kPlaying };
60 PlaybackState state_;
62 // Where audio comes from.
63 media::AudioRendererSink::RenderCallback* renderer_;
65 // When set via setClient() it overrides |sink_| for consuming audio.
66 WebKit::WebAudioSourceProviderClient* client_;
68 // Where audio ends up unless overridden by |client_|.
69 base::Lock sink_lock_;
70 scoped_refptr<media::AudioRendererSink> sink_;
71 scoped_ptr<media::AudioBus> bus_wrapper_;
73 DISALLOW_IMPLICIT_CONSTRUCTORS(WebAudioSourceProviderImpl);
76 } // namespace webkit_media
78 #endif // WEBKIT_MEDIA_WEBAUDIOSOURCEPROVIDER_IMPL_H_