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 MEDIA_BLINK_WEBAUDIOSOURCEPROVIDER_IMPL_H_ | 5 #ifndef MEDIA_BLINK_WEBAUDIOSOURCEPROVIDER_IMPL_H_ |
6 #define MEDIA_BLINK_WEBAUDIOSOURCEPROVIDER_IMPL_H_ | 6 #define MEDIA_BLINK_WEBAUDIOSOURCEPROVIDER_IMPL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "media/base/audio_renderer_sink.h" | 16 #include "media/base/audio_renderer_sink.h" |
17 #include "media/blink/media_blink_export.h" | 17 #include "media/blink/media_blink_export.h" |
18 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" | 18 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" |
19 #include "third_party/WebKit/public/platform/WebVector.h" | 19 #include "third_party/WebKit/public/platform/WebVector.h" |
20 | 20 |
21 namespace blink { | 21 namespace blink { |
22 class WebAudioSourceProviderClient; | 22 class WebAudioSourceProviderClient; |
23 } | 23 } |
24 | 24 |
25 namespace media { | 25 namespace media { |
26 class MediaLog; | |
26 | 27 |
27 // WebAudioSourceProviderImpl is either one of two things (but not both): | 28 // WebAudioSourceProviderImpl is either one of two things (but not both): |
28 // - a connection between a RestartableAudioRendererSink (the |sink_|) passed in | 29 // - a connection between a RestartableAudioRendererSink (the |sink_|) passed in |
29 // constructor and an AudioRendererSink::RenderCallback passed on Initialize() | 30 // constructor and an AudioRendererSink::RenderCallback passed on Initialize() |
30 // by means of an internal AudioRendererSink::RenderCallback. | 31 // by means of an internal AudioRendererSink::RenderCallback. |
31 // - a connection between the said AudioRendererSink::RenderCallback and a | 32 // - a connection between the said AudioRendererSink::RenderCallback and a |
32 // blink::WebAudioSourceProviderClient passed via setClient() (the |client_|), | 33 // blink::WebAudioSourceProviderClient passed via setClient() (the |client_|), |
33 // again using the internal AudioRendererSink::RenderCallback. Blink calls | 34 // again using the internal AudioRendererSink::RenderCallback. Blink calls |
34 // provideInput() periodically to fetch the appropriate data. | 35 // provideInput() periodically to fetch the appropriate data. |
35 // | 36 // |
36 // In either case, the internal RenderCallback allows for delivering a copy of | 37 // In either case, the internal RenderCallback allows for delivering a copy of |
37 // the data if a listener is configured. WASPImpl is also a | 38 // the data if a listener is configured. WASPImpl is also a |
38 // RestartableAudioRendererSink itself in order to be controlled (Play(), | 39 // RestartableAudioRendererSink itself in order to be controlled (Play(), |
39 // Pause() etc). | 40 // Pause() etc). |
40 // | 41 // |
41 // All calls are protected by a lock. | 42 // All calls are protected by a lock. |
42 class MEDIA_BLINK_EXPORT WebAudioSourceProviderImpl | 43 class MEDIA_BLINK_EXPORT WebAudioSourceProviderImpl |
43 : NON_EXPORTED_BASE(public blink::WebAudioSourceProvider), | 44 : NON_EXPORTED_BASE(public blink::WebAudioSourceProvider), |
44 NON_EXPORTED_BASE(public SwitchableAudioRendererSink) { | 45 NON_EXPORTED_BASE(public SwitchableAudioRendererSink) { |
45 public: | 46 public: |
46 using CopyAudioCB = base::Callback<void(std::unique_ptr<AudioBus>, | 47 using CopyAudioCB = base::Callback<void(std::unique_ptr<AudioBus>, |
47 uint32_t frames_delayed, | 48 uint32_t frames_delayed, |
48 int sample_rate)>; | 49 int sample_rate)>; |
49 | 50 |
50 explicit WebAudioSourceProviderImpl( | 51 explicit WebAudioSourceProviderImpl( |
DaleCurtis
2016/12/02 18:28:56
Drop explicit now.
o1ka
2016/12/05 09:54:13
Done.
| |
51 const scoped_refptr<SwitchableAudioRendererSink>& sink); | 52 const scoped_refptr<SwitchableAudioRendererSink>& sink, |
DaleCurtis
2016/12/02 18:28:57
Convert to non const& or flip media_log to const&?
o1ka
2016/12/05 09:54:13
Done.
| |
53 scoped_refptr<MediaLog> media_log); | |
52 | 54 |
53 // blink::WebAudioSourceProvider implementation. | 55 // blink::WebAudioSourceProvider implementation. |
54 void setClient(blink::WebAudioSourceProviderClient* client) override; | 56 void setClient(blink::WebAudioSourceProviderClient* client) override; |
55 void provideInput(const blink::WebVector<float*>& audio_data, | 57 void provideInput(const blink::WebVector<float*>& audio_data, |
56 size_t number_of_frames) override; | 58 size_t number_of_frames) override; |
57 | 59 |
58 // RestartableAudioRendererSink implementation. | 60 // RestartableAudioRendererSink implementation. |
59 void Initialize(const AudioParameters& params, | 61 void Initialize(const AudioParameters& params, |
60 RenderCallback* renderer) override; | 62 RenderCallback* renderer) override; |
61 void Start() override; | 63 void Start() override; |
62 void Stop() override; | 64 void Stop() override; |
63 void Play() override; | 65 void Play() override; |
64 void Pause() override; | 66 void Pause() override; |
65 bool SetVolume(double volume) override; | 67 bool SetVolume(double volume) override; |
66 OutputDeviceInfo GetOutputDeviceInfo() override; | 68 OutputDeviceInfo GetOutputDeviceInfo() override; |
67 bool CurrentThreadIsRenderingThread() override; | 69 bool CurrentThreadIsRenderingThread() override; |
68 void SwitchOutputDevice(const std::string& device_id, | 70 void SwitchOutputDevice(const std::string& device_id, |
69 const url::Origin& security_origin, | 71 const url::Origin& security_origin, |
70 const OutputDeviceStatusCB& callback) override; | 72 const OutputDeviceStatusCB& callback) override; |
71 | 73 |
72 // These methods allow a client to get a copy of the rendered audio. | 74 // These methods allow a client to get a copy of the rendered audio. |
73 void SetCopyAudioCallback(const CopyAudioCB& callback); | 75 void SetCopyAudioCallback(const CopyAudioCB& callback); |
74 void ClearCopyAudioCallback(); | 76 void ClearCopyAudioCallback(); |
75 | 77 |
76 int RenderForTesting(AudioBus* audio_bus); | 78 int RenderForTesting(AudioBus* audio_bus); |
77 | 79 |
80 protected: | |
81 virtual scoped_refptr<SwitchableAudioRendererSink> CreateFallbackSink(); | |
82 ~WebAudioSourceProviderImpl() override; | |
83 | |
78 private: | 84 private: |
79 friend class WebAudioSourceProviderImplTest; | 85 friend class WebAudioSourceProviderImplTest; |
80 ~WebAudioSourceProviderImpl() override; | |
81 | 86 |
82 // Calls setFormat() on |client_| from the Blink renderer thread. | 87 // Calls setFormat() on |client_| from the Blink renderer thread. |
83 void OnSetFormat(); | 88 void OnSetFormat(); |
84 | 89 |
85 // Used to keep the volume across reconfigurations. | 90 // Used to keep the volume across reconfigurations. |
86 double volume_; | 91 double volume_; |
87 | 92 |
88 // Tracks the current playback state. | 93 // Tracks the current playback state. |
89 enum PlaybackState { kStopped, kStarted, kPlaying }; | 94 enum PlaybackState { kStopped, kStarted, kPlaying }; |
90 PlaybackState state_; | 95 PlaybackState state_; |
91 | 96 |
92 // Closure that calls OnSetFormat() on |client_| on the renderer thread. | 97 // Closure that calls OnSetFormat() on |client_| on the renderer thread. |
93 base::Closure set_format_cb_; | 98 base::Closure set_format_cb_; |
94 // When set via setClient() it overrides |sink_| for consuming audio. | 99 // When set via setClient() it overrides |sink_| for consuming audio. |
95 blink::WebAudioSourceProviderClient* client_; | 100 blink::WebAudioSourceProviderClient* client_; |
96 | 101 |
97 // Where audio ends up unless overridden by |client_|. | 102 // Where audio ends up unless overridden by |client_|. |
98 base::Lock sink_lock_; | 103 base::Lock sink_lock_; |
99 const scoped_refptr<SwitchableAudioRendererSink> sink_; | 104 scoped_refptr<SwitchableAudioRendererSink> sink_; |
100 std::unique_ptr<AudioBus> bus_wrapper_; | 105 std::unique_ptr<AudioBus> bus_wrapper_; |
101 | 106 |
102 // An inner class acting as a T filter where actual data can be tapped. | 107 // An inner class acting as a T filter where actual data can be tapped. |
103 class TeeFilter; | 108 class TeeFilter; |
104 const std::unique_ptr<TeeFilter> tee_filter_; | 109 const std::unique_ptr<TeeFilter> tee_filter_; |
105 | 110 |
111 const scoped_refptr<MediaLog> media_log_; | |
112 | |
106 // NOTE: Weak pointers must be invalidated before all other member variables. | 113 // NOTE: Weak pointers must be invalidated before all other member variables. |
107 base::WeakPtrFactory<WebAudioSourceProviderImpl> weak_factory_; | 114 base::WeakPtrFactory<WebAudioSourceProviderImpl> weak_factory_; |
108 | 115 |
109 DISALLOW_IMPLICIT_CONSTRUCTORS(WebAudioSourceProviderImpl); | 116 DISALLOW_IMPLICIT_CONSTRUCTORS(WebAudioSourceProviderImpl); |
110 }; | 117 }; |
111 | 118 |
112 } // namespace media | 119 } // namespace media |
113 | 120 |
114 #endif // MEDIA_BLINK_WEBAUDIOSOURCEPROVIDER_IMPL_H_ | 121 #endif // MEDIA_BLINK_WEBAUDIOSOURCEPROVIDER_IMPL_H_ |
OLD | NEW |