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

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

Issue 2701613006: [Chromecast] Process streams with different post-processing. (Closed)
Patch Set: Move audio_device_ids to chromecast/media/base 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/filter_group.h
diff --git a/chromecast/media/cma/backend/alsa/filter_group.h b/chromecast/media/cma/backend/alsa/filter_group.h
new file mode 100644
index 0000000000000000000000000000000000000000..5bbd54398eff5f9ee86f20ef5a7fcf98bb16f826
--- /dev/null
+++ b/chromecast/media/cma/backend/alsa/filter_group.h
@@ -0,0 +1,83 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMECAST_MEDIA_CMA_BACKEND_ALSA_FILTER_GROUP_H_
+#define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_FILTER_GROUP_H_
+
+#include <string>
+#include <unordered_set>
+
+#include "chromecast/media/cma/backend/alsa/audio_filter_factory.h"
+#include "chromecast/media/cma/backend/alsa/stream_mixer_alsa.h"
+
+namespace chromecast {
+namespace media {
+class AudioBus;
+
+// FilterGroup contains state for an AudioFilter.
+// It takes multiple StreamMixerAlsa::InputQueues,
+// mixes them, and processes them.
+
+// ActiveInputs are added with TryAddActiveInput(), then cleared when
+// MixAndFilter() is called (they must be added each time data is queried).
+class FilterGroup {
+ public:
+ // |input_types| is a set of strings that is used as a filter to determine
+ // if an input belongs to this group (InputQueue->name() must exactly match an
+ // entry in |input_types| to be processed by this group.
+ // |filter_type| is passed to AudioFilterFactory to create an AudioFilter.
+ FilterGroup(const std::unordered_set<std::string>& input_types,
+ AudioFilterFactory::FilterType filter_type);
+
+ // Sets the sample rate and format in the AudioFilter.
+ void Initialize(int output_samples_per_second,
+ ::media::SampleFormat format,
+ ssize_t bytes_per_output_format_sample);
+
+ // Adds |input| to |active_inputs_| if |input->name()| matches
+ // an entry in |input_types_|.
+ // If |true| is returned, the caller should get the processed data with
+ // GetInterleaved.
+ // If |false| is returned, there is no new data, and the data from
+ // GetInterleaved may be stale.
+ bool TryAddActiveInput(StreamMixerAlsa::InputQueue* input);
+
+ // Retrieves a pointer to the output buffer |interleaved_|.
+ std::vector<uint8_t>* GetInterleaved();
+
+ // Mixes all active inputs and passes them through the audio filter.
+ // |active_inputs_| is cleared afterwards.
+ bool MixAndFilter(int chunk_size);
+
+ // Overwrites |interleaved_| with 0's, ensuring at least
+ // |chunk_size| bytes.
+ void ClearInterleaved(int chunk_size);
+
+ private:
+ void ResizeBuffersIfNecessary(int chunk_size);
+
+ const std::unordered_set<std::string> input_types_;
+ std::vector<StreamMixerAlsa::InputQueue*> active_inputs_;
+
+ int output_samples_per_second_;
+ ::media::SampleFormat sample_format_;
+ ssize_t bytes_per_output_format_sample_;
wzhong 2017/02/22 16:13:01 Initialize POD to default value here or in constru
bshaya 2017/02/22 20:45:25 Done.
+
+ // Buffers that hold audio data while it is mixed.
+ // These are kept as members of this class to minimize copies and
+ // allocations.
+ std::unique_ptr<::media::AudioBus> temp_;
+ std::unique_ptr<::media::AudioBus> mixed_;
+ std::vector<uint8_t> interleaved_;
+
+ std::unique_ptr<AudioFilterInterface> audio_filter_;
+ int silence_frames_filtered_;
+
+ FilterGroup(const FilterGroup&) = delete;
+ const FilterGroup& operator=(const FilterGroup&) = delete;
+};
+
+} // namespace media
+} // namespace chromecast
+#endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_FILTER_GROUP_H_

Powered by Google App Engine
This is Rietveld 408576698