IPrefetchStatus.c revision 4ee246c55533bdab8ab5fa0f0581744fe58e7c91
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/* PrefetchStatus implementation */
18
19#include "sles_allinclusive.h"
20
21
22static SLresult IPrefetchStatus_GetPrefetchStatus(SLPrefetchStatusItf self, SLuint32 *pStatus)
23{
24    SL_ENTER_INTERFACE
25
26    if (NULL == pStatus) {
27        result = SL_RESULT_PARAMETER_INVALID;
28    } else {
29        IPrefetchStatus *thiz = (IPrefetchStatus *) self;
30        interface_lock_peek(thiz);
31        SLuint32 status = thiz->mStatus;
32        interface_unlock_peek(thiz);
33        *pStatus = status;
34        result = SL_RESULT_SUCCESS;
35    }
36
37    SL_LEAVE_INTERFACE
38}
39
40
41static SLresult IPrefetchStatus_GetFillLevel(SLPrefetchStatusItf self, SLpermille *pLevel)
42{
43    SL_ENTER_INTERFACE
44
45    if (NULL == pLevel) {
46        result = SL_RESULT_PARAMETER_INVALID;
47    } else {
48        IPrefetchStatus *thiz = (IPrefetchStatus *) self;
49        interface_lock_peek(thiz);
50        SLpermille level = thiz->mLevel;
51        interface_unlock_peek(thiz);
52        *pLevel = level;
53        result = SL_RESULT_SUCCESS;
54    }
55
56    SL_LEAVE_INTERFACE
57}
58
59
60static SLresult IPrefetchStatus_RegisterCallback(SLPrefetchStatusItf self,
61    slPrefetchCallback callback, void *pContext)
62{
63    SL_ENTER_INTERFACE
64
65    IPrefetchStatus *thiz = (IPrefetchStatus *) self;
66    interface_lock_exclusive(thiz);
67    thiz->mCallback = callback;
68    thiz->mContext = pContext;
69    interface_unlock_exclusive(thiz);
70    result = SL_RESULT_SUCCESS;
71
72    SL_LEAVE_INTERFACE
73}
74
75
76static SLresult IPrefetchStatus_SetCallbackEventsMask(SLPrefetchStatusItf self, SLuint32 eventFlags)
77{
78    SL_ENTER_INTERFACE
79
80    IPrefetchStatus *thiz = (IPrefetchStatus *) self;
81    interface_lock_poke(thiz);
82    thiz->mCallbackEventsMask = eventFlags;
83    interface_unlock_poke(thiz);
84    result = SL_RESULT_SUCCESS;
85
86    SL_LEAVE_INTERFACE
87}
88
89
90static SLresult IPrefetchStatus_GetCallbackEventsMask(SLPrefetchStatusItf self,
91    SLuint32 *pEventFlags)
92{
93    SL_ENTER_INTERFACE
94
95    if (NULL == pEventFlags) {
96        result = SL_RESULT_PARAMETER_INVALID;
97    } else {
98        IPrefetchStatus *thiz = (IPrefetchStatus *) self;
99        interface_lock_peek(thiz);
100        SLuint32 callbackEventsMask = thiz->mCallbackEventsMask;
101        interface_unlock_peek(thiz);
102        *pEventFlags = callbackEventsMask;
103        result = SL_RESULT_SUCCESS;
104    }
105
106    SL_LEAVE_INTERFACE
107}
108
109
110static SLresult IPrefetchStatus_SetFillUpdatePeriod(SLPrefetchStatusItf self, SLpermille period)
111{
112    SL_ENTER_INTERFACE
113
114    if (0 == period) {
115        result = SL_RESULT_PARAMETER_INVALID;
116    } else {
117        IPrefetchStatus *thiz = (IPrefetchStatus *) self;
118        interface_lock_poke(thiz);
119        thiz->mFillUpdatePeriod = period;
120#ifdef ANDROID
121        if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) {
122            CAudioPlayer *ap = (CAudioPlayer *) thiz->mThis;
123            android_audioPlayer_setBufferingUpdateThresholdPerMille(ap, period);
124        }
125#endif
126        interface_unlock_poke(thiz);
127        result = SL_RESULT_SUCCESS;
128    }
129
130    SL_LEAVE_INTERFACE
131}
132
133
134static SLresult IPrefetchStatus_GetFillUpdatePeriod(SLPrefetchStatusItf self, SLpermille *pPeriod)
135{
136    SL_ENTER_INTERFACE
137
138    if (NULL == pPeriod) {
139        result = SL_RESULT_PARAMETER_INVALID;
140    } else {
141        IPrefetchStatus *thiz = (IPrefetchStatus *) self;
142        interface_lock_peek(thiz);
143        SLpermille fillUpdatePeriod = thiz->mFillUpdatePeriod;
144        interface_unlock_peek(thiz);
145        *pPeriod = fillUpdatePeriod;
146        result = SL_RESULT_SUCCESS;
147    }
148
149    SL_LEAVE_INTERFACE
150}
151
152
153static const struct SLPrefetchStatusItf_ IPrefetchStatus_Itf = {
154    IPrefetchStatus_GetPrefetchStatus,
155    IPrefetchStatus_GetFillLevel,
156    IPrefetchStatus_RegisterCallback,
157    IPrefetchStatus_SetCallbackEventsMask,
158    IPrefetchStatus_GetCallbackEventsMask,
159    IPrefetchStatus_SetFillUpdatePeriod,
160    IPrefetchStatus_GetFillUpdatePeriod
161};
162
163void IPrefetchStatus_init(void *self)
164{
165    IPrefetchStatus *thiz = (IPrefetchStatus *) self;
166    thiz->mItf = &IPrefetchStatus_Itf;
167    thiz->mStatus = SL_PREFETCHSTATUS_UNDERFLOW;
168    thiz->mLevel = 0;
169    thiz->mCallback = NULL;
170    thiz->mContext = NULL;
171    thiz->mCallbackEventsMask = 0;
172    thiz->mFillUpdatePeriod = 100;
173}
174