2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 /* Seek implementation */
19 #include "sles_allinclusive.h"
22 static SLresult ISeek_SetPosition(SLSeekItf self, SLmillisecond pos, SLuint32 seekMode)
27 case SL_SEEKMODE_FAST:
28 case SL_SEEKMODE_ACCURATE:
30 // maximum position is a special value that indicates a seek is not pending
31 if (SL_TIME_UNKNOWN == pos) {
32 pos = SL_TIME_UNKNOWN - 1;
34 ISeek *this = (ISeek *) self;
35 interface_lock_exclusive(this);
37 // at this point the seek is merely pending, so do not yet update other fields
38 interface_unlock_exclusive_attributes(this, ATTR_POSITION);
39 result = SL_RESULT_SUCCESS;
43 result = SL_RESULT_PARAMETER_INVALID;
51 static SLresult ISeek_SetLoop(SLSeekItf self, SLboolean loopEnable,
52 SLmillisecond startPos, SLmillisecond endPos)
56 if (!(startPos < endPos)) {
57 result = SL_RESULT_PARAMETER_INVALID;
59 ISeek *this = (ISeek *) self;
60 interface_lock_exclusive(this);
62 if ((startPos != 0) && (endPos != SL_TIME_UNKNOWN)) {
63 result = SL_RESULT_FEATURE_UNSUPPORTED;
65 this->mLoopEnabled = SL_BOOLEAN_FALSE != loopEnable; // normalize
66 // start and end positions already initialized to [0, end of stream]
67 /*this->mStartPos = 0;
68 this->mEndPos = (SLmillisecond) SL_TIME_UNKNOWN;*/
69 CAudioPlayer *ap = InterfaceToCAudioPlayer(this);
71 android_audioPlayer_loop(ap, loopEnable);
73 result = SL_RESULT_SUCCESS;
76 this->mLoopEnabled = SL_BOOLEAN_FALSE != loopEnable; // normalize
77 this->mStartPos = startPos;
78 this->mEndPos = endPos;
79 result = SL_RESULT_SUCCESS;
81 interface_unlock_exclusive(this);
88 static SLresult ISeek_GetLoop(SLSeekItf self, SLboolean *pLoopEnabled,
89 SLmillisecond *pStartPos, SLmillisecond *pEndPos)
93 if (NULL == pLoopEnabled || NULL == pStartPos || NULL == pEndPos) {
94 result = SL_RESULT_PARAMETER_INVALID;
96 ISeek *this = (ISeek *) self;
97 interface_lock_shared(this);
98 SLboolean loopEnabled = this->mLoopEnabled;
99 SLmillisecond startPos = this->mStartPos;
100 SLmillisecond endPos = this->mEndPos;
101 interface_unlock_shared(this);
102 *pLoopEnabled = loopEnabled;
103 *pStartPos = startPos;
105 result = SL_RESULT_SUCCESS;
112 static const struct SLSeekItf_ ISeek_Itf = {
118 void ISeek_init(void *self)
120 ISeek *this = (ISeek *) self;
121 this->mItf = &ISeek_Itf;
122 this->mPos = (SLmillisecond) SL_TIME_UNKNOWN;
123 this->mStartPos = (SLmillisecond) 0;
124 this->mEndPos = (SLmillisecond) SL_TIME_UNKNOWN;
125 this->mLoopEnabled = SL_BOOLEAN_FALSE;