OLD | NEW |
| (Empty) |
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 // RenderAudioSourceProvider provides a bridge between classes: | |
6 // WebKit::WebAudioSourceProvider <---> media::AudioRendererSink | |
7 // | |
8 // RenderAudioSourceProvider is a "sink" of audio, and uses a default | |
9 // AudioOutputDevice 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 AudioOutputDevice | |
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_MEDIA_RENDER_AUDIOSOURCEPROVIDER_H_ | |
23 #define CONTENT_RENDERER_MEDIA_RENDER_AUDIOSOURCEPROVIDER_H_ | |
24 | |
25 #include "base/synchronization/lock.h" | |
26 #include "media/base/audio_renderer_sink.h" | |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAudioSourceProvide
r.h" | |
29 | |
30 namespace WebKit { | |
31 class WebAudioSourceProviderClient; | |
32 } | |
33 | |
34 namespace content { | |
35 | |
36 class RenderAudioSourceProvider | |
37 : public WebKit::WebAudioSourceProvider, | |
38 public media::AudioRendererSink { | |
39 public: | |
40 explicit RenderAudioSourceProvider(int source_render_view_id); | |
41 | |
42 // WebKit::WebAudioSourceProvider implementation. | |
43 | |
44 // WebKit calls setClient() if it desires to take control of the rendered | |
45 // audio stream. We call client's setFormat() when the audio stream format | |
46 // is known. | |
47 virtual void setClient(WebKit::WebAudioSourceProviderClient* client); | |
48 | |
49 // If setClient() has been called, then WebKit calls provideInput() | |
50 // periodically to get the rendered audio stream. | |
51 virtual void provideInput(const WebKit::WebVector<float*>& audio_data, | |
52 size_t number_of_frames); | |
53 | |
54 // AudioRendererSink implementation. | |
55 virtual void Start() OVERRIDE; | |
56 virtual void Stop() OVERRIDE; | |
57 virtual void Play() OVERRIDE; | |
58 virtual void Pause(bool flush) OVERRIDE; | |
59 virtual bool SetVolume(double volume) OVERRIDE; | |
60 virtual void Initialize(const media::AudioParameters& params, | |
61 RenderCallback* renderer) OVERRIDE; | |
62 | |
63 protected: | |
64 virtual ~RenderAudioSourceProvider(); | |
65 | |
66 private: | |
67 // Set to true when Initialize() is called. | |
68 bool is_initialized_; | |
69 int channels_; | |
70 int sample_rate_; | |
71 | |
72 bool is_running_; | |
73 media::AudioRendererSink::RenderCallback* renderer_; | |
74 WebKit::WebAudioSourceProviderClient* client_; | |
75 | |
76 // Protects access to sink_ | |
77 base::Lock sink_lock_; | |
78 | |
79 // default_sink_ is the default sink. | |
80 scoped_refptr<media::AudioRendererSink> default_sink_; | |
81 | |
82 DISALLOW_IMPLICIT_CONSTRUCTORS(RenderAudioSourceProvider); | |
83 }; | |
84 | |
85 } // namespace content | |
86 | |
87 #endif // CONTENT_RENDERER_MEDIA_RENDER_AUDIOSOURCEPROVIDER_H_ | |
OLD | NEW |