| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_FILTER_GROUP_H_ | 5 #ifndef CHROMECAST_MEDIA_CMA_BACKEND_ALSA_FILTER_GROUP_H_ |
| 6 #define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_FILTER_GROUP_H_ | 6 #define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_FILTER_GROUP_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <unordered_set> | 12 #include <unordered_set> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "chromecast/media/cma/backend/alsa/audio_filter_factory.h" | 16 #include "chromecast/media/cma/backend/alsa/audio_filter_factory.h" |
| 17 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa.h" | 17 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa.h" |
| 18 #include "chromecast/public/volume_control.h" |
| 19 |
| 20 namespace media { |
| 21 class AudioBus; |
| 22 } // namespace media |
| 18 | 23 |
| 19 namespace chromecast { | 24 namespace chromecast { |
| 20 namespace media { | 25 namespace media { |
| 21 class AudioBus; | |
| 22 | 26 |
| 23 // FilterGroup contains state for an AudioFilter. | 27 // FilterGroup contains state for an AudioFilter. |
| 24 // It takes multiple StreamMixerAlsa::InputQueues, | 28 // It takes multiple StreamMixerAlsa::InputQueues, |
| 25 // mixes them, and processes them. | 29 // mixes them, and processes them. |
| 26 | 30 |
| 27 // ActiveInputs are added with AddActiveInput(), then cleared when | 31 // ActiveInputs are added with AddActiveInput(), then cleared when |
| 28 // MixAndFilter() is called (they must be added each time data is queried). | 32 // MixAndFilter() is called (they must be added each time data is queried). |
| 29 class FilterGroup { | 33 class FilterGroup { |
| 30 public: | 34 public: |
| 31 // |input_types| is a set of strings that is used as a filter to determine | 35 // |input_types| is a set of strings that is used as a filter to determine |
| 32 // if an input belongs to this group (InputQueue->name() must exactly match an | 36 // if an input belongs to this group (InputQueue->name() must exactly match an |
| 33 // entry in |input_types| to be processed by this group. | 37 // entry in |input_types| to be processed by this group. |
| 34 // |filter_type| is passed to AudioFilterFactory to create an AudioFilter. | 38 // |filter_type| is passed to AudioFilterFactory to create an AudioFilter. |
| 35 FilterGroup(const std::unordered_set<std::string>& input_types, | 39 FilterGroup(const std::unordered_set<std::string>& input_types, |
| 36 AudioFilterFactory::FilterType filter_type); | 40 AudioFilterFactory::FilterType filter_type, |
| 41 AudioContentType content_type); |
| 37 ~FilterGroup(); | 42 ~FilterGroup(); |
| 38 | 43 |
| 44 AudioContentType content_type() const { return content_type_; } |
| 45 |
| 46 void set_volume(float volume) { volume_ = volume; } |
| 47 |
| 39 // Sets the sample rate and format in the AudioFilter. | 48 // Sets the sample rate and format in the AudioFilter. |
| 40 void Initialize(int output_samples_per_second, ::media::SampleFormat format); | 49 void Initialize(int output_samples_per_second, ::media::SampleFormat format); |
| 41 | 50 |
| 42 // Returns |true| if this FilterGroup is appropriate to process |input|. | 51 // Returns |true| if this FilterGroup is appropriate to process |input|. |
| 43 bool CanProcessInput(StreamMixerAlsa::InputQueue* input); | 52 bool CanProcessInput(StreamMixerAlsa::InputQueue* input); |
| 44 | 53 |
| 45 // Adds |input| to |active_inputs_|. | 54 // Adds |input| to |active_inputs_|. |
| 46 void AddActiveInput(StreamMixerAlsa::InputQueue* input); | 55 void AddActiveInput(StreamMixerAlsa::InputQueue* input); |
| 47 | 56 |
| 48 // Retrieves a pointer to the output buffer |interleaved_|. | 57 // Retrieves a pointer to the output buffer |interleaved_|. |
| 49 std::vector<uint8_t>* GetInterleaved(); | 58 std::vector<uint8_t>* GetInterleaved(); |
| 50 | 59 |
| 51 // Mixes all active inputs and passes them through the audio filter. | 60 // Mixes all active inputs and passes them through the audio filter. |
| 52 bool MixAndFilter(int chunk_size); | 61 bool MixAndFilter(int chunk_size); |
| 53 | 62 |
| 54 // Overwrites |interleaved_| with 0's, ensuring at least | 63 // Overwrites |interleaved_| with 0's, ensuring at least |
| 55 // |chunk_size| bytes. | 64 // |chunk_size| bytes. |
| 56 void ClearInterleaved(int chunk_size); | 65 void ClearInterleaved(int chunk_size); |
| 57 | 66 |
| 58 // Clear all |active_inputs_|. This should be called before AddActiveInputs | 67 // Clear all |active_inputs_|. This should be called before AddActiveInputs |
| 59 // on each mixing iteration. | 68 // on each mixing iteration. |
| 60 void ClearActiveInputs(); | 69 void ClearActiveInputs(); |
| 61 | 70 |
| 62 private: | 71 private: |
| 63 void ResizeBuffersIfNecessary(int chunk_size); | 72 void ResizeBuffersIfNecessary(int chunk_size); |
| 64 int BytesPerOutputFormatSample(); | 73 int BytesPerOutputFormatSample(); |
| 65 | 74 |
| 66 const std::unordered_set<std::string> input_types_; | 75 const std::unordered_set<std::string> input_types_; |
| 76 const AudioContentType content_type_; |
| 67 std::vector<StreamMixerAlsa::InputQueue*> active_inputs_; | 77 std::vector<StreamMixerAlsa::InputQueue*> active_inputs_; |
| 68 | 78 |
| 69 int output_samples_per_second_; | 79 int output_samples_per_second_; |
| 70 ::media::SampleFormat sample_format_; | 80 ::media::SampleFormat sample_format_; |
| 71 | 81 |
| 82 float volume_ = 0.0f; |
| 83 |
| 72 // Buffers that hold audio data while it is mixed. | 84 // Buffers that hold audio data while it is mixed. |
| 73 // These are kept as members of this class to minimize copies and | 85 // These are kept as members of this class to minimize copies and |
| 74 // allocations. | 86 // allocations. |
| 75 std::unique_ptr<::media::AudioBus> temp_; | 87 std::unique_ptr<::media::AudioBus> temp_; |
| 76 std::unique_ptr<::media::AudioBus> mixed_; | 88 std::unique_ptr<::media::AudioBus> mixed_; |
| 77 std::vector<uint8_t> interleaved_; | 89 std::vector<uint8_t> interleaved_; |
| 78 | 90 |
| 79 std::unique_ptr<AudioFilterInterface> audio_filter_; | 91 std::unique_ptr<AudioFilterInterface> audio_filter_; |
| 80 int silence_frames_filtered_; | 92 int silence_frames_filtered_; |
| 81 | 93 |
| 82 DISALLOW_COPY_AND_ASSIGN(FilterGroup); | 94 DISALLOW_COPY_AND_ASSIGN(FilterGroup); |
| 83 }; | 95 }; |
| 84 | 96 |
| 85 } // namespace media | 97 } // namespace media |
| 86 } // namespace chromecast | 98 } // namespace chromecast |
| 87 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_FILTER_GROUP_H_ | 99 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_FILTER_GROUP_H_ |
| OLD | NEW |