1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #ifndef LOG_TAG
16 #define LOG_TAG "ProcessConfig"
17 #endif
18
19 #include "audio_process_config.h"
20
21 #include <map>
22 #include <sstream>
23
24 #include "audio_errors.h"
25 #include "audio_service_log.h"
26
27 namespace OHOS {
28 namespace AudioStandard {
29 namespace {
30 static std::map<StreamUsage, std::string> USAGE_TO_STRING_MAP = {
31 {STREAM_USAGE_INVALID, "INVALID"},
32 {STREAM_USAGE_UNKNOWN, "UNKNOWN"},
33 {STREAM_USAGE_MEDIA, "MEDIA"},
34 {STREAM_USAGE_MUSIC, "MUSIC"},
35 {STREAM_USAGE_VOICE_COMMUNICATION, "VOICE_COMMUNICATION"},
36 {STREAM_USAGE_VOICE_ASSISTANT, "VOICE_ASSISTANT"},
37 {STREAM_USAGE_ALARM, "ALARM"},
38 {STREAM_USAGE_VOICE_MESSAGE, "VOICE_MESSAGE"},
39 {STREAM_USAGE_NOTIFICATION_RINGTONE, "NOTIFICATION_RINGTONE"},
40 {STREAM_USAGE_RINGTONE, "RINGTONE"},
41 {STREAM_USAGE_NOTIFICATION, "NOTIFICATION"},
42 {STREAM_USAGE_ACCESSIBILITY, "ACCESSIBILITY"},
43 {STREAM_USAGE_SYSTEM, "SYSTEM"},
44 {STREAM_USAGE_MOVIE, "MOVIE"},
45 {STREAM_USAGE_GAME, "GAME"},
46 {STREAM_USAGE_AUDIOBOOK, "AUDIOBOOK"},
47 {STREAM_USAGE_NAVIGATION, "NAVIGATION"},
48 {STREAM_USAGE_DTMF, "DTMF"},
49 {STREAM_USAGE_ENFORCED_TONE, "ENFORCED_TONE"},
50 {STREAM_USAGE_ULTRASONIC, "ULTRASONIC"},
51 {STREAM_USAGE_VIDEO_COMMUNICATION, "VIDEO_COMMUNICATION"},
52 {STREAM_USAGE_RANGING, "RANGING"},
53 {STREAM_USAGE_VOICE_CALL_ASSISTANT, "VOICE_CALL_ASSISTANT"},
54 {STREAM_USAGE_VOICE_MODEM_COMMUNICATION, "VOICE_MODEM_COMMUNICATION"}
55 };
56 }
57
58 // INCLUDE 3 usages { 1 2 4 } && EXCLUDE 1 pids { 1234 }
DumpInnerCapConfig(const AudioPlaybackCaptureConfig & config)59 std::string ProcessConfig::DumpInnerCapConfig(const AudioPlaybackCaptureConfig &config)
60 {
61 std::stringstream temp;
62
63 // filterOptions
64 switch (config.filterOptions.usageFilterMode) {
65 case FilterMode::INCLUDE:
66 temp << "INCLUDE";
67 break;
68 case FilterMode::EXCLUDE:
69 temp << "EXCLUDE";
70 break;
71 default:
72 temp << "INVALID";
73 break;
74 }
75 temp << " " << config.filterOptions.usages.size() << " usages { ";
76 for (size_t i = 0; i < config.filterOptions.usages.size(); i++) {
77 StreamUsage usage = config.filterOptions.usages[i];
78 temp << USAGE_TO_STRING_MAP[usage] << " ";
79 }
80 temp << "} && ";
81
82 // INCLUDE 3 pids { 1 2 4 }
83 switch (config.filterOptions.pidFilterMode) {
84 case FilterMode::INCLUDE:
85 temp << "INCLUDE";
86 break;
87 case FilterMode::EXCLUDE:
88 temp << "EXCLUDE";
89 break;
90 default:
91 temp << "INVALID";
92 break;
93 }
94 temp << " " << config.filterOptions.pids.size() << " pids { ";
95 for (size_t i = 0; i < config.filterOptions.pids.size(); i++) {
96 temp << config.filterOptions.pids[i] << " ";
97 }
98 temp << "}";
99 // silentCapture will not be dumped.
100
101 return temp.str();
102 }
103
DumpProcessConfig(const AudioProcessConfig & config)104 std::string ProcessConfig::DumpProcessConfig(const AudioProcessConfig &config)
105 {
106 std::stringstream temp;
107
108 // AppInfo
109 temp << "appInfo:pid<" << config.appInfo.appPid << "> uid<" << config.appInfo.appUid << "> tokenId<" <<
110 config.appInfo.appTokenId << "> ";
111
112 // streamInfo
113 temp << "streamInfo:format(" << config.streamInfo.format << ") encoding(" << config.streamInfo.encoding <<
114 ") channels(" << config.streamInfo.channels << ") samplingRate(" << config.streamInfo.samplingRate << ") ";
115
116 // audioMode
117 if (config.audioMode == AudioMode::AUDIO_MODE_PLAYBACK) {
118 temp << "[rendererInfo]:streamUsage(" << config.rendererInfo.streamUsage << ") contentType(" <<
119 config.rendererInfo.contentType << ") flag(" << config.rendererInfo.rendererFlags << ") ";
120 } else {
121 temp << "[capturerInfo]:sourceType(" << config.capturerInfo.sourceType << ") flag(" <<
122 config.capturerInfo.capturerFlags << ") ";
123 }
124
125 temp << "streamType<" << config.streamType << "> ";
126
127 temp << "originalSessionId<" << config.originalSessionId << ">";
128
129 return temp.str();
130 }
131 } // namespace AudioStandard
132 } // namespace OHOS
133
134