ISeek.cpp revision 0b167267bda99b68346045ccab14e810121d5de4
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/* Seek implementation */ 18 19#include "sles_allinclusive.h" 20 21static SLresult ISeek_SetPosition(SLSeekItf self, SLmillisecond pos, 22 SLuint32 seekMode) 23{ 24 switch (seekMode) { 25 case SL_SEEKMODE_FAST: 26 case SL_SEEKMODE_ACCURATE: 27 break; 28 default: 29 return SL_RESULT_PARAMETER_INVALID; 30 } 31 ISeek *this = (ISeek *) self; 32 interface_lock_poke(this); 33 this->mPos = pos; 34 interface_unlock_poke(this); 35 return SL_RESULT_SUCCESS; 36} 37 38static SLresult ISeek_SetLoop(SLSeekItf self, SLboolean loopEnable, 39 SLmillisecond startPos, SLmillisecond endPos) 40{ 41 ISeek *this = (ISeek *) self; 42 interface_lock_exclusive(this); 43 this->mLoopEnabled = loopEnable; 44 this->mStartPos = startPos; 45 this->mEndPos = endPos; 46 interface_unlock_exclusive(this); 47 return SL_RESULT_SUCCESS; 48} 49 50static SLresult ISeek_GetLoop(SLSeekItf self, SLboolean *pLoopEnabled, 51 SLmillisecond *pStartPos, SLmillisecond *pEndPos) 52{ 53 if (NULL == pLoopEnabled || NULL == pStartPos || NULL == pEndPos) 54 return SL_RESULT_PARAMETER_INVALID; 55 ISeek *this = (ISeek *) self; 56 interface_lock_shared(this); 57 SLboolean loopEnabled = this->mLoopEnabled; 58 SLmillisecond startPos = this->mStartPos; 59 SLmillisecond endPos = this->mEndPos; 60 interface_unlock_shared(this); 61 *pLoopEnabled = loopEnabled; 62 *pStartPos = startPos; 63 *pEndPos = endPos; 64 return SL_RESULT_SUCCESS; 65} 66 67static const struct SLSeekItf_ ISeek_Itf = { 68 ISeek_SetPosition, 69 ISeek_SetLoop, 70 ISeek_GetLoop 71}; 72 73void ISeek_init(void *self) 74{ 75 ISeek *this = (ISeek *) self; 76 this->mItf = &ISeek_Itf; 77 this->mPos = (SLmillisecond) -1; 78 this->mStartPos = (SLmillisecond) -1; 79 this->mEndPos = (SLmillisecond) -1; 80#ifndef NDEBUG 81 this->mLoopEnabled = SL_BOOLEAN_FALSE; 82#endif 83} 84