| Index: chromecast/media/cma/backend/alsa/post_processing_pipeline_impl.cc
|
| diff --git a/chromecast/media/cma/backend/alsa/post_processing_pipeline.cc b/chromecast/media/cma/backend/alsa/post_processing_pipeline_impl.cc
|
| similarity index 65%
|
| rename from chromecast/media/cma/backend/alsa/post_processing_pipeline.cc
|
| rename to chromecast/media/cma/backend/alsa/post_processing_pipeline_impl.cc
|
| index d8c7c5eea2f9f0e9e7e00d6d7d8e89e4dc8f08c1..f67875b760d7ff064fc97bd53e206359bb6e9c5f 100644
|
| --- a/chromecast/media/cma/backend/alsa/post_processing_pipeline.cc
|
| +++ b/chromecast/media/cma/backend/alsa/post_processing_pipeline_impl.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chromecast/media/cma/backend/alsa/post_processing_pipeline.h"
|
| +#include "chromecast/media/cma/backend/alsa/post_processing_pipeline_impl.h"
|
|
|
| #include <string>
|
|
|
| @@ -12,6 +12,7 @@
|
| #include "base/values.h"
|
| #include "chromecast/base/serializers.h"
|
| #include "chromecast/public/media/audio_post_processor_shlib.h"
|
| +#include "chromecast/public/volume_control.h"
|
|
|
| namespace chromecast {
|
| namespace media {
|
| @@ -20,15 +21,25 @@ namespace {
|
|
|
| const int kNoSampleRate = -1;
|
| const char kSoCreateFunction[] = "AudioPostProcessorShlib_Create";
|
| +const char kProcessorKey[] = "processor";
|
|
|
| } // namespace
|
|
|
| using CreatePostProcessor = AudioPostProcessor* (*)(const std::string&, int);
|
|
|
| -PostProcessingPipeline::PostProcessingPipeline(
|
| +std::unique_ptr<PostProcessingPipeline> PostProcessingPipeline::Create(
|
| + const std::string& name,
|
| + const base::ListValue* filter_description_list,
|
| + int num_channels) {
|
| + return base::MakeUnique<PostProcessingPipelineImpl>(
|
| + name, filter_description_list, num_channels);
|
| +}
|
| +
|
| +PostProcessingPipelineImpl::PostProcessingPipelineImpl(
|
| + const std::string& name,
|
| const base::ListValue* filter_description_list,
|
| int channels)
|
| - : sample_rate_(kNoSampleRate) {
|
| + : name_(name), sample_rate_(kNoSampleRate) {
|
| if (!filter_description_list) {
|
| return; // Warning logged.
|
| }
|
| @@ -37,7 +48,7 @@ PostProcessingPipeline::PostProcessingPipeline(
|
| CHECK(
|
| filter_description_list->GetDictionary(i, &processor_description_dict));
|
| std::string library_path;
|
| - CHECK(processor_description_dict->GetString("processor", &library_path));
|
| + CHECK(processor_description_dict->GetString(kProcessorKey, &library_path));
|
| if (library_path == "null" || library_path == "none") {
|
| continue;
|
| }
|
| @@ -62,12 +73,12 @@ PostProcessingPipeline::PostProcessingPipeline(
|
| }
|
| }
|
|
|
| -PostProcessingPipeline::~PostProcessingPipeline() = default;
|
| +PostProcessingPipelineImpl::~PostProcessingPipelineImpl() = default;
|
|
|
| -int PostProcessingPipeline::ProcessFrames(const std::vector<float*>& data,
|
| - int num_frames,
|
| - float current_volume,
|
| - bool is_silence) {
|
| +int PostProcessingPipelineImpl::ProcessFrames(const std::vector<float*>& data,
|
| + int num_frames,
|
| + float current_multiplier,
|
| + bool is_silence) {
|
| DCHECK_NE(sample_rate_, kNoSampleRate);
|
| if (is_silence) {
|
| if (!IsRinging()) {
|
| @@ -78,15 +89,17 @@ int PostProcessingPipeline::ProcessFrames(const std::vector<float*>& data,
|
| silence_frames_processed_ = 0;
|
| }
|
|
|
| + UpdateCastVolume(current_multiplier);
|
| +
|
| total_delay_frames_ = 0;
|
| for (auto& processor : processors_) {
|
| total_delay_frames_ +=
|
| - processor->ProcessFrames(data, num_frames, current_volume);
|
| + processor->ProcessFrames(data, num_frames, cast_volume_);
|
| }
|
| return total_delay_frames_;
|
| }
|
|
|
| -bool PostProcessingPipeline::SetSampleRate(int sample_rate) {
|
| +bool PostProcessingPipelineImpl::SetSampleRate(int sample_rate) {
|
| sample_rate_ = sample_rate;
|
| bool result = true;
|
| for (auto& processor : processors_) {
|
| @@ -97,11 +110,11 @@ bool PostProcessingPipeline::SetSampleRate(int sample_rate) {
|
| return result;
|
| }
|
|
|
| -bool PostProcessingPipeline::IsRinging() {
|
| +bool PostProcessingPipelineImpl::IsRinging() {
|
| return silence_frames_processed_ < ringing_time_in_frames_;
|
| }
|
|
|
| -int PostProcessingPipeline::GetRingingTimeInFrames() {
|
| +int PostProcessingPipelineImpl::GetRingingTimeInFrames() {
|
| int memory_frames = 0;
|
| for (auto& processor : processors_) {
|
| memory_frames += processor->GetRingingTimeInFrames();
|
| @@ -109,5 +122,17 @@ int PostProcessingPipeline::GetRingingTimeInFrames() {
|
| return memory_frames;
|
| }
|
|
|
| +void PostProcessingPipelineImpl::UpdateCastVolume(float multiplier) {
|
| + DCHECK_GE(multiplier, 0.0);
|
| +
|
| + if (multiplier == current_multiplier_) {
|
| + return;
|
| + }
|
| + current_multiplier_ = multiplier;
|
| + float dbfs = std::log10(multiplier) * 20;
|
| + DCHECK(chromecast::media::VolumeControl::DbFSToVolume);
|
| + cast_volume_ = chromecast::media::VolumeControl::DbFSToVolume(dbfs);
|
| +}
|
| +
|
| } // namespace media
|
| } // namespace chromecast
|
|
|