OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ | 5 #ifndef MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ |
6 #define MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ | 6 #define MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "media/base/audio_converter.h" | 12 #include "media/base/audio_converter.h" |
13 #include "media/base/audio_renderer_sink.h" | 13 #include "media/base/audio_renderer_sink.h" |
14 #include "media/base/output_device.h" | 14 #include "media/base/output_device.h" |
15 #include "url/origin.h" | 15 #include "url/origin.h" |
16 | 16 |
17 namespace media { | 17 namespace media { |
18 | 18 |
19 class AudioRendererMixer; | 19 class AudioRendererMixer; |
20 | 20 |
21 class MEDIA_EXPORT AudioRendererMixerInput | 21 class MEDIA_EXPORT AudioRendererMixerInput |
22 : NON_EXPORTED_BASE(public RestartableAudioRendererSink), | 22 : NON_EXPORTED_BASE(public SwitchableAudioRendererSink), |
23 NON_EXPORTED_BASE(public OutputDevice), | |
24 public AudioConverter::InputCallback { | 23 public AudioConverter::InputCallback { |
25 public: | 24 public: |
26 typedef base::Callback<AudioRendererMixer*(const AudioParameters& params, | 25 typedef base::Callback<AudioRendererMixer*(const AudioParameters& params, |
27 const std::string& device_id, | 26 const std::string& device_id, |
28 const url::Origin& security_origin, | 27 const url::Origin& security_origin, |
29 OutputDeviceStatus* device_status)> | 28 OutputDeviceStatus* device_status)> |
30 GetMixerCB; | 29 GetMixerCB; |
31 typedef base::Callback<void(const AudioParameters& params, | 30 typedef base::Callback<void(const AudioParameters& params, |
32 const std::string& device_id, | 31 const std::string& device_id, |
33 const url::Origin& security_origin)> | 32 const url::Origin& security_origin)> |
34 RemoveMixerCB; | 33 RemoveMixerCB; |
35 | 34 |
36 typedef base::Callback<AudioParameters(const std::string& device_id, | |
37 const url::Origin& security_origin)> | |
38 GetHardwareParamsCB; | |
39 | |
40 AudioRendererMixerInput(const GetMixerCB& get_mixer_cb, | 35 AudioRendererMixerInput(const GetMixerCB& get_mixer_cb, |
41 const RemoveMixerCB& remove_mixer_cb, | 36 const RemoveMixerCB& remove_mixer_cb, |
42 const GetHardwareParamsCB& get_hardware_params_cb, | |
43 const std::string& device_id, | 37 const std::string& device_id, |
44 const url::Origin& security_origin); | 38 const url::Origin& security_origin); |
45 | 39 |
46 // RestartableAudioRendererSink implementation. | 40 // SwitchableAudioRendererSink implementation. |
47 void Start() override; | 41 void Start() override; |
48 void Stop() override; | 42 void Stop() override; |
49 void Play() override; | 43 void Play() override; |
50 void Pause() override; | 44 void Pause() override; |
51 bool SetVolume(double volume) override; | 45 bool SetVolume(double volume) override; |
52 OutputDevice* GetOutputDevice() override; | 46 OutputDevice* GetOutputDevice() override; |
53 void Initialize(const AudioParameters& params, | 47 void Initialize(const AudioParameters& params, |
54 AudioRendererSink::RenderCallback* renderer) override; | 48 AudioRendererSink::RenderCallback* renderer) override; |
55 | |
56 // OutputDevice implementation. | |
57 void SwitchOutputDevice(const std::string& device_id, | 49 void SwitchOutputDevice(const std::string& device_id, |
58 const url::Origin& security_origin, | 50 const url::Origin& security_origin, |
59 const SwitchOutputDeviceCB& callback) override; | 51 const OutputDeviceStatusCB& callback) override; |
60 AudioParameters GetOutputParameters() override; | |
61 OutputDeviceStatus GetDeviceStatus() override; | |
62 | 52 |
63 // Called by AudioRendererMixer when an error occurs. | 53 // Called by AudioRendererMixer when an error occurs. |
64 void OnRenderError(); | 54 void OnRenderError(); |
65 | 55 |
66 protected: | 56 protected: |
67 ~AudioRendererMixerInput() override; | 57 ~AudioRendererMixerInput() override; |
68 | 58 |
69 private: | 59 private: |
70 friend class AudioRendererMixerInputTest; | 60 friend class AudioRendererMixerInputTest; |
71 | 61 |
72 bool started_; | 62 bool started_; |
73 bool playing_; | 63 bool playing_; |
74 double volume_; | 64 double volume_; |
75 | 65 |
76 // AudioConverter::InputCallback implementation. | 66 // AudioConverter::InputCallback implementation. |
77 double ProvideInput(AudioBus* audio_bus, | 67 double ProvideInput(AudioBus* audio_bus, |
78 base::TimeDelta buffer_delay) override; | 68 base::TimeDelta buffer_delay) override; |
79 | 69 |
80 // Callbacks provided during construction which allow AudioRendererMixerInput | 70 // Callbacks provided during construction which allow AudioRendererMixerInput |
81 // to retrieve a mixer during Initialize() and notify when it's done with it. | 71 // to retrieve a mixer during Initialize() and notify when it's done with it. |
82 const GetMixerCB get_mixer_cb_; | 72 const GetMixerCB get_mixer_cb_; |
83 const RemoveMixerCB remove_mixer_cb_; | 73 const RemoveMixerCB remove_mixer_cb_; |
84 | 74 |
85 // Callbacks provided during construction which allows AudioRendererMixerInput | |
86 // to access hardware output parameters when it is detached from the mixer. | |
87 const GetHardwareParamsCB get_hardware_params_cb_; | |
88 | |
89 // AudioParameters received during Initialize(). | 75 // AudioParameters received during Initialize(). |
90 AudioParameters params_; | 76 AudioParameters params_; |
91 | 77 |
92 // ID of hardware device to use | 78 // ID of hardware device to use |
93 std::string device_id_; | 79 std::string device_id_; |
94 url::Origin security_origin_; | 80 url::Origin security_origin_; |
95 | 81 |
96 // AudioRendererMixer provided through |get_mixer_cb_| during Initialize(), | 82 // AudioRendererMixer provided through |get_mixer_cb_| during Initialize(), |
97 // guaranteed to live (at least) until |remove_mixer_cb_| is called. | 83 // guaranteed to live (at least) until |remove_mixer_cb_| is called. |
98 AudioRendererMixer* mixer_; | 84 AudioRendererMixer* mixer_; |
99 | 85 |
100 // Source of audio data which is provided to the mixer. | 86 // Source of audio data which is provided to the mixer. |
101 AudioRendererSink::RenderCallback* callback_; | 87 AudioRendererSink::RenderCallback* callback_; |
102 | 88 |
103 // Error callback for handing to AudioRendererMixer. | 89 // Error callback for handing to AudioRendererMixer. |
104 const base::Closure error_cb_; | 90 const base::Closure error_cb_; |
105 | 91 |
106 // Pending switch-device callback, in case SwitchOutputDevice() is invoked | 92 // Pending switch-device callback, in case SwitchOutputDevice() is invoked |
107 // before Start() | 93 // before Start() |
108 SwitchOutputDeviceCB pending_switch_callback_; | 94 OutputDeviceStatusCB pending_switch_callback_; |
109 std::string pending_switch_device_id_; | 95 std::string pending_switch_device_id_; |
110 url::Origin pending_switch_security_origin_; | 96 url::Origin pending_switch_security_origin_; |
111 | 97 |
112 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInput); | 98 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInput); |
113 }; | 99 }; |
114 | 100 |
115 } // namespace media | 101 } // namespace media |
116 | 102 |
117 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ | 103 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ |
OLD | NEW |