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