OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ | 5 #ifndef CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ |
6 #define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ | 6 #define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ |
7 | 7 |
8 #include <alsa/asoundlib.h> | 8 #include <alsa/asoundlib.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <map> | |
11 #include <memory> | 12 #include <memory> |
12 #include <string> | 13 #include <string> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
17 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
18 #include "base/timer/timer.h" | 19 #include "base/timer/timer.h" |
19 #include "chromecast/media/cma/backend/alsa/audio_filter_interface.h" | 20 #include "chromecast/media/cma/backend/alsa/audio_filter_interface.h" |
20 #include "chromecast/media/cma/backend/alsa/media_pipeline_backend_alsa.h" | 21 #include "chromecast/media/cma/backend/alsa/media_pipeline_backend_alsa.h" |
21 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input.h" | 22 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input.h" |
22 #include "chromecast/public/cast_media_shlib.h" | 23 #include "chromecast/public/cast_media_shlib.h" |
24 #include "chromecast/public/volume_control.h" | |
23 | 25 |
24 namespace media { | 26 namespace media { |
25 class AudioBus; | 27 class AudioBus; |
26 } // namespace media | 28 } // namespace media |
27 | 29 |
28 namespace chromecast { | 30 namespace chromecast { |
29 namespace media { | 31 namespace media { |
30 class AlsaWrapper; | 32 class AlsaWrapper; |
31 class FilterGroup; | 33 class FilterGroup; |
32 | 34 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 | 68 |
67 // Returns true if the stream is primary. Primary streams will be given | 69 // Returns true if the stream is primary. Primary streams will be given |
68 // precedence for sample rates and will dictate when data is polled. | 70 // precedence for sample rates and will dictate when data is polled. |
69 virtual bool primary() const = 0; | 71 virtual bool primary() const = 0; |
70 | 72 |
71 // Returns a string describing the content type class. | 73 // Returns a string describing the content type class. |
72 // Should be from chromecast/media/base/audio_device_ids.h | 74 // Should be from chromecast/media/base/audio_device_ids.h |
73 // or media/audio/audio_device_description.h | 75 // or media/audio/audio_device_description.h |
74 virtual std::string device_id() const = 0; | 76 virtual std::string device_id() const = 0; |
75 | 77 |
78 // Returns the content type for volume control. | |
79 virtual AudioContentType content_type() const = 0; | |
80 | |
76 // Returns true if PrepareToDelete() has been called. | 81 // Returns true if PrepareToDelete() has been called. |
77 virtual bool IsDeleting() const = 0; | 82 virtual bool IsDeleting() const = 0; |
78 | 83 |
79 // Initializes the InputQueue after the mixer is set up. At this point the | 84 // Initializes the InputQueue after the mixer is set up. At this point the |
80 // input can correctly determine the mixer's output sample rate. | 85 // input can correctly determine the mixer's output sample rate. |
81 virtual void Initialize(const MediaPipelineBackendAlsa::RenderingDelay& | 86 virtual void Initialize(const MediaPipelineBackendAlsa::RenderingDelay& |
82 mixer_rendering_delay) = 0; | 87 mixer_rendering_delay) = 0; |
83 | 88 |
84 // Sets and gets the FilterGroup the InputQueue matches. | 89 // Sets and gets the FilterGroup the InputQueue matches. |
85 // This is determined at creation to save time matching the InputQueue | 90 // This is determined at creation to save time matching the InputQueue |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 mixer_rendering_delay) = 0; | 127 mixer_rendering_delay) = 0; |
123 | 128 |
124 // This will be called when a fatal error occurs in the mixer. | 129 // This will be called when a fatal error occurs in the mixer. |
125 virtual void SignalError(StreamMixerAlsaInput::MixerError error) = 0; | 130 virtual void SignalError(StreamMixerAlsaInput::MixerError error) = 0; |
126 | 131 |
127 // Notifies the input that it is being removed by the upper layers, and | 132 // Notifies the input that it is being removed by the upper layers, and |
128 // should do whatever is necessary to become ready to delete from the mixer. | 133 // should do whatever is necessary to become ready to delete from the mixer. |
129 // Once the input is ready to be removed, it should call the supplied | 134 // Once the input is ready to be removed, it should call the supplied |
130 // |delete_cb|; this should only happen once per input. | 135 // |delete_cb|; this should only happen once per input. |
131 virtual void PrepareToDelete(const OnReadyToDeleteCb& delete_cb) = 0; | 136 virtual void PrepareToDelete(const OnReadyToDeleteCb& delete_cb) = 0; |
137 | |
138 // Sets the multiplier based on this stream's content type. The resulting | |
139 // output volume should be the content type volume * the per-stream volume | |
140 // multiplier. | |
141 virtual void SetContentTypeVolume(float volume) = 0; | |
142 | |
143 // Sets whether or not this stream should be muted. | |
144 virtual void SetMuted(bool muted) = 0; | |
132 }; | 145 }; |
133 | 146 |
134 enum State { | 147 enum State { |
135 kStateUninitialized, | 148 kStateUninitialized, |
136 kStateNormalPlayback, | 149 kStateNormalPlayback, |
137 kStateError, | 150 kStateError, |
138 }; | 151 }; |
139 | 152 |
140 static StreamMixerAlsa* Get(); | 153 static StreamMixerAlsa* Get(); |
141 static void MakeSingleThreadedForTest(); | 154 static void MakeSingleThreadedForTest(); |
(...skipping 20 matching lines...) Expand all Loading... | |
162 void SetAlsaWrapperForTest(std::unique_ptr<AlsaWrapper> alsa_wrapper); | 175 void SetAlsaWrapperForTest(std::unique_ptr<AlsaWrapper> alsa_wrapper); |
163 void WriteFramesForTest(); // Can be called on any thread. | 176 void WriteFramesForTest(); // Can be called on any thread. |
164 void ClearInputsForTest(); // Removes all inputs. | 177 void ClearInputsForTest(); // Removes all inputs. |
165 | 178 |
166 void AddLoopbackAudioObserver( | 179 void AddLoopbackAudioObserver( |
167 CastMediaShlib::LoopbackAudioObserver* observer); | 180 CastMediaShlib::LoopbackAudioObserver* observer); |
168 | 181 |
169 void RemoveLoopbackAudioObserver( | 182 void RemoveLoopbackAudioObserver( |
170 CastMediaShlib::LoopbackAudioObserver* observer); | 183 CastMediaShlib::LoopbackAudioObserver* observer); |
171 | 184 |
185 // Sets the volume multiplier for the given content |type|. | |
186 void SetVolume(AudioContentType type, float level); | |
187 | |
188 // Sets the mute state for the given content |type|. | |
189 void SetMuted(AudioContentType type, bool muted); | |
190 | |
191 // Sets the volume multiplier limit for the given content |type|. | |
192 void SetOutputLimit(AudioContentType type, float limit); | |
193 | |
172 protected: | 194 protected: |
173 StreamMixerAlsa(); | 195 StreamMixerAlsa(); |
174 virtual ~StreamMixerAlsa(); | 196 virtual ~StreamMixerAlsa(); |
175 | 197 |
176 private: | 198 private: |
177 void ResetTaskRunnerForTest(); | 199 void ResetTaskRunnerForTest(); |
178 void FinalizeOnMixerThread(); | 200 void FinalizeOnMixerThread(); |
179 void FinishFinalize(); | 201 void FinishFinalize(); |
180 | 202 |
181 // Reads the buffer size, period size, start threshold, and avail min value | 203 // Reads the buffer size, period size, start threshold, and avail min value |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 int output_samples_per_second_; | 247 int output_samples_per_second_; |
226 snd_pcm_t* pcm_; | 248 snd_pcm_t* pcm_; |
227 snd_pcm_hw_params_t* pcm_hw_params_; | 249 snd_pcm_hw_params_t* pcm_hw_params_; |
228 snd_pcm_status_t* pcm_status_; | 250 snd_pcm_status_t* pcm_status_; |
229 snd_pcm_format_t pcm_format_; | 251 snd_pcm_format_t pcm_format_; |
230 | 252 |
231 // User-configurable ALSA parameters. This caches the results, so the code | 253 // User-configurable ALSA parameters. This caches the results, so the code |
232 // only has to interact with the command line parameters once. | 254 // only has to interact with the command line parameters once. |
233 std::string alsa_device_name_; | 255 std::string alsa_device_name_; |
234 snd_pcm_uframes_t alsa_buffer_size_; | 256 snd_pcm_uframes_t alsa_buffer_size_; |
235 bool alsa_period_explicitly_set; | |
236 snd_pcm_uframes_t alsa_period_size_; | 257 snd_pcm_uframes_t alsa_period_size_; |
237 snd_pcm_uframes_t alsa_start_threshold_; | 258 snd_pcm_uframes_t alsa_start_threshold_; |
238 snd_pcm_uframes_t alsa_avail_min_; | 259 snd_pcm_uframes_t alsa_avail_min_; |
239 | 260 |
240 State state_; | 261 State state_; |
241 | 262 |
242 std::vector<std::unique_ptr<InputQueue>> inputs_; | 263 std::vector<std::unique_ptr<InputQueue>> inputs_; |
243 std::vector<std::unique_ptr<InputQueue>> ignored_inputs_; | 264 std::vector<std::unique_ptr<InputQueue>> ignored_inputs_; |
244 MediaPipelineBackendAlsa::RenderingDelay rendering_delay_; | 265 MediaPipelineBackendAlsa::RenderingDelay rendering_delay_; |
245 | 266 |
246 std::unique_ptr<base::Timer> retry_write_frames_timer_; | 267 std::unique_ptr<base::Timer> retry_write_frames_timer_; |
247 | 268 |
248 int check_close_timeout_; | 269 int check_close_timeout_; |
249 std::unique_ptr<base::Timer> check_close_timer_; | 270 std::unique_ptr<base::Timer> check_close_timer_; |
250 | 271 |
251 std::vector<std::unique_ptr<FilterGroup>> filter_groups_; | 272 std::vector<std::unique_ptr<FilterGroup>> filter_groups_; |
252 std::vector<CastMediaShlib::LoopbackAudioObserver*> loopback_observers_; | 273 std::vector<CastMediaShlib::LoopbackAudioObserver*> loopback_observers_; |
253 | 274 |
275 std::map<AudioContentType, float> volume_; | |
slan
2017/03/13 22:09:51
Why not std::unordered_map?
I think that Chrome a
kmackay
2017/03/14 00:21:00
The comment in https://cs.chromium.org/chromium/sr
slan
2017/03/14 17:21:28
Acknowledged.
| |
276 std::map<AudioContentType, float> volume_limit_; | |
277 std::map<AudioContentType, bool> muted_; | |
278 | |
254 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsa); | 279 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsa); |
255 }; | 280 }; |
256 | 281 |
257 } // namespace media | 282 } // namespace media |
258 } // namespace chromecast | 283 } // namespace chromecast |
259 | 284 |
260 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ | 285 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ |
OLD | NEW |