| 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..bee93a8e70a8f5ebec74c2ba1410e71aa6dda4a0 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,101 @@ 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() {
|
| +PostProcessingPipelineParser::PostProcessingPipelineParser(
|
| + const std::string& json) {
|
| + config_dict_ = base::DictionaryValue::From(DeserializeFromJson(json));
|
| +}
|
| +
|
| +PostProcessingPipelineParser::PostProcessingPipelineParser() {
|
| if (!base::PathExists(base::FilePath(kPostProcessingPipelineFilePath))) {
|
| - LOG(WARNING) << "No post-processing config found in "
|
| + 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;
|
| + // TODO(bshaya): Parse and print an ascii visualization of the pipeline.
|
| }
|
|
|
| -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::file_path() {
|
| + 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;
|
| }
|
|
|
|
|