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/post_processing_pipeline_impl.h" | 5 #include "chromecast/media/cma/backend/alsa/post_processing_pipeline_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/scoped_native_library.h" | 12 #include "base/scoped_native_library.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chromecast/base/serializers.h" | 14 #include "chromecast/base/serializers.h" |
15 #include "chromecast/public/media/audio_post_processor_shlib.h" | 15 #include "chromecast/public/media/audio_post_processor_shlib.h" |
16 #include "chromecast/public/volume_control.h" | 16 #include "chromecast/public/volume_control.h" |
17 | 17 |
18 namespace chromecast { | 18 namespace chromecast { |
19 namespace media { | 19 namespace media { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const int kNoSampleRate = -1; | 23 const int kNoSampleRate = -1; |
24 const char kSoCreateFunction[] = "AudioPostProcessorShlib_Create"; | |
25 const char kProcessorKey[] = "processor"; | 24 const char kProcessorKey[] = "processor"; |
26 const char kNameKey[] = "name"; | 25 const char kNameKey[] = "name"; |
27 } // namespace | 26 } // namespace |
28 | 27 |
29 using CreatePostProcessor = AudioPostProcessor* (*)(const std::string&, int); | |
30 | |
31 std::unique_ptr<PostProcessingPipeline> PostProcessingPipeline::Create( | 28 std::unique_ptr<PostProcessingPipeline> PostProcessingPipeline::Create( |
32 const std::string& name, | 29 const std::string& name, |
33 const base::ListValue* filter_description_list, | 30 const base::ListValue* filter_description_list, |
34 int num_channels) { | 31 int num_channels) { |
35 return base::MakeUnique<PostProcessingPipelineImpl>( | 32 return base::MakeUnique<PostProcessingPipelineImpl>( |
36 name, filter_description_list, num_channels); | 33 name, filter_description_list, num_channels); |
37 } | 34 } |
38 | 35 |
39 PostProcessingPipelineImpl::PostProcessingPipelineImpl( | 36 PostProcessingPipelineImpl::PostProcessingPipelineImpl( |
40 const std::string& name, | 37 const std::string& name, |
(...skipping 19 matching lines...) Expand all Loading... |
60 << "Duplicate postprocessor name " << processor_name; | 57 << "Duplicate postprocessor name " << processor_name; |
61 std::string library_path; | 58 std::string library_path; |
62 CHECK(processor_description_dict->GetString(kProcessorKey, &library_path)); | 59 CHECK(processor_description_dict->GetString(kProcessorKey, &library_path)); |
63 if (library_path == "null" || library_path == "none") { | 60 if (library_path == "null" || library_path == "none") { |
64 continue; | 61 continue; |
65 } | 62 } |
66 | 63 |
67 const base::Value* processor_config_val; | 64 const base::Value* processor_config_val; |
68 CHECK(processor_description_dict->Get("config", &processor_config_val)); | 65 CHECK(processor_description_dict->Get("config", &processor_config_val)); |
69 CHECK(processor_config_val->is_dict() || processor_config_val->is_string()); | 66 CHECK(processor_config_val->is_dict() || processor_config_val->is_string()); |
70 auto processor_config_string = SerializeToJson(*processor_config_val); | 67 std::unique_ptr<std::string> processor_config_string = |
| 68 SerializeToJson(*processor_config_val); |
71 | 69 |
72 LOG(INFO) << "Creating an instance of " << library_path << "(" | 70 LOG(INFO) << "Creating an instance of " << library_path << "(" |
73 << *processor_config_string << ")"; | 71 << *processor_config_string << ")"; |
74 libraries_.push_back(base::MakeUnique<base::ScopedNativeLibrary>( | |
75 base::FilePath(library_path))); | |
76 CHECK(libraries_.back()->is_valid()) | |
77 << "Could not open post processing library " << library_path; | |
78 CreatePostProcessor create = reinterpret_cast<CreatePostProcessor>( | |
79 libraries_.back()->GetFunctionPointer(kSoCreateFunction)); | |
80 | 72 |
81 CHECK(create) << "Could not find " << kSoCreateFunction << "() in " | 73 processors_.emplace_back( |
82 << library_path; | 74 PostProcessorInfo{factory_.CreatePostProcessor( |
83 processors_.emplace_back(PostProcessorInfo{ | 75 library_path, *processor_config_string, channels), |
84 base::WrapUnique(create(*processor_config_string, channels)), | 76 processor_name}); |
85 processor_name}); | |
86 } | 77 } |
87 } | 78 } |
88 | 79 |
89 PostProcessingPipelineImpl::~PostProcessingPipelineImpl() = default; | 80 PostProcessingPipelineImpl::~PostProcessingPipelineImpl() = default; |
90 | 81 |
91 int PostProcessingPipelineImpl::ProcessFrames(float* data, | 82 int PostProcessingPipelineImpl::ProcessFrames(float* data, |
92 int num_frames, | 83 int num_frames, |
93 float current_multiplier, | 84 float current_multiplier, |
94 bool is_silence) { | 85 bool is_silence) { |
95 DCHECK_NE(sample_rate_, kNoSampleRate); | 86 DCHECK_NE(sample_rate_, kNoSampleRate); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 [&name](PostProcessorInfo& p) { return p.name == name; }); | 148 [&name](PostProcessorInfo& p) { return p.name == name; }); |
158 if (it != processors_.end()) { | 149 if (it != processors_.end()) { |
159 it->ptr->UpdateParameters(config); | 150 it->ptr->UpdateParameters(config); |
160 LOG(INFO) << "Config string:\n" | 151 LOG(INFO) << "Config string:\n" |
161 << config << "\nwas delivered to postprocessor " << name; | 152 << config << "\nwas delivered to postprocessor " << name; |
162 } | 153 } |
163 } | 154 } |
164 | 155 |
165 } // namespace media | 156 } // namespace media |
166 } // namespace chromecast | 157 } // namespace chromecast |
OLD | NEW |