• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 DISTRIBUTED_AUDIO_TEST_H
17 #define DISTRIBUTED_AUDIO_TEST_H
18 
19 #include <chrono>
20 #include <iostream>
21 #include <string>
22 #include <cstdlib>
23 #include <sys/stat.h>
24 #include <thread>
25 #include <vector>
26 
27 #include "audio_adapter.h"
28 #include "audio_manager.h"
29 #include "audio_types.h"
30 #include "daudio_errcode.h"
31 #include "distributed_hardware_log.h"
32 
33 const std::string CMD_QUIT = "quit";
34 const std::string CMD_FIND = "find";
35 const std::string CMD_OPEN_SPK = "openspk";
36 const std::string CMD_CLOSE_SPK = "closespk";
37 const std::string CMD_START_SPK = "startspk";
38 const std::string CMD_STOP_SPK = "stopspk";
39 const std::string CMD_OPEN_MIC = "openmic";
40 const std::string CMD_CLOSE_MIC = "closemic";
41 const std::string CMD_START_MIC = "startmic";
42 const std::string CMD_STOP_MIC = "stopmic";
43 const std::string CMD_SET_VOL = "setvol";
44 const std::string CMD_GET_VOL = "getvol";
45 
46 const std::string CMD_QUIT_EXT = "0";
47 const std::string CMD_FIND_EXT = "9";
48 const std::string CMD_OPEN_SPK_EXT = "1";
49 const std::string CMD_CLOSE_SPK_EXT = "2";
50 const std::string CMD_START_SPK_EXT = "3";
51 const std::string CMD_STOP_SPK_EXT = "4";
52 const std::string CMD_OPEN_MIC_EXT = "5";
53 const std::string CMD_CLOSE_MIC_EXT = "6";
54 const std::string CMD_START_MIC_EXT = "7";
55 const std::string CMD_STOP_MIC_EXT = "8";
56 const std::string CMD_SET_VOL_EXT = "11";
57 const std::string CMD_GET_VOL_EXT = "12";
58 
59 const char DEV_TYPE_SPK = '1';
60 const char DEV_TYPE_MIC = '2';
61 const char SPK_FILE_PATH[128] = "/data/test.pcm";
62 const char MIC_FILE_PATH[128] = "/data/mic.pcm";
63 constexpr int32_t TYPE_OFFSET = 12;
64 constexpr int32_t AUDIO_SAMPLE_RATE = 48000;
65 constexpr int32_t VOLUME_MIN = 0;
66 constexpr int32_t VOLUME_MAX = 15;
67 constexpr int32_t VOLUME_BIT = 3;
68 constexpr int32_t RENDER_FRAME_SIZE = 4096;
69 constexpr int32_t RENDER_INTER_LEAVED = 1;
70 constexpr int32_t RENDER_STREAM_ID = 0;
71 constexpr int32_t RENDER_CHANNEL_MASK = 2;
72 constexpr int32_t CAPTURE_INTER_LEAVED = 1;
73 constexpr int32_t CAPTURE_STREAM_ID = 2;
74 constexpr int32_t CAPTURE_CHANNEL_MASK = 2;
75 constexpr int32_t MILLISECOND_PER_SECOND = 1000;
76 constexpr int64_t AUDIO_FRAME_TIME_INTERFAL_DEFAULT = 21333;
77 constexpr int32_t CMD_EXECUTING_RETURN_LENGHT_MAX = 500;
78 
79 typedef enum {
80     DEVICE_IDLE = 0,
81     DEVICE_OPEN = 1,
82     DEVICE_START = 2,
83     DEVICE_STOP = 3,
84 } DeviceStatus;
85 
86 struct WAV_HEADER {
87     /* RIFF Chunk Descriptor */
88     uint8_t riff[4] = {'R', 'I', 'F', 'F'};
89     uint32_t chunkSize = 0;
90     uint8_t wave[4] = {'W', 'A', 'V', 'E'};
91     /* "fmt" sub-chunk */
92     uint8_t fmt[4] = {'f', 'm', 't', ' '};
93     uint32_t subchunk1Size = 16;
94     uint16_t audioFormat = 1;
95     uint16_t numOfChan = 2;
96     uint32_t samplesPerSec = 44100;
97     uint32_t bytesPerSec = 176400;
98     uint16_t blockAlign = 2;
99     uint16_t bitsPerSample = 16;
100     /* "data" sub-chunk */
101     uint8_t subchunk2ID[4] = {'d', 'a', 't', 'a'};
102     uint32_t subchunk2Size = 0;
103 };
104 using WavHdr = struct WAV_HEADER;
105 int32_t InitTestDemo();
106 std::string FindAudioDevice();
107 std::string OpenSpk();
108 std::string StartRender();
109 std::string StopRender();
110 std::string CloseSpk();
111 std::string OpenMic();
112 std::string StartCapture();
113 std::string StopCapture();
114 std::string CloseMic();
115 std::string SetVolume(std::string vol);
116 std::string GetVolume();
117 #endif