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 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 enum class DeviceStatus : uint32_t { 34 DEVICE_IDLE = 0, 35 DEVICE_OPEN = 1, 36 DEVICE_START = 2, 37 DEVICE_STOP = 3, 38 }; 39 40 struct WAV_HEADER { 41 /* RIFF Chunk Descriptor */ 42 uint8_t riff[4] = {'R', 'I', 'F', 'F'}; 43 uint32_t chunkSize = 0; 44 uint8_t wave[4] = {'W', 'A', 'V', 'E'}; 45 /* "fmt" sub-chunk */ 46 uint8_t fmt[4] = {'f', 'm', 't', ' '}; 47 uint32_t subchunk1Size = 16; 48 uint16_t audioFormat = 1; 49 uint16_t numOfChan = 2; 50 uint32_t samplesPerSec = 44100; 51 uint32_t bytesPerSec = 176400; 52 uint16_t blockAlign = 2; 53 uint16_t bitsPerSample = 16; 54 /* "data" sub-chunk */ 55 uint8_t subchunk2ID[4] = {'d', 'a', 't', 'a'}; 56 uint32_t subchunk2Size = 0; 57 }; 58 using WavHdr = struct WAV_HEADER; 59 60 int32_t InitTestDemo(); 61 std::string FindAudioDevice(); 62 std::string OpenSpk(std::string devId); 63 std::string StartRender(); 64 std::string StopRender(); 65 std::string CloseSpk(); 66 std::string OpenMic(std::string devId); 67 std::string StartCapture(); 68 std::string StopCapture(); 69 std::string CloseMic(); 70 std::string SetVolume(int vol); 71 std::string GetVolume(); 72 std::string HandleAudioEvent(int32_t cmd); 73 74 #endif