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

Unified Diff: chromecast/media/cma/backend/alsa/stream_mixer_alsa.h

Issue 2701613006: [Chromecast] Process streams with different post-processing. (Closed)
Patch Set: Fix nits 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 side-by-side diff with in-line comments
Download patch
Index: chromecast/media/cma/backend/alsa/stream_mixer_alsa.h
diff --git a/chromecast/media/cma/backend/alsa/stream_mixer_alsa.h b/chromecast/media/cma/backend/alsa/stream_mixer_alsa.h
index 53a48911f72ae92fe6fed42b1db7703d52aab2fd..80f7658cca985b4b86ef666d04e06faf37668dbf 100644
--- a/chromecast/media/cma/backend/alsa/stream_mixer_alsa.h
+++ b/chromecast/media/cma/backend/alsa/stream_mixer_alsa.h
@@ -29,6 +29,8 @@ namespace chromecast {
namespace media {
class AlsaWrapper;
+const int kNumFilterGroups = 2;
+
// Mixer implementation. The mixer has one or more input queues; these can be
// added/removed at any time. When an input source pushes frames to an input
// queue, the queue should call StreamMixerAlsa::WriteFrames(); this causes
@@ -38,7 +40,28 @@ class AlsaWrapper;
// uses the minimum value). Assuming that all primary inputs have some data
// available, the calculated number of frames are pulled from each input (maybe
// resampled, if the input's incoming sample rate is not equal to the mixer's
-// output sample rate) and written to the ALSA stack.
+// output sample rate), mixed and written to the ALSA stack.
+//
+// MIXER ARCHITECTURE
+// The mixer allows multiple streams to be grouped together for post-processing
+// purposes. Each group has a single AudioFilterInterface instance that
+// is used to post-process the data before a final mixing stage.
+//
+// Stream Stream Stream Stream Stream <- Input streams
+// | | | | |
+// --------------------- ----------------
+// | Media Mixer | | System Mixer | <- Intermediate mix
+// --------------------- ----------------
+// | |
+// --------------------- -----------------
+// | Media Filter | | System Filter |
+// --------------------- -----------------
+// \ /
+// -----------------
+// | Final Mixer |
+// -----------------
+// |
+// ALSA
//
// The rendering delay is recalculated after every successful write to the ALSA
// stack. This delay is passed up to the input sources whenever some new data
@@ -67,6 +90,11 @@ class StreamMixerAlsa {
// precedence for sample rates and will dictate when data is polled.
virtual bool primary() const = 0;
+ // Returns a string describing the content type class.
+ // Should be from chromecast/public/media/audio_device_ids.h
+ // or media/audio/audio_device_description.h
+ virtual std::string name() const = 0;
+
// Returns true if PrepareToDelete() has been called.
virtual bool IsDeleting() const = 0;
@@ -195,10 +223,20 @@ class StreamMixerAlsa {
void WriteFrames();
bool TryWriteFrames();
- void WriteMixedPcm(const ::media::AudioBus& mixed, int frames,
- bool is_silence);
+
+ // Mixes |active_inputs| and processes the resulting buffer
+ // with pre_loopback_filter_[|filter|].
+ // If |accumulate| is false, |interleaved_| will be overwritten
+ // (rather than summed).
+ // Returns |true| if non-zero data was written to |interleaved_|.
+ bool MixAndFilterGroup(const std::vector<InputQueue*>& active_inputs,
+ int filter,
+ int frames,
+ bool accumulate);
+ void WriteMixedPcm(int frames);
void UpdateRenderingDelay(int newly_pushed_frames);
ssize_t BytesPerOutputFormatSample();
+ void ResizeBuffersIfNecessary(int chunk_size);
static bool single_threaded_for_test_;
@@ -229,6 +267,8 @@ class StreamMixerAlsa {
std::vector<std::unique_ptr<InputQueue>> inputs_;
std::vector<std::unique_ptr<InputQueue>> ignored_inputs_;
MediaPipelineBackendAlsa::RenderingDelay rendering_delay_;
+ // Buffer to write intermediate mixes during post-processing.
+ std::vector<uint8_t> interleaved_intermediate_;
// Buffer to write final interleaved data before sending to snd_pcm_writei().
std::vector<uint8_t> interleaved_;
@@ -245,9 +285,8 @@ class StreamMixerAlsa {
std::vector<CastMediaShlib::LoopbackAudioObserver*> loopback_observers_;
- std::unique_ptr<AudioFilterInterface> pre_loopback_filter_;
- std::unique_ptr<AudioFilterInterface> post_loopback_filter_;
- int silence_frames_filtered_ = 0;
+ std::unique_ptr<AudioFilterInterface> pre_loopback_filter_[kNumFilterGroups];
tianyuwang1 2017/02/18 00:17:08 Since there's no post_loopback_filter_ anymore, ju
bshaya 2017/02/21 23:30:14 Done.
+ int silence_frames_filtered_[kNumFilterGroups];
DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsa);
};

Powered by Google App Engine
This is Rietveld 408576698