• 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 
slCreateEngine(SLObjectItf * pEngine,SLuint32 numOptions,const SLEngineOption * pEngineOptions,SLuint32 numInterfaces,const SLInterfaceID * pInterfaceIds,const SLboolean * pInterfaceRequired)18 SLresult SLAPIENTRY slCreateEngine(SLObjectItf *pEngine, SLuint32 numOptions,
19     const SLEngineOption *pEngineOptions, SLuint32 numInterfaces,
20     const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
21 {
22     if (pEngine == nullptr) {
23         return SL_RESULT_PARAMETER_INVALID;
24     }
25     ClassTable *engineClass = ObjectIdToClass(SL_OBJECTID_ENGINE);
26     CEngine *thiz = (CEngine *) Construct(engineClass, nullptr);
27     IObjectInit(&thiz->mObject);
28     IEngineInit(&thiz->mEngine);
29     *pEngine = &thiz->mObject.mItf;
30     return SL_RESULT_SUCCESS;
31 }
32 
ObjectIdToClass(SLuint32 objectId)33 ClassTable *ObjectIdToClass(SLuint32 objectId)
34 {
35     ClassTable *classTable = nullptr;
36     if (objectId == SL_OBJECTID_ENGINE) {
37         classTable = (ClassTable *) &EngineTab;
38     } else if (objectId == SL_OBJECTID_AUDIOPLAYER) {
39         classTable = (ClassTable *) &AudioPlayerTab;
40     } else if (objectId == SL_OBJECTID_OUTPUTMIX) {
41         classTable = (ClassTable *) &OutputMixTab;
42     }
43     return classTable;
44 }
45 
Construct(const ClassTable * classTable,SLEngineItf engine)46 IObject *Construct(const ClassTable *classTable, SLEngineItf engine)
47 {
48     IObject *thiz = (IObject *) calloc(1, classTable->mSize);
49     if (thiz != nullptr) {
50         IEngine *thisEngine = (IEngine *) engine;
51         if (thisEngine != nullptr) {
52             thiz->mEngine = (CEngine *) thisEngine->mThis;
53         } else {
54             thiz->mEngine = (CEngine *) thiz;
55         }
56         thiz->mClass = classTable;
57     }
58     return thiz;
59 }
60