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

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

Issue 2701613006: [Chromecast] Process streams with different post-processing. (Closed)
Patch Set: Created 3 years, 10 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 11 matching lines...) Expand all
22 #include "chromecast/public/cast_media_shlib.h" 22 #include "chromecast/public/cast_media_shlib.h"
23 23
24 namespace media { 24 namespace media {
25 class AudioBus; 25 class AudioBus;
26 } // namespace media 26 } // namespace media
27 27
28 namespace chromecast { 28 namespace chromecast {
29 namespace media { 29 namespace media {
30 class AlsaWrapper; 30 class AlsaWrapper;
31 31
32 const int kNumFilterGroups = 2;
33
32 // Mixer implementation. The mixer has one or more input queues; these can be 34 // Mixer implementation. The mixer has one or more input queues; these can be
33 // added/removed at any time. When an input source pushes frames to an input 35 // added/removed at any time. When an input source pushes frames to an input
34 // queue, the queue should call StreamMixerAlsa::WriteFrames(); this causes 36 // queue, the queue should call StreamMixerAlsa::WriteFrames(); this causes
35 // the mixer to attempt to mix and write out as many frames as possible. To do 37 // the mixer to attempt to mix and write out as many frames as possible. To do
36 // this, the mixer determines how many frames can be read from all inputs (ie, 38 // this, the mixer determines how many frames can be read from all inputs (ie,
37 // it gets the maximum number of frames that can be read from each input, and 39 // it gets the maximum number of frames that can be read from each input, and
38 // uses the minimum value). Assuming that all primary inputs have some data 40 // uses the minimum value). Assuming that all primary inputs have some data
39 // available, the calculated number of frames are pulled from each input (maybe 41 // available, the calculated number of frames are pulled from each input (maybe
40 // resampled, if the input's incoming sample rate is not equal to the mixer's 42 // resampled, if the input's incoming sample rate is not equal to the mixer's
41 // output sample rate) and written to the ALSA stack. 43 // output sample rate) and written to the ALSA stack.
(...skipping 18 matching lines...) Expand all
60 62
61 // Returns the sample rate of this stream *before* data is resampled to 63 // Returns the sample rate of this stream *before* data is resampled to
62 // match the sample rate expected by the mixer. The returned value must be 64 // match the sample rate expected by the mixer. The returned value must be
63 // positive. 65 // positive.
64 virtual int input_samples_per_second() const = 0; 66 virtual int input_samples_per_second() const = 0;
65 67
66 // Returns true if the stream is primary. Primary streams will be given 68 // Returns true if the stream is primary. Primary streams will be given
67 // precedence for sample rates and will dictate when data is polled. 69 // precedence for sample rates and will dictate when data is polled.
68 virtual bool primary() const = 0; 70 virtual bool primary() const = 0;
69 71
72 // Returns a string describing the content type class.
73 // Should be from chromecast/public/media/audio_device_ids.h
74 // or media/audio/audio_device_description.h
75 virtual std::string name() const = 0;
76
70 // Returns true if PrepareToDelete() has been called. 77 // Returns true if PrepareToDelete() has been called.
71 virtual bool IsDeleting() const = 0; 78 virtual bool IsDeleting() const = 0;
72 79
73 // Initializes the InputQueue after the mixer is set up. At this point the 80 // Initializes the InputQueue after the mixer is set up. At this point the
74 // input can correctly determine the mixer's output sample rate. 81 // input can correctly determine the mixer's output sample rate.
75 virtual void Initialize(const MediaPipelineBackendAlsa::RenderingDelay& 82 virtual void Initialize(const MediaPipelineBackendAlsa::RenderingDelay&
76 mixer_rendering_delay) = 0; 83 mixer_rendering_delay) = 0;
77 84
78 // Returns the maximum number of frames that can be read from this input 85 // Returns the maximum number of frames that can be read from this input
79 // stream without filling with zeros. This should return 0 if the queue is 86 // stream without filling with zeros. This should return 0 if the queue is
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // May be called on any thread. 195 // May be called on any thread.
189 void DeleteInputQueue(InputQueue* input); 196 void DeleteInputQueue(InputQueue* input);
190 // Runs on mixer thread to complete input queue deletion. 197 // Runs on mixer thread to complete input queue deletion.
191 void DeleteInputQueueInternal(InputQueue* input); 198 void DeleteInputQueueInternal(InputQueue* input);
192 // Called after a timeout period to close the PCM handle if no inputs are 199 // Called after a timeout period to close the PCM handle if no inputs are
193 // present. 200 // present.
194 void CheckClose(); 201 void CheckClose();
195 202
196 void WriteFrames(); 203 void WriteFrames();
197 bool TryWriteFrames(); 204 bool TryWriteFrames();
198 void WriteMixedPcm(const ::media::AudioBus& mixed, int frames, 205
199 bool is_silence); 206 // Mixes |acitve_inputs| and processes the resulting buffer
kmackay 2017/02/17 06:11:25 active_inputs
bshaya 2017/02/17 18:26:54 Done.
207 // with pre_loopback_filter_[|filter|].
208 // If |accumulate| is false, |interleaved_| will be overwritten
209 // (rather than summed).
210 // Returns |true| if non-zero data was written to |interleaved_|.
211 bool MixAndFilterGroup(const std::vector<InputQueue*>& active_inputs,
212 int filter,
213 int frames,
214 bool accumulate);
215 void WriteMixedPcm(int frames, bool filter_frames);
200 void UpdateRenderingDelay(int newly_pushed_frames); 216 void UpdateRenderingDelay(int newly_pushed_frames);
201 ssize_t BytesPerOutputFormatSample(); 217 ssize_t BytesPerOutputFormatSample();
218 void ResizeBuffersIfNecessary(int chunk_size);
202 219
203 static bool single_threaded_for_test_; 220 static bool single_threaded_for_test_;
204 221
205 std::unique_ptr<AlsaWrapper> alsa_; 222 std::unique_ptr<AlsaWrapper> alsa_;
206 std::unique_ptr<base::Thread> mixer_thread_; 223 std::unique_ptr<base::Thread> mixer_thread_;
207 scoped_refptr<base::SingleThreadTaskRunner> mixer_task_runner_; 224 scoped_refptr<base::SingleThreadTaskRunner> mixer_task_runner_;
208 225
209 unsigned int fixed_output_samples_per_second_; 226 unsigned int fixed_output_samples_per_second_;
210 unsigned int low_sample_rate_cutoff_; 227 unsigned int low_sample_rate_cutoff_;
211 int requested_output_samples_per_second_; 228 int requested_output_samples_per_second_;
(...skipping 10 matching lines...) Expand all
222 bool alsa_period_explicitly_set; 239 bool alsa_period_explicitly_set;
223 snd_pcm_uframes_t alsa_period_size_; 240 snd_pcm_uframes_t alsa_period_size_;
224 snd_pcm_uframes_t alsa_start_threshold_; 241 snd_pcm_uframes_t alsa_start_threshold_;
225 snd_pcm_uframes_t alsa_avail_min_; 242 snd_pcm_uframes_t alsa_avail_min_;
226 243
227 State state_; 244 State state_;
228 245
229 std::vector<std::unique_ptr<InputQueue>> inputs_; 246 std::vector<std::unique_ptr<InputQueue>> inputs_;
230 std::vector<std::unique_ptr<InputQueue>> ignored_inputs_; 247 std::vector<std::unique_ptr<InputQueue>> ignored_inputs_;
231 MediaPipelineBackendAlsa::RenderingDelay rendering_delay_; 248 MediaPipelineBackendAlsa::RenderingDelay rendering_delay_;
249 // Buffer to write interleaved data for each stream type before
250 // writing to |interleaved_|.
kmackay 2017/02/17 06:11:25 Could you clarify the comment a bit? Something abo
bshaya 2017/02/17 18:26:54 Done.
251 std::vector<uint8_t> interleaved_intermediate_;
232 // Buffer to write final interleaved data before sending to snd_pcm_writei(). 252 // Buffer to write final interleaved data before sending to snd_pcm_writei().
233 std::vector<uint8_t> interleaved_; 253 std::vector<uint8_t> interleaved_;
234 254
235 // Buffers that hold audio data while it is mixed, before it is passed to the 255 // Buffers that hold audio data while it is mixed, before it is passed to the
236 // ALSA layer. These are kept as members of this class to minimize copies and 256 // ALSA layer. These are kept as members of this class to minimize copies and
237 // allocations. 257 // allocations.
238 std::unique_ptr<::media::AudioBus> temp_; 258 std::unique_ptr<::media::AudioBus> temp_;
239 std::unique_ptr<::media::AudioBus> mixed_; 259 std::unique_ptr<::media::AudioBus> mixed_;
240 260
241 std::unique_ptr<base::Timer> retry_write_frames_timer_; 261 std::unique_ptr<base::Timer> retry_write_frames_timer_;
242 262
243 int check_close_timeout_; 263 int check_close_timeout_;
244 std::unique_ptr<base::Timer> check_close_timer_; 264 std::unique_ptr<base::Timer> check_close_timer_;
245 265
246 std::vector<CastMediaShlib::LoopbackAudioObserver*> loopback_observers_; 266 std::vector<CastMediaShlib::LoopbackAudioObserver*> loopback_observers_;
247 267
248 std::unique_ptr<AudioFilterInterface> pre_loopback_filter_; 268 std::unique_ptr<AudioFilterInterface> pre_loopback_filter_[kNumFilterGroups];
249 std::unique_ptr<AudioFilterInterface> post_loopback_filter_; 269 std::unique_ptr<AudioFilterInterface> post_loopback_filter_;
250 int silence_frames_filtered_ = 0; 270 int silence_frames_filtered_[kNumFilterGroups];
251 271
252 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsa); 272 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsa);
253 }; 273 };
254 274
255 } // namespace media 275 } // namespace media
256 } // namespace chromecast 276 } // namespace chromecast
257 277
258 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ 278 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698