|
1 /* |
|
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 new position timer implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "prefetchlevelupdatetimer.h" |
|
19 #include <mdaaudiosampleplayer.h> |
|
20 #include <mdaaudiosampleplayer.h> |
|
21 #include <videoplayer2.h> |
|
22 #include <e32math.h> |
|
23 |
|
24 extern "C" |
|
25 { |
|
26 #include "xaadaptationmmf.h" |
|
27 } |
|
28 |
|
29 #define RET_ERR_IF_ERR(s) if (s!=KErrNone) return s; |
|
30 #define RET_IF_ERR(s) if (s!=KErrNone) return; |
|
31 |
|
32 CPrefetchLevelUpdateTimer::CPrefetchLevelUpdateTimer( CMdaAudioPlayerUtility* aAudioPlayer, |
|
33 CVideoPlayerUtility2* aVideoPlayer) : |
|
34 CActive(CActive::EPriorityStandard), |
|
35 iAudioPlayer(aAudioPlayer), |
|
36 iVideoPlayer(aVideoPlayer), |
|
37 iNotifyIncrement(10), |
|
38 iLastIncrement(0) |
|
39 { |
|
40 CActiveScheduler::Add(this); |
|
41 } |
|
42 |
|
43 CPrefetchLevelUpdateTimer::~CPrefetchLevelUpdateTimer() |
|
44 { |
|
45 Cancel(); |
|
46 iTimer.Close(); |
|
47 } |
|
48 |
|
49 CPrefetchLevelUpdateTimer* CPrefetchLevelUpdateTimer::NewL( CMdaAudioPlayerUtility* aAudioPlayer, |
|
50 CVideoPlayerUtility2* aVideoPlayer) |
|
51 { |
|
52 CPrefetchLevelUpdateTimer* self = new (ELeave) CPrefetchLevelUpdateTimer(aAudioPlayer,aVideoPlayer); |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop(self); |
|
56 return self; |
|
57 } |
|
58 |
|
59 void CPrefetchLevelUpdateTimer::ConstructL() |
|
60 { |
|
61 User::LeaveIfError(iTimer.CreateLocal()); |
|
62 } |
|
63 |
|
64 void CPrefetchLevelUpdateTimer::SetContext(TAny* aCtx) |
|
65 { |
|
66 iCtx = aCtx; |
|
67 } |
|
68 |
|
69 void CPrefetchLevelUpdateTimer::SetCallbackEventMask(XAuint32 aMask) |
|
70 { |
|
71 iCallbackEventMask = aMask; |
|
72 } |
|
73 |
|
74 void CPrefetchLevelUpdateTimer::SetPrefetchLevelUpdatePeriod(XAmillisecond aPos) |
|
75 { |
|
76 iUpdatePeriod = TTimeIntervalMicroSeconds32(aPos * 1000); |
|
77 } |
|
78 |
|
79 void CPrefetchLevelUpdateTimer::SetUpdateIncrement(XApermille inc) |
|
80 { |
|
81 if(0<=inc && inc<=1000) |
|
82 { |
|
83 iNotifyIncrement = inc / 10; |
|
84 } |
|
85 } |
|
86 |
|
87 void CPrefetchLevelUpdateTimer::UseAudioPlayer() |
|
88 { |
|
89 iPlayerToUse = static_cast<CBase*> (iAudioPlayer); |
|
90 } |
|
91 void CPrefetchLevelUpdateTimer::UseVideoPlayer() |
|
92 { |
|
93 iPlayerToUse = static_cast<CBase*> (iVideoPlayer); |
|
94 } |
|
95 |
|
96 void CPrefetchLevelUpdateTimer::ResetPlayer() |
|
97 { |
|
98 iPlayerToUse = NULL; |
|
99 } |
|
100 |
|
101 void CPrefetchLevelUpdateTimer::Start() |
|
102 { |
|
103 if (IsActive()) |
|
104 { |
|
105 Cancel(); |
|
106 } |
|
107 |
|
108 SendFillLevelChangeEvent(); //send a fill level change event (0%) right away |
|
109 iLastIncrement = 0; |
|
110 |
|
111 |
|
112 iStatus = KRequestPending; |
|
113 iTimer.After(iStatus, iUpdatePeriod); |
|
114 SetActive(); |
|
115 } |
|
116 |
|
117 void CPrefetchLevelUpdateTimer::Stop() |
|
118 { |
|
119 if (IsActive()) |
|
120 { |
|
121 SendFillLevelChangeEvent(); //send a fill level change event (100%) |
|
122 } |
|
123 |
|
124 Cancel(); |
|
125 iLastIncrement = 0; |
|
126 } |
|
127 |
|
128 void CPrefetchLevelUpdateTimer::RunL() |
|
129 { |
|
130 if ((iStatus == KErrNone) && iPlayerToUse) |
|
131 { |
|
132 TInt progress = 0; |
|
133 if(GetLoadingProgress(progress) == KErrNone) |
|
134 { |
|
135 if(progress==100) |
|
136 { |
|
137 Stop(); |
|
138 } |
|
139 else if(progress >= (iLastIncrement + iNotifyIncrement)) |
|
140 { |
|
141 SendFillLevelChangeEvent(); |
|
142 iLastIncrement = progress - (progress % iNotifyIncrement); |
|
143 } |
|
144 } |
|
145 } |
|
146 |
|
147 iStatus = KRequestPending; |
|
148 iTimer.After(iStatus, iUpdatePeriod); |
|
149 SetActive(); |
|
150 } |
|
151 |
|
152 void CPrefetchLevelUpdateTimer::DoCancel() |
|
153 { |
|
154 iTimer.Cancel(); |
|
155 } |
|
156 |
|
157 TInt CPrefetchLevelUpdateTimer::RunError(TInt aError) |
|
158 { |
|
159 return aError; |
|
160 } |
|
161 |
|
162 TInt CPrefetchLevelUpdateTimer::GetLoadingProgress(TInt& progress) |
|
163 { |
|
164 TInt err(KErrNone); |
|
165 if (iPlayerToUse && (iPlayerToUse == iAudioPlayer)) |
|
166 { |
|
167 //TRAP(err, iAudioPlayer->GetAudioLoadingProgressL(progress)); |
|
168 //always retrun 100 for audio |
|
169 progress = 100; |
|
170 } |
|
171 else if (iPlayerToUse && (iPlayerToUse == iVideoPlayer)) |
|
172 { |
|
173 TRAP(err, iVideoPlayer->GetVideoLoadingProgressL(progress)); |
|
174 } |
|
175 else |
|
176 { |
|
177 err = KErrNotFound; |
|
178 } |
|
179 |
|
180 return err; |
|
181 } |
|
182 |
|
183 void CPrefetchLevelUpdateTimer::SendFillLevelChangeEvent() |
|
184 { |
|
185 if(iCallbackEventMask & XA_PREFETCHEVENT_FILLLEVELCHANGE) |
|
186 { |
|
187 //use callback to send progress |
|
188 XAAdaptEvent xaevent = |
|
189 { |
|
190 XA_PREFETCHITFEVENTS, XA_PREFETCHEVENT_FILLLEVELCHANGE, 0, 0 |
|
191 }; |
|
192 |
|
193 XAAdaptationBase_SendAdaptEvents((XAAdaptationBaseCtx*) iCtx, &xaevent); |
|
194 } |
|
195 |
|
196 } |
|
197 |
|
198 |