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
SetVolumeLevel(SLVolumeItf self,SLmillibel level)20 static SLresult SetVolumeLevel(SLVolumeItf self, SLmillibel level)
21 {
22 if (self == nullptr) {
23 return SL_RESULT_PARAMETER_INVALID;
24 }
25 IVolume *thiz = (IVolume *)self;
26 AudioPlayerAdapter::GetInstance()->SetVolumeLevelAdapter(thiz->mId, level);
27 return SL_RESULT_SUCCESS;
28 }
29
GetVolumeLevel(SLVolumeItf self,SLmillibel * level)30 static SLresult GetVolumeLevel(SLVolumeItf self, SLmillibel *level)
31 {
32 if (self == nullptr || level == nullptr) {
33 return SL_RESULT_PARAMETER_INVALID;
34 }
35 IVolume *thiz = (IVolume *)self;
36 AudioPlayerAdapter::GetInstance()->GetVolumeLevelAdapter(thiz->mId, level);
37 return SL_RESULT_SUCCESS;
38 }
39
GetMaxVolumeLevel(SLVolumeItf self,SLmillibel * maxLevel)40 static SLresult GetMaxVolumeLevel(SLVolumeItf self, SLmillibel *maxLevel)
41 {
42 if (self == nullptr || maxLevel == nullptr) {
43 return SL_RESULT_PARAMETER_INVALID;
44 }
45 IVolume *thiz = (IVolume *)self;
46 AudioPlayerAdapter::GetInstance()->GetMaxVolumeLevelAdapter(thiz->mId, maxLevel);
47 return SL_RESULT_SUCCESS;
48 }
49
SetMute(SLVolumeItf self,SLboolean state)50 static SLresult SetMute(SLVolumeItf self, SLboolean state)
51 {
52 return SL_RESULT_FEATURE_UNSUPPORTED;
53 }
54
GetMute(SLVolumeItf self,SLboolean * state)55 static SLresult GetMute(SLVolumeItf self, SLboolean *state)
56 {
57 return SL_RESULT_FEATURE_UNSUPPORTED;
58 }
59
EnableStereoPosition(SLVolumeItf self,SLboolean enable)60 static SLresult EnableStereoPosition(SLVolumeItf self, SLboolean enable)
61 {
62 return SL_RESULT_FEATURE_UNSUPPORTED;
63 }
64
IsEnabledStereoPosition(SLVolumeItf self,SLboolean * pEnable)65 static SLresult IsEnabledStereoPosition(SLVolumeItf self, SLboolean *pEnable)
66 {
67 return SL_RESULT_FEATURE_UNSUPPORTED;
68 }
69
SetStereoPosition(SLVolumeItf self,SLpermille stereoPosition)70 static SLresult SetStereoPosition(SLVolumeItf self, SLpermille stereoPosition)
71 {
72 return SL_RESULT_FEATURE_UNSUPPORTED;
73 }
74
GetStereoPosition(SLVolumeItf self,SLpermille * pStereoPosition)75 static SLresult GetStereoPosition(SLVolumeItf self, SLpermille *pStereoPosition)
76 {
77 return SL_RESULT_FEATURE_UNSUPPORTED;
78 }
79
80 static const struct SLVolumeItf_ VolumeItf = {
81 SetVolumeLevel,
82 GetVolumeLevel,
83 GetMaxVolumeLevel,
84 SetMute,
85 GetMute,
86 EnableStereoPosition,
87 IsEnabledStereoPosition,
88 SetStereoPosition,
89 GetStereoPosition
90 };
91
IVolumeInit(void * self,SLuint32 id)92 void IVolumeInit(void *self, SLuint32 id)
93 {
94 IVolume *thiz = (IVolume *) self;
95 thiz->mItf = &VolumeItf;
96 thiz->mId = id;
97 }
98