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

Side by Side Diff: chromecast/media/cma/backend/alsa/post_processing_pipeline_parser.cc

Issue 2771143002: Implement runtime audio post-processing pipeline. See go/cast_audio.json (Closed)
Patch Set: Address CR comments. Created 3 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chromecast/media/cma/backend/alsa/post_processing_pipeline_parser.h"
6
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "base/logging.h"
10 #include "chromecast/base/serializers.h"
11 #include "chromecast/media/base/audio_device_ids.h"
12 #include "media/audio/audio_device_description.h"
13
14 namespace chromecast {
15 namespace media {
16
17 namespace {
18
19 const base::FilePath::CharType kPostProcessingPipelineFilePath[] =
20 FILE_PATH_LITERAL("/etc/cast_audio.json");
21
22 const char kCommunicationPipelineKey[] = "communication";
23 const char kAlarmPipelineKey[] = "alarm";
24 const char kTtsPipelineKey[] = "tts";
25 const char kMediaPipelineKey[] = "media";
26
27 // TODO(bshaya): Use AudioContentType instead.
28 std::string GetPipelineKey(const std::string& device_id) {
29 if (device_id == ::media::AudioDeviceDescription::kCommunicationsDeviceId) {
30 return kCommunicationPipelineKey;
31 }
32 if (device_id == kAlarmAudioDeviceId) {
33 return kAlarmPipelineKey;
34 }
35 if (device_id == kTtsAudioDeviceId) {
36 return kTtsPipelineKey;
37 }
38 if (device_id == ::media::AudioDeviceDescription::kDefaultDeviceId) {
39 return kMediaPipelineKey;
40 }
41 NOTREACHED() << "Invalid device_id: " << device_id;
42 return "";
43 }
44
45 } // namespace
46
47 PostProcessingPipelineParser::PostProcessingPipelineParser() = default;
48 PostProcessingPipelineParser::~PostProcessingPipelineParser() = default;
49
50 void PostProcessingPipelineParser::Initialize() {
51 if (!base::PathExists(base::FilePath(kPostProcessingPipelineFilePath))) {
52 LOG(WARNING) << "No post-processing config found in "
53 << kPostProcessingPipelineFilePath << ".";
54 return;
55 }
56
57 cast_audio_config_data_ =
58 DeserializeJsonFromFile(base::FilePath(kPostProcessingPipelineFilePath));
59 base::DictionaryValue* audio_cfg_dict;
60 CHECK(cast_audio_config_data_->GetAsDictionary(&audio_cfg_dict))
61 << "JSON formatting error in " << kPostProcessingPipelineFilePath;
62
63 CHECK(audio_cfg_dict->GetDictionary("post_processing", &pipeline_dict_))
64 << "No \"post_processing\" object found in "
65 << kPostProcessingPipelineFilePath;
66 }
67
68 base::ListValue* PostProcessingPipelineParser::GetPipelineByDeviceId(
69 const std::string& device_id) {
70 if (!pipeline_dict_) {
71 return nullptr;
72 }
73
74 base::ListValue* out_list;
75 std::string key = GetPipelineKey(device_id);
76 if (!pipeline_dict_->GetList(key, &out_list)) {
77 LOG(WARNING) << "No post-processor description found for \"" << key
78 << "\" in " << kPostProcessingPipelineFilePath
79 << ". Using passthrough.";
80 return nullptr;
81 }
82 return out_list;
83 }
84
85 } // namepsace media
86 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698