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, | 35 typedef base::Callback<OutputDevice*(const std::string& device_id, |
37 const url::Origin& security_origin)> | 36 const url::Origin& security_origin)> |
38 GetHardwareParamsCB; | 37 GetOutputDeviceCB; |
39 | 38 |
40 AudioRendererMixerInput(const GetMixerCB& get_mixer_cb, | 39 AudioRendererMixerInput(const GetMixerCB& get_mixer_cb, |
41 const RemoveMixerCB& remove_mixer_cb, | 40 const RemoveMixerCB& remove_mixer_cb, |
42 const GetHardwareParamsCB& get_hardware_params_cb, | 41 const GetOutputDeviceCB& get_output_device_cb, |
43 const std::string& device_id, | 42 const std::string& device_id, |
44 const url::Origin& security_origin); | 43 const url::Origin& security_origin); |
45 | 44 |
46 // RestartableAudioRendererSink implementation. | 45 // SwitchableAudioRendererSink implementation. |
47 void Start() override; | 46 void Start() override; |
48 void Stop() override; | 47 void Stop() override; |
49 void Play() override; | 48 void Play() override; |
50 void Pause() override; | 49 void Pause() override; |
51 bool SetVolume(double volume) override; | 50 bool SetVolume(double volume) override; |
52 OutputDevice* GetOutputDevice() override; | 51 OutputDevice* GetOutputDevice() override; |
53 void Initialize(const AudioParameters& params, | 52 void Initialize(const AudioParameters& params, |
54 AudioRendererSink::RenderCallback* renderer) override; | 53 AudioRendererSink::RenderCallback* renderer) override; |
55 | |
56 // OutputDevice implementation. | |
57 void SwitchOutputDevice(const std::string& device_id, | 54 void SwitchOutputDevice(const std::string& device_id, |
58 const url::Origin& security_origin, | 55 const url::Origin& security_origin, |
59 const SwitchOutputDeviceCB& callback) override; | 56 const SwitchOutputDeviceCB& callback) override; |
60 AudioParameters GetOutputParameters() override; | |
61 OutputDeviceStatus GetDeviceStatus() override; | |
62 | 57 |
63 // Called by AudioRendererMixer when an error occurs. | 58 // Called by AudioRendererMixer when an error occurs. |
64 void OnRenderError(); | 59 void OnRenderError(); |
65 | 60 |
66 protected: | 61 protected: |
67 ~AudioRendererMixerInput() override; | 62 ~AudioRendererMixerInput() override; |
68 | 63 |
69 private: | 64 private: |
70 friend class AudioRendererMixerInputTest; | 65 friend class AudioRendererMixerInputTest; |
71 | 66 |
72 bool started_; | 67 bool started_; |
73 bool playing_; | 68 bool playing_; |
74 double volume_; | 69 double volume_; |
75 | 70 |
76 // AudioConverter::InputCallback implementation. | 71 // AudioConverter::InputCallback implementation. |
77 double ProvideInput(AudioBus* audio_bus, | 72 double ProvideInput(AudioBus* audio_bus, |
78 base::TimeDelta buffer_delay) override; | 73 base::TimeDelta buffer_delay) override; |
79 | 74 |
80 // Callbacks provided during construction which allow AudioRendererMixerInput | 75 // Callbacks provided during construction which allow AudioRendererMixerInput |
81 // to retrieve a mixer during Initialize() and notify when it's done with it. | 76 // to retrieve a mixer during Initialize() and notify when it's done with it. |
82 const GetMixerCB get_mixer_cb_; | 77 const GetMixerCB get_mixer_cb_; |
83 const RemoveMixerCB remove_mixer_cb_; | 78 const RemoveMixerCB remove_mixer_cb_; |
84 | 79 |
85 // Callbacks provided during construction which allows AudioRendererMixerInput | 80 // Callbacks provided during construction which allows AudioRendererMixerInput |
86 // to access hardware output parameters when it is detached from the mixer. | 81 // to access output device when no mixer is attached. |
87 const GetHardwareParamsCB get_hardware_params_cb_; | 82 const GetOutputDeviceCB get_output_device_cb_; |
88 | 83 |
89 // AudioParameters received during Initialize(). | 84 // AudioParameters received during Initialize(). |
90 AudioParameters params_; | 85 AudioParameters params_; |
91 | 86 |
92 // ID of hardware device to use | 87 // ID of hardware device to use |
93 std::string device_id_; | 88 std::string device_id_; |
94 url::Origin security_origin_; | 89 url::Origin security_origin_; |
95 | 90 |
96 // AudioRendererMixer provided through |get_mixer_cb_| during Initialize(), | 91 // AudioRendererMixer provided through |get_mixer_cb_| during Initialize(), |
97 // guaranteed to live (at least) until |remove_mixer_cb_| is called. | 92 // guaranteed to live (at least) until |remove_mixer_cb_| is called. |
(...skipping 10 matching lines...) Expand all Loading... |
108 SwitchOutputDeviceCB pending_switch_callback_; | 103 SwitchOutputDeviceCB pending_switch_callback_; |
109 std::string pending_switch_device_id_; | 104 std::string pending_switch_device_id_; |
110 url::Origin pending_switch_security_origin_; | 105 url::Origin pending_switch_security_origin_; |
111 | 106 |
112 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInput); | 107 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInput); |
113 }; | 108 }; |
114 | 109 |
115 } // namespace media | 110 } // namespace media |
116 | 111 |
117 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ | 112 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ |
OLD | NEW |