| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_WEBAUDIOSOURCEPROVIDER_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBAUDIOSOURCEPROVIDER_IMPL_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBAUDIOSOURCEPROVIDER_IMPL_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBAUDIOSOURCEPROVIDER_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
| 9 #include "content/common/content_export.h" | 9 #include "content/common/content_export.h" |
| 10 #include "media/base/audio_renderer_sink.h" | 10 #include "media/base/audio_renderer_sink.h" |
| 11 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" | 11 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" |
| 12 #include "third_party/WebKit/public/platform/WebVector.h" | 12 #include "third_party/WebKit/public/platform/WebVector.h" |
| 13 | 13 |
| 14 namespace WebKit { | 14 namespace blink { |
| 15 class WebAudioSourceProviderClient; | 15 class WebAudioSourceProviderClient; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 // WebAudioSourceProviderImpl provides a bridge between classes: | 20 // WebAudioSourceProviderImpl provides a bridge between classes: |
| 21 // WebKit::WebAudioSourceProvider <---> media::AudioRendererSink | 21 // blink::WebAudioSourceProvider <---> media::AudioRendererSink |
| 22 // | 22 // |
| 23 // WebAudioSourceProviderImpl wraps an existing audio sink that is used unless | 23 // WebAudioSourceProviderImpl wraps an existing audio sink that is used unless |
| 24 // WebKit has set a client via setClient(). While a client is set WebKit will | 24 // WebKit has set a client via setClient(). While a client is set WebKit will |
| 25 // periodically call provideInput() to render a certain number of audio | 25 // periodically call provideInput() to render a certain number of audio |
| 26 // sample-frames using the sink's RenderCallback to get the data. | 26 // sample-frames using the sink's RenderCallback to get the data. |
| 27 // | 27 // |
| 28 // All calls are protected by a lock. | 28 // All calls are protected by a lock. |
| 29 class CONTENT_EXPORT WebAudioSourceProviderImpl | 29 class CONTENT_EXPORT WebAudioSourceProviderImpl |
| 30 : NON_EXPORTED_BASE(public WebKit::WebAudioSourceProvider), | 30 : NON_EXPORTED_BASE(public blink::WebAudioSourceProvider), |
| 31 NON_EXPORTED_BASE(public media::AudioRendererSink) { | 31 NON_EXPORTED_BASE(public media::AudioRendererSink) { |
| 32 public: | 32 public: |
| 33 explicit WebAudioSourceProviderImpl( | 33 explicit WebAudioSourceProviderImpl( |
| 34 const scoped_refptr<media::AudioRendererSink>& sink); | 34 const scoped_refptr<media::AudioRendererSink>& sink); |
| 35 | 35 |
| 36 // WebKit::WebAudioSourceProvider implementation. | 36 // blink::WebAudioSourceProvider implementation. |
| 37 virtual void setClient(WebKit::WebAudioSourceProviderClient* client); | 37 virtual void setClient(blink::WebAudioSourceProviderClient* client); |
| 38 virtual void provideInput(const WebKit::WebVector<float*>& audio_data, | 38 virtual void provideInput(const blink::WebVector<float*>& audio_data, |
| 39 size_t number_of_frames); | 39 size_t number_of_frames); |
| 40 | 40 |
| 41 // media::AudioRendererSink implementation. | 41 // media::AudioRendererSink implementation. |
| 42 virtual void Start() OVERRIDE; | 42 virtual void Start() OVERRIDE; |
| 43 virtual void Stop() OVERRIDE; | 43 virtual void Stop() OVERRIDE; |
| 44 virtual void Play() OVERRIDE; | 44 virtual void Play() OVERRIDE; |
| 45 virtual void Pause() OVERRIDE; | 45 virtual void Pause() OVERRIDE; |
| 46 virtual bool SetVolume(double volume) OVERRIDE; | 46 virtual bool SetVolume(double volume) OVERRIDE; |
| 47 virtual void Initialize(const media::AudioParameters& params, | 47 virtual void Initialize(const media::AudioParameters& params, |
| 48 RenderCallback* renderer) OVERRIDE; | 48 RenderCallback* renderer) OVERRIDE; |
| 49 | 49 |
| 50 protected: | 50 protected: |
| 51 virtual ~WebAudioSourceProviderImpl(); | 51 virtual ~WebAudioSourceProviderImpl(); |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 // Set to true when Initialize() is called. | 54 // Set to true when Initialize() is called. |
| 55 int channels_; | 55 int channels_; |
| 56 int sample_rate_; | 56 int sample_rate_; |
| 57 double volume_; | 57 double volume_; |
| 58 | 58 |
| 59 // Tracks the current playback state. | 59 // Tracks the current playback state. |
| 60 enum PlaybackState { kStopped, kStarted, kPlaying }; | 60 enum PlaybackState { kStopped, kStarted, kPlaying }; |
| 61 PlaybackState state_; | 61 PlaybackState state_; |
| 62 | 62 |
| 63 // Where audio comes from. | 63 // Where audio comes from. |
| 64 media::AudioRendererSink::RenderCallback* renderer_; | 64 media::AudioRendererSink::RenderCallback* renderer_; |
| 65 | 65 |
| 66 // When set via setClient() it overrides |sink_| for consuming audio. | 66 // When set via setClient() it overrides |sink_| for consuming audio. |
| 67 WebKit::WebAudioSourceProviderClient* client_; | 67 blink::WebAudioSourceProviderClient* client_; |
| 68 | 68 |
| 69 // Where audio ends up unless overridden by |client_|. | 69 // Where audio ends up unless overridden by |client_|. |
| 70 base::Lock sink_lock_; | 70 base::Lock sink_lock_; |
| 71 scoped_refptr<media::AudioRendererSink> sink_; | 71 scoped_refptr<media::AudioRendererSink> sink_; |
| 72 scoped_ptr<media::AudioBus> bus_wrapper_; | 72 scoped_ptr<media::AudioBus> bus_wrapper_; |
| 73 | 73 |
| 74 DISALLOW_IMPLICIT_CONSTRUCTORS(WebAudioSourceProviderImpl); | 74 DISALLOW_IMPLICIT_CONSTRUCTORS(WebAudioSourceProviderImpl); |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 } // namespace content | 77 } // namespace content |
| 78 | 78 |
| 79 #endif // CONTENT_RENDERER_MEDIA_WEBAUDIOSOURCEPROVIDER_IMPL_H_ | 79 #endif // CONTENT_RENDERER_MEDIA_WEBAUDIOSOURCEPROVIDER_IMPL_H_ |
| OLD | NEW |