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