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