Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Unified Diff: chromecast/media/cma/backend/alsa/post_processing_pipeline_parser.cc

Issue 2847673002: [Chromecast] Complete PostProcessingPipeline changes (Closed)
Patch Set: Fix deps Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chromecast/media/cma/backend/alsa/post_processing_pipeline_parser.cc
diff --git a/chromecast/media/cma/backend/alsa/post_processing_pipeline_parser.cc b/chromecast/media/cma/backend/alsa/post_processing_pipeline_parser.cc
index a24e111d1a7cd7ab47e497b6602e777974fba36b..8f2e8b8046a5dc747498c5c0be9c5e84f2ccec87 100644
--- a/chromecast/media/cma/backend/alsa/post_processing_pipeline_parser.cc
+++ b/chromecast/media/cma/backend/alsa/post_processing_pipeline_parser.cc
@@ -20,54 +20,103 @@ namespace {
const base::FilePath::CharType kPostProcessingPipelineFilePath[] =
FILE_PATH_LITERAL("/etc/cast_audio.json");
-const char kMediaPipelineKey[] = "media";
-const char kTtsPipelineKey[] = "tts";
-
-// TODO(bshaya): Use AudioContentType instead.
-std::string GetPipelineKey(const std::string& device_id) {
- if (device_id == kTtsAudioDeviceId) {
- return kTtsPipelineKey;
- }
- if (device_id == ::media::AudioDeviceDescription::kDefaultDeviceId) {
- return kMediaPipelineKey;
- }
- NOTREACHED() << "Invalid device_id: " << device_id;
- return "";
-}
+const char kOutputStreamsKey[] = "output_streams";
+const char kMixPipelineKey[] = "mix";
+const char kLinearizePipelineKey[] = "linearize";
+const char kProcessorsKey[] = "processors";
+const char kStreamsKey[] = "streams";
} // namespace
-PostProcessingPipelineParser::PostProcessingPipelineParser() = default;
-PostProcessingPipelineParser::~PostProcessingPipelineParser() = default;
+StreamPipelineDescriptor::StreamPipelineDescriptor(
+ base::ListValue* pipeline_in,
+ const std::unordered_set<std::string>& stream_types_in)
+ : pipeline(pipeline_in), stream_types(stream_types_in) {}
+
+StreamPipelineDescriptor::~StreamPipelineDescriptor() = default;
+
+StreamPipelineDescriptor::StreamPipelineDescriptor(
+ const StreamPipelineDescriptor& other)
+ : StreamPipelineDescriptor(other.pipeline, other.stream_types) {}
-void PostProcessingPipelineParser::Initialize() {
- if (!base::PathExists(base::FilePath(kPostProcessingPipelineFilePath))) {
- LOG(WARNING) << "No post-processing config found in "
+PostProcessingPipelineParser::PostProcessingPipelineParser(
+ const std::string& json) {
+ if (json.empty() &&
+ !base::PathExists(base::FilePath(kPostProcessingPipelineFilePath))) {
+ LOG(WARNING) << "Could not open post-processing config in "
<< kPostProcessingPipelineFilePath << ".";
return;
}
- config_dict_ = base::DictionaryValue::From(
- DeserializeJsonFromFile(base::FilePath(kPostProcessingPipelineFilePath)));
- CHECK(config_dict_->GetDictionary("post_processing", &pipeline_dict_))
- << "No \"post_processing\" object found in "
- << kPostProcessingPipelineFilePath;
+ if (json.empty()) {
+ config_dict_ = base::DictionaryValue::From(DeserializeJsonFromFile(
+ base::FilePath(kPostProcessingPipelineFilePath)));
+ } else {
+ config_dict_ = base::DictionaryValue::From(DeserializeFromJson(json));
+ }
+
+ CHECK(config_dict_) << "Invalid JSON in " << kPostProcessingPipelineFilePath;
}
-base::ListValue* PostProcessingPipelineParser::GetPipelineByDeviceId(
- const std::string& device_id) {
- if (!pipeline_dict_) {
- return nullptr;
+PostProcessingPipelineParser::~PostProcessingPipelineParser() = default;
+
+std::vector<StreamPipelineDescriptor>
+PostProcessingPipelineParser::GetStreamPipelines() {
+ base::ListValue* pipelines_list;
+ std::vector<StreamPipelineDescriptor> descriptors;
+ if (!config_dict_ ||
+ !config_dict_->GetList(kOutputStreamsKey, &pipelines_list)) {
+ LOG(WARNING) << "No post-processors found for streams (key = "
+ << kOutputStreamsKey
+ << ").\n No stream-specific processing will occur.";
+ return descriptors;
}
+ for (size_t i = 0; i < pipelines_list->GetSize(); ++i) {
+ base::DictionaryValue* pipeline_description_dict;
+ CHECK(pipelines_list->GetDictionary(i, &pipeline_description_dict));
- base::ListValue* out_list;
- std::string key = GetPipelineKey(device_id);
- if (!pipeline_dict_->GetList(key, &out_list)) {
+ base::ListValue* processors_list;
+ CHECK(pipeline_description_dict->GetList(kProcessorsKey, &processors_list));
+
+ base::ListValue* streams_list;
+ CHECK(pipeline_description_dict->GetList(kStreamsKey, &streams_list));
+ std::unordered_set<std::string> streams_set;
+ for (size_t stream = 0; stream < streams_list->GetSize(); ++stream) {
+ std::string stream_name;
+ CHECK(streams_list->GetString(stream, &stream_name));
+ CHECK(streams_set.insert(stream_name).second)
+ << "Duplicate stream type: " << stream_name;
+ }
+
+ descriptors.emplace_back(processors_list, std::move(streams_set));
+ }
+ return descriptors;
+}
+
+std::string PostProcessingPipelineParser::GetFilePath() {
+ return kPostProcessingPipelineFilePath;
+}
+
+base::ListValue* PostProcessingPipelineParser::GetMixPipeline() {
+ return GetPipelineByKey(kMixPipelineKey);
+}
+
+base::ListValue* PostProcessingPipelineParser::GetLinearizePipeline() {
+ return GetPipelineByKey(kLinearizePipelineKey);
+}
+
+base::ListValue* PostProcessingPipelineParser::GetPipelineByKey(
+ const std::string& key) {
+ base::DictionaryValue* stream_dict;
+ if (!config_dict_ || !config_dict_->GetDictionary(key, &stream_dict)) {
LOG(WARNING) << "No post-processor description found for \"" << key
<< "\" in " << kPostProcessingPipelineFilePath
<< ". Using passthrough.";
return nullptr;
}
+ base::ListValue* out_list;
+ CHECK(stream_dict->GetList(kProcessorsKey, &out_list));
+
return out_list;
}

Powered by Google App Engine
This is Rietveld 408576698