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 #include <common.h>
17
18 using namespace OHOS::AudioStandard;
19
20 static SLuint32 audioPlayerId = 0;
21 static SLuint32 audioRecorderId = 0;
22
CreateLEDDevice(SLEngineItf self,SLObjectItf * pDevice,SLuint32 deviceID,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)23 static SLresult CreateLEDDevice(
24 SLEngineItf self, SLObjectItf *pDevice, SLuint32 deviceID, SLuint32 numInterfaces,
25 const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
26 {
27 return SL_RESULT_FEATURE_UNSUPPORTED;
28 }
29
CreateVibraDevice(SLEngineItf self,SLObjectItf * pDevice,SLuint32 deviceID,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)30 static SLresult CreateVibraDevice(
31 SLEngineItf self, SLObjectItf *pDevice, SLuint32 deviceID, SLuint32 numInterfaces,
32 const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
33 {
34 return SL_RESULT_FEATURE_UNSUPPORTED;
35 }
36
CreateAudioPlayer(SLEngineItf self,SLObjectItf * pPlayer,SLDataSource * pAudioSrc,SLDataSink * pAudioSnk,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)37 static SLresult CreateAudioPlayer(
38 SLEngineItf self, SLObjectItf *pPlayer, SLDataSource *pAudioSrc, SLDataSink *pAudioSnk, SLuint32 numInterfaces,
39 const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
40 {
41 if (pPlayer == nullptr) {
42 return SL_RESULT_PARAMETER_INVALID;
43 }
44 ClassTable *audioPlayerClass = ObjectIdToClass(SL_OBJECTID_AUDIOPLAYER);
45 CAudioPlayer *thiz = (CAudioPlayer *) Construct(audioPlayerClass, self);
46 if (thiz == nullptr) {
47 return SL_RESULT_PARAMETER_INVALID;
48 }
49 thiz->mId = audioPlayerId;
50 IObjectInit(&thiz->mObject);
51 IPlayInit(&thiz->mPlay, audioPlayerId);
52 IVolumeInit(&thiz->mVolume, audioPlayerId);
53 IOHBufferQueueInit(&thiz->mBufferQueue, SL_IID_PLAY, audioPlayerId);
54 *pPlayer = &thiz->mObject.mItf;
55 AudioPlayerAdapter::GetInstance()->
56 CreateAudioPlayerAdapter(audioPlayerId, pAudioSrc, pAudioSnk, OHOS::AudioStandard::STREAM_MUSIC);
57 audioPlayerId++;
58
59 return SL_RESULT_SUCCESS;
60 }
61
CreateAudioRecorder(SLEngineItf self,SLObjectItf * pRecorder,SLDataSource * pAudioSrc,SLDataSink * pAudioSnk,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)62 static SLresult CreateAudioRecorder(
63 SLEngineItf self, SLObjectItf *pRecorder, SLDataSource *pAudioSrc, SLDataSink *pAudioSnk, SLuint32 numInterfaces,
64 const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
65 {
66 if (pRecorder == nullptr) {
67 return SL_RESULT_PARAMETER_INVALID;
68 }
69 ClassTable *audioRecorderClass = ObjectIdToClass(SL_OBJECTID_AUDIORECORDER);
70 CAudioRecorder *thiz = (CAudioRecorder *) Construct(audioRecorderClass, self);
71 thiz->mId = audioRecorderId;
72 IObjectInit(&thiz->mObject);
73 IRecordInit(&thiz->mRecord, audioRecorderId);
74 IOHBufferQueueInit(&thiz->mBufferQueue, SL_IID_RECORD, audioRecorderId);
75 *pRecorder = &thiz->mObject.mItf;
76 AudioCapturerAdapter::GetInstance()->
77 CreateAudioCapturerAdapter(audioRecorderId, pAudioSrc, pAudioSnk, OHOS::AudioStandard::STREAM_MUSIC);
78 audioRecorderId++;
79
80 return SL_RESULT_SUCCESS;
81 }
82
CreateMidiPlayer(SLEngineItf self,SLObjectItf * pPlayer,SLDataSource * pMIDISrc,SLDataSource * pBankSrc,SLDataSink * pAudioOutput,SLDataSink * pVibra,SLDataSink * pLEDArray,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)83 static SLresult CreateMidiPlayer(
84 SLEngineItf self, SLObjectItf *pPlayer, SLDataSource *pMIDISrc, SLDataSource *pBankSrc, SLDataSink *pAudioOutput,
85 SLDataSink *pVibra, SLDataSink *pLEDArray, SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds,
86 const SLboolean *pInterfaceRequired)
87 {
88 return SL_RESULT_FEATURE_UNSUPPORTED;
89 }
90
CreateListener(SLEngineItf self,SLObjectItf * pListener,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)91 static SLresult CreateListener(
92 SLEngineItf self, SLObjectItf *pListener, SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds,
93 const SLboolean *pInterfaceRequired)
94 {
95 return SL_RESULT_FEATURE_UNSUPPORTED;
96 }
97
Create3DGroup(SLEngineItf self,SLObjectItf * pGroup,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)98 static SLresult Create3DGroup(
99 SLEngineItf self, SLObjectItf *pGroup, SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds,
100 const SLboolean *pInterfaceRequired)
101 {
102 return SL_RESULT_FEATURE_UNSUPPORTED;
103 }
104
CreateOutputMix(SLEngineItf self,SLObjectItf * pMix,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)105 static SLresult CreateOutputMix(
106 SLEngineItf self, SLObjectItf *pMix, SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds,
107 const SLboolean *pInterfaceRequired)
108 {
109 if (pMix == nullptr) {
110 return SL_RESULT_PARAMETER_INVALID;
111 }
112 ClassTable *outputMixClass = ObjectIdToClass(SL_OBJECTID_OUTPUTMIX);
113 COutputMix *thiz = (COutputMix *) Construct(outputMixClass, self);
114 if (thiz == nullptr) {
115 return SL_RESULT_PARAMETER_INVALID;
116 }
117 IObjectInit(&thiz->mObject);
118 *pMix = &thiz->mObject.mItf;
119 return SL_RESULT_SUCCESS;
120 }
121
CreateMetadataExtractor(SLEngineItf self,SLObjectItf * pMetadataExtractor,SLDataSource * pDataSource,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)122 static SLresult CreateMetadataExtractor(
123 SLEngineItf self, SLObjectItf *pMetadataExtractor, SLDataSource *pDataSource, SLuint32 numInterfaces,
124 const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
125 {
126 return SL_RESULT_FEATURE_UNSUPPORTED;
127 }
128
CreateExtensionObject(SLEngineItf self,SLObjectItf * pObject,void * pParameters,SLuint32 objectID,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)129 static SLresult CreateExtensionObject(
130 SLEngineItf self, SLObjectItf *pObject, void *pParameters, SLuint32 objectID, SLuint32 numInterfaces,
131 const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
132 {
133 return SL_RESULT_FEATURE_UNSUPPORTED;
134 }
135
QueryNumSupportedInterfaces(SLEngineItf self,SLuint32 objectID,SLuint32 * pNumSupportedInterfaces)136 static SLresult QueryNumSupportedInterfaces(SLEngineItf self, SLuint32 objectID, SLuint32 *pNumSupportedInterfaces)
137 {
138 return SL_RESULT_FEATURE_UNSUPPORTED;
139 }
140
QuerySupportedInterfaces(SLEngineItf self,SLuint32 objectID,SLuint32 index,SLInterfaceID * pInterfaceId)141 static SLresult QuerySupportedInterfaces(
142 SLEngineItf self, SLuint32 objectID, SLuint32 index, SLInterfaceID *pInterfaceId)
143 {
144 return SL_RESULT_FEATURE_UNSUPPORTED;
145 }
146
QueryNumSupportedExtensions(SLEngineItf self,SLuint32 * pNumExtensions)147 static SLresult QueryNumSupportedExtensions(SLEngineItf self, SLuint32 *pNumExtensions)
148 {
149 return SL_RESULT_FEATURE_UNSUPPORTED;
150 }
151
QuerySupportedExtension(SLEngineItf self,SLuint32 index,SLchar * pExtensionName,SLint16 * pNameLength)152 static SLresult QuerySupportedExtension(
153 SLEngineItf self, SLuint32 index, SLchar *pExtensionName, SLint16 *pNameLength)
154 {
155 return SL_RESULT_FEATURE_UNSUPPORTED;
156 }
157
IsExtensionSupported(SLEngineItf self,const SLchar * pExtensionName,SLboolean * pSupported)158 static SLresult IsExtensionSupported(SLEngineItf self, const SLchar *pExtensionName, SLboolean *pSupported)
159 {
160 return SL_RESULT_FEATURE_UNSUPPORTED;
161 }
162
163 static const struct SLEngineItf_ EngineItf = {
164 CreateLEDDevice,
165 CreateVibraDevice,
166 CreateAudioPlayer,
167 CreateAudioRecorder,
168 CreateMidiPlayer,
169 CreateListener,
170 Create3DGroup,
171 CreateOutputMix,
172 CreateMetadataExtractor,
173 CreateExtensionObject,
174 QueryNumSupportedInterfaces,
175 QuerySupportedInterfaces,
176 QueryNumSupportedExtensions,
177 QuerySupportedExtension,
178 IsExtensionSupported
179 };
180
IEngineInit(void * self)181 void IEngineInit(void *self)
182 {
183 IEngine *thiz = (IEngine *) self;
184 thiz->mItf = &EngineItf;
185 }
186