1 /*
2 * Copyright (c) 2024 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
16 #ifndef LOG_TAG
17 #define LOG_TAG "AudioDumpTest"
18 #endif
19
20 #include <iostream>
21 #include <set>
22 #include <string>
23 #include <unistd.h>
24
25 #include "audio_system_manager.h"
26
27 using namespace std;
28 using namespace OHOS;
29 using namespace OHOS::AudioStandard;
30
31 namespace AudioDumpTest {
32 const int FIRST_ARG = 1;
33 const int SECOND_ARG = 2;
34 }
35
36 namespace {
37 const string AudioDumpKey = "PCM_DUMP";
38 const string AudioDumpType = "R_AND_D";
39 const set<string> SupportInput = {"0", "1"};
40 }
41
PrintUsage(void)42 static void PrintUsage(void)
43 {
44 cout << "NAME" << endl << endl;
45 cout << "\taudio_dump_test - Audio Dump Test " << endl << endl;
46 cout << "\t./audio_dump_test [OPTIONS]..." << endl << endl;
47 cout << "\t OPTIONS: 0(close) or 1(open) " << endl << endl;
48 }
49
IsSupportInputArgs(string & input)50 static bool IsSupportInputArgs(string& input)
51 {
52 if (SupportInput.find(input) != SupportInput.end()) {
53 return true;
54 }
55
56 return false;
57 }
58
AudioDumpCmd(int opt)59 static void AudioDumpCmd(int opt)
60 {
61 AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance();
62 vector<pair<string, string>> kvpairs;
63 if (opt) {
64 kvpairs.push_back({AudioDumpType, "true"});
65 } else {
66 kvpairs.push_back({AudioDumpType, "false"});
67 }
68 audioSystemMgr->SetExtraParameters(AudioDumpKey, kvpairs);
69 }
70
main(int argc,char * argv[])71 int main(int argc, char *argv[])
72 {
73 int opt = 0;
74 if (argc < AudioDumpTest::SECOND_ARG) {
75 PrintUsage();
76 return 0;
77 }
78
79 if (geteuid() != 0) {
80 cout << "need root !" << endl << endl;
81 return 0;
82 }
83
84 string inArgv = argv[AudioDumpTest::FIRST_ARG];
85 if (!IsSupportInputArgs(inArgv)) {
86 PrintUsage();
87 return 0;
88 }
89
90 opt = stoi(inArgv);
91 AudioDumpCmd(opt);
92 return 0;
93 }
94