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 22 static 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 *this = (IPrefetchStatus *) self; 30 interface_lock_peek(this); 31 SLuint32 status = this->mStatus; 32 interface_unlock_peek(this); 33 *pStatus = status; 34 result = SL_RESULT_SUCCESS; 35 } 36 37 SL_LEAVE_INTERFACE 38 } 39 40 41 static 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 *this = (IPrefetchStatus *) self; 49 interface_lock_peek(this); 50 SLpermille level = this->mLevel; 51 interface_unlock_peek(this); 52 *pLevel = level; 53 result = SL_RESULT_SUCCESS; 54 } 55 56 SL_LEAVE_INTERFACE 57 } 58 59 60 static SLresult IPrefetchStatus_RegisterCallback(SLPrefetchStatusItf self, 61 slPrefetchCallback callback, void *pContext) 62 { 63 SL_ENTER_INTERFACE 64 65 IPrefetchStatus *this = (IPrefetchStatus *) self; 66 interface_lock_exclusive(this); 67 this->mCallback = callback; 68 this->mContext = pContext; 69 interface_unlock_exclusive(this); 70 result = SL_RESULT_SUCCESS; 71 72 SL_LEAVE_INTERFACE 73 } 74 75 76 static SLresult IPrefetchStatus_SetCallbackEventsMask(SLPrefetchStatusItf self, SLuint32 eventFlags) 77 { 78 SL_ENTER_INTERFACE 79 80 IPrefetchStatus *this = (IPrefetchStatus *) self; 81 interface_lock_poke(this); 82 this->mCallbackEventsMask = eventFlags; 83 interface_unlock_poke(this); 84 result = SL_RESULT_SUCCESS; 85 86 SL_LEAVE_INTERFACE 87 } 88 89 90 static 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 *this = (IPrefetchStatus *) self; 99 interface_lock_peek(this); 100 SLuint32 callbackEventsMask = this->mCallbackEventsMask; 101 interface_unlock_peek(this); 102 *pEventFlags = callbackEventsMask; 103 result = SL_RESULT_SUCCESS; 104 } 105 106 SL_LEAVE_INTERFACE 107 } 108 109 110 static 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 *this = (IPrefetchStatus *) self; 118 interface_lock_poke(this); 119 this->mFillUpdatePeriod = period; 120 interface_unlock_poke(this); 121 result = SL_RESULT_SUCCESS; 122 } 123 124 SL_LEAVE_INTERFACE 125 } 126 127 128 static SLresult IPrefetchStatus_GetFillUpdatePeriod(SLPrefetchStatusItf self, SLpermille *pPeriod) 129 { 130 SL_ENTER_INTERFACE 131 132 if (NULL == pPeriod) { 133 result = SL_RESULT_PARAMETER_INVALID; 134 } else { 135 IPrefetchStatus *this = (IPrefetchStatus *) self; 136 interface_lock_peek(this); 137 SLpermille fillUpdatePeriod = this->mFillUpdatePeriod; 138 interface_unlock_peek(this); 139 *pPeriod = fillUpdatePeriod; 140 result = SL_RESULT_SUCCESS; 141 } 142 143 SL_LEAVE_INTERFACE 144 } 145 146 147 static const struct SLPrefetchStatusItf_ IPrefetchStatus_Itf = { 148 IPrefetchStatus_GetPrefetchStatus, 149 IPrefetchStatus_GetFillLevel, 150 IPrefetchStatus_RegisterCallback, 151 IPrefetchStatus_SetCallbackEventsMask, 152 IPrefetchStatus_GetCallbackEventsMask, 153 IPrefetchStatus_SetFillUpdatePeriod, 154 IPrefetchStatus_GetFillUpdatePeriod 155 }; 156 157 void IPrefetchStatus_init(void *self) 158 { 159 IPrefetchStatus *this = (IPrefetchStatus *) self; 160 this->mItf = &IPrefetchStatus_Itf; 161 this->mStatus = SL_PREFETCHSTATUS_UNDERFLOW; 162 this->mLevel = 0; 163 this->mCallback = NULL; 164 this->mContext = NULL; 165 this->mCallbackEventsMask = 0; 166 this->mFillUpdatePeriod = 100; 167 } 168