10704ebd2Sopenharmony_ci/*
20704ebd2Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
30704ebd2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
40704ebd2Sopenharmony_ci * you may not use this file except in compliance with the License.
50704ebd2Sopenharmony_ci * You may obtain a copy of the License at
60704ebd2Sopenharmony_ci *
70704ebd2Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
80704ebd2Sopenharmony_ci *
90704ebd2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
100704ebd2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
110704ebd2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120704ebd2Sopenharmony_ci * See the License for the specific language governing permissions and
130704ebd2Sopenharmony_ci * limitations under the License.
140704ebd2Sopenharmony_ci */
150704ebd2Sopenharmony_ci
160704ebd2Sopenharmony_ci#ifndef DISTRIBUTED_AUDIO_TEST_H
170704ebd2Sopenharmony_ci#define DISTRIBUTED_AUDIO_TEST_H
180704ebd2Sopenharmony_ci
190704ebd2Sopenharmony_ci#include <chrono>
200704ebd2Sopenharmony_ci#include <iostream>
210704ebd2Sopenharmony_ci#include <string>
220704ebd2Sopenharmony_ci#include <cstdlib>
230704ebd2Sopenharmony_ci#include <sys/stat.h>
240704ebd2Sopenharmony_ci#include <thread>
250704ebd2Sopenharmony_ci#include <vector>
260704ebd2Sopenharmony_ci
270704ebd2Sopenharmony_ci#include <v1_0/iaudio_adapter.h>
280704ebd2Sopenharmony_ci#include <v1_0/iaudio_manager.h>
290704ebd2Sopenharmony_ci#include <v1_0/iaudio_callback.h>
300704ebd2Sopenharmony_ci#include <v1_0/audio_types.h>
310704ebd2Sopenharmony_ci#include "distributed_hardware_log.h"
320704ebd2Sopenharmony_ci#include "softbus_bus_center.h"
330704ebd2Sopenharmony_ci#include "softbus_common.h"
340704ebd2Sopenharmony_ci#include "token_setproc.h"
350704ebd2Sopenharmony_ci
360704ebd2Sopenharmony_cienum class DeviceStatus : uint32_t {
370704ebd2Sopenharmony_ci    DEVICE_IDLE = 0,
380704ebd2Sopenharmony_ci    DEVICE_OPEN = 1,
390704ebd2Sopenharmony_ci    DEVICE_START = 2,
400704ebd2Sopenharmony_ci    DEVICE_STOP = 3,
410704ebd2Sopenharmony_ci};
420704ebd2Sopenharmony_ci
430704ebd2Sopenharmony_cistruct WAV_HEADER {
440704ebd2Sopenharmony_ci    /* RIFF Chunk Descriptor */
450704ebd2Sopenharmony_ci    uint8_t riff[4] = {'R', 'I', 'F', 'F'};
460704ebd2Sopenharmony_ci    uint32_t chunkSize = 0;
470704ebd2Sopenharmony_ci    uint8_t wave[4] = {'W', 'A', 'V', 'E'};
480704ebd2Sopenharmony_ci    /* "fmt" sub-chunk */
490704ebd2Sopenharmony_ci    uint8_t fmt[4] = {'f', 'm', 't', ' '};
500704ebd2Sopenharmony_ci    uint32_t subchunk1Size = 16;
510704ebd2Sopenharmony_ci    uint16_t audioFormat = 1;
520704ebd2Sopenharmony_ci    uint16_t numOfChan = 2;
530704ebd2Sopenharmony_ci    uint32_t samplesPerSec = 44100;
540704ebd2Sopenharmony_ci    uint32_t bytesPerSec = 176400;
550704ebd2Sopenharmony_ci    uint16_t blockAlign = 2;
560704ebd2Sopenharmony_ci    uint16_t bitsPerSample = 16;
570704ebd2Sopenharmony_ci    /* "data" sub-chunk */
580704ebd2Sopenharmony_ci    uint8_t subchunk2ID[4] = {'d', 'a', 't', 'a'};
590704ebd2Sopenharmony_ci    uint32_t subchunk2Size = 0;
600704ebd2Sopenharmony_ci};
610704ebd2Sopenharmony_ci
620704ebd2Sopenharmony_cienum DAudioErrorCode {
630704ebd2Sopenharmony_ci    DH_SUCCESS = 0,
640704ebd2Sopenharmony_ci    ERR_DH_AUDIO_NULLPTR = -40000,
650704ebd2Sopenharmony_ci    ERR_DH_AUDIO_FAILED = -40001,
660704ebd2Sopenharmony_ci    ERR_DH_AUDIO_NOT_SUPPORT = -40002,
670704ebd2Sopenharmony_ci
680704ebd2Sopenharmony_ci    ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED = -40003,
690704ebd2Sopenharmony_ci    ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED = -40004,
700704ebd2Sopenharmony_ci    ERR_DH_AUDIO_SA_CALLBACK_NOT_FOUND = -40005,
710704ebd2Sopenharmony_ci    ERR_DH_AUDIO_SA_INVALID_INTERFACE_TOKEN = -40006,
720704ebd2Sopenharmony_ci    ERR_DH_AUDIO_SA_WAIT_TIMEOUT = -40007,
730704ebd2Sopenharmony_ci    ERR_DH_AUDIO_SA_PARAM_INVALID = -40008,
740704ebd2Sopenharmony_ci    ERR_DH_AUDIO_SA_DEVICE_NOT_EXIST = -40009,
750704ebd2Sopenharmony_ci    ERR_DH_AUDIO_SA_PROXY_NOT_INIT = -40010,
760704ebd2Sopenharmony_ci    ERR_DH_AUDIO_SA_LOAD_FAILED = -40011,
770704ebd2Sopenharmony_ci    ERR_DH_AUDIO_SA_STATUS_ERR = -40012,
780704ebd2Sopenharmony_ci    ERR_DH_AUDIO_NOT_FOUND_KEY = -40013,
790704ebd2Sopenharmony_ci    ERR_DH_AUDIO_SA_DEVID_ILLEGAL = -40014,
800704ebd2Sopenharmony_ci    ERR_DH_AUDIO_SA_PERMISSION_FAIED = -40015,
810704ebd2Sopenharmony_ci
820704ebd2Sopenharmony_ci    // trans error
830704ebd2Sopenharmony_ci    ERR_DH_AUDIO_TRANS_ERROR = -40015,
840704ebd2Sopenharmony_ci    ERR_DH_AUDIO_TRANS_ILLEGAL_OPERATION = -40016,
850704ebd2Sopenharmony_ci    ERR_DH_AUDIO_TRANS_SESSION_NOT_OPEN = -40017,
860704ebd2Sopenharmony_ci
870704ebd2Sopenharmony_ci    // codec error
880704ebd2Sopenharmony_ci    ERR_DH_AUDIO_BAD_VALUE = -42000,
890704ebd2Sopenharmony_ci    ERR_DH_AUDIO_BAD_OPERATE = -42001,
900704ebd2Sopenharmony_ci    ERR_DH_AUDIO_CODEC_CONFIG = -42002,
910704ebd2Sopenharmony_ci    ERR_DH_AUDIO_CODEC_START = -42003,
920704ebd2Sopenharmony_ci    ERR_DH_AUDIO_CODEC_STOP = -42004,
930704ebd2Sopenharmony_ci    ERR_DH_AUDIO_CODEC_RELEASE = -42005,
940704ebd2Sopenharmony_ci    ERR_DH_AUDIO_CODEC_INPUT = -42006,
950704ebd2Sopenharmony_ci
960704ebd2Sopenharmony_ci    // spk client error
970704ebd2Sopenharmony_ci    ERR_DH_AUDIO_CLIENT_PARAM_ERROR = -43000,
980704ebd2Sopenharmony_ci    ERR_DH_AUDIO_CLIENT_RENDER_CREATE_FAILED = -43001,
990704ebd2Sopenharmony_ci    ERR_DH_AUDIO_CLIENT_RENDER_STARTUP_FAILURE = -43002,
1000704ebd2Sopenharmony_ci    ERR_DH_AUDIO_CLIENT_RENDER_STOP_FAILED = -43003,
1010704ebd2Sopenharmony_ci    ERR_DH_AUDIO_CLIENT_RENDER_RELEASE_FAILED = -43004,
1020704ebd2Sopenharmony_ci    ERR_DH_AUDIO_CLIENT_SET_VOLUME_FAILED = -43005,
1030704ebd2Sopenharmony_ci    ERR_DH_AUDIO_CLIENT_SET_MUTE_FAILED = -43006,
1040704ebd2Sopenharmony_ci
1050704ebd2Sopenharmony_ci    // mic client error
1060704ebd2Sopenharmony_ci    ERR_DH_AUDIO_CLIENT_CAPTURER_CREATE_FAILED = -43007,
1070704ebd2Sopenharmony_ci    ERR_DH_AUDIO_CLIENT_CAPTURER_START_FAILED = -43008,
1080704ebd2Sopenharmony_ci
1090704ebd2Sopenharmony_ci    // other error
1100704ebd2Sopenharmony_ci    ERR_DH_AUDIO_HDI_CALL_FAILED = -44000,
1110704ebd2Sopenharmony_ci    ERR_DH_AUDIO_HDI_INVALID_PARAM = -44001,
1120704ebd2Sopenharmony_ci    ERR_DH_AV_TRANS_CREATE_CHANNEL_FAILED = -44002,
1130704ebd2Sopenharmony_ci    ERR_DH_AUDIO_ACCESS_PERMISSION_CHECK_FAIL = -44003,
1140704ebd2Sopenharmony_ci};
1150704ebd2Sopenharmony_ci
1160704ebd2Sopenharmony_ciusing WavHdr = struct WAV_HEADER;
1170704ebd2Sopenharmony_ciint32_t InitTestDemo();
1180704ebd2Sopenharmony_cistd::string FindAudioDevice();
1190704ebd2Sopenharmony_cistd::string OpenSpk(std::string devId);
1200704ebd2Sopenharmony_cistd::string StartRender();
1210704ebd2Sopenharmony_cistd::string StopRender();
1220704ebd2Sopenharmony_cistd::string CloseSpk();
1230704ebd2Sopenharmony_cistd::string OpenMic(std::string devId);
1240704ebd2Sopenharmony_cistd::string StartCapture();
1250704ebd2Sopenharmony_cistd::string StopCapture();
1260704ebd2Sopenharmony_cistd::string CloseMic();
1270704ebd2Sopenharmony_cistd::string SetVolume(int vol);
1280704ebd2Sopenharmony_cistd::string GetVolume();
1290704ebd2Sopenharmony_cistd::string HandleAudioEvent(int32_t cmd);
1300704ebd2Sopenharmony_ciint32_t GetSyncOnlineDevices(std::string& netWorkId);
1310704ebd2Sopenharmony_civoid PrintNodeProperty(NodeBasicInfo *nodeInfo);
1320704ebd2Sopenharmony_civoid PrintNodeProperty(NodeBasicInfo *nodeInfo, std::string& netWorkId);
1330704ebd2Sopenharmony_civoid AddPermission(void);
1340704ebd2Sopenharmony_ci#endif