Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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 // RenderAudioSourceProvider provides a bridge between classes: | |
| 6 // WebKit::WebAudioSourceProvider <---> media::AudioRendererSink | |
| 7 // | |
| 8 // RenderAudioSourceProvider is a "sink" of audio, and uses a default | |
| 9 // AudioDevice if a client has not explicitly been set. | |
| 10 // | |
| 11 // WebKit optionally sets a client, and then periodically calls provideInput() | |
| 12 // to render a certain number of audio sample-frames. provideInput() | |
| 13 // uses the renderer to get this data, and then massages it into the form | |
| 14 // required by provideInput(). In this case, the default AudioDevice | |
| 15 // is no longer used. | |
| 16 // | |
| 17 // THREAD SAFETY: | |
| 18 // It is assumed that the callers to setClient() and provideInput() | |
| 19 // implement appropriate locking for thread safety when making | |
| 20 // these calls. This happens in WebKit. | |
| 21 | |
| 22 #ifndef CONTENT_RENDERER_RENDER_AUDIOSOURCEPROVIDER_H_ | |
| 23 #define CONTENT_RENDERER_RENDER_AUDIOSOURCEPROVIDER_H_ | |
| 24 | |
| 25 #include <vector> | |
| 26 | |
| 27 #include "content/renderer/media/audio_device.h" | |
| 28 #include "media/filters/audio_renderer_sink.h" | |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAudioSourceProvide r.h" | |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | |
| 31 | |
| 32 namespace WebKit { | |
| 33 class WebAudioSourceProviderClient; | |
| 34 } | |
| 35 | |
| 36 class RenderAudioSourceProvider | |
| 37 : public WebKit::WebAudioSourceProvider, | |
| 38 public media::AudioRendererSink { | |
| 39 public: | |
| 40 RenderAudioSourceProvider(); | |
| 41 virtual ~RenderAudioSourceProvider(); | |
| 42 | |
| 43 // We use the renderer to get the audio stream for provideInput(). | |
| 44 void SetRenderer(media::AudioRendererSink::RenderCallback* renderer); | |
| 45 | |
| 46 // WebKit::WebAudioSourceProvider implementation. | |
| 47 | |
| 48 // WebKit calls setClient() if it desires to take control of the rendered | |
| 49 // audio stream. We call client's setFormat() when the audio stream format | |
| 50 // is known. | |
| 51 virtual void setClient(WebKit::WebAudioSourceProviderClient* client); | |
| 52 | |
| 53 // If setClient() has been called, then WebKit calls provideInput() | |
| 54 // periodically to get the rendered audio stream. | |
| 55 virtual void provideInput(const WebKit::WebVector<float*>& audio_data, | |
| 56 size_t number_of_frames); | |
| 57 | |
| 58 // AudioRendererSink implementation. | |
| 59 virtual void Start() OVERRIDE; | |
| 60 virtual void Stop() OVERRIDE; | |
| 61 virtual void Play() OVERRIDE; | |
| 62 virtual void Pause(bool flush) OVERRIDE; | |
| 63 virtual bool SetVolume(double volume) OVERRIDE; | |
| 64 virtual void GetVolume(double* volume) OVERRIDE; | |
| 65 virtual void Initialize(size_t buffer_size, | |
| 66 int channels, | |
| 67 double sample_rate, | |
| 68 AudioParameters::Format latency_format, | |
| 69 RenderCallback* callback) OVERRIDE; | |
| 70 | |
| 71 private: | |
| 72 // Set to true when Initialize() is called. | |
| 73 bool is_initialized_; | |
| 74 int channels_; | |
| 75 double sample_rate_; | |
| 76 | |
| 77 bool is_running_; | |
| 78 double volume_; | |
| 79 media::AudioRendererSink::RenderCallback* renderer_; | |
| 80 WebKit::WebAudioSourceProviderClient* client_; | |
| 81 | |
| 82 // Protects access to sink_ | |
| 83 base::Lock sink_lock_; | |
| 84 | |
| 85 // audio_device_ is the default sink. | |
| 86 scoped_refptr<AudioDevice> audio_device_; | |
|
acolwell GONE FROM CHROMIUM
2011/12/21 22:53:56
Do we need to know this is an AudioDevice? Could t
Chris Rogers
2011/12/22 00:54:33
Done.
| |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(RenderAudioSourceProvider); | |
| 89 }; | |
| 90 | |
| 91 #endif // CONTENT_RENDERER_RENDER_AUDIOSOURCEPROVIDER_H_ | |
| OLD | NEW |