1 /* 2 * Copyright (c) 2022-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 COMMON_H 17 #define COMMON_H 18 19 #include <OpenSLES.h> 20 #include <OpenSLES_OpenHarmony.h> 21 #include <OpenSLES_Platform.h> 22 23 #include <iostream> 24 #include <cstdlib> 25 #include <stddef.h> 26 27 #include "audio_common_log.h" 28 #include "audioplayer_adapter.h" 29 #include "audiocapturer_adapter.h" 30 31 struct CEngine; 32 33 struct ClassTable; 34 35 /** itf struct **/ 36 37 struct IObject { 38 const struct SLObjectItf_ *mItf; 39 CEngine *mEngine; 40 const ClassTable *mClass; 41 SLuint8 mState; 42 }; 43 44 struct IEngine { 45 const struct SLEngineItf_ *mItf; 46 IObject *mThis; 47 }; 48 49 struct IPlay { 50 const struct SLPlayItf_ *mItf; 51 SLuint32 mState; 52 SLuint8 mId; 53 }; 54 55 struct IRecord { 56 const struct SLRecordItf_ *mItf; 57 SLuint32 mState; 58 SLuint8 mId; 59 }; 60 61 struct IOHBufferQueue { 62 const struct SLOHBufferQueueItf_ *mItf; 63 SLuint32 mState; 64 SLInterfaceID mIid; 65 SLuint8 mId; 66 }; 67 68 struct IVolume { 69 const struct SLVolumeItf_ *mItf; 70 SLuint8 mId; 71 }; 72 73 /** class struct **/ 74 75 struct CEngine { 76 IObject mObject; 77 IEngine mEngine; 78 }; 79 80 struct CAudioPlayer { 81 IObject mObject; 82 IPlay mPlay; 83 IVolume mVolume; 84 IOHBufferQueue mBufferQueue; 85 SLuint32 mId; 86 }; 87 88 struct CAudioRecorder { 89 IObject mObject; 90 IRecord mRecord; 91 IOHBufferQueue mBufferQueue; 92 SLuint32 mId; 93 }; 94 95 struct COutputMix { 96 IObject mObject; 97 }; 98 99 struct ClassTable { 100 SLuint32 mObjectId; 101 size_t mSize; 102 }; 103 104 extern ClassTable EngineTab; 105 106 extern ClassTable AudioPlayerTab; 107 108 extern ClassTable AudioRecorderTab; 109 110 extern ClassTable OutputMixTab; 111 112 ClassTable *ObjectIdToClass(SLuint32 objectId); 113 114 IObject *Construct(const ClassTable *classTable, SLEngineItf itf); 115 116 void IOHBufferQueueInit(void *self, const SLInterfaceID iid, SLuint32 id); 117 118 void IEngineInit(void *self); 119 120 void IObjectInit(void *self); 121 122 void IPlayInit(void *self, SLuint32 id); 123 124 void IVolumeInit(void *self, SLuint32 id); 125 126 void IRecordInit(void *self, SLuint32 id); 127 128 SLresult EngineDestory(void* self); 129 130 SLresult AudioPlayerDestroy(void* self); 131 132 SLresult OutputMixDestroy(void* self); 133 134 SLresult AudioRecorderDestroy(void *self); 135 #endif 136