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

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: Fix unittests Created 3 years, 9 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 10 matching lines...) Expand all
21 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input.h" 21 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input.h"
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 class FilterGroup;
31 32
32 // Mixer implementation. The mixer has one or more input queues; these can be 33 // 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 34 // added/removed at any time. When an input source pushes frames to an input
34 // queue, the queue should call StreamMixerAlsa::WriteFrames(); this causes 35 // 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 36 // 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, 37 // 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 38 // 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 39 // 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 40 // 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 41 // resampled, if the input's incoming sample rate is not equal to the mixer's
(...skipping 19 matching lines...) Expand all
60 61
61 // Returns the sample rate of this stream *before* data is resampled to 62 // 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 63 // match the sample rate expected by the mixer. The returned value must be
63 // positive. 64 // positive.
64 virtual int input_samples_per_second() const = 0; 65 virtual int input_samples_per_second() const = 0;
65 66
66 // Returns true if the stream is primary. Primary streams will be given 67 // Returns true if the stream is primary. Primary streams will be given
67 // precedence for sample rates and will dictate when data is polled. 68 // precedence for sample rates and will dictate when data is polled.
68 virtual bool primary() const = 0; 69 virtual bool primary() const = 0;
69 70
71 // Returns a string describing the content type class.
72 // Should be from chromecast/media/base/audio_device_ids.h
73 // or media/audio/audio_device_description.h
74 virtual std::string device_id() const = 0;
75
70 // Returns true if PrepareToDelete() has been called. 76 // Returns true if PrepareToDelete() has been called.
71 virtual bool IsDeleting() const = 0; 77 virtual bool IsDeleting() const = 0;
72 78
73 // Initializes the InputQueue after the mixer is set up. At this point the 79 // Initializes the InputQueue after the mixer is set up. At this point the
74 // input can correctly determine the mixer's output sample rate. 80 // input can correctly determine the mixer's output sample rate.
75 virtual void Initialize(const MediaPipelineBackendAlsa::RenderingDelay& 81 virtual void Initialize(const MediaPipelineBackendAlsa::RenderingDelay&
76 mixer_rendering_delay) = 0; 82 mixer_rendering_delay) = 0;
77 83
84 // Sets and gets the FilterGroup the InputQueue matches.
85 // This is determined at creation to save time matching the InputQueue
86 // to a FilterGroup every time it needs to be mixed.
87 virtual void set_filter_group(FilterGroup* filter_group) = 0;
88 virtual FilterGroup* filter_group() = 0;
89
78 // Returns the maximum number of frames that can be read from this input 90 // 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 91 // stream without filling with zeros. This should return 0 if the queue is
80 // empty and EOS has not been queued. 92 // empty and EOS has not been queued.
81 virtual int MaxReadSize() = 0; 93 virtual int MaxReadSize() = 0;
82 94
83 // Pulls data from the input stream. The input stream should populate |dest| 95 // Pulls data from the input stream. The input stream should populate |dest|
84 // with |frames| frames of data to be mixed. The mixer expects data to be 96 // with |frames| frames of data to be mixed. The mixer expects data to be
85 // at a sample rate of |output_samples_per_second()|, so each input stream 97 // at a sample rate of |output_samples_per_second()|, so each input stream
86 // should resample as necessary before returning. |frames| is guaranteed to 98 // should resample as necessary before returning. |frames| is guaranteed to
87 // be no larger than the value returned by the most recent call to 99 // be no larger than the value returned by the most recent call to
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // May be called on any thread. 200 // May be called on any thread.
189 void DeleteInputQueue(InputQueue* input); 201 void DeleteInputQueue(InputQueue* input);
190 // Runs on mixer thread to complete input queue deletion. 202 // Runs on mixer thread to complete input queue deletion.
191 void DeleteInputQueueInternal(InputQueue* input); 203 void DeleteInputQueueInternal(InputQueue* input);
192 // Called after a timeout period to close the PCM handle if no inputs are 204 // Called after a timeout period to close the PCM handle if no inputs are
193 // present. 205 // present.
194 void CheckClose(); 206 void CheckClose();
195 207
196 void WriteFrames(); 208 void WriteFrames();
197 bool TryWriteFrames(); 209 bool TryWriteFrames();
198 void WriteMixedPcm(const ::media::AudioBus& mixed, int frames, 210 void WriteMixedPcm(std::vector<uint8_t>* interleaved, int frames);
199 bool is_silence);
200 void UpdateRenderingDelay(int newly_pushed_frames); 211 void UpdateRenderingDelay(int newly_pushed_frames);
212 size_t InterleavedSize(int frames);
201 ssize_t BytesPerOutputFormatSample(); 213 ssize_t BytesPerOutputFormatSample();
214 void ResizeBuffersIfNecessary(int chunk_size);
202 215
203 static bool single_threaded_for_test_; 216 static bool single_threaded_for_test_;
204 217
205 std::unique_ptr<AlsaWrapper> alsa_; 218 std::unique_ptr<AlsaWrapper> alsa_;
206 std::unique_ptr<base::Thread> mixer_thread_; 219 std::unique_ptr<base::Thread> mixer_thread_;
207 scoped_refptr<base::SingleThreadTaskRunner> mixer_task_runner_; 220 scoped_refptr<base::SingleThreadTaskRunner> mixer_task_runner_;
208 221
209 unsigned int fixed_output_samples_per_second_; 222 unsigned int fixed_output_samples_per_second_;
210 unsigned int low_sample_rate_cutoff_; 223 unsigned int low_sample_rate_cutoff_;
211 int requested_output_samples_per_second_; 224 int requested_output_samples_per_second_;
(...skipping 10 matching lines...) Expand all
222 bool alsa_period_explicitly_set; 235 bool alsa_period_explicitly_set;
223 snd_pcm_uframes_t alsa_period_size_; 236 snd_pcm_uframes_t alsa_period_size_;
224 snd_pcm_uframes_t alsa_start_threshold_; 237 snd_pcm_uframes_t alsa_start_threshold_;
225 snd_pcm_uframes_t alsa_avail_min_; 238 snd_pcm_uframes_t alsa_avail_min_;
226 239
227 State state_; 240 State state_;
228 241
229 std::vector<std::unique_ptr<InputQueue>> inputs_; 242 std::vector<std::unique_ptr<InputQueue>> inputs_;
230 std::vector<std::unique_ptr<InputQueue>> ignored_inputs_; 243 std::vector<std::unique_ptr<InputQueue>> ignored_inputs_;
231 MediaPipelineBackendAlsa::RenderingDelay rendering_delay_; 244 MediaPipelineBackendAlsa::RenderingDelay rendering_delay_;
232 // Buffer to write final interleaved data before sending to snd_pcm_writei().
233 std::vector<uint8_t> interleaved_;
234
235 // 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
237 // allocations.
238 std::unique_ptr<::media::AudioBus> temp_;
239 std::unique_ptr<::media::AudioBus> mixed_;
240 245
241 std::unique_ptr<base::Timer> retry_write_frames_timer_; 246 std::unique_ptr<base::Timer> retry_write_frames_timer_;
242 247
243 int check_close_timeout_; 248 int check_close_timeout_;
244 std::unique_ptr<base::Timer> check_close_timer_; 249 std::unique_ptr<base::Timer> check_close_timer_;
245 250
251 std::vector<std::unique_ptr<FilterGroup>> filter_groups_;
246 std::vector<CastMediaShlib::LoopbackAudioObserver*> loopback_observers_; 252 std::vector<CastMediaShlib::LoopbackAudioObserver*> loopback_observers_;
247 253
248 std::unique_ptr<AudioFilterInterface> pre_loopback_filter_;
249 std::unique_ptr<AudioFilterInterface> post_loopback_filter_;
250 int silence_frames_filtered_ = 0;
251
252 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsa); 254 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsa);
253 }; 255 };
254 256
255 } // namespace media 257 } // namespace media
256 } // namespace chromecast 258 } // namespace chromecast
257 259
258 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ 260 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698