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