1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /* RatePitch implementation */
18 
19 #include "sles_allinclusive.h"
20 
21 
IRatePitch_SetRate(SLRatePitchItf self,SLpermille rate)22 static SLresult IRatePitch_SetRate(SLRatePitchItf self, SLpermille rate)
23 {
24     SL_ENTER_INTERFACE
25 
26     IRatePitch *thiz = (IRatePitch *) self;
27     if (!(thiz->mMinRate <= rate && rate <= thiz->mMaxRate)) {
28         result = SL_RESULT_PARAMETER_INVALID;
29     } else {
30         interface_lock_poke(thiz);
31         thiz->mRate = rate;
32         interface_unlock_poke(thiz);
33         result = SL_RESULT_SUCCESS;
34     }
35 
36     SL_LEAVE_INTERFACE
37 }
38 
39 
IRatePitch_GetRate(SLRatePitchItf self,SLpermille * pRate)40 static SLresult IRatePitch_GetRate(SLRatePitchItf self, SLpermille *pRate)
41 {
42     SL_ENTER_INTERFACE
43 
44     if (NULL == pRate) {
45         result = SL_RESULT_PARAMETER_INVALID;
46     } else {
47         IRatePitch *thiz = (IRatePitch *) self;
48         interface_lock_peek(thiz);
49         SLpermille rate = thiz->mRate;
50         interface_unlock_peek(thiz);
51         *pRate = rate;
52         result = SL_RESULT_SUCCESS;
53     }
54 
55     SL_LEAVE_INTERFACE
56 }
57 
58 
IRatePitch_GetRatePitchCapabilities(SLRatePitchItf self,SLpermille * pMinRate,SLpermille * pMaxRate)59 static SLresult IRatePitch_GetRatePitchCapabilities(SLRatePitchItf self,
60     SLpermille *pMinRate, SLpermille *pMaxRate)
61 {
62     SL_ENTER_INTERFACE
63 
64     // per spec, each is optional, and does not require that at least one must be non-NULL
65 #if 0
66     if (NULL == pMinRate && NULL == pMaxRate)
67         result = SL_RESULT_PARAMETER_INVALID;
68 #endif
69     IRatePitch *thiz = (IRatePitch *) self;
70     // const, so no lock required
71     SLpermille minRate = thiz->mMinRate;
72     SLpermille maxRate = thiz->mMaxRate;
73     if (NULL != pMinRate)
74         *pMinRate = minRate;
75     if (NULL != pMaxRate)
76         *pMaxRate = maxRate;
77     result = SL_RESULT_SUCCESS;
78 
79     SL_LEAVE_INTERFACE
80 }
81 
82 
83 static const struct SLRatePitchItf_ IRatePitch_Itf = {
84     IRatePitch_SetRate,
85     IRatePitch_GetRate,
86     IRatePitch_GetRatePitchCapabilities
87 };
88 
IRatePitch_init(void * self)89 void IRatePitch_init(void *self)
90 {
91     IRatePitch *thiz = (IRatePitch *) self;
92     thiz->mItf = &IRatePitch_Itf;
93     thiz->mRate = 1000;
94     // const
95     thiz->mMinRate = 500;
96     thiz->mMaxRate = 2000;
97 }
98