javauis/mmapi_akn/baseline/src.nga/cmmavideoplayer.cpp
branchRCL_3
changeset 21 4376525cdefb
parent 14 04becd199f91
child 24 6c158198356e
equal deleted inserted replaced
19:71c436fe3ce0 21:4376525cdefb
    23 #include "mmmadisplay.h"
    23 #include "mmmadisplay.h"
    24 #include "cmmaeventsource.h"
    24 #include "cmmaeventsource.h"
    25 #include "cmmasurfacewindow.h"
    25 #include "cmmasurfacewindow.h"
    26 
    26 
    27 // CONSTANTS
    27 // CONSTANTS
       
    28 const TInt KErrorMessageSize = 32;
    28 _LIT(KVideoControlName, "VideoControl");
    29 _LIT(KVideoControlName, "VideoControl");
       
    30 _LIT(KAccMonError, "Accessory monitor Error: %d");
    29 
    31 
    30 CMMAVideoPlayer* CMMAVideoPlayer::NewLC(
    32 CMMAVideoPlayer* CMMAVideoPlayer::NewLC(
    31     CMMAMMFResolver* aResolver)
    33     CMMAMMFResolver* aResolver)
    32 {
    34 {
    33     CMMAVideoPlayer* self =
    35     CMMAVideoPlayer* self =
    68         {
    70         {
    69             __ASSERT_DEBUG(EFalse, User::Invariant());
    71             __ASSERT_DEBUG(EFalse, User::Invariant());
    70         }
    72         }
    71     }
    73     }
    72 
    74 
       
    75     iAccMonCapabilityArray.Close();
       
    76     delete iAccMonitor;
    73     delete iEmptySnapshotImage;
    77     delete iEmptySnapshotImage;
    74     delete iActiveSchedulerWait;
    78     delete iActiveSchedulerWait;
    75 }
    79 }
    76 
    80 
    77 CMMAVideoPlayer::CMMAVideoPlayer(
    81 CMMAVideoPlayer::CMMAVideoPlayer(
    84     iMMASurface.iPrevSurfaceAvailable = EFalse;
    88     iMMASurface.iPrevSurfaceAvailable = EFalse;
    85 }
    89 }
    86 
    90 
    87 void CMMAVideoPlayer::ConstructL()
    91 void CMMAVideoPlayer::ConstructL()
    88 {
    92 {
       
    93     DEBUG("MMA::CMMAVideoPlayer::ConstructL +");
    89     CMMAAudioPlayer::ConstructL();
    94     CMMAAudioPlayer::ConstructL();
    90     iActiveSchedulerWait = new(ELeave)CActiveSchedulerWait;
    95     iActiveSchedulerWait = new(ELeave)CActiveSchedulerWait;
       
    96     iAccMonitor = CAccMonitor::NewL();
       
    97     iAccMonCapabilityArray.Append(KAccMonAVDevice);
       
    98     iAccMonitor->StartObservingL(this, iAccMonCapabilityArray);
       
    99     DEBUG("MMA::CMMAVideoPlayer::ConstructL -");
       
   100 }
       
   101 
       
   102 // static cleanup function
       
   103 static void PointerArrayCleanup(TAny* aArray)
       
   104 {
       
   105     static_cast<RPointerArray<CAccMonitorInfo>*>(aArray)->ResetAndDestroy();
    91 }
   106 }
    92 
   107 
    93 EXPORT_C void CMMAVideoPlayer::SetPlayerListenerObjectL(jobject aListenerObject,
   108 EXPORT_C void CMMAVideoPlayer::SetPlayerListenerObjectL(jobject aListenerObject,
    94         JNIEnv* aJni,
   109         JNIEnv* aJni,
    95         MMMAEventPoster* aEventPoster)
   110         MMMAEventPoster* aEventPoster)
    99                                          aEventPoster);
   114                                          aEventPoster);
   100 
   115 
   101     // this method must be called only ones
   116     // this method must be called only ones
   102     __ASSERT_DEBUG(!iSurfaceWindow, User::Invariant());
   117     __ASSERT_DEBUG(!iSurfaceWindow, User::Invariant());
   103 
   118 
       
   119     // get audio/video cable connected status
       
   120     TBool avCableConnStatus(EFalse);
       
   121     RConnectedAccessories connectedAccessories;
       
   122     TCleanupItem arrayCleanup(PointerArrayCleanup, 
       
   123                               &connectedAccessories);
       
   124     CleanupStack::PushL(arrayCleanup);
       
   125     TInt accCount = 
       
   126         iAccMonitor->GetConnectedAccessoriesL(connectedAccessories);
       
   127     for (TInt i = 0; i < accCount; i++)
       
   128     {
       
   129         if (KAccMonAVDevice == connectedAccessories[i]->AccDeviceType())
       
   130         {
       
   131             avCableConnStatus = ETrue;
       
   132             break;
       
   133         }
       
   134     }
       
   135     CleanupStack::PopAndDestroy();
       
   136 
   104     // create window for videoplayer
   137     // create window for videoplayer
   105     // event poster is always CMMAEventSource type.
   138     // event poster is always CMMAEventSource type.
   106 
       
   107     iSurfaceWindow = CMMASurfaceWindow::NewL(
   139     iSurfaceWindow = CMMASurfaceWindow::NewL(
   108                          static_cast< CMMAEventSource* >(iEventPoster),
   140                          static_cast< CMMAEventSource* >(iEventPoster),
   109                          this);
   141                          this, avCableConnStatus);
   110 }
   142 }
   111 
   143 
   112 EXPORT_C void CMMAVideoPlayer::SetDisplayL(MMMADisplay* aDisplay)
   144 EXPORT_C void CMMAVideoPlayer::SetDisplayL(MMMADisplay* aDisplay)
   113 {
   145 {
   114     // now it is ready to draw
   146     // now it is ready to draw
   208     // event KMMFEventCategoryPlaybackComplete is handled by both Video
   240     // event KMMFEventCategoryPlaybackComplete is handled by both Video
   209     // and Audio players. first it should be handled by Video player
   241     // and Audio players. first it should be handled by Video player
   210     if (aEvent.iEventType == KMMFEventCategoryPlaybackComplete)
   242     if (aEvent.iEventType == KMMFEventCategoryPlaybackComplete)
   211     {
   243     {
   212         iSurfaceWindow->RemoveSurface();
   244         iSurfaceWindow->RemoveSurface();
       
   245     }
       
   246 
       
   247     // Start player again and ignore error 
       
   248     if ((aEvent.iEventType == KMMFEventCategoryVideoPlayerGeneralError) &&
       
   249             (aEvent.iErrorCode == KMMVideoBlitError))
       
   250     {
       
   251         TRAPD(error, StartL(EFalse));
       
   252         if (KErrNone != error)
       
   253         {
       
   254             DEBUG_INT("MMA:CMMAVideoPlayer::HandleEvent, StartL() error %d", error);
       
   255         }
       
   256         return;
   213     }
   257     }
   214 
   258 
   215     // KNotCompleteVideoError can be notified when video is not complete
   259     // KNotCompleteVideoError can be notified when video is not complete
   216     // ( missing sound ) but still can be played. Because
   260     // ( missing sound ) but still can be played. Because
   217     // CMMAAudioPlayer::HandleEvent fails with all negative error codes,
   261     // CMMAAudioPlayer::HandleEvent fails with all negative error codes,
   517 {
   561 {
   518     iDisplay->SourceSizeChanged(iSourceSize);
   562     iDisplay->SourceSizeChanged(iSourceSize);
   519     NotifyWithStringEvent(CMMAPlayerEvent::ESizeChanged, KVideoControlName);
   563     NotifyWithStringEvent(CMMAPlayerEvent::ESizeChanged, KVideoControlName);
   520 }
   564 }
   521 
   565 
       
   566 void CMMAVideoPlayer::ConnectedL(CAccMonitorInfo* aAccessoryInfo)
       
   567 {
       
   568     TAccMonCapability deviceType = aAccessoryInfo->AccDeviceType() ;
       
   569     DEBUG_INT("MID::CMMAVideoPlayer::ConnectedL %d", deviceType);
       
   570     if (iSurfaceWindow && (deviceType == KAccMonAVDevice))
       
   571     {
       
   572         iSurfaceWindow->SetAVCableConnStatus(ETrue);
       
   573     }
       
   574 }
       
   575 
       
   576 void CMMAVideoPlayer::DisconnectedL(CAccMonitorInfo* aAccessoryInfo)
       
   577 {
       
   578     TAccMonCapability deviceType = aAccessoryInfo->AccDeviceType() ;
       
   579     DEBUG_INT("MID::CMMAVideoPlayer::DisconnectedL %d", deviceType);
       
   580     if (iSurfaceWindow && (deviceType == KAccMonAVDevice))
       
   581     {
       
   582         iSurfaceWindow->SetAVCableConnStatus(EFalse);
       
   583     }
       
   584 }
       
   585 
       
   586 void CMMAVideoPlayer::AccMonitorObserverError(TInt aError)
       
   587 {
       
   588     DEBUG_INT("MMA::CMMAVideoPlayer::AccMonitorObserverError %d", aError);
       
   589     TBuf<KErrorMessageSize> errorMessage;
       
   590     errorMessage.Format(KAccMonError, aError);
       
   591     PostStringEvent(CMMAPlayerEvent::EError, errorMessage);
       
   592 }
       
   593 
   522 //  END OF FILE
   594 //  END OF FILE