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