• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     SLresult ret = AudioPlayerAdapter::GetInstance()->
56         CreateAudioPlayerAdapter(audioPlayerId, pAudioSrc, pAudioSnk, OHOS::AudioStandard::STREAM_MUSIC);
57     if (ret != SL_RESULT_SUCCESS) {
58         return SL_RESULT_RESOURCE_ERROR;
59     }
60     audioPlayerId++;
61 
62     return SL_RESULT_SUCCESS;
63 }
64 
CreateAudioRecorder(SLEngineItf self,SLObjectItf * pRecorder,SLDataSource * pAudioSrc,SLDataSink * pAudioSnk,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)65 static SLresult CreateAudioRecorder(
66     SLEngineItf self, SLObjectItf *pRecorder, SLDataSource *pAudioSrc, SLDataSink *pAudioSnk, SLuint32 numInterfaces,
67     const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
68 {
69     if (pRecorder == nullptr) {
70         return SL_RESULT_PARAMETER_INVALID;
71     }
72     ClassTable *audioRecorderClass = ObjectIdToClass(SL_OBJECTID_AUDIORECORDER);
73     CAudioRecorder *thiz = (CAudioRecorder *) Construct(audioRecorderClass, self);
74     thiz->mId = audioRecorderId;
75     IObjectInit(&thiz->mObject);
76     IRecordInit(&thiz->mRecord, audioRecorderId);
77     IOHBufferQueueInit(&thiz->mBufferQueue, SL_IID_RECORD, audioRecorderId);
78     *pRecorder = &thiz->mObject.mItf;
79     SLresult ret = AudioCapturerAdapter::GetInstance()->
80         CreateAudioCapturerAdapter(audioRecorderId, pAudioSrc, pAudioSnk, OHOS::AudioStandard::STREAM_MUSIC);
81     if (ret != SL_RESULT_SUCCESS) {
82         return SL_RESULT_RESOURCE_ERROR;
83     }
84     audioRecorderId++;
85 
86     return SL_RESULT_SUCCESS;
87 }
88 
CreateMidiPlayer(SLEngineItf self,SLObjectItf * pPlayer,SLDataSource * pMIDISrc,SLDataSource * pBankSrc,SLDataSink * pAudioOutput,SLDataSink * pVibra,SLDataSink * pLEDArray,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)89 static SLresult CreateMidiPlayer(
90     SLEngineItf self, SLObjectItf *pPlayer, SLDataSource *pMIDISrc, SLDataSource *pBankSrc, SLDataSink *pAudioOutput,
91     SLDataSink *pVibra, SLDataSink *pLEDArray, SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds,
92     const SLboolean *pInterfaceRequired)
93 {
94     return SL_RESULT_FEATURE_UNSUPPORTED;
95 }
96 
CreateListener(SLEngineItf self,SLObjectItf * pListener,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)97 static SLresult CreateListener(
98     SLEngineItf self, SLObjectItf *pListener, SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds,
99     const SLboolean *pInterfaceRequired)
100 {
101     return SL_RESULT_FEATURE_UNSUPPORTED;
102 }
103 
Create3DGroup(SLEngineItf self,SLObjectItf * pGroup,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)104 static SLresult Create3DGroup(
105     SLEngineItf self, SLObjectItf *pGroup, SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds,
106     const SLboolean *pInterfaceRequired)
107 {
108     return SL_RESULT_FEATURE_UNSUPPORTED;
109 }
110 
CreateOutputMix(SLEngineItf self,SLObjectItf * pMix,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)111 static SLresult CreateOutputMix(
112     SLEngineItf self, SLObjectItf *pMix, SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds,
113     const SLboolean *pInterfaceRequired)
114 {
115     if (pMix == nullptr) {
116         return SL_RESULT_PARAMETER_INVALID;
117     }
118     ClassTable *outputMixClass = ObjectIdToClass(SL_OBJECTID_OUTPUTMIX);
119     COutputMix *thiz = (COutputMix *) Construct(outputMixClass, self);
120     if (thiz == nullptr) {
121         return SL_RESULT_PARAMETER_INVALID;
122     }
123     IObjectInit(&thiz->mObject);
124     *pMix = &thiz->mObject.mItf;
125     return SL_RESULT_SUCCESS;
126 }
127 
CreateMetadataExtractor(SLEngineItf self,SLObjectItf * pMetadataExtractor,SLDataSource * pDataSource,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)128 static SLresult CreateMetadataExtractor(
129     SLEngineItf self, SLObjectItf *pMetadataExtractor, SLDataSource *pDataSource, SLuint32 numInterfaces,
130     const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
131 {
132     return SL_RESULT_FEATURE_UNSUPPORTED;
133 }
134 
CreateExtensionObject(SLEngineItf self,SLObjectItf * pObject,void * pParameters,SLuint32 objectID,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)135 static SLresult CreateExtensionObject(
136     SLEngineItf self, SLObjectItf *pObject, void *pParameters, SLuint32 objectID, SLuint32 numInterfaces,
137     const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
138 {
139     return SL_RESULT_FEATURE_UNSUPPORTED;
140 }
141 
QueryNumSupportedInterfaces(SLEngineItf self,SLuint32 objectID,SLuint32 * pNumSupportedInterfaces)142 static SLresult QueryNumSupportedInterfaces(SLEngineItf self, SLuint32 objectID, SLuint32 *pNumSupportedInterfaces)
143 {
144     return SL_RESULT_FEATURE_UNSUPPORTED;
145 }
146 
QuerySupportedInterfaces(SLEngineItf self,SLuint32 objectID,SLuint32 index,SLInterfaceID * pInterfaceId)147 static SLresult QuerySupportedInterfaces(
148     SLEngineItf self, SLuint32 objectID, SLuint32 index, SLInterfaceID *pInterfaceId)
149 {
150     return SL_RESULT_FEATURE_UNSUPPORTED;
151 }
152 
QueryNumSupportedExtensions(SLEngineItf self,SLuint32 * pNumExtensions)153 static SLresult QueryNumSupportedExtensions(SLEngineItf self, SLuint32 *pNumExtensions)
154 {
155     return SL_RESULT_FEATURE_UNSUPPORTED;
156 }
157 
QuerySupportedExtension(SLEngineItf self,SLuint32 index,SLchar * pExtensionName,SLint16 * pNameLength)158 static SLresult QuerySupportedExtension(
159     SLEngineItf self, SLuint32 index, SLchar *pExtensionName, SLint16 *pNameLength)
160 {
161     return SL_RESULT_FEATURE_UNSUPPORTED;
162 }
163 
IsExtensionSupported(SLEngineItf self,const SLchar * pExtensionName,SLboolean * pSupported)164 static SLresult IsExtensionSupported(SLEngineItf self, const SLchar *pExtensionName, SLboolean *pSupported)
165 {
166     return SL_RESULT_FEATURE_UNSUPPORTED;
167 }
168 
169 static const struct SLEngineItf_ EngineItf = {
170     CreateLEDDevice,
171     CreateVibraDevice,
172     CreateAudioPlayer,
173     CreateAudioRecorder,
174     CreateMidiPlayer,
175     CreateListener,
176     Create3DGroup,
177     CreateOutputMix,
178     CreateMetadataExtractor,
179     CreateExtensionObject,
180     QueryNumSupportedInterfaces,
181     QuerySupportedInterfaces,
182     QueryNumSupportedExtensions,
183     QuerySupportedExtension,
184     IsExtensionSupported
185 };
186 
IEngineInit(void * self)187 void IEngineInit(void *self)
188 {
189     IEngine *thiz = (IEngine *) self;
190     thiz->mItf = &EngineItf;
191 }
192