1 /* 2 * Copyright (c) 2021 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 /* 17 * @addtogroup Audio 18 * @{ 19 * 20 * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, 21 * accessing a driver adapter, and rendering and capturing audios. 22 * 23 * @since 1.0 24 * @version 1.0 25 */ 26 27 /* 28 * @file audio_adapter.h 29 * 30 * @brief Declares APIs for operations related to the audio adapter. 31 * 32 * @since 1.0 33 * @version 1.0 34 */ 35 36 #ifndef AUDIO_HDI_FUZZER_COMMON_H 37 #define AUDIO_HDI_FUZZER_COMMON_H 38 #include <iostream> 39 #include <cstring> 40 #include "hdf_log.h" 41 #include "audio_adapter.h" 42 #include "audio_internal.h" 43 #include "audio_types.h" 44 45 namespace OHOS { 46 namespace Audio { 47 using namespace std; 48 49 #ifdef AUDIO_ADM_SO 50 const std::string FUNCTION_NAME = "GetAudioManagerFuncs"; 51 const std::string RESOLVED_PATH = HDF_LIBRARY_FULL_PATH("libhdi_audio"); 52 #endif 53 #ifdef AUDIO_ADM_SERVICE 54 const std::string FUNCTION_NAME = "GetAudioManagerFuncs"; 55 const std::string RESOLVED_PATH = HDF_LIBRARY_FULL_PATH("libhdi_audio_client"); 56 #endif 57 using TestAudioManager = struct AudioManager; 58 const uint32_t INT_32_MAX = 0x7fffffff; 59 const uint32_t MOVE_RIGHT_NUM = 3; 60 const int MOVE_LEFT_NUM = 8; 61 const int CHANNELCOUNT = 2; 62 const int FILE_CAPTURE_SIZE = 1024 * 1024 * 1; 63 const int SAMPLERATE = 48000; 64 const int DEEP_BUFFER_RENDER_PERIOD_SIZE = 4096; 65 const int BUFFER_LENTH = 1024 * 16; 66 const uint64_t MEGABYTE = 1024; 67 const int FRAME_SIZE = 1024; 68 const int FRAME_COUNT = 4; 69 const int ADAPTER_COUNT = 32; 70 const int TRY_NUM_FRAME = 20; 71 const string AUDIO_LOW_LATENCY_CAPTURE_FILE = "/data/lowlatencycapturetest.wav"; 72 const string AUDIO_LOW_LATENCY_RENDER_FILE = "/data/lowlatencyrendertest.wav"; 73 const string ADAPTER_NAME = "primary"; 74 75 enum AudioPCMBit { 76 PCM_8_BIT = 8, 77 PCM_16_BIT = 16, 78 PCM_24_BIT = 24, 79 PCM_32_BIT = 32, 80 }; 81 int32_t GetManager(TestAudioManager *&manager); 82 83 int32_t InitAttrs(struct AudioSampleAttributes& attrs); 84 85 int32_t InitDevDesc(struct AudioDeviceDescriptor& devDesc, const uint32_t portId, enum AudioPortPin pins); 86 87 int32_t GetAdapters(TestAudioManager *manager, struct AudioAdapterDescriptor **descs, int &size); 88 89 int32_t GetLoadAdapter(TestAudioManager *manager, struct AudioAdapter **adapter, struct AudioPort *&audioPort); 90 91 int32_t AudioCreateRender(TestAudioManager *manager, struct AudioAdapter **adapter, struct AudioRender **render); 92 93 int32_t AudioGetManagerCreateRender(TestAudioManager *&manager, struct AudioAdapter **adapter, 94 struct AudioRender **render); 95 96 int32_t AudioGetManagerCreateStartRender(TestAudioManager *&manager, struct AudioAdapter **adapter, 97 struct AudioRender **render); 98 99 int32_t AudioCreateCapture(TestAudioManager *manager, struct AudioAdapter **adapter, struct AudioCapture **capture); 100 101 int32_t AudioGetManagerCreateCapture(TestAudioManager *&manager, struct AudioAdapter **adapter, 102 struct AudioCapture **capture); 103 104 int32_t AudioGetManagerCreateStartCapture(TestAudioManager *&manager, struct AudioAdapter **adapter, 105 struct AudioCapture **capture); 106 107 int32_t InitMmapDesc(FILE *fp, struct AudioMmapBufferDescripter &desc, int32_t &reqSize, bool flag); 108 } 109 } 110 #endif // AUDIO_HDI_FUZZER_COMMON_H 111 112