1 /* |
1 /* |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: Handles marker timer implementation |
14 * Description: Handles marker timer implementation |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "markerpositiontimer.h" |
18 #include "markerpositiontimer.h" |
19 #include <mdaaudiosampleplayer.h> |
19 #include <mdaaudiosampleplayer.h> |
20 #include <videoplayer2.h> |
20 #include <videoplayer2.h> |
21 #include <e32math.h> |
21 #include <e32math.h> |
22 |
22 |
23 extern "C" { |
23 extern "C" |
|
24 { |
24 #include "xarecorditfadaptationmmf.h" |
25 #include "xarecorditfadaptationmmf.h" |
25 } |
26 } |
26 |
27 |
27 #define RET_ERR_IF_ERR(s) if (s!=KErrNone) return s; |
28 #define RET_ERR_IF_ERR(s) if (s!=KErrNone) return s; |
28 #define RET_IF_ERR(s) if (s!=KErrNone) return; |
29 #define RET_IF_ERR(s) if (s!=KErrNone) return; |
29 |
30 |
30 CMarkerPositionTimer::CMarkerPositionTimer( |
31 CMarkerPositionTimer::CMarkerPositionTimer( |
31 CMdaAudioPlayerUtility* aAudioPlayer, |
32 CMdaAudioPlayerUtility* aAudioPlayer, |
32 CVideoPlayerUtility2* aVideoPlayer) |
33 CVideoPlayerUtility2* aVideoPlayer) : |
33 :CActive(CActive::EPriorityStandard), |
34 CActive(CActive::EPriorityStandard), iAudioPlayer(aAudioPlayer), |
34 iAudioPlayer(aAudioPlayer), |
35 iVideoPlayer(aVideoPlayer) |
35 iVideoPlayer(aVideoPlayer) |
|
36 { |
36 { |
37 CActiveScheduler::Add(this); |
37 CActiveScheduler::Add(this); |
38 } |
38 } |
39 |
39 |
40 CMarkerPositionTimer::~CMarkerPositionTimer() |
40 CMarkerPositionTimer::~CMarkerPositionTimer() |
45 |
45 |
46 CMarkerPositionTimer* CMarkerPositionTimer::NewL( |
46 CMarkerPositionTimer* CMarkerPositionTimer::NewL( |
47 CMdaAudioPlayerUtility* aAudioPlayer, |
47 CMdaAudioPlayerUtility* aAudioPlayer, |
48 CVideoPlayerUtility2* aVideoPlayer) |
48 CVideoPlayerUtility2* aVideoPlayer) |
49 { |
49 { |
50 CMarkerPositionTimer* self = new (ELeave)CMarkerPositionTimer(aAudioPlayer, aVideoPlayer); |
50 CMarkerPositionTimer* self = new (ELeave) CMarkerPositionTimer( |
|
51 aAudioPlayer, aVideoPlayer); |
51 CleanupStack::PushL(self); |
52 CleanupStack::PushL(self); |
52 self->ConstructL(); |
53 self->ConstructL(); |
53 CleanupStack::Pop(self); |
54 CleanupStack::Pop(self); |
54 return self; |
55 return self; |
55 } |
56 } |
56 |
57 |
57 void CMarkerPositionTimer::ConstructL() |
58 void CMarkerPositionTimer::ConstructL() |
58 { |
59 { |
59 User::LeaveIfError(iTimer.CreateLocal()); |
60 User::LeaveIfError(iTimer.CreateLocal()); |
60 } |
61 } |
61 |
62 |
62 void CMarkerPositionTimer::SetContext(TAny* aCtx) |
63 void CMarkerPositionTimer::SetContext(TAny* aCtx) |
63 { |
64 { |
64 iCtx = aCtx; |
65 iCtx = aCtx; |
65 } |
66 } |
66 |
67 |
67 void CMarkerPositionTimer::SetMarkerPosition(XAmillisecond aMarkerPos) |
68 void CMarkerPositionTimer::SetMarkerPosition(XAmillisecond aMarkerPos) |
68 { |
69 { |
69 iMarkerPosition = aMarkerPos; |
70 iMarkerPosition = aMarkerPos; |
79 iCallback = aCallback; |
80 iCallback = aCallback; |
80 } |
81 } |
81 |
82 |
82 void CMarkerPositionTimer::UseAudioPlayer() |
83 void CMarkerPositionTimer::UseAudioPlayer() |
83 { |
84 { |
84 iPlayerToUse = static_cast<CBase*>(iAudioPlayer); |
85 iPlayerToUse = static_cast<CBase*> (iAudioPlayer); |
85 } |
86 } |
86 void CMarkerPositionTimer::UseVideoPlayer() |
87 void CMarkerPositionTimer::UseVideoPlayer() |
87 { |
88 { |
88 iPlayerToUse = static_cast<CBase*>(iVideoPlayer); |
89 iPlayerToUse = static_cast<CBase*> (iVideoPlayer); |
89 } |
90 } |
90 |
91 |
91 void CMarkerPositionTimer::ResetPlayer() |
92 void CMarkerPositionTimer::ResetPlayer() |
92 { |
93 { |
93 iPlayerToUse = NULL; |
94 iPlayerToUse = NULL; |
98 TInt retVal(KErrNone); |
99 TInt retVal(KErrNone); |
99 if (IsActive()) |
100 if (IsActive()) |
100 { |
101 { |
101 Cancel(); |
102 Cancel(); |
102 } |
103 } |
103 if ((iMarkerPosition != XA_TIME_UNKNOWN) && |
104 if ((iMarkerPosition != XA_TIME_UNKNOWN) && (iCallbackEventMask |
104 (iCallbackEventMask & XA_PLAYEVENT_HEADATMARKER) && |
105 & XA_PLAYEVENT_HEADATMARKER) && iCallback && iPlayerToUse) |
105 iCallback && |
|
106 iPlayerToUse) |
|
107 { |
106 { |
108 TTimeIntervalMicroSeconds32 delay; |
107 TTimeIntervalMicroSeconds32 delay; |
109 /* Convert milli to micro */ |
108 /* Convert milli to micro */ |
110 TTimeIntervalMicroSeconds markerPos(iMarkerPosition * 1000); |
109 TTimeIntervalMicroSeconds markerPos(iMarkerPosition * 1000); |
111 TReal res; |
110 TReal res; |
130 // Keep this block for debugging purposes |
129 // Keep this block for debugging purposes |
131 RDebug::Print(_L("CMarkerPositionTimer::RunL:SyncPlayHead[%u]Delay Reset[%u]microSec"), |
130 RDebug::Print(_L("CMarkerPositionTimer::RunL:SyncPlayHead[%u]Delay Reset[%u]microSec"), |
132 iSyncToPlayHeadStartPos.Int64(), |
131 iSyncToPlayHeadStartPos.Int64(), |
133 delay.Int()); |
132 delay.Int()); |
134 #endif /* MARKERPOSITIONTIMERLOG */ |
133 #endif /* MARKERPOSITIONTIMERLOG */ |
135 if ( delay >= TTimeIntervalMicroSeconds32(0)) |
134 if (delay >= TTimeIntervalMicroSeconds32(0)) |
136 { |
135 { |
137 iStatus = KRequestPending; |
136 iStatus = KRequestPending; |
138 iTimer.After(iStatus, delay); |
137 iTimer.After(iStatus, delay); |
139 SetActive(); |
138 SetActive(); |
140 } |
139 } |
149 |
148 |
150 void CMarkerPositionTimer::RunL() |
149 void CMarkerPositionTimer::RunL() |
151 { |
150 { |
152 TInt retVal(KErrNone); |
151 TInt retVal(KErrNone); |
153 /* Make sure some of the attributes are not unset */ |
152 /* Make sure some of the attributes are not unset */ |
154 if ((iStatus == KErrNone) && |
153 if ((iStatus == KErrNone) && iCtx && (iMarkerPosition != XA_TIME_UNKNOWN) |
155 iCtx && |
154 && (iCallbackEventMask & XA_PLAYEVENT_HEADATMARKER) && iCallback |
156 (iMarkerPosition != XA_TIME_UNKNOWN) && |
155 && iPlayerToUse) |
157 (iCallbackEventMask & XA_PLAYEVENT_HEADATMARKER) && |
|
158 iCallback && |
|
159 iPlayerToUse) |
|
160 { |
156 { |
161 TTimeIntervalMicroSeconds curPlayPos; |
157 TTimeIntervalMicroSeconds curPlayPos; |
162 if (iSyncToPlayHead) |
158 if (iSyncToPlayHead) |
163 { |
159 { |
164 retVal = GetCurrentPlayPosition(curPlayPos); |
160 retVal = GetCurrentPlayPosition(curPlayPos); |
166 |
162 |
167 /* If the play head hasn't moved, re-start all over again */ |
163 /* If the play head hasn't moved, re-start all over again */ |
168 if (curPlayPos == iSyncToPlayHeadStartPos) |
164 if (curPlayPos == iSyncToPlayHeadStartPos) |
169 { |
165 { |
170 #ifdef MARKERPOSITIONTIMERLOG |
166 #ifdef MARKERPOSITIONTIMERLOG |
171 RDebug::Print(_L("CMarkerPositionTimer::RunL:CurPlayPos[%u]SyncPlayHead[%u]microSec. Restart"), |
167 RDebug::Print(_L("CMarkerPositionTimer::RunL:CurPlayPos[%u]SyncPlayHead[%u]microSec. Restart"), |
172 iSyncToPlayHeadStartPos.Int64(), |
168 iSyncToPlayHeadStartPos.Int64(), |
173 curPlayPos.Int64()); |
169 curPlayPos.Int64()); |
174 #endif /* MARKERPOSITIONTIMERLOG */ |
170 #endif /* MARKERPOSITIONTIMERLOG */ |
175 Start(); |
171 Start(); |
176 return; |
172 return; |
177 } |
173 } |
178 /* Play head has moved. calculate remaining time and set the timer */ |
174 /* Play head has moved. calculate remaining time and set the timer */ |
193 RDebug::Print(_L("CMarkerPositionTimer::RunL:CurPlayPos[%u]SyncPlayHead[%u]Delay Reset[%u]microSec"), |
189 RDebug::Print(_L("CMarkerPositionTimer::RunL:CurPlayPos[%u]SyncPlayHead[%u]Delay Reset[%u]microSec"), |
194 iSyncToPlayHeadStartPos.Int64(), |
190 iSyncToPlayHeadStartPos.Int64(), |
195 curPlayPos.Int64(), |
191 curPlayPos.Int64(), |
196 delay.Int()); |
192 delay.Int()); |
197 #endif /* MARKERPOSITIONTIMERLOG */ |
193 #endif /* MARKERPOSITIONTIMERLOG */ |
198 if ( delay >= TTimeIntervalMicroSeconds32(0)) |
194 if (delay >= TTimeIntervalMicroSeconds32(0)) |
199 { |
195 { |
200 iStatus = KRequestPending; |
196 iStatus = KRequestPending; |
201 iTimer.After(iStatus, delay); |
197 iTimer.After(iStatus, delay); |
202 SetActive(); |
198 SetActive(); |
203 } |
199 } |
206 |
202 |
207 #ifdef MARKERPOSITIONTIMERLOG |
203 #ifdef MARKERPOSITIONTIMERLOG |
208 retVal = GetCurrentPlayPosition(curPlayPos); |
204 retVal = GetCurrentPlayPosition(curPlayPos); |
209 RDebug::Print(_L("CMarkerPositionTimer::RunL:CurPlayPos[%u]microSec. Posting XA_PLAYEVENT_HEADATMARKER."), curPlayPos.Int64()); |
205 RDebug::Print(_L("CMarkerPositionTimer::RunL:CurPlayPos[%u]microSec. Posting XA_PLAYEVENT_HEADATMARKER."), curPlayPos.Int64()); |
210 #endif /* MARKERPOSITIONTIMERLOG */ |
206 #endif /* MARKERPOSITIONTIMERLOG */ |
211 XAAdaptEvent xaevent = {XA_PLAYITFEVENTS, XA_PLAYEVENT_HEADATMARKER, 0, 0 }; |
207 XAAdaptEvent xaevent = |
212 XAAdaptationBase_SendAdaptEvents((XAAdaptationBaseCtx*)iCtx, &xaevent ); |
208 { |
|
209 XA_PLAYITFEVENTS, XA_PLAYEVENT_HEADATMARKER, 0, 0 |
|
210 }; |
|
211 XAAdaptationBase_SendAdaptEvents((XAAdaptationBaseCtx*) iCtx, |
|
212 &xaevent); |
213 } |
213 } |
214 } |
214 } |
215 |
215 |
216 void CMarkerPositionTimer::DoCancel() |
216 void CMarkerPositionTimer::DoCancel() |
217 { |
217 { |