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 <iostream> 24 #include <cstdlib> 25 #include <stddef.h> 26 #include "media_log.h" 27 28 struct CEngine; 29 30 struct ClassTable; 31 32 /** itf struct **/ 33 34 struct IObject { 35 const struct SLObjectItf_ *mItf; 36 CEngine *mEngine; 37 const ClassTable *mClass; 38 SLuint8 mState; 39 }; 40 41 struct IEngine { 42 const struct SLEngineItf_ *mItf; 43 IObject *mThis; 44 }; 45 46 struct IPlay { 47 const struct SLPlayItf_ *mItf; 48 SLuint32 mState; 49 SLuint8 mId; 50 }; 51 52 struct IOHBufferQueue { 53 const struct SLOHBufferQueueItf_ *mItf; 54 SLuint32 mState; 55 SLuint8 mId; 56 }; 57 58 struct IVolume { 59 const struct SLVolumeItf_ *mItf; 60 SLuint8 mId; 61 }; 62 63 /** class struct **/ 64 65 struct CEngine { 66 IObject mObject; 67 IEngine mEngine; 68 }; 69 70 struct CAudioPlayer { 71 IObject mObject; 72 IPlay mPlay; 73 IVolume mVolume; 74 IOHBufferQueue mBufferQueue; 75 SLuint32 mId; 76 }; 77 78 struct COutputMix { 79 IObject mObject; 80 }; 81 82 struct ClassTable { 83 SLuint32 mObjectId; 84 size_t mSize; 85 }; 86 87 extern ClassTable EngineTab; 88 89 extern ClassTable AudioPlayerTab; 90 91 extern ClassTable OutputMixTab; 92 93 ClassTable *ObjectIdToClass(SLuint32 objectId); 94 95 IObject *Construct(const ClassTable *classTable, SLEngineItf itf); 96 97 void IOHBufferQueueInit(void *self, SLuint32 id); 98 99 void IEngineInit(void *self); 100 101 void IObjectInit(void *self); 102 103 void IPlayInit(void *self, SLuint32 id); 104 105 void IVolumeInit(void *self, SLuint32 id); 106 107 SLresult EngineDestory(void* self); 108 109 SLresult AudioPlayerDestroy(void* self); 110 111 SLresult OutputMixDestroy(void* self); 112 #endif 113