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> |
(...skipping 23 matching lines...) Expand all Loading... |
34 // provideInput() periodically to fetch the appropriate data. | 34 // provideInput() periodically to fetch the appropriate data. |
35 // | 35 // |
36 // In either case, the internal RenderCallback allows for delivering a copy of | 36 // In either case, the internal RenderCallback allows for delivering a copy of |
37 // the data if a listener is configured. WASPImpl is also a | 37 // the data if a listener is configured. WASPImpl is also a |
38 // RestartableAudioRendererSink itself in order to be controlled (Play(), | 38 // RestartableAudioRendererSink itself in order to be controlled (Play(), |
39 // Pause() etc). | 39 // Pause() etc). |
40 // | 40 // |
41 // All calls are protected by a lock. | 41 // All calls are protected by a lock. |
42 class MEDIA_BLINK_EXPORT WebAudioSourceProviderImpl | 42 class MEDIA_BLINK_EXPORT WebAudioSourceProviderImpl |
43 : NON_EXPORTED_BASE(public blink::WebAudioSourceProvider), | 43 : NON_EXPORTED_BASE(public blink::WebAudioSourceProvider), |
44 NON_EXPORTED_BASE(public RestartableAudioRendererSink) { | 44 NON_EXPORTED_BASE(public SwitchableAudioRendererSink) { |
45 public: | 45 public: |
46 using CopyAudioCB = base::Callback< | 46 using CopyAudioCB = base::Callback< |
47 void(scoped_ptr<AudioBus>, uint32_t delay_milliseconds, int sample_rate)>; | 47 void(scoped_ptr<AudioBus>, uint32_t delay_milliseconds, int sample_rate)>; |
48 | 48 |
49 explicit WebAudioSourceProviderImpl( | 49 explicit WebAudioSourceProviderImpl( |
50 const scoped_refptr<RestartableAudioRendererSink>& sink); | 50 const scoped_refptr<SwitchableAudioRendererSink>& sink); |
51 | 51 |
52 // blink::WebAudioSourceProvider implementation. | 52 // blink::WebAudioSourceProvider implementation. |
53 void setClient(blink::WebAudioSourceProviderClient* client) override; | 53 void setClient(blink::WebAudioSourceProviderClient* client) override; |
54 void provideInput(const blink::WebVector<float*>& audio_data, | 54 void provideInput(const blink::WebVector<float*>& audio_data, |
55 size_t number_of_frames) override; | 55 size_t number_of_frames) override; |
56 | 56 |
57 // RestartableAudioRendererSink implementation. | 57 // RestartableAudioRendererSink implementation. |
58 void Start() override; | 58 void Start() override; |
59 void Stop() override; | 59 void Stop() override; |
60 void Play() override; | 60 void Play() override; |
61 void Pause() override; | 61 void Pause() override; |
62 bool SetVolume(double volume) override; | 62 bool SetVolume(double volume) override; |
63 OutputDevice* GetOutputDevice() override; | 63 OutputDeviceInfo GetOutputDeviceInfo() override; |
64 void Initialize(const AudioParameters& params, | 64 void Initialize(const AudioParameters& params, |
65 RenderCallback* renderer) override; | 65 RenderCallback* renderer) override; |
| 66 void SwitchOutputDevice(const std::string& device_id, |
| 67 const url::Origin& security_origin, |
| 68 const OutputDeviceStatusCB& callback) override; |
66 | 69 |
67 // These methods allow a client to get a copy of the rendered audio. | 70 // These methods allow a client to get a copy of the rendered audio. |
68 void SetCopyAudioCallback(const CopyAudioCB& callback); | 71 void SetCopyAudioCallback(const CopyAudioCB& callback); |
69 void ClearCopyAudioCallback(); | 72 void ClearCopyAudioCallback(); |
70 | 73 |
71 private: | 74 private: |
72 friend class WebAudioSourceProviderImplTest; | 75 friend class WebAudioSourceProviderImplTest; |
73 ~WebAudioSourceProviderImpl() override; | 76 ~WebAudioSourceProviderImpl() override; |
74 | 77 |
75 // Calls setFormat() on |client_| from the Blink renderer thread. | 78 // Calls setFormat() on |client_| from the Blink renderer thread. |
76 void OnSetFormat(); | 79 void OnSetFormat(); |
77 | 80 |
78 int RenderForTesting(AudioBus* audio_bus); | 81 int RenderForTesting(AudioBus* audio_bus); |
79 | 82 |
80 // Used to keep the volume across reconfigurations. | 83 // Used to keep the volume across reconfigurations. |
81 double volume_; | 84 double volume_; |
82 | 85 |
83 // Tracks the current playback state. | 86 // Tracks the current playback state. |
84 enum PlaybackState { kStopped, kStarted, kPlaying }; | 87 enum PlaybackState { kStopped, kStarted, kPlaying }; |
85 PlaybackState state_; | 88 PlaybackState state_; |
86 | 89 |
87 // Closure that calls OnSetFormat() on |client_| on the renderer thread. | 90 // Closure that calls OnSetFormat() on |client_| on the renderer thread. |
88 base::Closure set_format_cb_; | 91 base::Closure set_format_cb_; |
89 // When set via setClient() it overrides |sink_| for consuming audio. | 92 // When set via setClient() it overrides |sink_| for consuming audio. |
90 blink::WebAudioSourceProviderClient* client_; | 93 blink::WebAudioSourceProviderClient* client_; |
91 | 94 |
92 // Where audio ends up unless overridden by |client_|. | 95 // Where audio ends up unless overridden by |client_|. |
93 base::Lock sink_lock_; | 96 base::Lock sink_lock_; |
94 const scoped_refptr<RestartableAudioRendererSink> sink_; | 97 const scoped_refptr<SwitchableAudioRendererSink> sink_; |
95 scoped_ptr<AudioBus> bus_wrapper_; | 98 scoped_ptr<AudioBus> bus_wrapper_; |
96 | 99 |
97 // An inner class acting as a T filter where actual data can be tapped. | 100 // An inner class acting as a T filter where actual data can be tapped. |
98 class TeeFilter; | 101 class TeeFilter; |
99 scoped_ptr<TeeFilter> tee_filter_; | 102 scoped_ptr<TeeFilter> tee_filter_; |
100 | 103 |
101 // NOTE: Weak pointers must be invalidated before all other member variables. | 104 // NOTE: Weak pointers must be invalidated before all other member variables. |
102 base::WeakPtrFactory<WebAudioSourceProviderImpl> weak_factory_; | 105 base::WeakPtrFactory<WebAudioSourceProviderImpl> weak_factory_; |
103 | 106 |
104 DISALLOW_IMPLICIT_CONSTRUCTORS(WebAudioSourceProviderImpl); | 107 DISALLOW_IMPLICIT_CONSTRUCTORS(WebAudioSourceProviderImpl); |
105 }; | 108 }; |
106 | 109 |
107 } // namespace media | 110 } // namespace media |
108 | 111 |
109 #endif // MEDIA_BLINK_WEBAUDIOSOURCEPROVIDER_IMPL_H_ | 112 #endif // MEDIA_BLINK_WEBAUDIOSOURCEPROVIDER_IMPL_H_ |
OLD | NEW |