|
1 /* |
|
2 * Copyright (c) 2008 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 the License "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: Class for following and updating download progress.* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <mpxmedia.h> |
|
22 #include <mpxmediaarray.h> |
|
23 #include <mpxmediageneraldefs.h> |
|
24 |
|
25 #include "IptvDebug.h" |
|
26 #include <vcxmyvideosdefs.h> |
|
27 |
|
28 #include "vcxhgmyvideosdownloadupdater.h" |
|
29 #include "vcxhgmyvideosvideolist.h" |
|
30 #include "vcxhgmyvideosvideomodelhandler.h" |
|
31 #include "vcxhgmyvideospanics.h" |
|
32 |
|
33 // CONSTANTS |
|
34 const TInt KVcxHgUpdateDelay = 2500000; // 2,5 seconds |
|
35 |
|
36 // ========================== MEMBER FUNCTIONS =============================== |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // CVcxHgMyVideosDownloadUpdater::CVcxHgMyVideosDownloadUpdater() |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CVcxHgMyVideosDownloadUpdater::CVcxHgMyVideosDownloadUpdater( |
|
43 CVcxHgMyVideosVideoModelHandler& aParent, |
|
44 CVcxHgMyVideosVideoList& aVideoArray ) |
|
45 : iParent( aParent ), |
|
46 iVideoArray( aVideoArray ) |
|
47 { |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CVcxHgMyVideosDownloadUpdater::ConstructL() |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 void CVcxHgMyVideosDownloadUpdater::ConstructL() |
|
55 { |
|
56 iTimer = CPeriodic::NewL( EPriorityNormal ); |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CVcxHgMyVideosDownloadUpdater::NewL() |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CVcxHgMyVideosDownloadUpdater* CVcxHgMyVideosDownloadUpdater::NewL( |
|
64 CVcxHgMyVideosVideoModelHandler& aParent, |
|
65 CVcxHgMyVideosVideoList& aVideoArray ) |
|
66 { |
|
67 CVcxHgMyVideosDownloadUpdater* self = |
|
68 new( ELeave ) CVcxHgMyVideosDownloadUpdater( aParent, aVideoArray ); |
|
69 CleanupStack::PushL( self ); |
|
70 self->ConstructL(); |
|
71 CleanupStack::Pop( self ); |
|
72 return self; |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // CVcxHgMyVideosDownloadUpdater::~CVcxHgMyVideosDownloadUpdater() |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 CVcxHgMyVideosDownloadUpdater::~CVcxHgMyVideosDownloadUpdater() |
|
80 { |
|
81 if( iTimer ) |
|
82 { |
|
83 iTimer->Cancel(); |
|
84 } |
|
85 delete iTimer; |
|
86 iDownloadArray.Close(); |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CVcxHgMyVideosDownloadUpdater::VideoArrayChangedL() |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 void CVcxHgMyVideosDownloadUpdater::VideoArrayChangedL() |
|
94 { |
|
95 IPTVLOGSTRING_LOW_LEVEL( |
|
96 "MPX My Videos UI # CVcxHgMyVideosDownloadUpdater::VideoArrayChangedL()" ); |
|
97 |
|
98 ResetDownloadsToFollowL(); |
|
99 ContinueToFollowDownloads(); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CVcxHgMyVideosDownloadUpdater::VideoModifiedL() |
|
104 // |
|
105 // Note: Currently expects and handles only aEventType == EMPXItemModified. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 void CVcxHgMyVideosDownloadUpdater::VideoModifiedL( TMPXChangeEventType /*aEventType*/, |
|
109 TMPXItemId aMpxItemId, |
|
110 TInt32 /*aExtraInfo*/ ) |
|
111 { |
|
112 CMPXMedia* media = NULL; |
|
113 |
|
114 // If object is on download array, check if download has completed. |
|
115 for ( TInt i = 0; i < iDownloadArray.Count(); i++ ) |
|
116 { |
|
117 media = iDownloadArray[i].iMedia; |
|
118 |
|
119 if ( media->IsSupported( KMPXMediaGeneralId ) ) |
|
120 { |
|
121 if ( aMpxItemId == media->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) ) |
|
122 { |
|
123 TBool remove( EFalse ); |
|
124 |
|
125 if ( ! media->IsSupported( KVcxMediaMyVideosDownloadId ) || |
|
126 ! media->IsSupported( KVcxMediaMyVideosDownloadState ) ) |
|
127 { |
|
128 remove = ETrue; |
|
129 } |
|
130 else if ( *( media->Value<TUint32>( KVcxMediaMyVideosDownloadId ) ) == 0 ) |
|
131 { |
|
132 remove = ETrue; |
|
133 } |
|
134 else |
|
135 { |
|
136 TVcxMyVideosDownloadState state = static_cast<TVcxMyVideosDownloadState>( |
|
137 *( media->Value<TUint8>( KVcxMediaMyVideosDownloadState ) ) ); |
|
138 |
|
139 if ( state == EVcxMyVideosDlStateNone || |
|
140 state == EVcxMyVideosDlStateDownloaded ) |
|
141 { |
|
142 remove = ETrue; |
|
143 } |
|
144 } |
|
145 |
|
146 if ( remove ) |
|
147 { |
|
148 iDownloadArray.Remove( i ); |
|
149 } |
|
150 |
|
151 return; |
|
152 } |
|
153 } |
|
154 } |
|
155 |
|
156 // If object was not on download array, check if it should be added. |
|
157 media = iVideoArray.MPXMediaByMPXItemId( aMpxItemId ); |
|
158 |
|
159 if ( media && FindDownload( media ) == KErrNotFound ) |
|
160 { |
|
161 if ( media->IsSupported( KVcxMediaMyVideosDownloadId ) && |
|
162 media->IsSupported( KVcxMediaMyVideosDownloadState ) ) |
|
163 { |
|
164 // Download ID is non-zero if download status exists. |
|
165 if ( *( media->Value<TUint32>( KVcxMediaMyVideosDownloadId ) ) != 0 ) |
|
166 { |
|
167 TVcxMyVideosDownloadState state( EVcxMyVideosDlStateNone ); |
|
168 |
|
169 state = static_cast<TVcxMyVideosDownloadState>( |
|
170 *( media->Value<TUint8>( KVcxMediaMyVideosDownloadState ) ) ); |
|
171 |
|
172 if ( state == EVcxMyVideosDlStateDownloading || |
|
173 state == EVcxMyVideosDlStateFailed || |
|
174 state == EVcxMyVideosDlStatePaused ) |
|
175 { |
|
176 TDownloadItem item; |
|
177 item.iMedia = media; |
|
178 item.iProgress = 0; |
|
179 item.iState = state; |
|
180 item.iProgressivePlayQueried = EFalse; |
|
181 item.iIsPlayPossible = EFalse; |
|
182 iDownloadArray.AppendL( item ); |
|
183 } |
|
184 } |
|
185 } |
|
186 } |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // CVcxHgMyVideosDownloadUpdater::IsPlayPossible() |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 TBool CVcxHgMyVideosDownloadUpdater::IsPlayPossible( TInt aIndex ) |
|
194 { |
|
195 IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # CVcxHgMyVideosDownloadUpdater::IsPlayPossible" ); |
|
196 |
|
197 TInt dlIndex( KErrNotFound ); |
|
198 CMPXMedia* media = iVideoArray.MPXMedia( aIndex ); |
|
199 |
|
200 if ( ! media ) |
|
201 { |
|
202 return EFalse; |
|
203 } |
|
204 |
|
205 TInt count( iDownloadArray.Count() ); |
|
206 for ( TInt i = 0; i < count; i++ ) |
|
207 { |
|
208 // Compare pointers as they are the same in this case, and fast to use. |
|
209 if ( media == iDownloadArray[i].iMedia ) |
|
210 { |
|
211 dlIndex = i; |
|
212 break; |
|
213 } |
|
214 } |
|
215 |
|
216 if ( dlIndex != KErrNotFound ) |
|
217 { |
|
218 // These two lines make sure that class starts to follow availability |
|
219 // of progressive play, if it is not being followed yet. |
|
220 iDownloadArray[dlIndex].iProgressivePlayQueried = ETrue; |
|
221 ContinueToFollowDownloads(); |
|
222 |
|
223 iDownloadArray[dlIndex].iIsPlayPossible = |
|
224 ( iDownloadArray[dlIndex].iMedia->ValueTObjectL<TInt8>( KVcxMediaMyVideosDownloadProgress ) > 0 && |
|
225 iDownloadArray[dlIndex].iMedia->ValueText( KMPXMediaGeneralUri ).Length() > 0 ); |
|
226 |
|
227 // Return the response immediately, as it is needed from use cases like |
|
228 // DynInitMenuPaneL(). Real status will be updated |
|
229 // to UI asynchronously when background timer has checked the playability. |
|
230 return iDownloadArray[dlIndex].iIsPlayPossible; |
|
231 } |
|
232 |
|
233 return EFalse; |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CVcxHgMyVideosDownloadUpdater::SetPausedL() |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 void CVcxHgMyVideosDownloadUpdater::SetPausedL( TBool aPaused ) |
|
241 { |
|
242 IPTVLOGSTRING2_LOW_LEVEL( |
|
243 "MPX My Videos UI # CVcxHgMyVideosDownloadUpdater::SetPausedL(%d)", aPaused ); |
|
244 |
|
245 iPaused = aPaused; |
|
246 |
|
247 ContinueToFollowDownloads(); |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------------------------- |
|
251 // CVcxHgMyVideosDownloadUpdater::RemoveDownload() |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 void CVcxHgMyVideosDownloadUpdater::RemoveDownload( TMPXItemId aMPXItemId ) |
|
255 { |
|
256 CMPXMedia* media( NULL ); |
|
257 media = iVideoArray.MPXMediaByMPXItemId( aMPXItemId ); |
|
258 |
|
259 if ( media ) |
|
260 { |
|
261 TInt index( KErrNotFound ); |
|
262 index = FindDownload( media ); |
|
263 |
|
264 if ( index != KErrNotFound ) |
|
265 { |
|
266 iDownloadArray.Remove( index ); |
|
267 } |
|
268 |
|
269 if ( iDownloadArray.Count() < 1 ) |
|
270 { |
|
271 iTimer->Cancel(); |
|
272 } |
|
273 } |
|
274 } |
|
275 |
|
276 // --------------------------------------------------------------------------- |
|
277 // CVcxHgMyVideosDownloadUpdater::FindDownload() |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 TInt CVcxHgMyVideosDownloadUpdater::FindDownload( CMPXMedia* aMedia ) |
|
281 { |
|
282 TInt index( KErrNotFound ); |
|
283 |
|
284 if ( aMedia ) |
|
285 { |
|
286 for ( TInt i = iDownloadArray.Count() - 1; i >= 0; i-- ) |
|
287 { |
|
288 if ( iDownloadArray[i].iMedia->Match( *aMedia, KMPXMediaGeneralId ) ) |
|
289 { |
|
290 index = i; |
|
291 break; |
|
292 } |
|
293 } |
|
294 } |
|
295 return index; |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------------------------- |
|
299 // CVcxHgMyVideosDownloadUpdater::ContinueToFollowDownloads() |
|
300 // --------------------------------------------------------------------------- |
|
301 // |
|
302 void CVcxHgMyVideosDownloadUpdater::ContinueToFollowDownloads() |
|
303 { |
|
304 if ( iPaused || iDownloadArray.Count() == 0 ) |
|
305 { |
|
306 if ( iTimer->IsActive() ) |
|
307 { |
|
308 iTimer->Cancel(); |
|
309 } |
|
310 } |
|
311 else |
|
312 { |
|
313 if ( ! iTimer->IsActive() ) |
|
314 { |
|
315 TCallBack callback = TCallBack( Callback, this ); |
|
316 const TTimeIntervalMicroSeconds32 KUpdateInterval( KVcxHgUpdateDelay ); |
|
317 iTimer->Start( KUpdateInterval, KUpdateInterval, callback ); |
|
318 } |
|
319 } |
|
320 } |
|
321 |
|
322 // --------------------------------------------------------------------------- |
|
323 // CVcxHgMyVideosDownloadUpdater::ResetDownloadsToFollowL() |
|
324 // --------------------------------------------------------------------------- |
|
325 // |
|
326 void CVcxHgMyVideosDownloadUpdater::ResetDownloadsToFollowL() |
|
327 { |
|
328 iDownloadArray.Reset(); |
|
329 |
|
330 TVcxMyVideosDownloadState state( EVcxMyVideosDlStateNone ); |
|
331 TDownloadItem item; |
|
332 CMPXMedia* media = NULL; |
|
333 TInt count( iVideoArray.VideoCount() ); |
|
334 |
|
335 for ( TInt i = 0; i < count; i++ ) |
|
336 { |
|
337 media = iVideoArray.MPXMedia( i ); |
|
338 |
|
339 if ( media && |
|
340 media->IsSupported( KVcxMediaMyVideosDownloadId ) && |
|
341 media->IsSupported( KVcxMediaMyVideosDownloadState ) ) |
|
342 { |
|
343 // Download ID is non-zero if download status exists. |
|
344 if ( *( media->Value<TUint32>( KVcxMediaMyVideosDownloadId ) ) != 0 ) |
|
345 { |
|
346 state = static_cast<TVcxMyVideosDownloadState>( |
|
347 *( media->Value<TUint8>( KVcxMediaMyVideosDownloadState ) ) ); |
|
348 |
|
349 if ( state == EVcxMyVideosDlStateDownloading || |
|
350 state == EVcxMyVideosDlStateFailed || |
|
351 state == EVcxMyVideosDlStatePaused ) |
|
352 { |
|
353 item.iMedia = media; |
|
354 item.iProgress = 0; |
|
355 item.iState = state; |
|
356 item.iProgressivePlayQueried = EFalse; |
|
357 item.iIsPlayPossible = EFalse; |
|
358 iDownloadArray.AppendL( item ); |
|
359 |
|
360 IPTVLOGSTRING3_LOW_LEVEL( |
|
361 "MPX My Videos UI # Download to follow: Id:%d, State:%d", |
|
362 static_cast<TInt>( |
|
363 media->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) ), |
|
364 static_cast<TInt>( |
|
365 media->ValueTObjectL<TUint8>( KVcxMediaMyVideosDownloadState ) ) ); |
|
366 } |
|
367 } |
|
368 } |
|
369 } |
|
370 } |
|
371 |
|
372 // --------------------------------------------------------------------------- |
|
373 // CVcxHgMyVideosDownloadUpdater::Callback() |
|
374 // --------------------------------------------------------------------------- |
|
375 // |
|
376 TInt CVcxHgMyVideosDownloadUpdater::Callback( TAny *aPtr ) |
|
377 { |
|
378 CVcxHgMyVideosDownloadUpdater* ptr = static_cast<CVcxHgMyVideosDownloadUpdater*>( aPtr ); |
|
379 TRAP_IGNORE( ptr->UpdateDownloadsL() ); |
|
380 return 0; |
|
381 } |
|
382 |
|
383 // --------------------------------------------------------------------------- |
|
384 // CVcxHgMyVideosDownloadUpdater::UpdateDownloadsL() |
|
385 // --------------------------------------------------------------------------- |
|
386 // |
|
387 void CVcxHgMyVideosDownloadUpdater::UpdateDownloadsL() |
|
388 { |
|
389 for ( TInt i = 0; i < iDownloadArray.Count(); i++ ) |
|
390 { |
|
391 UpdateDownloadL( iDownloadArray[i] ); |
|
392 } |
|
393 } |
|
394 |
|
395 // --------------------------------------------------------------------------- |
|
396 // CVcxHgMyVideosDownloadUpdater::UpdateDownloadL() |
|
397 // --------------------------------------------------------------------------- |
|
398 // |
|
399 void CVcxHgMyVideosDownloadUpdater::UpdateDownloadL( TDownloadItem& aItem ) |
|
400 { |
|
401 TBool itemChanged( EFalse ); |
|
402 |
|
403 // Check download progress. |
|
404 TVcxMyVideosDownloadState state = static_cast<TVcxMyVideosDownloadState>( |
|
405 aItem.iMedia->ValueTObjectL<TUint8>( KVcxMediaMyVideosDownloadState ) ); |
|
406 TInt8 progress = aItem.iMedia->ValueTObjectL<TInt8>( KVcxMediaMyVideosDownloadProgress ); |
|
407 |
|
408 if ( progress == 0 && aItem.iProgress > 0 ) |
|
409 { |
|
410 IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # UpdateDownloadL() Resume started from beginning." ); |
|
411 TUint32 mpxId = aItem.iMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ).iId1; |
|
412 iParent.ResumeStartedFromBeginningL( mpxId ); |
|
413 } |
|
414 if ( state != aItem.iState || progress != aItem.iProgress ) |
|
415 { |
|
416 aItem.iState = state; |
|
417 aItem.iProgress = progress; |
|
418 itemChanged = ETrue; |
|
419 } |
|
420 |
|
421 // Progressive playback check is needed in two cases: |
|
422 // 1) It has been queried by user and old status is EFalse, in this case the status |
|
423 // has not been check ever yet. |
|
424 // 2) Progress has changed, and old status is EFalse. In this case we might have |
|
425 // received enough data to support progressive play. |
|
426 if ( ( aItem.iProgressivePlayQueried && ! aItem.iIsPlayPossible ) || |
|
427 ( itemChanged && ! aItem.iIsPlayPossible ) ) |
|
428 { |
|
429 aItem.iProgressivePlayQueried = EFalse; |
|
430 |
|
431 if ( aItem.iMedia->ValueTObjectL<TInt8>( KVcxMediaMyVideosDownloadProgress ) > 0 && |
|
432 aItem.iMedia->ValueText( KMPXMediaGeneralUri ).Length() > 0 ) |
|
433 { |
|
434 aItem.iIsPlayPossible = ETrue; |
|
435 } |
|
436 |
|
437 if ( aItem.iIsPlayPossible ) |
|
438 { |
|
439 itemChanged = ETrue; |
|
440 } |
|
441 } |
|
442 |
|
443 IPTVLOGSTRING4_LOW_LEVEL( |
|
444 "MPX My Videos UI # UpdateDownloadL() Id:%d State:%d Progress:%d", |
|
445 static_cast<TInt>( aItem.iMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) ), |
|
446 static_cast<TInt>( state ), static_cast<TInt>( progress ) ); |
|
447 IPTVLOGSTRING3_LOW_LEVEL( |
|
448 "MPX My Videos UI # UpdateDownloadL() Path:%S Progressive Play:%d", |
|
449 &( aItem.iMedia->ValueText( KMPXMediaGeneralUri ) ), |
|
450 static_cast<TInt>( aItem.iIsPlayPossible ) ); |
|
451 |
|
452 if ( itemChanged ) |
|
453 { |
|
454 iParent.VideoModifiedL( |
|
455 EMPXItemModified, |
|
456 aItem.iMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ), |
|
457 EVcxMyVideosListNoInfo, |
|
458 ETrue ); // Mark event as simulated, not originated from MPX Collection. |
|
459 } |
|
460 } |