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 #include "chromecast/media/cma/backend/alsa/filter_group.h" | 5 #include "chromecast/media/cma/backend/alsa/filter_group.h" |
6 #include "media/base/audio_bus.h" | 6 #include "media/base/audio_bus.h" |
7 | 7 |
8 namespace chromecast { | 8 namespace chromecast { |
9 namespace media { | 9 namespace media { |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 // How many seconds of silence should be passed to the filters to flush them. | 13 // How many seconds of silence should be passed to the filters to flush them. |
14 const float kSilenceSecondsToFilter = 1.0f; | 14 const float kSilenceSecondsToFilter = 1.0f; |
15 const int kNumOutputChannels = 2; | 15 const int kNumOutputChannels = 2; |
16 | 16 |
17 } // namespace | 17 } // namespace |
18 | 18 |
19 FilterGroup::FilterGroup(const std::unordered_set<std::string>& input_types, | 19 FilterGroup::FilterGroup(const std::unordered_set<std::string>& input_types, |
20 AudioFilterFactory::FilterType filter_type) | 20 AudioFilterFactory::FilterType filter_type, |
| 21 AudioContentType content_type) |
21 : input_types_(input_types), | 22 : input_types_(input_types), |
| 23 content_type_(content_type), |
22 output_samples_per_second_(0), | 24 output_samples_per_second_(0), |
23 sample_format_(::media::SampleFormat::kUnknownSampleFormat), | 25 sample_format_(::media::SampleFormat::kUnknownSampleFormat), |
24 audio_filter_(AudioFilterFactory::MakeAudioFilter(filter_type)), | 26 audio_filter_(AudioFilterFactory::MakeAudioFilter(filter_type)), |
25 silence_frames_filtered_(0) {} | 27 silence_frames_filtered_(0) {} |
26 | 28 |
27 FilterGroup::~FilterGroup() = default; | 29 FilterGroup::~FilterGroup() = default; |
28 | 30 |
29 void FilterGroup::Initialize(int output_samples_per_second, | 31 void FilterGroup::Initialize(int output_samples_per_second, |
30 ::media::SampleFormat format) { | 32 ::media::SampleFormat format) { |
31 output_samples_per_second_ = output_samples_per_second; | 33 output_samples_per_second_ = output_samples_per_second; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 input->GetResampledData(temp_.get(), chunk_size); | 73 input->GetResampledData(temp_.get(), chunk_size); |
72 for (int c = 0; c < kNumOutputChannels; ++c) { | 74 for (int c = 0; c < kNumOutputChannels; ++c) { |
73 input->VolumeScaleAccumulate(c, temp_->channel(c), chunk_size, | 75 input->VolumeScaleAccumulate(c, temp_->channel(c), chunk_size, |
74 mixed_->channel(c)); | 76 mixed_->channel(c)); |
75 } | 77 } |
76 } | 78 } |
77 | 79 |
78 mixed_->ToInterleaved(chunk_size, BytesPerOutputFormatSample(), | 80 mixed_->ToInterleaved(chunk_size, BytesPerOutputFormatSample(), |
79 interleaved_.data()); | 81 interleaved_.data()); |
80 if (audio_filter_) { | 82 if (audio_filter_) { |
81 audio_filter_->ProcessInterleaved(interleaved_.data(), chunk_size); | 83 audio_filter_->ProcessInterleaved(interleaved_.data(), chunk_size, volume_); |
82 } | 84 } |
83 | 85 |
84 return true; | 86 return true; |
85 } | 87 } |
86 | 88 |
87 void FilterGroup::ClearInterleaved(int chunk_size) { | 89 void FilterGroup::ClearInterleaved(int chunk_size) { |
88 ResizeBuffersIfNecessary(chunk_size); | 90 ResizeBuffersIfNecessary(chunk_size); |
89 memset(interleaved_.data(), 0, static_cast<size_t>(chunk_size) * | 91 memset(interleaved_.data(), 0, static_cast<size_t>(chunk_size) * |
90 kNumOutputChannels * | 92 kNumOutputChannels * |
91 BytesPerOutputFormatSample()); | 93 BytesPerOutputFormatSample()); |
(...skipping 18 matching lines...) Expand all Loading... |
110 int FilterGroup::BytesPerOutputFormatSample() { | 112 int FilterGroup::BytesPerOutputFormatSample() { |
111 return ::media::SampleFormatToBytesPerChannel(sample_format_); | 113 return ::media::SampleFormatToBytesPerChannel(sample_format_); |
112 } | 114 } |
113 | 115 |
114 void FilterGroup::ClearActiveInputs() { | 116 void FilterGroup::ClearActiveInputs() { |
115 active_inputs_.clear(); | 117 active_inputs_.clear(); |
116 } | 118 } |
117 | 119 |
118 } // namespace media | 120 } // namespace media |
119 } // namespace chromecast | 121 } // namespace chromecast |
OLD | NEW |