videoplayback/videohelix/src/mpxvideoplayerutility.cpp
changeset 0 96612d01cf9f
child 1 6711b85517b7
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     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:  This class is the interface between the playback plugin and RMMFController
       
    15  *
       
    16 */
       
    17 
       
    18 // Version : %version: 12 %
       
    19 
       
    20 
       
    21 #include <AudioPreference.h>
       
    22 #include <mmf/server/mmffile.h>
       
    23 #include <caf/caftypes.h>
       
    24 #include <mpxmessagegeneraldefs.h>
       
    25 
       
    26 #include "mpxvideoplayerutility.h"
       
    27 #include "mpxvideoplaybackcontroller.h"
       
    28 #include <mpxvideoplaybackdefs.h>
       
    29 #include "mpxvideo_debug.h"
       
    30 
       
    31 const TInt KBufferExpandSize = 100;
       
    32 const TUid KSourceUid = { KMmfUidFileSource };
       
    33 
       
    34 CMpxVideoPlayerUtility*
       
    35 CMpxVideoPlayerUtility::NewL( CMPXVideoPlaybackController* aVideoPlaybackCtrl )
       
    36 {
       
    37     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::NewL()"));
       
    38 
       
    39     CMpxVideoPlayerUtility* self = new (ELeave) CMpxVideoPlayerUtility( aVideoPlaybackCtrl );
       
    40     CleanupStack::PushL(self);
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop();
       
    43     return self;
       
    44 }
       
    45 
       
    46 CMpxVideoPlayerUtility::CMpxVideoPlayerUtility( CMPXVideoPlaybackController* aVideoPlaybackCtrl )
       
    47     : iVideoPlaybackController( aVideoPlaybackCtrl )
       
    48     , iVideoControllerCustomCommands( iController )
       
    49     , iVideoPlayControllerCustomCommands( iController )
       
    50     , iAudioPlayDeviceCustomCommands( iController )
       
    51     , iDrmCustomCommands( iController )
       
    52     , iVideoPlayControllerExtCustomCommands( iController )
       
    53 #ifdef SYMBIAN_BUILD_GCE
       
    54     , iVideoPlaySurfaceSupportCustomCommands( iController )
       
    55 #endif
       
    56 {
       
    57 }
       
    58 
       
    59 void CMpxVideoPlayerUtility::ConstructL()
       
    60 {
       
    61     OpenControllerL();
       
    62 }
       
    63 
       
    64 CMpxVideoPlayerUtility::~CMpxVideoPlayerUtility()
       
    65 {
       
    66     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::~CMpxVideoPlayerUtility()"));
       
    67 
       
    68     Close();
       
    69 
       
    70     delete iControllerEventMonitor;
       
    71 }
       
    72 
       
    73 void CMpxVideoPlayerUtility::Close()
       
    74 {
       
    75     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::Close()"));
       
    76 
       
    77     if ( iControllerEventMonitor )
       
    78     {
       
    79         iControllerEventMonitor->Cancel();
       
    80         delete iControllerEventMonitor;
       
    81         iControllerEventMonitor = NULL;
       
    82     }
       
    83 
       
    84     iController.Close();
       
    85     iDirectScreenAccessAbort = EFalse;
       
    86 }
       
    87 
       
    88 void CMpxVideoPlayerUtility::Reset()
       
    89 {
       
    90     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::Reset()"));
       
    91 
       
    92     Close();
       
    93     OpenControllerL();
       
    94 }
       
    95 
       
    96 void CMpxVideoPlayerUtility::OpenControllerL()
       
    97 {
       
    98     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::OpenControllerL()"));
       
    99 
       
   100     const TUid KHelixUID = {0x101F8514};
       
   101 
       
   102     TMMFPrioritySettings settings;
       
   103     settings.iPriority = KAudioPriorityRealOnePlayer;
       
   104     settings.iPref = TMdaPriorityPreference( KAudioPrefRealOneLocalPlayback );
       
   105 
       
   106     User::LeaveIfError( iController.Open( KHelixUID, settings, ETrue ) );
       
   107 
       
   108     //
       
   109     //  Let MMF Controller (Helix) handle evaluation & consumption of DRM rights
       
   110     //  this call is necessary since default Helix behavior (for OMA 1&2) is to
       
   111     //  not consume rights. Helix's default behavior for WMDRM is to consume rights.
       
   112     //  This call ensures Helix will consume rights for all DRM types.
       
   113     //
       
   114     iDrmCustomCommands.DisableAutomaticIntent( EFalse );
       
   115 
       
   116     //
       
   117     //  Start monitoring controller events
       
   118     //
       
   119     if ( iControllerEventMonitor )
       
   120     {
       
   121         iControllerEventMonitor->Cancel();
       
   122         delete iControllerEventMonitor;
       
   123         iControllerEventMonitor = NULL;
       
   124     }
       
   125 
       
   126     iControllerEventMonitor = CMMFControllerEventMonitor::NewL( *this, iController );
       
   127 
       
   128     iControllerEventMonitor->Start();
       
   129 }
       
   130 
       
   131 TTimeIntervalMicroSeconds CMpxVideoPlayerUtility::PositionL() const
       
   132 {
       
   133     TTimeIntervalMicroSeconds position;
       
   134     User::LeaveIfError( iController.GetPosition( position ) );
       
   135 
       
   136     MPX_DEBUG(_L("CMpxVideoPlayerUtility::PositionL(%Ld)"), position.Int64());
       
   137 
       
   138     return position;
       
   139 }
       
   140 
       
   141 TTimeIntervalMicroSeconds CMpxVideoPlayerUtility::DurationL() const
       
   142 {
       
   143     TTimeIntervalMicroSeconds duration;
       
   144     User::LeaveIfError( iController.GetDuration( duration ) );
       
   145 
       
   146     MPX_DEBUG(_L("CMpxVideoPlayerUtility::DurationL(%Ld)"), duration.Int64());
       
   147 
       
   148     return duration;
       
   149 }
       
   150 
       
   151 TInt CMpxVideoPlayerUtility::NumberOfMetaDataEntriesL() const
       
   152 {
       
   153     TInt num = 0;
       
   154     User::LeaveIfError( iController.GetNumberOfMetaDataEntries( num ) );
       
   155 
       
   156     MPX_DEBUG(_L("CMpxVideoPlayerUtility::NumberOfMetaDataEntriesL(%d)"), num);
       
   157 
       
   158     return num;
       
   159 }
       
   160 
       
   161 CMMFMetaDataEntry* CMpxVideoPlayerUtility::MetaDataEntryL( TInt aMetaDataIndex ) const
       
   162 {
       
   163     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::MetaDataEntryL()"),
       
   164                    _L("index = %d"), aMetaDataIndex );
       
   165 
       
   166     return iController.GetMetaDataEntryL( aMetaDataIndex );
       
   167 }
       
   168 
       
   169 void CMpxVideoPlayerUtility::SetVolumeL( TInt aVolume )
       
   170 {
       
   171     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::SetVolumeL()"),
       
   172                    _L("volume = %d"), aVolume );
       
   173 
       
   174     User::LeaveIfError( iAudioPlayDeviceCustomCommands.SetVolume( aVolume ) );
       
   175 }
       
   176 
       
   177 TInt CMpxVideoPlayerUtility::Volume() const
       
   178 {
       
   179     TInt vol = 0;
       
   180     iAudioPlayDeviceCustomCommands.GetVolume( vol );
       
   181 
       
   182     MPX_DEBUG(_L("CMpxVideoPlayerUtility::Volume(%d)"), vol);
       
   183 
       
   184     return vol;
       
   185 }
       
   186 
       
   187 TInt CMpxVideoPlayerUtility::MaxVolume() const
       
   188 {
       
   189     TInt maxVol = 0;
       
   190     iAudioPlayDeviceCustomCommands.GetMaxVolume( maxVol );
       
   191 
       
   192     MPX_DEBUG(_L("CMpxVideoPlayerUtility::MaxVolume(%d)"), maxVol);
       
   193 
       
   194     return maxVol;
       
   195 }
       
   196 
       
   197 void CMpxVideoPlayerUtility::VideoFrameSizeL( TSize& aSize ) const
       
   198 {
       
   199     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::VideoFrameSizeL()"));
       
   200     User::LeaveIfError( iVideoControllerCustomCommands.GetVideoFrameSize( aSize ) );
       
   201 }
       
   202 
       
   203 TInt CMpxVideoPlayerUtility::VideoBitRateL() const
       
   204 {
       
   205     TInt bitRate;
       
   206     User::LeaveIfError( iVideoControllerCustomCommands.GetVideoBitRate( bitRate ) );
       
   207 
       
   208     MPX_DEBUG(_L("CMpxVideoPlayerUtility::VideoBitRateL(%d)"), bitRate);
       
   209 
       
   210     return bitRate;
       
   211 }
       
   212 TInt CMpxVideoPlayerUtility::AudioBitRateL() const
       
   213 {
       
   214     TInt bitRate;
       
   215     User::LeaveIfError( iVideoControllerCustomCommands.GetAudioBitRate( bitRate ) );
       
   216 
       
   217     MPX_DEBUG(_L("CMpxVideoPlayerUtility::AudioBitRateL(%d)"), bitRate);
       
   218 
       
   219     return bitRate;
       
   220 }
       
   221 
       
   222 TInt CMpxVideoPlayerUtility::VideoFormatMimeType( TDes8& aMimeType ) const
       
   223 {
       
   224     return iVideoControllerCustomCommands.GetVideoMimeType( aMimeType );
       
   225 }
       
   226 
       
   227 TUint32 CMpxVideoPlayerUtility::FourCCCode() const
       
   228 {
       
   229     TFourCC aFourCC( 0 ); 
       
   230     iVideoControllerCustomCommands.GetAudioCodec( aFourCC );
       
   231     
       
   232     return aFourCC.FourCC();
       
   233 }
       
   234 
       
   235 void CMpxVideoPlayerUtility::RefreshFrameL()
       
   236 {
       
   237     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::RefreshFrameL()"));
       
   238 
       
   239     User::LeaveIfError( iVideoPlayControllerCustomCommands.RefreshFrame() );
       
   240 }
       
   241 
       
   242 void CMpxVideoPlayerUtility::RestartDsa( const TRegion& aRegion )
       
   243 {
       
   244     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::RestartDsa()"));
       
   245 
       
   246     iVideoPlayControllerCustomCommands.UpdateDisplayRegion( aRegion );
       
   247     iVideoPlayControllerCustomCommands.DirectScreenAccessEvent( EResumeDSA );
       
   248 }
       
   249 
       
   250 void CMpxVideoPlayerUtility::AbortDsa()
       
   251 {
       
   252     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::AbortDsa()"));
       
   253 
       
   254     iVideoPlayControllerCustomCommands.DirectScreenAccessEvent( EAbortDSA );
       
   255     iDirectScreenAccessAbort = ETrue;
       
   256 }
       
   257 
       
   258 void CMpxVideoPlayerUtility::SetDisplayWindowL( const TRect& aScreenRect,
       
   259                                                 const TRect& aClipRect,
       
   260                                                 const TRegion& aDrawingRegion )
       
   261 {
       
   262     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::SetDisplayWindowL()"));
       
   263 
       
   264     User::LeaveIfError(
       
   265             iVideoPlayControllerCustomCommands.SetDisplayWindow( aScreenRect, aClipRect) );
       
   266 
       
   267     User::LeaveIfError(
       
   268             iVideoPlayControllerCustomCommands.UpdateDisplayRegion( aDrawingRegion ) );
       
   269 
       
   270     if ( iDirectScreenAccessAbort )
       
   271     {
       
   272         User::LeaveIfError(
       
   273                 iVideoPlayControllerCustomCommands.DirectScreenAccessEvent( EResumeDSA ) );
       
   274 
       
   275         iDirectScreenAccessAbort = EFalse;
       
   276     }
       
   277 }
       
   278 
       
   279 TBool CMpxVideoPlayerUtility::AudioEnabledL() const
       
   280 {
       
   281     TBool enabled;
       
   282     User::LeaveIfError( iVideoPlayControllerCustomCommands.GetAudioEnabled( enabled ) );
       
   283 
       
   284     MPX_DEBUG(_L("CMpxVideoPlayerUtility::AudioEnabledL(%d)"), enabled);
       
   285 
       
   286     return enabled;
       
   287 }
       
   288 
       
   289 void CMpxVideoPlayerUtility::Prepare()
       
   290 {
       
   291     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::Prepare()"));
       
   292 
       
   293     TInt error = iVideoPlayControllerCustomCommands.Prepare();
       
   294 
       
   295     if ( error )
       
   296     {
       
   297         TMMFEvent event( KMMFEventCategoryVideoPrepareComplete, error );
       
   298         iVideoPlaybackController->HandleMMFEvent( event );
       
   299     }
       
   300 }
       
   301 
       
   302 void CMpxVideoPlayerUtility::GetVideoLoadingProgressL( TInt& aPercentageProgress )
       
   303 {
       
   304     User::LeaveIfError(
       
   305         iVideoPlayControllerCustomCommands.GetLoadingProgress( aPercentageProgress ) );
       
   306 
       
   307     MPX_DEBUG(_L("CMpxVideoPlayerUtility::GetVideoLoadingProgressL(%d)"), aPercentageProgress );
       
   308 }
       
   309 
       
   310 void CMpxVideoPlayerUtility::Play()
       
   311 {
       
   312     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::Play()"));
       
   313 
       
   314     TInt err = iController.Play();
       
   315 }
       
   316 
       
   317 void CMpxVideoPlayerUtility::PauseL()
       
   318 {
       
   319     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::PauseL()"));
       
   320 
       
   321     User::LeaveIfError( iController.Pause() );
       
   322 }
       
   323 
       
   324 void CMpxVideoPlayerUtility::SetPlayVelocityL( TInt aVelocity )
       
   325 {
       
   326     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::SetPlayVelocityL()"),
       
   327                    _L("velocity = %d"), aVelocity);
       
   328 
       
   329     User::LeaveIfError( iVideoPlayControllerExtCustomCommands.SetPlayVelocity( aVelocity ) );
       
   330 }
       
   331 
       
   332 void CMpxVideoPlayerUtility::SetPositionL(const TTimeIntervalMicroSeconds& aPosition)
       
   333 {
       
   334     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::SetPositionL()"),
       
   335                    _L("aPosition = %Ld"), aPosition.Int64());
       
   336 
       
   337     User::LeaveIfError( iController.SetPosition( aPosition ) );
       
   338 }
       
   339 
       
   340 TInt CMpxVideoPlayerUtility::Stop()
       
   341 {
       
   342     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::Stop()"));
       
   343 
       
   344     return iController.Stop();
       
   345 }
       
   346 
       
   347 void CMpxVideoPlayerUtility::HandleEvent( const TMMFEvent& aEvent )
       
   348 {
       
   349     MPX_ENTER_EXIT(
       
   350         _L("CMpxVideoPlayerUtility::HandleEvent()"),
       
   351         _L("EventType = 0x%08x, ErrorCode = %d"), aEvent.iEventType, aEvent.iErrorCode );
       
   352 
       
   353     //
       
   354     //  Call on the controller to handle the event
       
   355     //
       
   356     iVideoPlaybackController->HandleMMFEvent( aEvent );
       
   357 }
       
   358 
       
   359 void CMpxVideoPlayerUtility::OpenFileL( const RFile& aFile )
       
   360 {
       
   361     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::OpenFileL()"));
       
   362 
       
   363     RFile& file = const_cast<RFile&>( aFile );
       
   364 
       
   365     TMMFileHandleSource filehandlesource( file,
       
   366                                           ContentAccess::KDefaultContentObject,
       
   367                                           ContentAccess::EPlay );
       
   368 
       
   369     HBufC* uniqueId = filehandlesource.UniqueId().AllocL();
       
   370     CleanupStack::PushL( uniqueId );
       
   371 
       
   372     TBool enableUi = filehandlesource.IsUIEnabled();
       
   373 
       
   374     //
       
   375     //  Create config for file handle source
       
   376     //
       
   377     CBufFlat* buf = CBufFlat::NewL( KBufferExpandSize );
       
   378     CleanupStack::PushL( buf );
       
   379 
       
   380     RBufWriteStream stream;
       
   381     stream.Open( *buf );
       
   382 
       
   383     CleanupClosePushL( stream );
       
   384 
       
   385     TPckgBuf<RFile*> fileptr( &file );
       
   386 
       
   387     stream.WriteInt32L( KMMFileHandleSourceUid.iUid );
       
   388     stream.WriteL( fileptr );
       
   389 
       
   390     TInt length = 0;
       
   391 
       
   392     if ( uniqueId )
       
   393     {
       
   394         length = uniqueId->Length();
       
   395     }
       
   396 
       
   397     stream.WriteInt32L( length );
       
   398 
       
   399     if ( length > 0 )
       
   400     {
       
   401         stream.WriteL( *uniqueId );
       
   402     }
       
   403 
       
   404     stream.WriteInt32L( enableUi );
       
   405 
       
   406     stream.CommitL();
       
   407 
       
   408     CleanupStack::PopAndDestroy( &stream );
       
   409 
       
   410     HBufC8* sourceData = buf->Ptr(0).AllocL();
       
   411 
       
   412     iController.AddDataSource( KSourceUid, sourceData->Des() );
       
   413     iController.AddDataSink( KUidMmfAudioOutput, KNullDesC8 );
       
   414 
       
   415     delete sourceData;
       
   416 
       
   417 #ifdef SYMBIAN_BUILD_GCE
       
   418     iVideoPlaySurfaceSupportCustomCommands.UseSurfaces();
       
   419 #endif
       
   420 
       
   421     CleanupStack::PopAndDestroy( buf );
       
   422     CleanupStack::PopAndDestroy( uniqueId );
       
   423 }
       
   424 
       
   425 void CMpxVideoPlayerUtility::OpenFileL( const TDesC& aFileName )
       
   426 {
       
   427     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::OpenFileL()"),
       
   428                    _L("aFileName = %S"), &aFileName);
       
   429 
       
   430     TMMFFileConfig srcConfig;
       
   431     srcConfig().iPath = aFileName;
       
   432 
       
   433     const TUid KSourceUid = { KMmfUidFileSource };
       
   434 
       
   435     iController.AddDataSource( KSourceUid, srcConfig );
       
   436     iController.AddDataSink( KUidMmfAudioOutput, KNullDesC8 );
       
   437 }
       
   438 
       
   439 void CMpxVideoPlayerUtility::OpenUrlL( const TDesC& aUrl, TInt aApId )
       
   440 {
       
   441     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::OpenUrlL()"),
       
   442                    _L("aUrl = %S, ApId = %d"), &aUrl, aApId);
       
   443 
       
   444     CBufFlat* urlCfgBuffer = NULL;
       
   445 
       
   446     CMMFUrlParams* urlCfg = CMMFUrlParams::NewL( aUrl, aApId );
       
   447     CleanupStack::PushL( urlCfg );
       
   448 
       
   449     urlCfgBuffer = urlCfg->ExternalizeToCBufFlatLC();
       
   450 
       
   451     iController.AddDataSource( KUidMmfUrlSource, urlCfgBuffer->Ptr(0) );
       
   452     iController.AddDataSink( KUidMmfAudioOutput, KNullDesC8 );
       
   453 
       
   454 #ifdef SYMBIAN_BUILD_GCE
       
   455     iVideoPlaySurfaceSupportCustomCommands.UseSurfaces();
       
   456 #endif
       
   457 
       
   458     CleanupStack::PopAndDestroy( 2 );  // urlCfg & urlCfgBuffer
       
   459 }
       
   460 
       
   461 TInt CMpxVideoPlayerUtility::CustomCommandSync( const TMMFMessageDestinationPckg& aDestination,
       
   462                                                 TInt aFunction,
       
   463                                                 const TDesC8& aDataTo1,
       
   464                                                 const TDesC8& aDataTo2 )
       
   465 {
       
   466     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::CustomCommandSync()"));
       
   467 
       
   468     return iController.CustomCommandSync( aDestination, aFunction, aDataTo1, aDataTo2 );
       
   469 }
       
   470 
       
   471 
       
   472 #ifdef SYMBIAN_BUILD_GCE
       
   473 
       
   474 // -------------------------------------------------------------------------------------------------
       
   475 //   CMpxVideoPlayerUtility::VideoSurfaceCreated()
       
   476 // -------------------------------------------------------------------------------------------------
       
   477 //
       
   478 TInt CMpxVideoPlayerUtility::VideoSurfaceCreated()
       
   479 {
       
   480     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::VideoSurfaceCreated()"));
       
   481 
       
   482     TSurfaceId oldSurfaceId( iSurfaceId );
       
   483     TBool replaceSurface = ! ( iSurfaceId.IsNull() );
       
   484 
       
   485     TSurfaceId surfaceId;
       
   486     TRect cropRect;
       
   487     TVideoAspectRatio aspectRatio;
       
   488 
       
   489     TInt error =
       
   490         iVideoPlaySurfaceSupportCustomCommands.GetSurfaceParameters( surfaceId,
       
   491                                                                      cropRect,
       
   492                                                                      aspectRatio );
       
   493 
       
   494     if ( error == KErrNone )
       
   495     {
       
   496         //
       
   497         //  Send data to the display handler to remove old surface and add new surface
       
   498         //
       
   499         MPX_TRAPD( err, SendSurfaceCommandL( EPbMsgVideoSurfaceCreated,
       
   500                                              surfaceId,
       
   501                                              cropRect,
       
   502                                              aspectRatio ) );
       
   503 
       
   504         iSurfaceId = surfaceId;
       
   505 
       
   506         //
       
   507         //  if surface already existed tell video adaptation it is no longer in use.
       
   508         //  Video adaptation will remove the surface when it receives this call therefore
       
   509         //  the following code must be done at the end of this function.
       
   510         //
       
   511         if ( replaceSurface )
       
   512         {
       
   513             error = iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved( oldSurfaceId );
       
   514         }
       
   515     }
       
   516     else
       
   517     {
       
   518         if ( replaceSurface )
       
   519         {
       
   520             iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved( oldSurfaceId );
       
   521         }
       
   522     }
       
   523 
       
   524     return error;
       
   525 }
       
   526 
       
   527 // -------------------------------------------------------------------------------------------------
       
   528 //   CMpxVideoPlayerUtility::SurfaceParametersChanged()
       
   529 // -------------------------------------------------------------------------------------------------
       
   530 //
       
   531 TInt CMpxVideoPlayerUtility::SurfaceParametersChanged()
       
   532 {
       
   533     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::SurfaceParametersChanged()"));
       
   534 
       
   535     TInt error = KErrNone;
       
   536 
       
   537     if ( iSurfaceId.IsNull() )
       
   538     {
       
   539         error = KErrNotSupported;
       
   540     }
       
   541     else
       
   542     {
       
   543         TSurfaceId surfaceId;
       
   544         TRect cropRect;
       
   545         TVideoAspectRatio aspectRatio;
       
   546 
       
   547         error = iVideoPlaySurfaceSupportCustomCommands.GetSurfaceParameters( surfaceId,
       
   548                                                                              cropRect,
       
   549                                                                              aspectRatio );
       
   550 
       
   551         if ( error == KErrNone )
       
   552         {
       
   553             if ( iSurfaceId != surfaceId )
       
   554             {
       
   555                 error = KErrInUse;
       
   556             }
       
   557             else
       
   558             {
       
   559                 //
       
   560                 //  Send data to the display handler to remove old surface and add new surface
       
   561                 //
       
   562                 MPX_TRAPD( err, SendSurfaceCommandL( EPbMsgVideoSurfaceChanged,
       
   563                                                      surfaceId,
       
   564                                                      cropRect,
       
   565                                                      aspectRatio ) );
       
   566             }
       
   567         }
       
   568     }
       
   569 
       
   570     return error;
       
   571 }
       
   572 
       
   573 // -------------------------------------------------------------------------------------------------
       
   574 //   CMpxVideoPlayerUtility::RemoveSurface()
       
   575 // -------------------------------------------------------------------------------------------------
       
   576 //
       
   577 TInt CMpxVideoPlayerUtility::RemoveSurface()
       
   578 {
       
   579     TInt error = KErrNone;
       
   580 
       
   581     if ( iSurfaceId.IsNull() )
       
   582     {
       
   583         error = KErrNotFound;
       
   584     }
       
   585 
       
   586     //
       
   587     //  Send command to view to remove the surface
       
   588     //
       
   589     MPX_TRAPD( err, SendSurfaceCommandL( EPbMsgVideoSurfaceRemoved ) );
       
   590 
       
   591     error = iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved( iSurfaceId );
       
   592 
       
   593     iSurfaceId = TSurfaceId::CreateNullId();
       
   594 
       
   595     return error;
       
   596 }
       
   597 
       
   598 // -------------------------------------------------------------------------------------------------
       
   599 //   CMpxVideoPlayerUtility::SendSurfaceCommandL()
       
   600 // -------------------------------------------------------------------------------------------------
       
   601 //
       
   602 void CMpxVideoPlayerUtility::SendSurfaceCommandL( TInt aCmd )
       
   603 {
       
   604     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::SendSurfaceCommandL()"),
       
   605                    _L("aCmd = %d"), aCmd );
       
   606 
       
   607     if ( iVideoPlaybackController->iMPXPluginObs )
       
   608     {
       
   609         CMPXMessage* msg = CMPXMessage::NewL();
       
   610         CleanupStack::PushL( msg );
       
   611 
       
   612         msg->SetTObjectValueL<TInt>( KMPXMessageGeneralId, KMPXMediaIdVideoDisplayMessage );
       
   613         msg->SetTObjectValueL<TInt>( KMPXMediaVideoDisplayCommand, aCmd );
       
   614 
       
   615         iVideoPlaybackController->iMPXPluginObs->HandlePlaybackMessage( msg, KErrNone );
       
   616 
       
   617         CleanupStack::PopAndDestroy( msg );
       
   618     }
       
   619 }
       
   620 
       
   621 // -------------------------------------------------------------------------------------------------
       
   622 //   CMpxVideoPlayerUtility::SendSurfaceCommandL()
       
   623 // -------------------------------------------------------------------------------------------------
       
   624 //
       
   625 void CMpxVideoPlayerUtility::SendSurfaceCommandL( TInt aCmd,
       
   626                                                   const TSurfaceId& aSurfaceId,
       
   627                                                   const TRect& aCropRect,
       
   628                                                   TVideoAspectRatio aAspectRatio )
       
   629 {
       
   630     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::SendSurfaceCommandL()"),
       
   631                    _L("aCmd = %d"), aCmd );
       
   632 
       
   633     if ( iVideoPlaybackController->iMPXPluginObs )
       
   634     {
       
   635         CMPXMessage* msg = CMPXMessage::NewL();
       
   636         CleanupStack::PushL( msg );
       
   637 
       
   638         msg->SetTObjectValueL<TInt>( KMPXMessageGeneralId, KMPXMediaIdVideoDisplayMessage );
       
   639         msg->SetTObjectValueL<TInt>( KMPXMediaVideoDisplayCommand, aCmd );
       
   640         msg->SetTObjectValueL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId, aSurfaceId );
       
   641         msg->SetTObjectValueL<TRect>( KMPXMediaVideoDisplayCropRect, aCropRect );
       
   642         msg->SetTObjectValueL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio, aAspectRatio );
       
   643 
       
   644         iVideoPlaybackController->iMPXPluginObs->HandlePlaybackMessage( msg, KErrNone );
       
   645 
       
   646         CleanupStack::PopAndDestroy( msg );
       
   647     }
       
   648 }
       
   649 
       
   650 #endif
       
   651 
       
   652 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   653 
       
   654 void CMpxVideoPlayerUtility::OpenFile64L( const RFile64& aFile )
       
   655 {
       
   656     MPX_ENTER_EXIT(_L("CMpxVideoPlayerUtility::OpenFile64L( RFile64 )"));
       
   657 
       
   658     RFile64& file = const_cast<RFile64&>( aFile );
       
   659 
       
   660     TMMFileHandleSource filehandlesource( file,
       
   661                                           ContentAccess::KDefaultContentObject,
       
   662                                           ContentAccess::EPlay );
       
   663 
       
   664     HBufC* uniqueId = filehandlesource.UniqueId().AllocL();
       
   665     CleanupStack::PushL( uniqueId );
       
   666 
       
   667     TBool enableUi = filehandlesource.IsUIEnabled();
       
   668 
       
   669     //
       
   670     //  Create config for file handle source
       
   671     //
       
   672     CBufFlat* buf = CBufFlat::NewL( KBufferExpandSize );
       
   673     CleanupStack::PushL( buf );
       
   674 
       
   675     RBufWriteStream stream;
       
   676     stream.Open( *buf );
       
   677 
       
   678     CleanupClosePushL( stream );
       
   679 
       
   680     TPckgBuf<RFile64*> fileptr( &file );
       
   681 
       
   682     stream.WriteInt32L( KMMFileHandleSourceUid.iUid );
       
   683     stream.WriteL( fileptr );
       
   684 
       
   685     TInt length = 0;
       
   686 
       
   687     if ( uniqueId )
       
   688     {
       
   689         length = uniqueId->Length();
       
   690     }
       
   691 
       
   692     stream.WriteInt32L( length );
       
   693 
       
   694     if ( length > 0 )
       
   695     {
       
   696         stream.WriteL( *uniqueId );
       
   697     }
       
   698 
       
   699     stream.WriteInt32L( enableUi );
       
   700 
       
   701     stream.CommitL();
       
   702 
       
   703     CleanupStack::PopAndDestroy( &stream );
       
   704 
       
   705     HBufC8* sourceData = buf->Ptr(0).AllocL();
       
   706 
       
   707     iController.AddDataSource( KSourceUid, sourceData->Des() );
       
   708     iController.AddDataSink( KUidMmfAudioOutput, KNullDesC8 );
       
   709 
       
   710     delete sourceData;
       
   711 
       
   712 #ifdef SYMBIAN_BUILD_GCE
       
   713     iVideoPlaySurfaceSupportCustomCommands.UseSurfaces();
       
   714 #endif
       
   715 
       
   716     CleanupStack::PopAndDestroy( buf );
       
   717     CleanupStack::PopAndDestroy( uniqueId );
       
   718 }
       
   719 
       
   720 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   721