| 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 | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..65144e8f1734232660b27672d9c2e7b3b9289a8e | 
| --- /dev/null | 
| +++ b/chromecast/media/cma/backend/alsa/post_processing_pipeline_parser.cc | 
| @@ -0,0 +1,85 @@ | 
| +// Copyright 2017 The Chromium Authors. All rights reserved. | 
| +// 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_parser.h" | 
| + | 
| +#include "base/files/file_path.h" | 
| +#include "base/files/file_util.h" | 
| +#include "base/logging.h" | 
| +#include "chromecast/base/serializers.h" | 
| +#include "chromecast/media/base/audio_device_ids.h" | 
| +#include "media/audio/audio_device_description.h" | 
| + | 
| +namespace chromecast { | 
| +namespace media { | 
| + | 
| +namespace { | 
| + | 
| +const base::FilePath::CharType kPostProcessingPipelineFilePath[] = | 
| +    FILE_PATH_LITERAL("/etc/cast_audio.json"); | 
| + | 
| +const char kCommunicationPipelineKey[] = "communication"; | 
| +const char kAlarmPipelineKey[] = "alarm"; | 
| +const char kTtsPipelineKey[] = "tts"; | 
| +const char kMediaPipelineKey[] = "media"; | 
| + | 
| +// TODO(bshaya): Use AudioContentType instead. | 
| +std::string GetPipelineKey(const std::string& device_id) { | 
| +  if (device_id == ::media::AudioDeviceDescription::kCommunicationsDeviceId) { | 
| +    return kCommunicationPipelineKey; | 
| +  } | 
| +  if (device_id == kAlarmAudioDeviceId) { | 
| +    return kAlarmPipelineKey; | 
| +  } | 
| +  if (device_id == kTtsAudioDeviceId) { | 
| +    return kTtsPipelineKey; | 
| +  } | 
| +  if (device_id == ::media::AudioDeviceDescription::kDefaultDeviceId) { | 
| +    return kMediaPipelineKey; | 
| +  } | 
| +  NOTREACHED() << "Invalid device_id: " << device_id; | 
| +  return ""; | 
| +} | 
| + | 
| +}  // namespace | 
| + | 
| +PostProcessingPipelineParser::PostProcessingPipelineParser() = default; | 
| +PostProcessingPipelineParser::~PostProcessingPipelineParser() = default; | 
| + | 
| +void PostProcessingPipelineParser::Initialize() { | 
| +  if (!base::PathExists(base::FilePath(kPostProcessingPipelineFilePath))) { | 
| +    LOG(WARNING) << "No post-processing config found in " | 
| +                 << kPostProcessingPipelineFilePath << "."; | 
| +  } | 
| + | 
| +  cast_audio_config_data_ = | 
| +      DeserializeJsonFromFile(base::FilePath(kPostProcessingPipelineFilePath)); | 
| +  base::DictionaryValue* audio_cfg_dict; | 
| +  CHECK(cast_audio_config_data_->GetAsDictionary(&audio_cfg_dict)) | 
| +      << "JSON formatting error in " << kPostProcessingPipelineFilePath; | 
| + | 
| +  CHECK(audio_cfg_dict->GetDictionary("post_processing", &pipeline_dict_)) | 
| +      << "No \"post_processing\" object found in " | 
| +      << kPostProcessingPipelineFilePath; | 
| +} | 
| + | 
| +base::ListValue* PostProcessingPipelineParser::GetPipelineByDeviceId( | 
| +    const std::string& device_id) { | 
| +  if (!pipeline_dict_) { | 
| +    return nullptr; | 
| +  } | 
| + | 
| +  base::ListValue* out_list; | 
| +  std::string key = GetPipelineKey(device_id); | 
| +  if (!pipeline_dict_->GetList(key, &out_list)) { | 
| +    LOG(WARNING) << "No post-processor description found for \"" << key | 
| +                 << "\" in " << kPostProcessingPipelineFilePath | 
| +                 << ". Using passthrough."; | 
| +    return nullptr; | 
| +  } | 
| +  return out_list; | 
| +} | 
| + | 
| +}  // namepsace media | 
| +}  // namespace chromecast | 
|  |