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

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: Fix stray keystroke 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 }
55
56 cast_audio_config_data_ =
57 DeserializeJsonFromFile(base::FilePath(kPostProcessingPipelineFilePath));
58 base::DictionaryValue* audio_cfg_dict;
59 CHECK(cast_audio_config_data_->GetAsDictionary(&audio_cfg_dict))
60 << "JSON formatting error in " << kPostProcessingPipelineFilePath;
61
62 CHECK(audio_cfg_dict->GetDictionary("post_processing", &pipeline_dict_))
63 << "No \"post_processing\" object found in "
64 << kPostProcessingPipelineFilePath;
65 }
66
67 base::ListValue* PostProcessingPipelineParser::GetPipelineByDeviceId(
68 const std::string& device_id) {
69 if (!pipeline_dict_) {
70 return nullptr;
71 }
72
73 base::ListValue* out_list;
74 std::string key = GetPipelineKey(device_id);
75 if (!pipeline_dict_->GetList(key, &out_list)) {
76 LOG(WARNING) << "No post-processor description found for \"" << key
77 << "\" in " << kPostProcessingPipelineFilePath
78 << ". Using passthrough.";
79 return nullptr;
80 }
81 return out_list;
82 }
83
84 } // namepsace media
85 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698