• 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 
Realize(SLObjectItf self,SLboolean async)20 static SLresult Realize(SLObjectItf self, SLboolean async)
21 {
22     if (self == nullptr) {
23         return SL_RESULT_PARAMETER_INVALID;
24     }
25     IObject *thiz = (IObject *) self;
26     thiz->mState = SL_OBJECT_STATE_REALIZED;
27     return SL_RESULT_SUCCESS;
28 }
29 
Resume(SLObjectItf self,SLboolean async)30 static SLresult Resume(SLObjectItf self, SLboolean async)
31 {
32     return SL_RESULT_SUCCESS;
33 }
34 
GetState(SLObjectItf self,SLuint32 * state)35 static SLresult GetState(SLObjectItf self, SLuint32 *state)
36 {
37     if (self == nullptr) {
38         return SL_RESULT_PARAMETER_INVALID;
39     }
40     IObject *thiz = (IObject *) self;
41     *state = thiz->mState;
42     return SL_RESULT_SUCCESS;
43 }
44 
GetInterface(SLObjectItf self,const SLInterfaceID iid,void * interface)45 static SLresult GetInterface(SLObjectItf self, const SLInterfaceID iid, void *interface)
46 {
47     if (self == nullptr) {
48         return SL_RESULT_PARAMETER_INVALID;
49     }
50     if (iid == SL_IID_ENGINE) {
51         CEngine *cEngine = (CEngine *)self;
52         *(void **)interface = (void *)&(cEngine->mEngine.mItf);
53         return SL_RESULT_SUCCESS;
54     } else if (iid == SL_IID_PLAY) {
55         CAudioPlayer *cAudioPlayer = (CAudioPlayer *)self;
56         *(void **)interface = (void *)&(cAudioPlayer->mPlay.mItf);
57         return SL_RESULT_SUCCESS;
58     } else if (iid == SL_IID_VOLUME) {
59         CAudioPlayer *cAudioPlayer = (CAudioPlayer *)self;
60         *(void **)interface = (void *)&(cAudioPlayer->mVolume.mItf);
61         return SL_RESULT_SUCCESS;
62     } else if (iid == SL_IID_OH_BUFFERQUEUE) {
63         IObject *iObject = (IObject *)self;
64         if (iObject->mClass->mObjectId == SL_OBJECTID_AUDIOPLAYER) {
65             CAudioPlayer *cAudioPlayer = (CAudioPlayer *)iObject;
66             *(void **)interface = (void *)&(cAudioPlayer->mBufferQueue.mItf);
67         } else if (iObject->mClass->mObjectId == SL_OBJECTID_AUDIORECORDER) {
68             CAudioRecorder *cAudioRecorder = (CAudioRecorder *)iObject;
69             *(void **)interface = (void *)&(cAudioRecorder->mBufferQueue.mItf);
70         } else {
71             return SL_RESULT_FEATURE_UNSUPPORTED;
72         }
73         return SL_RESULT_SUCCESS;
74     } else if (iid == SL_IID_RECORD) {
75         CAudioRecorder *cAudioRecorder = (CAudioRecorder *)self;
76         *(void **)interface = (void *)&(cAudioRecorder->mRecord.mItf);
77         return SL_RESULT_SUCCESS;
78     } else {
79         AUDIO_ERR_LOG("GetInterface: SLInterfaceID not supported");
80         return SL_RESULT_FEATURE_UNSUPPORTED;
81     }
82 }
83 
RegisterCallback(SLObjectItf self,slObjectCallback callback,void * pContext)84 static SLresult RegisterCallback(SLObjectItf self, slObjectCallback callback, void *pContext)
85 {
86     return SL_RESULT_FEATURE_UNSUPPORTED;
87 }
88 
AbortAsyncOperation(SLObjectItf self)89 static void AbortAsyncOperation(SLObjectItf self)
90 {
91     return;
92 }
93 
SetPriority(SLObjectItf self,SLint32 priority,SLboolean preemptable)94 static SLresult SetPriority(SLObjectItf self, SLint32 priority, SLboolean preemptable)
95 {
96     return SL_RESULT_FEATURE_UNSUPPORTED;
97 }
98 
GetPriority(SLObjectItf self,SLint32 * pPriority,SLboolean * pPreemptable)99 static SLresult GetPriority(SLObjectItf self, SLint32 *pPriority, SLboolean *pPreemptable)
100 {
101     return SL_RESULT_FEATURE_UNSUPPORTED;
102 }
103 
SetLossOfControlInterfaces(SLObjectItf self,SLint16 numInterfaces,SLInterfaceID * pInterfaceIDs,SLboolean enabled)104 static SLresult SetLossOfControlInterfaces(SLObjectItf self,
105     SLint16 numInterfaces, SLInterfaceID *pInterfaceIDs, SLboolean enabled)
106 {
107     return SL_RESULT_FEATURE_UNSUPPORTED;
108 }
109 
Destroy(SLObjectItf self)110 void Destroy(SLObjectItf self)
111 {
112     if (self == nullptr) {
113         return;
114     }
115     IObject *iObject = (IObject *)self;
116     SLuint32 objectId = iObject->mClass->mObjectId;
117     switch (objectId) {
118         case SL_OBJECTID_AUDIOPLAYER:
119             AudioPlayerDestroy((void *)self);
120             break;
121         case SL_OBJECTID_ENGINE:
122             EngineDestory((void *)self);
123             break;
124         case SL_OBJECTID_OUTPUTMIX:
125             OutputMixDestroy((void *)self);
126             break;
127         case SL_OBJECTID_AUDIORECORDER:
128             AudioRecorderDestroy((void *)self);
129             break;
130         default:
131             AUDIO_ERR_LOG("objectId not supported");
132             break;
133     }
134     return;
135 }
136 
137 static const struct SLObjectItf_ ObjectItf = {
138     Realize,
139     Resume,
140     GetState,
141     GetInterface,
142     RegisterCallback,
143     AbortAsyncOperation,
144     Destroy,
145     SetPriority,
146     GetPriority,
147     SetLossOfControlInterfaces
148 };
149 
IObjectInit(void * self)150 void IObjectInit(void *self)
151 {
152     IObject *thiz = (IObject *) self;
153     thiz->mItf = &ObjectItf;
154     thiz->mState = SL_OBJECT_STATE_UNREALIZED;
155 }
156