Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(562)

Side by Side Diff: chromecast/media/cma/backend/alsa/stream_mixer_alsa.h

Issue 2847673002: [Chromecast] Complete PostProcessingPipeline changes (Closed)
Patch Set: Fix deps Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 12 matching lines...) Expand all
23 #include "chromecast/public/volume_control.h" 23 #include "chromecast/public/volume_control.h"
24 24
25 namespace media { 25 namespace media {
26 class AudioBus; 26 class AudioBus;
27 } // namespace media 27 } // namespace media
28 28
29 namespace chromecast { 29 namespace chromecast {
30 namespace media { 30 namespace media {
31 class AlsaWrapper; 31 class AlsaWrapper;
32 class FilterGroup; 32 class FilterGroup;
33 class PostProcessingPipelineParser;
33 34
34 // Mixer implementation. The mixer has one or more input queues; these can be 35 // Mixer implementation. The mixer has one or more input queues; these can be
35 // added/removed at any time. When an input source pushes frames to an input 36 // added/removed at any time. When an input source pushes frames to an input
36 // queue, the queue should call StreamMixerAlsa::WriteFrames(); this causes 37 // queue, the queue should call StreamMixerAlsa::WriteFrames(); this causes
37 // the mixer to attempt to mix and write out as many frames as possible. To do 38 // the mixer to attempt to mix and write out as many frames as possible. To do
38 // this, the mixer determines how many frames can be read from all inputs (ie, 39 // this, the mixer determines how many frames can be read from all inputs (ie,
39 // it gets the maximum number of frames that can be read from each input, and 40 // it gets the maximum number of frames that can be read from each input, and
40 // uses the minimum value). Assuming that all primary inputs have some data 41 // uses the minimum value). Assuming that all primary inputs have some data
41 // available, the calculated number of frames are pulled from each input (maybe 42 // available, the calculated number of frames are pulled from each input (maybe
42 // resampled, if the input's incoming sample rate is not equal to the mixer's 43 // resampled, if the input's incoming sample rate is not equal to the mixer's
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // RemoveInput(input) is called. Can be called on any thread. 169 // RemoveInput(input) is called. Can be called on any thread.
169 void AddInput(std::unique_ptr<InputQueue> input); 170 void AddInput(std::unique_ptr<InputQueue> input);
170 // Instructs the mixer to remove an input. The input should not be referenced 171 // Instructs the mixer to remove an input. The input should not be referenced
171 // after this is called. Can be called on any thread. 172 // after this is called. Can be called on any thread.
172 void RemoveInput(InputQueue* input); 173 void RemoveInput(InputQueue* input);
173 174
174 // Attempts to write some frames of audio to ALSA. Must only be called on the 175 // Attempts to write some frames of audio to ALSA. Must only be called on the
175 // mixer thread. 176 // mixer thread.
176 void OnFramesQueued(); 177 void OnFramesQueued();
177 178
179 void ResetPostProcessorsForTest(const std::string& pipeline_json);
178 void SetAlsaWrapperForTest(std::unique_ptr<AlsaWrapper> alsa_wrapper); 180 void SetAlsaWrapperForTest(std::unique_ptr<AlsaWrapper> alsa_wrapper);
179 void DisablePostProcessingForTest();
180 void WriteFramesForTest(); // Can be called on any thread. 181 void WriteFramesForTest(); // Can be called on any thread.
181 void ClearInputsForTest(); // Removes all inputs. 182 void ClearInputsForTest(); // Removes all inputs.
182 183
183 void AddLoopbackAudioObserver( 184 void AddLoopbackAudioObserver(
184 CastMediaShlib::LoopbackAudioObserver* observer); 185 CastMediaShlib::LoopbackAudioObserver* observer);
185 186
186 void RemoveLoopbackAudioObserver( 187 void RemoveLoopbackAudioObserver(
187 CastMediaShlib::LoopbackAudioObserver* observer); 188 CastMediaShlib::LoopbackAudioObserver* observer);
188 189
189 // Sets the volume multiplier for the given content |type|. 190 // Sets the volume multiplier for the given content |type|.
(...skipping 16 matching lines...) Expand all
206 207
207 float volume = 0.0f; 208 float volume = 0.0f;
208 float limit = 1.0f; 209 float limit = 1.0f;
209 bool muted = false; 210 bool muted = false;
210 }; 211 };
211 212
212 void ResetTaskRunnerForTest(); 213 void ResetTaskRunnerForTest();
213 void FinalizeOnMixerThread(); 214 void FinalizeOnMixerThread();
214 void FinishFinalize(); 215 void FinishFinalize();
215 216
217 void CreatePostProcessors(PostProcessingPipelineParser* pipeline_parser);
216 // Reads the buffer size, period size, start threshold, and avail min value 218 // Reads the buffer size, period size, start threshold, and avail min value
217 // from the provided command line flags or uses default values if no flags are 219 // from the provided command line flags or uses default values if no flags are
218 // provided. 220 // provided.
219 void DefineAlsaParameters(); 221 void DefineAlsaParameters();
220 222
221 // Takes the provided ALSA config and sets all ALSA output hardware/software 223 // Takes the provided ALSA config and sets all ALSA output hardware/software
222 // playback parameters. It will try to select sane fallback parameters based 224 // playback parameters. It will try to select sane fallback parameters based
223 // on what the output hardware supports and will log warnings if it does so. 225 // on what the output hardware supports and will log warnings if it does so.
224 // If any ALSA function returns an unexpected error code, the error code will 226 // If any ALSA function returns an unexpected error code, the error code will
225 // be returned by this function. Otherwise, it will return 0. 227 // be returned by this function. Otherwise, it will return 0.
226 int SetAlsaPlaybackParams(); 228 int SetAlsaPlaybackParams();
227 void Start(); 229 void Start();
228 void Stop(); 230 void Stop();
229 void Close(); 231 void Close();
230 void SignalError(); 232 void SignalError();
231 void CheckChangeOutputRate(int input_samples_per_second); 233 void CheckChangeOutputRate(int input_samples_per_second);
232 unsigned int DetermineOutputRate(unsigned int requested_rate); 234 unsigned int DetermineOutputRate(unsigned int requested_rate);
233 235
234 // Deletes an input queue that has finished preparing to delete itself. 236 // Deletes an input queue that has finished preparing to delete itself.
235 // May be called on any thread. 237 // May be called on any thread.
236 void DeleteInputQueue(InputQueue* input); 238 void DeleteInputQueue(InputQueue* input);
237 // Runs on mixer thread to complete input queue deletion. 239 // Runs on mixer thread to complete input queue deletion.
238 void DeleteInputQueueInternal(InputQueue* input); 240 void DeleteInputQueueInternal(InputQueue* input);
239 // Called after a timeout period to close the PCM handle if no inputs are 241 // Called after a timeout period to close the PCM handle if no inputs are
240 // present. 242 // present.
241 void CheckClose(); 243 void CheckClose();
242 244
243 void WriteFrames(); 245 void WriteFrames();
244 bool TryWriteFrames(); 246 bool TryWriteFrames();
245 void WriteMixedPcm(std::vector<uint8_t>* interleaved, int frames); 247 void WriteMixedPcm(int frames);
246 void UpdateRenderingDelay(int newly_pushed_frames); 248 void UpdateRenderingDelay(int newly_pushed_frames);
247 size_t InterleavedSize(int frames); 249 size_t InterleavedSize(int frames);
248 ssize_t BytesPerOutputFormatSample(); 250 ssize_t BytesPerOutputFormatSample();
249 void ResizeBuffersIfNecessary(int chunk_size); 251 void ResizeBuffersIfNecessary(int chunk_size);
250 252
251 static bool single_threaded_for_test_; 253 static bool single_threaded_for_test_;
252 254
253 std::unique_ptr<AlsaWrapper> alsa_; 255 std::unique_ptr<AlsaWrapper> alsa_;
254 std::unique_ptr<base::Thread> mixer_thread_; 256 std::unique_ptr<base::Thread> mixer_thread_;
255 scoped_refptr<base::SingleThreadTaskRunner> mixer_task_runner_; 257 scoped_refptr<base::SingleThreadTaskRunner> mixer_task_runner_;
(...skipping 12 matching lines...) Expand all
268 std::string alsa_device_name_; 270 std::string alsa_device_name_;
269 snd_pcm_uframes_t alsa_buffer_size_; 271 snd_pcm_uframes_t alsa_buffer_size_;
270 snd_pcm_uframes_t alsa_period_size_; 272 snd_pcm_uframes_t alsa_period_size_;
271 snd_pcm_uframes_t alsa_start_threshold_; 273 snd_pcm_uframes_t alsa_start_threshold_;
272 snd_pcm_uframes_t alsa_avail_min_; 274 snd_pcm_uframes_t alsa_avail_min_;
273 275
274 State state_; 276 State state_;
275 277
276 std::vector<std::unique_ptr<InputQueue>> inputs_; 278 std::vector<std::unique_ptr<InputQueue>> inputs_;
277 std::vector<std::unique_ptr<InputQueue>> ignored_inputs_; 279 std::vector<std::unique_ptr<InputQueue>> ignored_inputs_;
278 MediaPipelineBackendAlsa::RenderingDelay rendering_delay_; 280 MediaPipelineBackendAlsa::RenderingDelay alsa_rendering_delay_;
279 281
280 std::unique_ptr<base::Timer> retry_write_frames_timer_; 282 std::unique_ptr<base::Timer> retry_write_frames_timer_;
281 283
282 int check_close_timeout_; 284 int check_close_timeout_;
283 std::unique_ptr<base::Timer> check_close_timer_; 285 std::unique_ptr<base::Timer> check_close_timer_;
284 286
285 std::vector<std::unique_ptr<FilterGroup>> filter_groups_; 287 std::vector<std::unique_ptr<FilterGroup>> filter_groups_;
288 FilterGroup* default_filter_;
289 FilterGroup* mix_filter_;
290 FilterGroup* linearize_filter_;
291 std::vector<uint8_t> interleaved_;
292
286 std::vector<CastMediaShlib::LoopbackAudioObserver*> loopback_observers_; 293 std::vector<CastMediaShlib::LoopbackAudioObserver*> loopback_observers_;
287 294
288 std::map<AudioContentType, VolumeInfo> volume_info_; 295 std::map<AudioContentType, VolumeInfo> volume_info_;
289 296
290 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsa); 297 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsa);
291 }; 298 };
292 299
293 } // namespace media 300 } // namespace media
294 } // namespace chromecast 301 } // namespace chromecast
295 302
296 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ 303 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698