36 self->ConstructL(); |
36 self->ConstructL(); |
37 return self; |
37 return self; |
38 } |
38 } |
39 |
39 |
40 CMMAVideoPlayer::~CMMAVideoPlayer() |
40 CMMAVideoPlayer::~CMMAVideoPlayer() |
41 { |
41 { |
42 LOG(EJavaMMAPI,EInfo, "MMA::CMMAVideoPlayer::~CMMAVideoPlayer" ); |
42 LOG(EJavaMMAPI,EInfo, "MMA::CMMAVideoPlayer::~CMMAVideoPlayer"); |
43 |
43 |
44 // Window is not able to send any |
44 // Window is not able to send any |
45 // callback requests to UI from now. |
45 // callback requests to UI from now. |
46 if (iSurfaceWindow) |
46 if (iSurfaceWindow) |
47 { |
47 { |
48 iSurfaceWindow->SetDisplay(NULL); |
48 iSurfaceWindow->SetDisplay(NULL); |
49 } |
49 } |
50 |
50 |
51 if ( iDisplay && iDisplay->HasContainer() ) |
51 if (iDisplay && iDisplay->HasContainer()) |
52 { |
52 { |
53 // Window will delete itself |
53 // Window will delete itself |
54 // after all pending events are processed |
54 // after all pending events are processed |
55 // (lazy delete) |
55 // (lazy delete) |
56 // iDisplay->UIGetCallback( |
56 // iDisplay->UIGetCallback( |
57 // *iSurfaceWindow, CMMASurfaceWindow::EDestroyWindow ); |
57 // *iSurfaceWindow, CMMASurfaceWindow::EDestroyWindow ); |
58 iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::EDestroyWindow ); |
58 iDisplay->GetCallbackInUiThread((TInt)CMMASurfaceWindow::EDestroyWindow); |
59 } |
59 } |
60 else |
60 else |
61 { |
61 { |
62 delete iSurfaceWindow; |
62 delete iSurfaceWindow; |
63 } |
63 } |
64 |
64 |
112 |
112 |
113 EXPORT_C void CMMAVideoPlayer::SetDisplayL(MMMADisplay* aDisplay) |
113 EXPORT_C void CMMAVideoPlayer::SetDisplayL(MMMADisplay* aDisplay) |
114 { |
114 { |
115 // now it is ready to draw |
115 // now it is ready to draw |
116 iDisplay = aDisplay; |
116 iDisplay = aDisplay; |
117 iDisplay->SetWindowL( iSurfaceWindow ); |
117 iDisplay->SetWindowL(iSurfaceWindow); |
118 iSurfaceWindow->SetDisplay( aDisplay ); |
118 iSurfaceWindow->SetDisplay(aDisplay); |
119 iDisplay->SetUIPlayer(this); |
119 iDisplay->SetUIPlayer(this); |
120 |
120 |
121 |
121 |
122 /* |
122 /* |
123 // if state < prefeteched then we dont know actual source size yet |
123 // if state < prefeteched then we dont know actual source size yet |
124 // and it will be set after prefetch |
124 // and it will be set after prefetch |
125 if ( iState >= EPrefetched ) |
125 if ( iState >= EPrefetched ) |
126 { |
126 { |
127 SourceSizeChanged(); |
127 SourceSizeChanged(); |
128 } |
128 } |
129 */ |
129 */ |
130 } |
130 } |
131 void CMMAVideoPlayer::RealizeL() |
131 void CMMAVideoPlayer::RealizeL() |
132 { |
132 { |
133 LOG( EJavaMMAPI, EInfo, "CMMAVideoPlayer::RealizeL" ); |
133 LOG(EJavaMMAPI, EInfo, "CMMAVideoPlayer::RealizeL"); |
134 // DataSource must have at least 1 stream or |
134 // DataSource must have at least 1 stream or |
135 // we must have file to play |
135 // we must have file to play |
136 if ((iSourceStreams.Count() == 0) && !iFileName) |
136 if ((iSourceStreams.Count() == 0) && !iFileName) |
137 { |
137 { |
138 User::Leave(KErrNotEnoughStreams); |
138 User::Leave(KErrNotEnoughStreams); |
241 { |
241 { |
242 // free Surface |
242 // free Surface |
243 TInt error = iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(iMMASurface.iPrevSurfaceId); |
243 TInt error = iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(iMMASurface.iPrevSurfaceId); |
244 if (KErrNone != error) |
244 if (KErrNone != error) |
245 { |
245 { |
246 ELOG1( EJavaMMAPI, "CMMAVideoPlayer::HandleEvent:SurfaceRemoved error, %d", aEvent.iErrorCode); |
246 ELOG1(EJavaMMAPI, "CMMAVideoPlayer::HandleEvent:SurfaceRemoved error, %d", aEvent.iErrorCode); |
247 } |
247 } |
248 } |
248 } |
249 iMMASurface.iPrevSurfaceId = surfaceId; |
249 iMMASurface.iPrevSurfaceId = surfaceId; |
250 iMMASurface.iPrevSurfaceAvailable = ETrue; |
250 iMMASurface.iPrevSurfaceAvailable = ETrue; |
251 |
251 |
252 iSurfaceWindow->SetSurfaceParameters(surfaceId, |
252 iSurfaceWindow->SetSurfaceParameters(surfaceId, |
253 cropRect, |
253 cropRect, |
254 pixelAspectRatio); |
254 pixelAspectRatio); |
255 |
255 |
256 LOG( EJavaMMAPI, EInfo, "CMMAVideoPlayer::HandleEvent: KMMFEventCategoryVideoSurfaceCreated, surface parameters set" ); |
256 LOG(EJavaMMAPI, EInfo, "CMMAVideoPlayer::HandleEvent: KMMFEventCategoryVideoSurfaceCreated, surface parameters set"); |
257 } |
257 } |
258 else |
258 else |
259 { |
259 { |
260 ELOG1( EJavaMMAPI, "CMMAVideoPlayer::HandleEvent: error getting surface parameters, %d", aEvent.iErrorCode ); |
260 ELOG1(EJavaMMAPI, "CMMAVideoPlayer::HandleEvent: error getting surface parameters, %d", aEvent.iErrorCode); |
261 } |
261 } |
262 } |
262 } |
263 else if (aEvent.iEventType == KMMFEventCategoryVideoSurfaceParametersChanged) |
263 else if (aEvent.iEventType == KMMFEventCategoryVideoSurfaceParametersChanged) |
264 { |
264 { |
265 if (aEvent.iErrorCode == KErrNone) |
265 if (aEvent.iErrorCode == KErrNone) |
276 { |
276 { |
277 // free Surface |
277 // free Surface |
278 TInt error = iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(iMMASurface.iPrevSurfaceId); |
278 TInt error = iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(iMMASurface.iPrevSurfaceId); |
279 if (KErrNone != error) |
279 if (KErrNone != error) |
280 { |
280 { |
281 LOG1( EJavaMMAPI, EInfo, "CMMAVideoPlayer::HandleEvent:SurfaceRemoved error, %d", aEvent.iErrorCode); |
281 LOG1(EJavaMMAPI, EInfo, "CMMAVideoPlayer::HandleEvent:SurfaceRemoved error, %d", aEvent.iErrorCode); |
282 } |
282 } |
283 } |
283 } |
284 iMMASurface.iPrevSurfaceAvailable = ETrue; |
284 iMMASurface.iPrevSurfaceAvailable = ETrue; |
285 iMMASurface.iPrevSurfaceId = surfaceId; |
285 iMMASurface.iPrevSurfaceId = surfaceId; |
286 |
286 |
287 iSurfaceWindow->SetChangedSurfaceParameters(surfaceId, |
287 iSurfaceWindow->SetChangedSurfaceParameters(surfaceId, |
288 cropRect, |
288 cropRect, |
289 pixelAspectRatio); |
289 pixelAspectRatio); |
290 |
290 |
291 LOG( EJavaMMAPI, EInfo, "CMMAVideoPlayer::HandleEvent: KMMFEventCategoryVideoSurfaceParametersChanged" ); |
291 LOG(EJavaMMAPI, EInfo, "CMMAVideoPlayer::HandleEvent: KMMFEventCategoryVideoSurfaceParametersChanged"); |
292 } |
292 } |
293 else |
293 else |
294 { |
294 { |
295 ELOG1( EJavaMMAPI, "CMMAVideoPlayer::HandleEvent: surface parameters changed error, %d", aEvent.iErrorCode ); |
295 ELOG1(EJavaMMAPI, "CMMAVideoPlayer::HandleEvent: surface parameters changed error, %d", aEvent.iErrorCode); |
296 } |
296 } |
297 } |
297 } |
298 else if (aEvent.iEventType == KMMFEventCategoryVideoRemoveSurface) |
298 else if (aEvent.iEventType == KMMFEventCategoryVideoRemoveSurface) |
299 { |
299 { |
300 if (aEvent.iErrorCode == KErrNone) |
300 if (aEvent.iErrorCode == KErrNone) |
301 { |
301 { |
302 if (iMMASurface.iPrevSurfaceAvailable) |
302 if (iMMASurface.iPrevSurfaceAvailable) |
303 { |
303 { |
304 // free Surface |
304 // free Surface |
305 TInt error = iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(iMMASurface.iPrevSurfaceId); |
305 TInt error = iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(iMMASurface.iPrevSurfaceId); |
306 if (KErrNone != error) |
306 if (KErrNone != error) |
307 { |
307 { |
308 ELOG1( EJavaMMAPI, "CMMAVideoPlayer::HandleEvent:SurfaceRemoved error, %d", aEvent.iErrorCode); |
308 ELOG1(EJavaMMAPI, "CMMAVideoPlayer::HandleEvent:SurfaceRemoved error, %d", aEvent.iErrorCode); |
309 } |
309 } |
310 iMMASurface.iPrevSurfaceAvailable = EFalse; |
310 iMMASurface.iPrevSurfaceAvailable = EFalse; |
311 } |
311 } |
312 } |
312 } |
313 else |
313 else |
314 { |
314 { |
315 ELOG1( EJavaMMAPI, "CMMAVideoPlayer::HandleEvent:KMMFEventCategoryVideoRemoveSurface error, %d", aEvent.iErrorCode); |
315 ELOG1(EJavaMMAPI, "CMMAVideoPlayer::HandleEvent:KMMFEventCategoryVideoRemoveSurface error, %d", aEvent.iErrorCode); |
316 } |
316 } |
317 } |
317 } |
318 // video opened, preparing |
318 // video opened, preparing |
319 else if (aEvent.iEventType == KMMFEventCategoryVideoOpenComplete) |
319 else if (aEvent.iEventType == KMMFEventCategoryVideoOpenComplete) |
320 { |
320 { |
321 if (aEvent.iErrorCode == KErrNone) |
321 if (aEvent.iErrorCode == KErrNone) |
322 { |
322 { |
323 TInt error = iVideoPlaySurfaceSupportCustomCommands.UseSurfaces(); |
323 TInt error = iVideoPlaySurfaceSupportCustomCommands.UseSurfaces(); |
324 ELOG1( EJavaMMAPI, "MMA::CMMAVideoPlayer::HandleEvent::After UseSurfaces(), error = %d", error ); |
324 ELOG1(EJavaMMAPI, "MMA::CMMAVideoPlayer::HandleEvent::After UseSurfaces(), error = %d", error); |
325 TInt prepareError(iVideoPlayControllerCustomCommands.Prepare()); |
325 TInt prepareError(iVideoPlayControllerCustomCommands.Prepare()); |
326 if (prepareError != KErrNone) |
326 if (prepareError != KErrNone) |
327 { |
327 { |
328 // opening failed, notifying java |
328 // opening failed, notifying java |
329 PostActionCompleted(prepareError); |
329 PostActionCompleted(prepareError); |
375 } |
375 } |
376 } |
376 } |
377 |
377 |
378 void CMMAVideoPlayer::CompletePrefetch(TInt aError) |
378 void CMMAVideoPlayer::CompletePrefetch(TInt aError) |
379 { |
379 { |
380 ELOG1( EJavaMMAPI, "CMMAVideoPlayer::CompletePrefetch + error = %d",aError); |
380 ELOG1(EJavaMMAPI, "CMMAVideoPlayer::CompletePrefetch + error = %d",aError); |
381 // Post KNotCompleteVideoError as KErrNone to the Java side, because |
381 // Post KNotCompleteVideoError as KErrNone to the Java side, because |
382 // video can be played. |
382 // video can be played. |
383 if (aError == KNotCompleteVideoError) |
383 if (aError == KNotCompleteVideoError) |
384 { |
384 { |
385 LOG( EJavaMMAPI, EInfo, "CMMAVideoPlayer::CompletePrefetch KNotCompleteVideoError "); |
385 LOG(EJavaMMAPI, EInfo, "CMMAVideoPlayer::CompletePrefetch KNotCompleteVideoError "); |
386 // release java |
386 // release java |
387 PostActionCompleted(KErrNone); |
387 PostActionCompleted(KErrNone); |
388 } |
388 } |
389 else |
389 else |
390 { |
390 { |
391 LOG( EJavaMMAPI, EInfo, "CMMAVideoPlayer::CompletePrefetch CompleteVideoError "); |
391 LOG(EJavaMMAPI, EInfo, "CMMAVideoPlayer::CompletePrefetch CompleteVideoError "); |
392 // release java |
392 // release java |
393 PostActionCompleted(aError); |
393 PostActionCompleted(aError); |
394 } |
394 } |
395 |
395 |
396 if (aError == KErrNone || aError == KNotCompleteVideoError) |
396 if (aError == KErrNone || aError == KNotCompleteVideoError) |
397 { |
397 { |
398 ChangeState(EPrefetched); |
398 ChangeState(EPrefetched); |
399 } |
399 } |
400 LOG( EJavaMMAPI, EInfo, "CMMAVideoPlayer::CompletePrefetch - "); |
400 LOG(EJavaMMAPI, EInfo, "CMMAVideoPlayer::CompletePrefetch - "); |
401 } |
401 } |
402 |
402 |
403 void CMMAVideoPlayer::PrepareDisplay() |
403 void CMMAVideoPlayer::PrepareDisplay() |
404 { |
404 { |
405 LOG( EJavaMMAPI, EInfo, "CMMAVideoPlayer::PrepareDisplay +" ); |
405 LOG(EJavaMMAPI, EInfo, "CMMAVideoPlayer::PrepareDisplay +"); |
406 // construction should have leaved if iSurfaceWindow does not exist |
406 // construction should have leaved if iSurfaceWindow does not exist |
407 __ASSERT_DEBUG(iSurfaceWindow, |
407 __ASSERT_DEBUG(iSurfaceWindow, |
408 User::Panic(_L("CMMVideoPlayer::iSurfaceWindow is null"), |
408 User::Panic(_L("CMMVideoPlayer::iSurfaceWindow is null"), |
409 KErrArgument)); |
409 KErrArgument)); |
410 |
410 |
411 //First place where we are certain that source size can be fetched |
411 //First place where we are certain that source size can be fetched |
412 TSize sourceSize; |
412 TSize sourceSize; |
413 |
413 |
414 TInt err = iVideoControllerCustomCommands.GetVideoFrameSize(sourceSize); |
414 TInt err = iVideoControllerCustomCommands.GetVideoFrameSize(sourceSize); |
415 |
415 |
416 ELOG1( EJavaMMAPI, "MID::CMMAVideoPlayer::PrepareDisplay: GetVideoFrameSize err = %d", err ); |
416 ELOG1(EJavaMMAPI, "MID::CMMAVideoPlayer::PrepareDisplay: GetVideoFrameSize err = %d", err); |
417 |
417 |
418 // Still we did not get the size of video |
418 // Still we did not get the size of video |
419 if ((err != KErrNone) || |
419 if ((err != KErrNone) || |
420 (sourceSize.iWidth <= 0) || |
420 (sourceSize.iWidth <= 0) || |
421 (sourceSize.iHeight <= 0)) |
421 (sourceSize.iHeight <= 0)) |
422 { |
422 { |
423 LOG( EJavaMMAPI, EInfo, "MID::CMMAVideoPlayer::PrepareDisplay: No sourcesize found, using SurfaceWindow size" ); |
423 LOG(EJavaMMAPI, EInfo, "MID::CMMAVideoPlayer::PrepareDisplay: No sourcesize found, using SurfaceWindow size"); |
424 // setting size to window size (client rect) |
424 // setting size to window size (client rect) |
425 sourceSize = iSurfaceWindow->WindowSize(); |
425 sourceSize = iSurfaceWindow->WindowSize(); |
426 } |
426 } |
427 |
427 |
428 // If 1x1 was got (the default size of form), it must be replaced |
428 // If 1x1 was got (the default size of form), it must be replaced |
429 // with a valid size as controller will not accept 1x1. |
429 // with a valid size as controller will not accept 1x1. |
430 if ((sourceSize.iWidth < KMMAVideoMinDimension) || |
430 if ((sourceSize.iWidth < KMMAVideoMinDimension) || |
431 (sourceSize.iHeight < KMMAVideoMinDimension)) |
431 (sourceSize.iHeight < KMMAVideoMinDimension)) |
432 { |
432 { |
433 LOG( EJavaMMAPI, EInfo, "MID::CMMAVideoPlayer::PrepareDisplay: Unacceptable source size, using failsafe" ); |
433 LOG(EJavaMMAPI, EInfo, "MID::CMMAVideoPlayer::PrepareDisplay: Unacceptable source size, using failsafe"); |
434 // This is a special case and ought to be used only in |
434 // This is a special case and ought to be used only in |
435 // the rare case that real size is not got from stream. |
435 // the rare case that real size is not got from stream. |
436 sourceSize = TSize(KMMAVideoMinDimension, KMMAVideoMinDimension); |
436 sourceSize = TSize(KMMAVideoMinDimension, KMMAVideoMinDimension); |
437 } |
437 } |
438 |
438 |
439 iSourceSize = sourceSize; |
439 iSourceSize = sourceSize; |
440 |
440 |
441 // If init has been already done |
441 // If init has been already done |
442 if (iDisplay) |
442 if (iDisplay) |
443 { |
443 { |
444 LOG( EJavaMMAPI, EInfo, "MID::CMMAVideoPlayer::PrepareDisplay: display exists, changing source size" ); |
444 LOG(EJavaMMAPI, EInfo, "MID::CMMAVideoPlayer::PrepareDisplay: display exists, changing source size"); |
445 SourceSizeChanged(); |
445 SourceSizeChanged(); |
446 } |
446 } |
447 |
447 |
448 // Setting (in)visible if something has changed the DSA state |
448 // Setting (in)visible if something has changed the DSA state |
449 // (e.g. prepare). If initDisplayMode is not called, this will always |
449 // (e.g. prepare). If initDisplayMode is not called, this will always |
450 // set visibility to false. |
450 // set visibility to false. |
451 iSurfaceWindow->SetVisible(iSurfaceWindow->IsVisible(), EFalse); |
451 iSurfaceWindow->SetVisible(iSurfaceWindow->IsVisible(), EFalse); |
452 LOG( EJavaMMAPI, EInfo, "CMMAVideoPlayer::PrepareDisplay -" ); |
452 LOG(EJavaMMAPI, EInfo, "CMMAVideoPlayer::PrepareDisplay -"); |
453 } |
453 } |
454 |
454 |
455 EXPORT_C const TDesC& CMMAVideoPlayer::Type() |
455 EXPORT_C const TDesC& CMMAVideoPlayer::Type() |
456 { |
456 { |
457 return KMMAVideoPlayer; |
457 return KMMAVideoPlayer; |