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_parser.h" | 5 #include "chromecast/media/cma/backend/alsa/post_processing_pipeline_parser.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chromecast/base/serializers.h" | 11 #include "chromecast/base/serializers.h" |
12 #include "chromecast/media/base/audio_device_ids.h" | 12 #include "chromecast/media/base/audio_device_ids.h" |
| 13 #include "chromecast/media/cma/backend/alsa/cast_audio_json.h" |
13 #include "media/audio/audio_device_description.h" | 14 #include "media/audio/audio_device_description.h" |
14 | 15 |
15 namespace chromecast { | 16 namespace chromecast { |
16 namespace media { | 17 namespace media { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 const char kPostProcessorsKey[] = "postprocessors"; | 21 const char kPostProcessorsKey[] = "postprocessors"; |
21 const char kOutputStreamsKey[] = "output_streams"; | 22 const char kOutputStreamsKey[] = "output_streams"; |
22 const char kMixPipelineKey[] = "mix"; | 23 const char kMixPipelineKey[] = "mix"; |
23 const char kLinearizePipelineKey[] = "linearize"; | 24 const char kLinearizePipelineKey[] = "linearize"; |
24 const char kProcessorsKey[] = "processors"; | 25 const char kProcessorsKey[] = "processors"; |
25 const char kStreamsKey[] = "streams"; | 26 const char kStreamsKey[] = "streams"; |
26 | 27 |
27 } // namespace | 28 } // namespace |
28 | 29 |
29 const char kCastAudioConfigFilePath[] = "/etc/cast_audio.json"; | |
30 | |
31 StreamPipelineDescriptor::StreamPipelineDescriptor( | 30 StreamPipelineDescriptor::StreamPipelineDescriptor( |
32 const base::ListValue* pipeline_in, | 31 const base::ListValue* pipeline_in, |
33 const std::unordered_set<std::string>& stream_types_in) | 32 const std::unordered_set<std::string>& stream_types_in) |
34 : pipeline(pipeline_in), stream_types(stream_types_in) {} | 33 : pipeline(pipeline_in), stream_types(stream_types_in) {} |
35 | 34 |
36 StreamPipelineDescriptor::~StreamPipelineDescriptor() = default; | 35 StreamPipelineDescriptor::~StreamPipelineDescriptor() = default; |
37 | 36 |
38 StreamPipelineDescriptor::StreamPipelineDescriptor( | 37 StreamPipelineDescriptor::StreamPipelineDescriptor( |
39 const StreamPipelineDescriptor& other) | 38 const StreamPipelineDescriptor& other) |
40 : StreamPipelineDescriptor(other.pipeline, other.stream_types) {} | 39 : StreamPipelineDescriptor(other.pipeline, other.stream_types) {} |
41 | 40 |
42 PostProcessingPipelineParser::PostProcessingPipelineParser( | 41 PostProcessingPipelineParser::PostProcessingPipelineParser( |
43 const std::string& json) | 42 const std::string& json) |
44 : postprocessor_config_(nullptr) { | 43 : postprocessor_config_(nullptr) { |
45 if (json.empty() && | 44 if (json.empty() && |
46 !base::PathExists(base::FilePath(kCastAudioConfigFilePath))) { | 45 !base::PathExists(base::FilePath(kCastAudioJsonFilePath))) { |
47 LOG(WARNING) << "Could not open post-processing config in " | 46 LOG(WARNING) << "Could not open post-processing config in " |
48 << kCastAudioConfigFilePath << "."; | 47 << kCastAudioJsonFilePath << "."; |
49 return; | 48 return; |
50 } | 49 } |
51 | 50 |
52 if (json.empty()) { | 51 if (json.empty()) { |
53 config_dict_ = base::DictionaryValue::From( | 52 config_dict_ = base::DictionaryValue::From( |
54 DeserializeJsonFromFile(base::FilePath(kCastAudioConfigFilePath))); | 53 DeserializeJsonFromFile(base::FilePath(kCastAudioJsonFilePath))); |
55 } else { | 54 } else { |
56 config_dict_ = base::DictionaryValue::From(DeserializeFromJson(json)); | 55 config_dict_ = base::DictionaryValue::From(DeserializeFromJson(json)); |
57 } | 56 } |
58 | 57 |
59 CHECK(config_dict_) << "Invalid JSON in " << kCastAudioConfigFilePath; | 58 CHECK(config_dict_) << "Invalid JSON in " << kCastAudioJsonFilePath; |
60 if (!config_dict_->GetDictionary(kPostProcessorsKey, | 59 if (!config_dict_->GetDictionary(kPostProcessorsKey, |
61 &postprocessor_config_)) { | 60 &postprocessor_config_)) { |
62 LOG(WARNING) << "No post-processor config found."; | 61 LOG(WARNING) << "No post-processor config found."; |
63 } | 62 } |
64 } | 63 } |
65 | 64 |
66 PostProcessingPipelineParser::~PostProcessingPipelineParser() = default; | 65 PostProcessingPipelineParser::~PostProcessingPipelineParser() = default; |
67 | 66 |
68 std::vector<StreamPipelineDescriptor> | 67 std::vector<StreamPipelineDescriptor> |
69 PostProcessingPipelineParser::GetStreamPipelines() { | 68 PostProcessingPipelineParser::GetStreamPipelines() { |
(...skipping 21 matching lines...) Expand all Loading... |
91 CHECK(streams_list->GetString(stream, &stream_name)); | 90 CHECK(streams_list->GetString(stream, &stream_name)); |
92 CHECK(streams_set.insert(stream_name).second) | 91 CHECK(streams_set.insert(stream_name).second) |
93 << "Duplicate stream type: " << stream_name; | 92 << "Duplicate stream type: " << stream_name; |
94 } | 93 } |
95 | 94 |
96 descriptors.emplace_back(processors_list, std::move(streams_set)); | 95 descriptors.emplace_back(processors_list, std::move(streams_set)); |
97 } | 96 } |
98 return descriptors; | 97 return descriptors; |
99 } | 98 } |
100 | 99 |
101 std::string PostProcessingPipelineParser::GetFilePath() { | |
102 return kCastAudioConfigFilePath; | |
103 } | |
104 | |
105 const base::ListValue* PostProcessingPipelineParser::GetMixPipeline() { | 100 const base::ListValue* PostProcessingPipelineParser::GetMixPipeline() { |
106 return GetPipelineByKey(kMixPipelineKey); | 101 return GetPipelineByKey(kMixPipelineKey); |
107 } | 102 } |
108 | 103 |
109 const base::ListValue* PostProcessingPipelineParser::GetLinearizePipeline() { | 104 const base::ListValue* PostProcessingPipelineParser::GetLinearizePipeline() { |
110 return GetPipelineByKey(kLinearizePipelineKey); | 105 return GetPipelineByKey(kLinearizePipelineKey); |
111 } | 106 } |
112 | 107 |
113 const base::ListValue* PostProcessingPipelineParser::GetPipelineByKey( | 108 const base::ListValue* PostProcessingPipelineParser::GetPipelineByKey( |
114 const std::string& key) { | 109 const std::string& key) { |
115 const base::DictionaryValue* stream_dict; | 110 const base::DictionaryValue* stream_dict; |
116 if (!postprocessor_config_ || | 111 if (!postprocessor_config_ || |
117 !postprocessor_config_->GetDictionary(key, &stream_dict)) { | 112 !postprocessor_config_->GetDictionary(key, &stream_dict)) { |
118 LOG(WARNING) << "No post-processor description found for \"" << key | 113 LOG(WARNING) << "No post-processor description found for \"" << key |
119 << "\" in " << kCastAudioConfigFilePath | 114 << "\" in " << kCastAudioJsonFilePath |
120 << ". Using passthrough."; | 115 << ". Using passthrough."; |
121 return nullptr; | 116 return nullptr; |
122 } | 117 } |
123 const base::ListValue* out_list; | 118 const base::ListValue* out_list; |
124 CHECK(stream_dict->GetList(kProcessorsKey, &out_list)); | 119 CHECK(stream_dict->GetList(kProcessorsKey, &out_list)); |
125 | 120 |
126 return out_list; | 121 return out_list; |
127 } | 122 } |
128 | 123 |
129 } // namepsace media | 124 } // namepsace media |
130 } // namespace chromecast | 125 } // namespace chromecast |
OLD | NEW |