19
|
1 |
/*
|
25
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Handles marker timer implementation
|
|
15 |
*
|
|
16 |
*/
|
19
|
17 |
|
|
18 |
#include "markerpositiontimer.h"
|
|
19 |
#include <mdaaudiosampleplayer.h>
|
|
20 |
#include <videoplayer2.h>
|
|
21 |
#include <e32math.h>
|
|
22 |
|
25
|
23 |
extern "C"
|
|
24 |
{
|
19
|
25 |
#include "xarecorditfadaptationmmf.h"
|
25
|
26 |
}
|
19
|
27 |
|
|
28 |
#define RET_ERR_IF_ERR(s) if (s!=KErrNone) return s;
|
|
29 |
#define RET_IF_ERR(s) if (s!=KErrNone) return;
|
|
30 |
|
|
31 |
CMarkerPositionTimer::CMarkerPositionTimer(
|
|
32 |
CMdaAudioPlayerUtility* aAudioPlayer,
|
25
|
33 |
CVideoPlayerUtility2* aVideoPlayer) :
|
|
34 |
CActive(CActive::EPriorityStandard), iAudioPlayer(aAudioPlayer),
|
|
35 |
iVideoPlayer(aVideoPlayer)
|
19
|
36 |
{
|
|
37 |
CActiveScheduler::Add(this);
|
|
38 |
}
|
|
39 |
|
|
40 |
CMarkerPositionTimer::~CMarkerPositionTimer()
|
|
41 |
{
|
|
42 |
Cancel();
|
|
43 |
iTimer.Close();
|
|
44 |
}
|
|
45 |
|
|
46 |
CMarkerPositionTimer* CMarkerPositionTimer::NewL(
|
|
47 |
CMdaAudioPlayerUtility* aAudioPlayer,
|
|
48 |
CVideoPlayerUtility2* aVideoPlayer)
|
|
49 |
{
|
25
|
50 |
CMarkerPositionTimer* self = new (ELeave) CMarkerPositionTimer(
|
|
51 |
aAudioPlayer, aVideoPlayer);
|
19
|
52 |
CleanupStack::PushL(self);
|
|
53 |
self->ConstructL();
|
|
54 |
CleanupStack::Pop(self);
|
|
55 |
return self;
|
|
56 |
}
|
|
57 |
|
|
58 |
void CMarkerPositionTimer::ConstructL()
|
|
59 |
{
|
25
|
60 |
User::LeaveIfError(iTimer.CreateLocal());
|
19
|
61 |
}
|
|
62 |
|
|
63 |
void CMarkerPositionTimer::SetContext(TAny* aCtx)
|
|
64 |
{
|
25
|
65 |
iCtx = aCtx;
|
19
|
66 |
}
|
|
67 |
|
|
68 |
void CMarkerPositionTimer::SetMarkerPosition(XAmillisecond aMarkerPos)
|
|
69 |
{
|
|
70 |
iMarkerPosition = aMarkerPos;
|
|
71 |
}
|
|
72 |
|
|
73 |
void CMarkerPositionTimer::SetCallbackEventMask(XAuint32 aMask)
|
|
74 |
{
|
|
75 |
iCallbackEventMask = aMask;
|
|
76 |
}
|
|
77 |
|
|
78 |
void CMarkerPositionTimer::RegisterCallback(xaPlayCallback aCallback)
|
|
79 |
{
|
|
80 |
iCallback = aCallback;
|
|
81 |
}
|
|
82 |
|
|
83 |
void CMarkerPositionTimer::UseAudioPlayer()
|
|
84 |
{
|
25
|
85 |
iPlayerToUse = static_cast<CBase*> (iAudioPlayer);
|
19
|
86 |
}
|
|
87 |
void CMarkerPositionTimer::UseVideoPlayer()
|
|
88 |
{
|
25
|
89 |
iPlayerToUse = static_cast<CBase*> (iVideoPlayer);
|
19
|
90 |
}
|
|
91 |
|
|
92 |
void CMarkerPositionTimer::ResetPlayer()
|
|
93 |
{
|
|
94 |
iPlayerToUse = NULL;
|
|
95 |
}
|
|
96 |
|
|
97 |
TInt CMarkerPositionTimer::Start()
|
|
98 |
{
|
|
99 |
TInt retVal(KErrNone);
|
|
100 |
if (IsActive())
|
|
101 |
{
|
|
102 |
Cancel();
|
|
103 |
}
|
25
|
104 |
if ((iMarkerPosition != XA_TIME_UNKNOWN) && (iCallbackEventMask
|
|
105 |
& XA_PLAYEVENT_HEADATMARKER) && iCallback && iPlayerToUse)
|
19
|
106 |
{
|
|
107 |
TTimeIntervalMicroSeconds32 delay;
|
|
108 |
/* Convert milli to micro */
|
|
109 |
TTimeIntervalMicroSeconds markerPos(iMarkerPosition * 1000);
|
|
110 |
TReal res;
|
|
111 |
TReal p;
|
|
112 |
TReal q(markerPos.Int64());
|
|
113 |
|
|
114 |
iSyncToPlayHead = ETrue;
|
|
115 |
|
|
116 |
retVal = GetCurrentPlayPosition(iSyncToPlayHeadStartPos);
|
|
117 |
RET_ERR_IF_ERR(retVal);
|
|
118 |
|
|
119 |
p = iSyncToPlayHeadStartPos.Int64();
|
|
120 |
/* Adjust delay based on current play position
|
|
121 |
* user may call this in the middle of playback */
|
|
122 |
retVal = Math::Mod(res, p, q);
|
|
123 |
RET_ERR_IF_ERR(retVal);
|
|
124 |
|
|
125 |
/* Let the timer go off early and then re-adjust
|
|
126 |
* the remaining time based on then current position */
|
|
127 |
delay = (markerPos.Int64() - res) / 2;
|
|
128 |
#ifdef MARKERPOSITIONTIMERLOG
|
|
129 |
// Keep this block for debugging purposes
|
|
130 |
RDebug::Print(_L("CMarkerPositionTimer::RunL:SyncPlayHead[%u]Delay Reset[%u]microSec"),
|
|
131 |
iSyncToPlayHeadStartPos.Int64(),
|
|
132 |
delay.Int());
|
|
133 |
#endif /* MARKERPOSITIONTIMERLOG */
|
25
|
134 |
if (delay >= TTimeIntervalMicroSeconds32(0))
|
19
|
135 |
{
|
|
136 |
iStatus = KRequestPending;
|
|
137 |
iTimer.After(iStatus, delay);
|
|
138 |
SetActive();
|
|
139 |
}
|
|
140 |
}
|
|
141 |
return retVal;
|
|
142 |
}
|
|
143 |
|
|
144 |
void CMarkerPositionTimer::Stop()
|
|
145 |
{
|
|
146 |
Cancel();
|
|
147 |
}
|
|
148 |
|
|
149 |
void CMarkerPositionTimer::RunL()
|
|
150 |
{
|
|
151 |
TInt retVal(KErrNone);
|
|
152 |
/* Make sure some of the attributes are not unset */
|
25
|
153 |
if ((iStatus == KErrNone) && iCtx && (iMarkerPosition != XA_TIME_UNKNOWN)
|
|
154 |
&& (iCallbackEventMask & XA_PLAYEVENT_HEADATMARKER) && iCallback
|
|
155 |
&& iPlayerToUse)
|
19
|
156 |
{
|
|
157 |
TTimeIntervalMicroSeconds curPlayPos;
|
|
158 |
if (iSyncToPlayHead)
|
|
159 |
{
|
|
160 |
retVal = GetCurrentPlayPosition(curPlayPos);
|
|
161 |
RET_IF_ERR(retVal);
|
|
162 |
|
|
163 |
/* If the play head hasn't moved, re-start all over again */
|
|
164 |
if (curPlayPos == iSyncToPlayHeadStartPos)
|
|
165 |
{
|
|
166 |
#ifdef MARKERPOSITIONTIMERLOG
|
25
|
167 |
RDebug::Print(_L("CMarkerPositionTimer::RunL:CurPlayPos[%u]SyncPlayHead[%u]microSec. Restart"),
|
|
168 |
iSyncToPlayHeadStartPos.Int64(),
|
|
169 |
curPlayPos.Int64());
|
19
|
170 |
#endif /* MARKERPOSITIONTIMERLOG */
|
|
171 |
Start();
|
|
172 |
return;
|
|
173 |
}
|
|
174 |
/* Play head has moved. calculate remaining time and set the timer */
|
|
175 |
/* Convert milli to micro */
|
|
176 |
TTimeIntervalMicroSeconds markerPos(iMarkerPosition * 1000);
|
|
177 |
TReal res;
|
|
178 |
TReal p;
|
|
179 |
TReal q(markerPos.Int64());
|
|
180 |
|
|
181 |
p = curPlayPos.Int64();
|
|
182 |
iSyncToPlayHead = EFalse;
|
|
183 |
|
|
184 |
retVal = Math::Mod(res, p, q);
|
|
185 |
RET_IF_ERR(retVal);
|
|
186 |
|
|
187 |
TTimeIntervalMicroSeconds32 delay = (markerPos.Int64() - res);
|
|
188 |
#ifdef MARKERPOSITIONTIMERLOG
|
|
189 |
RDebug::Print(_L("CMarkerPositionTimer::RunL:CurPlayPos[%u]SyncPlayHead[%u]Delay Reset[%u]microSec"),
|
|
190 |
iSyncToPlayHeadStartPos.Int64(),
|
|
191 |
curPlayPos.Int64(),
|
|
192 |
delay.Int());
|
|
193 |
#endif /* MARKERPOSITIONTIMERLOG */
|
25
|
194 |
if (delay >= TTimeIntervalMicroSeconds32(0))
|
19
|
195 |
{
|
|
196 |
iStatus = KRequestPending;
|
|
197 |
iTimer.After(iStatus, delay);
|
|
198 |
SetActive();
|
|
199 |
}
|
|
200 |
return;
|
|
201 |
} /* of if (iSyncToPlayHead) */
|
|
202 |
|
|
203 |
#ifdef MARKERPOSITIONTIMERLOG
|
|
204 |
retVal = GetCurrentPlayPosition(curPlayPos);
|
|
205 |
RDebug::Print(_L("CMarkerPositionTimer::RunL:CurPlayPos[%u]microSec. Posting XA_PLAYEVENT_HEADATMARKER."), curPlayPos.Int64());
|
|
206 |
#endif /* MARKERPOSITIONTIMERLOG */
|
25
|
207 |
XAAdaptEvent xaevent =
|
|
208 |
{
|
|
209 |
XA_PLAYITFEVENTS, XA_PLAYEVENT_HEADATMARKER, 0, 0
|
|
210 |
};
|
|
211 |
XAAdaptationBase_SendAdaptEvents((XAAdaptationBaseCtx*) iCtx,
|
|
212 |
&xaevent);
|
19
|
213 |
}
|
|
214 |
}
|
|
215 |
|
|
216 |
void CMarkerPositionTimer::DoCancel()
|
|
217 |
{
|
|
218 |
iTimer.Cancel();
|
|
219 |
}
|
|
220 |
|
|
221 |
TInt CMarkerPositionTimer::RunError(TInt /*aError*/)
|
|
222 |
{
|
|
223 |
return KErrNone;
|
|
224 |
}
|
|
225 |
|
25
|
226 |
TInt CMarkerPositionTimer::GetCurrentPlayPosition(
|
|
227 |
TTimeIntervalMicroSeconds& aPos)
|
19
|
228 |
{
|
|
229 |
TTimeIntervalMicroSeconds pos;
|
|
230 |
TInt err(KErrNone);
|
|
231 |
if (iPlayerToUse == iAudioPlayer)
|
|
232 |
{
|
|
233 |
iAudioPlayer->GetPosition(aPos);
|
|
234 |
}
|
|
235 |
else if (iPlayerToUse == iVideoPlayer)
|
|
236 |
{
|
|
237 |
TRAP(err, aPos = iVideoPlayer->PositionL());
|
|
238 |
}
|
|
239 |
return err;
|
|
240 |
}
|