Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(694)

Side by Side Diff: webkit/media/webaudiosourceprovider_impl.h

Issue 11830004: Refactor content::RenderAudioSourceProvider as webkit_media::WebAudioSourceProviderImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 // RenderAudioSourceProvider provides a bridge between classes: 5 #ifndef WEBKIT_MEDIA_WEBAUDIOSOURCEPROVIDER_IMPL_H_
6 #define WEBKIT_MEDIA_WEBAUDIOSOURCEPROVIDER_IMPL_H_
7
8 #include "base/synchronization/lock.h"
9 #include "media/base/audio_renderer_sink.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAudioSourceProvide r.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
12
13 namespace WebKit {
14 class WebAudioSourceProviderClient;
15 }
16
17 namespace webkit_media {
18
19 // WebAudioSourceProviderImpl provides a bridge between classes:
6 // WebKit::WebAudioSourceProvider <---> media::AudioRendererSink 20 // WebKit::WebAudioSourceProvider <---> media::AudioRendererSink
7 // 21 //
8 // RenderAudioSourceProvider is a "sink" of audio, and uses a default 22 // WebAudioSourceProviderImpl wraps an existing audio sink that is used unless
9 // AudioOutputDevice if a client has not explicitly been set. 23 // WebKit has set a client via setClient(). While a client is set WebKit will
10 // 24 // periodically call provideInput() to render a certain number of audio
11 // WebKit optionally sets a client, and then periodically calls provideInput() 25 // sample-frames using the sink's RenderCallback to get the data.
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 // 26 //
17 // THREAD SAFETY: 27 // THREAD SAFETY:
18 // It is assumed that the callers to setClient() and provideInput() 28 // It is assumed that the callers to setClient() and provideInput()
19 // implement appropriate locking for thread safety when making 29 // implement appropriate locking for thread safety when making
20 // these calls. This happens in WebKit. 30 // these calls. This happens in WebKit.
21 31 class WebAudioSourceProviderImpl
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, 32 : public WebKit::WebAudioSourceProvider,
38 public media::AudioRendererSink { 33 public media::AudioRendererSink {
39 public: 34 public:
40 explicit RenderAudioSourceProvider(int source_render_view_id); 35 explicit WebAudioSourceProviderImpl(
36 const scoped_refptr<media::AudioRendererSink>& sink);
41 37
42 // WebKit::WebAudioSourceProvider implementation. 38 // 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); 39 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, 40 virtual void provideInput(const WebKit::WebVector<float*>& audio_data,
52 size_t number_of_frames); 41 size_t number_of_frames);
53 42
54 // AudioRendererSink implementation. 43 // media::AudioRendererSink implementation.
55 virtual void Start() OVERRIDE; 44 virtual void Start() OVERRIDE;
56 virtual void Stop() OVERRIDE; 45 virtual void Stop() OVERRIDE;
57 virtual void Play() OVERRIDE; 46 virtual void Play() OVERRIDE;
58 virtual void Pause(bool flush) OVERRIDE; 47 virtual void Pause(bool flush) OVERRIDE;
59 virtual bool SetVolume(double volume) OVERRIDE; 48 virtual bool SetVolume(double volume) OVERRIDE;
60 virtual void Initialize(const media::AudioParameters& params, 49 virtual void Initialize(const media::AudioParameters& params,
61 RenderCallback* renderer) OVERRIDE; 50 RenderCallback* renderer) OVERRIDE;
62 51
63 protected: 52 protected:
64 virtual ~RenderAudioSourceProvider(); 53 virtual ~WebAudioSourceProviderImpl();
65 54
66 private: 55 private:
67 // Set to true when Initialize() is called. 56 // Set to true when Initialize() is called.
68 bool is_initialized_; 57 bool is_initialized_;
69 int channels_; 58 int channels_;
70 int sample_rate_; 59 int sample_rate_;
71 60
61 // Tracks if |sink_| has been instructed to consume audio.
72 bool is_running_; 62 bool is_running_;
63
64 // Where audio comes from.
73 media::AudioRendererSink::RenderCallback* renderer_; 65 media::AudioRendererSink::RenderCallback* renderer_;
66
67 // When set via setClient() it overrides |sink_| for consuming audio.
74 WebKit::WebAudioSourceProviderClient* client_; 68 WebKit::WebAudioSourceProviderClient* client_;
75 69
76 // Protects access to sink_ 70 // Where audio ends up unless overridden by |client_|.
77 base::Lock sink_lock_; 71 base::Lock sink_lock_;
72 scoped_refptr<media::AudioRendererSink> sink_;
miu 2013/01/09 18:48:35 nit: Since sink_ is set via the ctor initializer l
78 73
79 // default_sink_ is the default sink. 74 DISALLOW_IMPLICIT_CONSTRUCTORS(WebAudioSourceProviderImpl);
80 scoped_refptr<media::AudioRendererSink> default_sink_;
81
82 DISALLOW_IMPLICIT_CONSTRUCTORS(RenderAudioSourceProvider);
83 }; 75 };
84 76
85 } // namespace content 77 } // namespace webkit_media
86 78
87 #endif // CONTENT_RENDERER_MEDIA_RENDER_AUDIOSOURCEPROVIDER_H_ 79 #endif // WEBKIT_MEDIA_WEBAUDIOSOURCEPROVIDER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698