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..7b059e5a2b11c9d2f7ed3eac45d181ad95470c17 |
--- /dev/null |
+++ b/chromecast/media/cma/backend/alsa/filter_group.h |
@@ -0,0 +1,81 @@ |
+// 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_ |
+ |
kmackay
2017/02/23 20:52:56
<memory>
<vector>
<stdint.h>
bshaya
2017/02/24 00:17:07
Done.
|
+#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. |
kmackay
2017/02/23 20:52:56
I guess technically we could determine which filte
bshaya
2017/02/24 00:17:07
Done.
|
+ 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); |
+ |
+ // 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); |
+ int BytesPerOutputFormatSample(); |
+ |
+ const std::unordered_set<std::string> input_types_; |
+ std::vector<StreamMixerAlsa::InputQueue*> active_inputs_; |
+ |
+ int output_samples_per_second_; |
+ ::media::SampleFormat sample_format_; |
+ |
+ // 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; |
kmackay
2017/02/23 20:52:56
DISALLOW_COPY_AND_ASSIGN is still preferred (?) Or
bshaya
2017/02/24 00:17:07
The Google Style Guide only mentions = delete.
The
halliwell
2017/02/24 00:28:09
Search the chromium-dev mailing list, there was a
|
+}; |
+ |
+} // namespace media |
+} // namespace chromecast |
+#endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_FILTER_GROUP_H_ |