|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * Video player status monitor definitions, class CStatusMonitor. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // EXTERNAL RESOURCES |
|
22 |
|
23 |
|
24 // Include Files |
|
25 |
|
26 #include "movieprocessorimpl.h" |
|
27 #include "statusmonitor.h" |
|
28 #include "vedmovie.h" |
|
29 |
|
30 |
|
31 // LOCAL CONSTANTS AND MACROS |
|
32 // Debug print macro |
|
33 #if defined _DEBUG |
|
34 #include <e32svr.h> |
|
35 #define PRINT(x) RDebug::Print x; |
|
36 #else |
|
37 #define PRINT(x) |
|
38 #endif |
|
39 |
|
40 |
|
41 // MEMBER FUNCTIONS |
|
42 |
|
43 |
|
44 //============================================================================= |
|
45 |
|
46 |
|
47 |
|
48 /* |
|
49 ----------------------------------------------------------------------------- |
|
50 |
|
51 CStatusMonitor |
|
52 |
|
53 CStatusMonitor() |
|
54 |
|
55 Standard C++ constructor |
|
56 |
|
57 ----------------------------------------------------------------------------- |
|
58 */ |
|
59 |
|
60 CStatusMonitor::CStatusMonitor(MVedMovieProcessingObserver *anObserver, |
|
61 CMovieProcessorImpl *aMovieProcessor, |
|
62 CVedMovie *aMovie, TInt aPriority) |
|
63 : CActive(aPriority) |
|
64 { |
|
65 // Remember the objects |
|
66 iObserver = anObserver; |
|
67 iProcessor = aMovieProcessor; |
|
68 iMovie = aMovie; |
|
69 // Initialize status: |
|
70 |
|
71 iPrepared = EFalse; |
|
72 iPreparing = EFalse; |
|
73 |
|
74 iProcessingStarted = EFalse; |
|
75 iProcessing = EFalse; |
|
76 iClipProcessed = EFalse; |
|
77 iComplete = EFalse; |
|
78 iCancelled = EFalse; |
|
79 iError = KErrNone; |
|
80 iOutError = KErrNone; |
|
81 |
|
82 } |
|
83 |
|
84 |
|
85 |
|
86 /* |
|
87 ----------------------------------------------------------------------------- |
|
88 |
|
89 CStatusMonitor |
|
90 |
|
91 ~CStatusMonitor() |
|
92 |
|
93 Standard C++ destructor |
|
94 |
|
95 ----------------------------------------------------------------------------- |
|
96 */ |
|
97 |
|
98 CStatusMonitor::~CStatusMonitor() |
|
99 { |
|
100 Cancel(); |
|
101 } |
|
102 |
|
103 |
|
104 |
|
105 /* |
|
106 ----------------------------------------------------------------------------- |
|
107 |
|
108 CStatusMonitor |
|
109 |
|
110 ConstructL() |
|
111 |
|
112 Symbian OS second-phase constructor |
|
113 |
|
114 ----------------------------------------------------------------------------- |
|
115 */ |
|
116 |
|
117 void CStatusMonitor::ConstructL() |
|
118 { |
|
119 // Add to active scheduler: |
|
120 CActiveScheduler::Add(this); |
|
121 |
|
122 // Make us active: |
|
123 if (!IsActive()) |
|
124 { |
|
125 SetActive(); |
|
126 iStatus = KRequestPending; |
|
127 } |
|
128 } |
|
129 |
|
130 |
|
131 |
|
132 /* |
|
133 ----------------------------------------------------------------------------- |
|
134 |
|
135 CStatusMonitor |
|
136 |
|
137 Error() |
|
138 |
|
139 An error has occurred |
|
140 |
|
141 ----------------------------------------------------------------------------- |
|
142 */ |
|
143 |
|
144 void CStatusMonitor::Error(TInt anErrorCode) |
|
145 { |
|
146 // Remember the error |
|
147 iError = anErrorCode; |
|
148 |
|
149 #ifndef _DEBUG |
|
150 if (iError < KErrHardwareNotAvailable) |
|
151 iError = KErrGeneral; |
|
152 #endif |
|
153 |
|
154 PRINT((_L("CStatusMonitor::Error() Error = %d "), iError )); |
|
155 |
|
156 // Activate the object: |
|
157 if ( iStatus == KRequestPending ) |
|
158 { |
|
159 TRequestStatus *status = &iStatus; |
|
160 User::RequestComplete(status, KErrNone); |
|
161 } |
|
162 } |
|
163 |
|
164 |
|
165 |
|
166 /* |
|
167 ----------------------------------------------------------------------------- |
|
168 |
|
169 CStatusMonitor |
|
170 |
|
171 StartOpening() |
|
172 |
|
173 The stream opening has been started |
|
174 |
|
175 ----------------------------------------------------------------------------- |
|
176 */ |
|
177 |
|
178 void CStatusMonitor::StartPreparing() |
|
179 { |
|
180 __ASSERT_DEBUG((!iPrepared) && (!iPreparing) && (!iProcessing), |
|
181 User::Panic(_L("CVideoProcessor"), EInvalidStateTransition)); |
|
182 |
|
183 // Note the state change: |
|
184 iPreparing = ETrue; |
|
185 } |
|
186 |
|
187 |
|
188 |
|
189 /* |
|
190 ----------------------------------------------------------------------------- |
|
191 |
|
192 CStatusMonitor |
|
193 |
|
194 Opened() |
|
195 |
|
196 The stream has been opened and it is ready for playback |
|
197 |
|
198 ----------------------------------------------------------------------------- |
|
199 */ |
|
200 |
|
201 void CStatusMonitor::PrepareComplete() |
|
202 { |
|
203 __ASSERT_DEBUG((!iPrepared) && iPreparing && (!iProcessing), |
|
204 User::Panic(_L("CVideoProcessor"), EInvalidStateTransition)); |
|
205 |
|
206 // Note the state change |
|
207 iPrepared = ETrue; |
|
208 iPreparing = EFalse; |
|
209 |
|
210 } |
|
211 |
|
212 void CStatusMonitor::StreamEndReached() |
|
213 { |
|
214 |
|
215 |
|
216 } |
|
217 |
|
218 void CStatusMonitor::Progress(TInt aPercentage) |
|
219 { |
|
220 PRINT((_L("CStatusMonitor::Progress() Progress = %d "), aPercentage )); |
|
221 |
|
222 iObserver->NotifyMovieProcessingProgressed(*iMovie, aPercentage); |
|
223 } |
|
224 |
|
225 /* |
|
226 ----------------------------------------------------------------------------- |
|
227 |
|
228 CStatusMonitor |
|
229 |
|
230 Closed() |
|
231 |
|
232 The stream has been closed |
|
233 |
|
234 ----------------------------------------------------------------------------- |
|
235 */ |
|
236 |
|
237 void CStatusMonitor::Closed() |
|
238 { |
|
239 __ASSERT_DEBUG((iPrepared || iPreparing) && (!iProcessing), |
|
240 User::Panic(_L("CVideoProcessor"), EInvalidStateTransition)); |
|
241 |
|
242 // Note the state change: |
|
243 iPreparing = EFalse; |
|
244 |
|
245 // Do not report a stream open if one had been done |
|
246 iPrepared = EFalse; |
|
247 } |
|
248 |
|
249 |
|
250 |
|
251 /* |
|
252 ----------------------------------------------------------------------------- |
|
253 |
|
254 CStatusMonitor |
|
255 |
|
256 ProcessingStarted() |
|
257 |
|
258 Processing has been started |
|
259 |
|
260 ----------------------------------------------------------------------------- |
|
261 */ |
|
262 |
|
263 void CStatusMonitor::ProcessingStarted(TBool aNotifyObserver) |
|
264 { |
|
265 __ASSERT_DEBUG( (!iProcessing) && (!iProcessingStarted) && (iPrepared), |
|
266 User::Panic(_L("CVideoProcessor"), EInvalidStateTransition)); |
|
267 |
|
268 // Note the state change: |
|
269 iProcessing = ETrue; |
|
270 |
|
271 if (aNotifyObserver) |
|
272 { |
|
273 iProcessingStarted = ETrue; |
|
274 |
|
275 // Activate the object: |
|
276 if ( iStatus == KRequestPending ) |
|
277 { |
|
278 TRequestStatus *status = &iStatus; |
|
279 User::RequestComplete(status, KErrNone); |
|
280 } |
|
281 } |
|
282 } |
|
283 |
|
284 |
|
285 |
|
286 /* |
|
287 ----------------------------------------------------------------------------- |
|
288 |
|
289 CStatusMonitor |
|
290 |
|
291 ProcessingStopped() |
|
292 |
|
293 Processing has been stopped |
|
294 |
|
295 ----------------------------------------------------------------------------- |
|
296 */ |
|
297 |
|
298 void CStatusMonitor::ProcessingStopped() |
|
299 { |
|
300 __ASSERT_DEBUG(iProcessing, |
|
301 User::Panic(_L("CVideoProcessor"), EInvalidStateTransition)); |
|
302 |
|
303 // Note the state change: |
|
304 iProcessing = EFalse; |
|
305 } |
|
306 |
|
307 |
|
308 |
|
309 /* |
|
310 ----------------------------------------------------------------------------- |
|
311 |
|
312 CStatusMonitor |
|
313 |
|
314 ClipProcessed() |
|
315 |
|
316 The video clip end has been reached |
|
317 |
|
318 ----------------------------------------------------------------------------- |
|
319 */ |
|
320 |
|
321 void CStatusMonitor::ClipProcessed() |
|
322 { |
|
323 __ASSERT_DEBUG( (iProcessing), |
|
324 User::Panic(_L("CVideoProcessor"), EInvalidStateTransition)); |
|
325 |
|
326 // Note the stream end: |
|
327 iClipProcessed = ETrue; |
|
328 |
|
329 // Activate the object: |
|
330 if ( iStatus == KRequestPending ) |
|
331 { |
|
332 TRequestStatus *status = &iStatus; |
|
333 User::RequestComplete(status, KErrNone); |
|
334 } |
|
335 } |
|
336 |
|
337 void CStatusMonitor::ProcessingComplete() |
|
338 { |
|
339 __ASSERT_DEBUG((!iProcessing), |
|
340 User::Panic(_L("CVideoProcessor"), EInvalidStateTransition)); |
|
341 |
|
342 // Note the stream end: |
|
343 iComplete = ETrue; |
|
344 |
|
345 // Activate the object: |
|
346 if ( iStatus == KRequestPending ) |
|
347 { |
|
348 TRequestStatus *status = &iStatus; |
|
349 User::RequestComplete(status, KErrNone); |
|
350 } |
|
351 } |
|
352 |
|
353 void CStatusMonitor::ProcessingCancelled() |
|
354 { |
|
355 __ASSERT_DEBUG((!iProcessing), |
|
356 User::Panic(_L("CVideoProcessor"), EInvalidStateTransition)); |
|
357 |
|
358 iCancelled = ETrue; |
|
359 |
|
360 // Activate the object: |
|
361 if ( iStatus == KRequestPending ) |
|
362 { |
|
363 TRequestStatus *status = &iStatus; |
|
364 User::RequestComplete(status, KErrNone); |
|
365 } |
|
366 } |
|
367 |
|
368 |
|
369 |
|
370 /* |
|
371 ----------------------------------------------------------------------------- |
|
372 |
|
373 CStatusMonitor |
|
374 |
|
375 FatalError() |
|
376 |
|
377 A fatal non-recovereable error has occurred |
|
378 |
|
379 ----------------------------------------------------------------------------- |
|
380 */ |
|
381 |
|
382 void CStatusMonitor::FatalError(TInt anError) |
|
383 { |
|
384 PRINT((_L("CStatusMonitor::FatalError Error = %d "), anError )); |
|
385 |
|
386 // Pass the error to the observer |
|
387 iObserver->NotifyMovieProcessingCompleted(*iMovie, anError); |
|
388 |
|
389 // The observer returned -- panic the program |
|
390 User::Panic(_L("CVideoProcessor"), anError); |
|
391 |
|
392 } |
|
393 |
|
394 |
|
395 |
|
396 /* |
|
397 ----------------------------------------------------------------------------- |
|
398 |
|
399 CStatusMonitor |
|
400 |
|
401 RunL() |
|
402 |
|
403 The active object running method, called by the active scheduler when the |
|
404 object has been activated. |
|
405 |
|
406 ----------------------------------------------------------------------------- |
|
407 */ |
|
408 |
|
409 void CStatusMonitor::RunL() |
|
410 { |
|
411 TInt error; |
|
412 |
|
413 // Re-activate us: |
|
414 if (!IsActive()) |
|
415 { |
|
416 SetActive(); |
|
417 iStatus = KRequestPending; |
|
418 } |
|
419 |
|
420 // Check if an error occurred: |
|
421 if ( iError != KErrNone ) |
|
422 { |
|
423 // Yes, stop processing if we are processing, close stream if it was open: |
|
424 if ( iProcessing ) |
|
425 { |
|
426 if ( iProcessor ) |
|
427 { |
|
428 iProcessor->CancelProcessingL(); |
|
429 } |
|
430 iProcessing = EFalse; |
|
431 } |
|
432 else |
|
433 { |
|
434 if ( iPrepared || iPreparing ) |
|
435 { |
|
436 if ( iProcessor ) |
|
437 { |
|
438 iProcessor->CancelProcessingL(); |
|
439 } |
|
440 iPreparing = EFalse; |
|
441 iPrepared = EFalse; |
|
442 } |
|
443 } |
|
444 |
|
445 // Report the error to the observer: |
|
446 //iObserver->NotifyMovieProcessingCompleted(*iMovie, iError); |
|
447 iOutError = iError; |
|
448 iError = KErrNone; |
|
449 |
|
450 |
|
451 } |
|
452 |
|
453 else |
|
454 { |
|
455 // Nope, no errors |
|
456 |
|
457 // If processing has been started, report that: |
|
458 if ( iProcessingStarted ) |
|
459 { |
|
460 iProcessingStarted = EFalse; |
|
461 TRAP(error, iObserver->NotifyMovieProcessingStartedL(*iMovie)); |
|
462 if ( error != KErrNone ) |
|
463 FatalError(error); |
|
464 } |
|
465 else if ( iCancelled ) |
|
466 { |
|
467 // processing has been cancelled |
|
468 iCancelled = EFalse; |
|
469 iComplete = EFalse; |
|
470 iClipProcessed = EFalse; |
|
471 |
|
472 if ( iOutError == KErrNone ) |
|
473 iObserver->NotifyMovieProcessingCompleted(*iMovie, KErrCancel); |
|
474 else |
|
475 iObserver->NotifyMovieProcessingCompleted(*iMovie, iOutError); |
|
476 |
|
477 iOutError = KErrNone; |
|
478 |
|
479 } |
|
480 |
|
481 else if ( iClipProcessed ) |
|
482 { |
|
483 // a clip has been processed |
|
484 iClipProcessed = EFalse; |
|
485 iProcessor->FinalizeVideoClip(); |
|
486 } |
|
487 |
|
488 else |
|
489 { |
|
490 if ( iComplete ) |
|
491 { |
|
492 // If the movie has been completed, report that: |
|
493 iComplete = EFalse; |
|
494 iObserver->NotifyMovieProcessingCompleted(*iMovie, KErrNone); |
|
495 |
|
496 } |
|
497 } |
|
498 } |
|
499 } |
|
500 |
|
501 |
|
502 |
|
503 /* |
|
504 ----------------------------------------------------------------------------- |
|
505 |
|
506 CStatusMonitor |
|
507 |
|
508 DoCancel() |
|
509 |
|
510 Cancels the internal request |
|
511 |
|
512 ----------------------------------------------------------------------------- |
|
513 */ |
|
514 |
|
515 void CStatusMonitor::DoCancel() |
|
516 { |
|
517 // Cancel it: |
|
518 TRequestStatus *status = &iStatus; |
|
519 User::RequestComplete(status, KErrCancel); |
|
520 } |
|
521 |
|
522 |
|
523 |
|
524 |
|
525 // OTHER EXPORTED FUNCTIONS |
|
526 |
|
527 |
|
528 //============================================================================= |
|
529 |
|
530 |
|
531 // End of File |