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
Enqueue(SLOHBufferQueueItf self,const void * buffer,SLuint32 size)20 SLresult Enqueue(SLOHBufferQueueItf self, const void *buffer, SLuint32 size)
21 {
22 if (self == nullptr) {
23 return SL_RESULT_PARAMETER_INVALID;
24 }
25 IOHBufferQueue *thiz = (IOHBufferQueue *)self;
26 AudioPlayerAdapter::GetInstance()->EnqueueAdapter(thiz->mId, buffer, size);
27 return SL_RESULT_SUCCESS;
28 }
29
Clear(SLOHBufferQueueItf self)30 SLresult Clear(SLOHBufferQueueItf self)
31 {
32 if (self == nullptr) {
33 return SL_RESULT_PARAMETER_INVALID;
34 }
35 IOHBufferQueue *thiz = (IOHBufferQueue *)self;
36 AudioPlayerAdapter::GetInstance()->ClearAdapter(thiz->mId);
37 return SL_RESULT_SUCCESS;
38 }
39
GetState(SLOHBufferQueueItf self,SLOHBufferQueueState * state)40 SLresult GetState(SLOHBufferQueueItf self, SLOHBufferQueueState *state)
41 {
42 if (self == nullptr) {
43 return SL_RESULT_PARAMETER_INVALID;
44 }
45 IOHBufferQueue *thiz = (IOHBufferQueue *)self;
46 AudioPlayerAdapter::GetInstance()->GetStateAdapter(thiz->mId, state);
47 return SL_RESULT_SUCCESS;
48 }
49
GetBuffer(SLOHBufferQueueItf self,SLuint8 ** buffer,SLuint32 & size)50 SLresult GetBuffer(SLOHBufferQueueItf self, SLuint8 **buffer, SLuint32 &size)
51 {
52 if (self == nullptr) {
53 return SL_RESULT_PARAMETER_INVALID;
54 }
55 IOHBufferQueue *thiz = (IOHBufferQueue *)self;
56 AudioPlayerAdapter::GetInstance()->GetBufferAdapter(thiz->mId, buffer, size);
57 return SL_RESULT_SUCCESS;
58 }
59
RegisterCallback(SLOHBufferQueueItf self,SlOHBufferQueueCallback callback,void * pContext)60 SLresult RegisterCallback(SLOHBufferQueueItf self,
61 SlOHBufferQueueCallback callback, void *pContext)
62 {
63 if (self == nullptr || callback == nullptr) {
64 return SL_RESULT_PARAMETER_INVALID;
65 }
66 AudioPlayerAdapter::GetInstance()->RegisterCallbackAdapter(self, callback, pContext);
67 return SL_RESULT_SUCCESS;
68 }
69
70 static const struct SLOHBufferQueueItf_ IOHBufferQueueItf = {
71 Enqueue,
72 Clear,
73 GetState,
74 GetBuffer,
75 RegisterCallback
76 };
77
IOHBufferQueueInit(void * self,SLuint32 id)78 void IOHBufferQueueInit(void *self, SLuint32 id)
79 {
80 IOHBufferQueue *thiz = (IOHBufferQueue *) self;
81 thiz->mItf = &IOHBufferQueueItf;
82 thiz->mId = id;
83 thiz->mState = SL_PLAYSTATE_STOPPED;
84 }
85