videoeditorengine/vedtranscoder/src/Ctrvideodecoderclient.cpp
changeset 0 951a5db380a0
equal deleted inserted replaced
-1:000000000000 0:951a5db380a0
       
     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 decoder client.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <devvideoconstants.h>
       
    24 #include "ctrvideodecoderclient.h"
       
    25 #include "ctrtranscoder.h"
       
    26 #include "ctrdevvideoclientobserver.h"
       
    27 #include "ctrsettings.h"
       
    28 #include "ctrhwsettings.h"
       
    29 
       
    30 
       
    31 // MACROS
       
    32 #define TRASSERT(x) __ASSERT_DEBUG(x, User::Panic(_L("CTRANSCODERVIDEODECODERCLIENT"), -10010))
       
    33 
       
    34 
       
    35 // CONSTANTS
       
    36 
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CTRVideoDecoderClient::NewL
       
    42 // Two-phased constructor.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CTRVideoDecoderClient* CTRVideoDecoderClient::NewL(MTRDevVideoClientObserver& aObserver)
       
    46     {
       
    47     PRINT((_L("CTRVideoDecoderClient::NewL(), In")))
       
    48     CTRVideoDecoderClient* self = new (ELeave) CTRVideoDecoderClient(aObserver);
       
    49     CleanupStack::PushL(self);
       
    50     self->ConstructL();
       
    51     CleanupStack::Pop();
       
    52 
       
    53     PRINT((_L("CTRVideoDecoderClient::NewL(), Out")))
       
    54     return self;
       
    55     }
       
    56 
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CTRVideoDecoderClient::CTRVideoDecoderClient
       
    60 // C++ default constructor can NOT contain any code, that
       
    61 // might leave.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CTRVideoDecoderClient::CTRVideoDecoderClient(MTRDevVideoClientObserver& aObserver) :
       
    65     iObserver(aObserver)
       
    66     {
       
    67     iDevVideoPlay = NULL;
       
    68     iCompresedFormat = NULL;
       
    69     iUid = TUid::Null();
       
    70     iFallbackUid = TUid::Null();
       
    71     iHwDeviceId = THwDeviceId(0);
       
    72     iInputBuffer = NULL;
       
    73     iCodedBuffer = NULL;
       
    74     iDecodedPicture = NULL;
       
    75     
       
    76     iVideoResourceHandlerCI = NULL;   
       
    77     
       
    78     iFatalError = KErrNone;
       
    79     iDataUnitType = EDuCodedPicture;
       
    80     iStop = EFalse;
       
    81     iLastTimestamp = -1;
       
    82     iAcceleratedCodecSelected = EFalse;
       
    83     }
       
    84 
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CTRVideoDecoderClient::ConstructL
       
    88 // Symbian 2nd phase constructor can leave.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CTRVideoDecoderClient::ConstructL()
       
    92     {
       
    93     iDevVideoPlay = CMMFDevVideoPlay::NewL(*this);
       
    94     }
       
    95 
       
    96 
       
    97 // ---------------------------------------------------------
       
    98 // CTRVideoDecoderClient::~CTRVideoDecoderClient()
       
    99 // Destructor
       
   100 // ---------------------------------------------------------
       
   101 //
       
   102 CTRVideoDecoderClient::~CTRVideoDecoderClient()
       
   103     {
       
   104     PRINT((_L("CTRVideoDecoderClient::~CTRVideoDecoderClient(), In")))
       
   105 
       
   106     if (iDevVideoPlay)
       
   107         {
       
   108         delete iDevVideoPlay;
       
   109         iDevVideoPlay = NULL;
       
   110         }
       
   111 
       
   112     iInputBuffer = NULL;
       
   113     
       
   114     if (iCompresedFormat)
       
   115         {
       
   116         delete iCompresedFormat;
       
   117         }
       
   118 
       
   119     PRINT((_L("CTRVideoDecoderClient::~CTRVideoDecoderClient(), Out")))
       
   120     }
       
   121 
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CTRVideoDecoderClient::SupportsCodec
       
   125 // Checks whether this coded is supported
       
   126 // (other items were commented in a header).
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 TBool CTRVideoDecoderClient::SupportsCodec(const TDesC8& aFormat, const TDesC8& aShortFormat, TInt aUid, TInt aFallbackUid)
       
   130     {
       
   131     TBool supports = EFalse;
       
   132     TBool preferredFound = EFalse;
       
   133     TBool fallbackFound = EFalse;
       
   134 
       
   135     if (iDevVideoPlay)
       
   136         {
       
   137         RArray<TUid> decoders;
       
   138         
       
   139         TRAPD( status, iDevVideoPlay->FindDecodersL(aShortFormat, 0/*aPreProcType*/, decoders, EFalse/*aExactMatch*/) );
       
   140 
       
   141         if( status != KErrNone  )
       
   142             {
       
   143             PRINT((_L("CTRVideoDecoderClient::SupportsCodec(), status[%d]"), status))
       
   144             supports = EFalse;
       
   145             }
       
   146         else if( decoders.Count() <= 0 )
       
   147             {
       
   148             PRINT((_L("CTRVideoDecoderClient::SupportsCodec(), No decoders found")))
       
   149             supports = EFalse;
       
   150             }
       
   151         else
       
   152             {
       
   153             
       
   154             PRINT((_L("CTRVideoDecoderClient::SupportsCodec(), %d decoders found"), decoders.Count() ))
       
   155             
       
   156             // Check if any of the found decoders matches with the given Uids
       
   157             for( TInt i = 0; i < decoders.Count(); ++i )
       
   158                 {
       
   159                 
       
   160                 PRINT((_L("CTRVideoDecoderClient::SupportsCodec(), found codec 0x%x"), decoders[i].iUid))
       
   161                 
       
   162                 if( decoders[i].iUid == aUid )
       
   163                     {
       
   164                     PRINT((_L("CTRVideoDecoderClient::SupportsCodec(), preferred found")))
       
   165                     iUid = decoders[i];
       
   166                     preferredFound = ETrue;
       
   167                     }
       
   168                 if( decoders[i].iUid == aFallbackUid )
       
   169                     {
       
   170                     PRINT((_L("CTRVideoDecoderClient::SupportsCodec(), fallback found")))
       
   171                     iFallbackUid = decoders[i];
       
   172                     fallbackFound = ETrue;
       
   173                     }
       
   174                 
       
   175                 if( preferredFound && fallbackFound )
       
   176                     {
       
   177                     // No need to search anymore
       
   178                     break;
       
   179                     }
       
   180                 }
       
   181             }
       
   182 
       
   183         decoders.Reset();
       
   184         decoders.Close();
       
   185         }
       
   186         
       
   187     if( !preferredFound )
       
   188         {
       
   189         // Preferred decoder was not found => Probably the given decoder Uid is wrong
       
   190         PRINT((_L("CTRVideoDecoderClient::SupportsCodec(), No supported decoders found")))
       
   191         supports = EFalse;
       
   192         }
       
   193     else
       
   194         {
       
   195         PRINT((_L("CTRVideoDecoderClient::SupportsCodec(), Supported decoder found: 0x%x"), iUid.iUid))
       
   196         iMimeType = aFormat;
       
   197         iShortMimeType = aShortFormat;
       
   198         supports = ETrue;
       
   199         }
       
   200 
       
   201     return supports;
       
   202     }
       
   203 
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CTRVideoDecoderClient::SetCodecParametersL
       
   207 // Sets codec parameters
       
   208 // (other items were commented in a header).
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 void CTRVideoDecoderClient::SetCodecParametersL(TInt aCodecType, TInt aCodecLevel, const TTRVideoFormat& aInputFormat, 
       
   212                                                 const TTRVideoFormat& aOutputFormat)
       
   213     {
       
   214     PRINT((_L("CTRVideoDecoderClient::SetCodecParametersL(), In")))
       
   215     TInt status = KErrNone;
       
   216     iCodecType = aCodecType;
       
   217     iCodecLevel = aCodecLevel;
       
   218     iInputFormat = aInputFormat;
       
   219     iOutputFormat = aOutputFormat;
       
   220 
       
   221     // Input format
       
   222     if (!iCompresedFormat)
       
   223         {
       
   224         iCompresedFormat = CCompressedVideoFormat::NewL( iMimeType );
       
   225         }
       
   226         
       
   227     TRAP( status, iAcceleratedCodecSelected = CheckCodecInfoL(iUid) );
       
   228     
       
   229     if (status != KErrNone)
       
   230         {
       
   231         // Try again with the fallback decoder if one exists
       
   232         if( (iFallbackUid != TUid::Null()) && (iFallbackUid.iUid != iUid.iUid) )
       
   233             {
       
   234             TRAP( status, iAcceleratedCodecSelected = CheckCodecInfoL(iFallbackUid) );
       
   235             
       
   236             if (status != KErrNone)
       
   237                 {
       
   238                 PRINT((_L("CTRVideoDecoderClient::SetCodecParametersL(), Failed to get codec info")))
       
   239                 User::Leave(KErrNotSupported);
       
   240                 }
       
   241                 
       
   242             PRINT((_L("CTRVideoDecoderClient::SetCodecParametersL(), Reverting to fallback decoder")))
       
   243             
       
   244             // Fallback ok, take it    
       
   245             iUid = iFallbackUid;
       
   246             }
       
   247         else
       
   248             {
       
   249             PRINT((_L("CTRVideoDecoderClient::SetCodecParametersL(), No suitable decoders found")))
       
   250             User::Leave(KErrNotSupported);
       
   251             }
       
   252         }
       
   253       
       
   254     PRINT((_L("CTRVideoDecoderClient::SetCodecParametersL(), Out")))
       
   255     }
       
   256 
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CTRVideoDecoderClient::CheckCodecInfoL
       
   260 // Checks coded info
       
   261 // (other items were commented in a header).
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 TBool CTRVideoDecoderClient::CheckCodecInfoL(TUid aUid)
       
   265     {
       
   266     CVideoDecoderInfo* decoderInfo = NULL; // Decoder info for retrieving capabilities
       
   267     TInt status = KErrNone;
       
   268     TBool accelerated = EFalse;
       
   269 
       
   270 
       
   271     // Check decoder
       
   272     PRINT((_L("CTRVideoDecoderClient::CheckCodecInfoL(), getting info from [0x%x]"), aUid.iUid ))
       
   273     decoderInfo = iDevVideoPlay->VideoDecoderInfoLC( aUid );
       
   274 
       
   275     if (!decoderInfo)
       
   276         {
       
   277         PRINT((_L("CTRVideoDecoderClient::CheckCodecInfoL(), getting info from [0x%x] failed[%d]"), aUid.iUid, status ))
       
   278         User::Leave(KErrNotSupported);
       
   279         } //  AA skip info check before symbian fix
       
   280     else /* if ( !decoderInfo->SupportsFormat(*iCompresedFormat) ) // Check input format
       
   281         {
       
   282         PRINT((_L("CTRVideoDecoderClient::CheckCodecInfoL(), Input format is not supported")))
       
   283         status = KErrNotSupported;
       
   284         }
       
   285     else */
       
   286         {
       
   287         // Check max rate for requested image format
       
   288         TSize maxSize = decoderInfo->MaxPictureSize();
       
   289 
       
   290         if ( (iInputFormat.iSize.iWidth > maxSize.iWidth) || (iInputFormat.iSize.iHeight > maxSize.iHeight) )
       
   291             {
       
   292             PRINT((_L("CTRVideoDecoderClient::CheckCodecInfoL(), Picture size is not supported")))
       
   293             status = KErrNotSupported;
       
   294             }
       
   295         }
       
   296         
       
   297     accelerated = decoderInfo->Accelerated();
       
   298 
       
   299     // Delete codec info
       
   300     CleanupStack::PopAndDestroy(decoderInfo);
       
   301 
       
   302     if (status != KErrNone)
       
   303         {
       
   304         User::Leave(status);
       
   305         }
       
   306 
       
   307     return accelerated;
       
   308     }
       
   309 
       
   310 
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CTRVideoDecoderClient::InitializeL
       
   314 // Initializes encoder
       
   315 // (other items were commented in a header).
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 void CTRVideoDecoderClient::InitializeL()
       
   319     {
       
   320     PRINT((_L("CTRVideoDecoderClient::InitializeL(), In")))
       
   321     TUint maxBufferSize = 0;
       
   322     TInt status = KErrNone;
       
   323 
       
   324 
       
   325     switch(iInputFormat.iDataType)
       
   326         {
       
   327         case CTRTranscoder::ETRDuCodedPicture:
       
   328             {
       
   329             iDataUnitType = EDuCodedPicture;
       
   330             break;
       
   331             }
       
   332 
       
   333         case CTRTranscoder::ETRDuVideoSegment:
       
   334             {
       
   335             iDataUnitType = EDuVideoSegment;
       
   336             break;
       
   337             }
       
   338 
       
   339         default:
       
   340             {
       
   341             // Should never happend. Decoder does not support uncompressed input format. 
       
   342             TRASSERT(0);
       
   343             }
       
   344         }
       
   345 
       
   346     iBufferOptions.iMinNumInputBuffers = KTRDecoderMinNumberOfBuffers;
       
   347 
       
   348     // Select decoder first
       
   349     this->SelectDecoderL();
       
   350 
       
   351     // Set now output format for this device    
       
   352     TRAP(status, iDevVideoPlay->SetOutputFormatL(iHwDeviceId, iUncompressedFormat));
       
   353     
       
   354     // 3. Buffer options
       
   355     iBufferOptions.iPreDecodeBufferSize = 0;            // "0" - use default decoder value
       
   356     iBufferOptions.iMaxPostDecodeBufferSize = 0;        // No limitations
       
   357     iBufferOptions.iPreDecoderBufferPeriod = 0;
       
   358     iBufferOptions.iPostDecoderBufferPeriod = 0;
       
   359     
       
   360     // Check max coded picture size for specified codec level
       
   361     switch(iCodecLevel)
       
   362         {
       
   363         case KTRH263CodecLevel10:
       
   364             {
       
   365             maxBufferSize = KTRMaxBufferSizeLevel10;
       
   366             break;
       
   367             }
       
   368 
       
   369         case KTRH263CodecLevel20:
       
   370             {
       
   371             maxBufferSize = KTRMaxBufferSizeLevel20;
       
   372             break;
       
   373             }
       
   374 
       
   375         case KTRH263CodecLevel30:
       
   376             {
       
   377             maxBufferSize = KTRMaxBufferSizeLevel30;
       
   378             break;
       
   379             }
       
   380 
       
   381         case KTRH263CodecLevel40:
       
   382             {
       
   383             maxBufferSize = KTRMaxBufferSizeLevel40;
       
   384             break;
       
   385             }
       
   386 
       
   387         case KTRH263CodecLevel50:
       
   388             {
       
   389             maxBufferSize = KTRMaxBufferSizeLevel50;
       
   390             break;
       
   391             }
       
   392 
       
   393         case KTRH263CodecLevel60:
       
   394             {
       
   395             maxBufferSize = KTRMaxBufferSizeLevel60;
       
   396             break;
       
   397             }
       
   398 
       
   399         case KTRH263CodecLevel70:
       
   400             {
       
   401             maxBufferSize = KTRMaxBufferSizeLevel70;
       
   402             break;
       
   403             }
       
   404             
       
   405         case KTRH264CodecLevel10:
       
   406             {
       
   407             maxBufferSize = KTRMaxBufferSizeH264Level10;
       
   408             break;
       
   409             }
       
   410             
       
   411         case KTRH264CodecLevel10b:
       
   412             {
       
   413             maxBufferSize = KTRMaxBufferSizeH264Level10b;
       
   414             break;
       
   415             }
       
   416             
       
   417         case KTRH264CodecLevel11:
       
   418             {
       
   419             maxBufferSize = KTRMaxBufferSizeH264Level11;
       
   420             break;
       
   421             }
       
   422             
       
   423         case KTRH264CodecLevel12:
       
   424             {
       
   425             maxBufferSize = KTRMaxBufferSizeH264Level12;
       
   426             break;
       
   427             }
       
   428             
       
   429         case KTRH264CodecLevel13:
       
   430             {
       
   431             maxBufferSize = KTRMaxBufferSizeH264Level13;
       
   432             break;
       
   433             }
       
   434             
       
   435         case KTRH264CodecLevel20:
       
   436             {
       
   437             maxBufferSize = KTRMaxBufferSizeH264Level20;
       
   438             break;
       
   439             }
       
   440             
       
   441         case KTRH264CodecLevel30:
       
   442             {
       
   443             maxBufferSize = KTRMaxBufferSizeH264Level30;
       
   444             break;
       
   445             }
       
   446             
       
   447         case KTRH264CodecLevel31:
       
   448             {
       
   449             maxBufferSize = KTRMaxBufferSizeH264Level31;
       
   450             break;
       
   451             }
       
   452 
       
   453         case KTRMPEG4CodecLevel0:
       
   454             {
       
   455             maxBufferSize = KTRMaxBufferSizeLevel0;
       
   456             break;
       
   457             }
       
   458             
       
   459         case KTRMPEG4CodecLevel1:
       
   460             {
       
   461             maxBufferSize = KTRMaxBufferSizeLevel1;
       
   462             break;
       
   463             }
       
   464             
       
   465         case KTRMPEG4CodecLevel2:
       
   466             {
       
   467             maxBufferSize = KTRMaxBufferSizeLevel2;
       
   468             break;
       
   469             }
       
   470             
       
   471         case KTRMPEG4CodecLevel3:
       
   472             {
       
   473             maxBufferSize = KTRMaxBufferSizeLevel3;
       
   474             break;
       
   475             }
       
   476 
       
   477         case KTRMPEG4CodecLevel0b:
       
   478             {
       
   479             maxBufferSize = KTRMaxBufferSizeLevel0b;
       
   480             break;
       
   481             }
       
   482 
       
   483         case KTRMPEG4CodecLevel4a:
       
   484             {
       
   485             maxBufferSize = KTRMaxBufferSizeLevel4a;
       
   486             break;
       
   487             }
       
   488 
       
   489         default:
       
   490             {
       
   491             maxBufferSize = KTRMaxBufferSizeLevel0;
       
   492             break;
       
   493             }
       
   494         }
       
   495 
       
   496     iBufferOptions.iMaxInputBufferSize = maxBufferSize;
       
   497     PRINT((_L("CTRVideoDecoderClient::InitializeL(), InputBufferSize[%d], NumberOfBuffers[%d]"), 
       
   498                iBufferOptions.iMaxInputBufferSize, iBufferOptions.iMinNumInputBuffers ))
       
   499 
       
   500     iDevVideoPlay->SetBufferOptionsL(iBufferOptions);
       
   501     
       
   502     if (iScalingInUse)
       
   503         {
       
   504         PRINT((_L("CTRVideoDecoderClient::InitializeL(), Enabling scaling")))
       
   505         if (iScalingWithDeblocking)
       
   506             {
       
   507             // Enable scaling with deblocking
       
   508             iDevVideoPlay->SetPostProcessTypesL(iHwDeviceId, EPpScale | EPpDeblocking);
       
   509             }
       
   510         else
       
   511             {
       
   512             // Deblocking not supported, enable just scaling
       
   513             iDevVideoPlay->SetPostProcessTypesL(iHwDeviceId, EPpScale);
       
   514             }
       
   515         
       
   516         iDevVideoPlay->SetScaleOptionsL(iHwDeviceId, iScaledOutputSize, EFalse);
       
   517         }
       
   518 
       
   519     // Initialize devVideoPlay
       
   520     iDevVideoPlay->Initialize();
       
   521 
       
   522     PRINT((_L("CTRVideoDecoderClient::InitializeL(), Out")))
       
   523     }
       
   524 
       
   525 
       
   526 // -----------------------------------------------------------------------------
       
   527 // CTRVideoDecoderClient::SelectDecoderL
       
   528 // Selects decoder
       
   529 // (other items were commented in a header).
       
   530 // -----------------------------------------------------------------------------
       
   531 //
       
   532 void CTRVideoDecoderClient::SelectDecoderL()
       
   533     {
       
   534     PRINT(( _L("CTRVideoDecoderClient::SelectDecoderL(), In") ))
       
   535     TInt status = KErrNone;
       
   536     TBool exit = EFalse;
       
   537     
       
   538     TVideoDataUnitEncapsulation dataUnitEncapsulation = EDuElementaryStream;
       
   539     
       
   540     // Use generic payload encapsulation for H.264
       
   541     if (iCodecType == EH264)
       
   542         {
       
   543         dataUnitEncapsulation = EDuGenericPayload;
       
   544         }
       
   545 
       
   546     if (iUid != TUid::Null())
       
   547         {
       
   548         TRAP( status, iHwDeviceId = iDevVideoPlay->SelectDecoderL(iUid) );
       
   549         }
       
   550     else
       
   551         {
       
   552         // Probably the error already exists, if iUid == NULL; 
       
   553         status = KErrAlreadyExists;
       
   554         }
       
   555 
       
   556     while (!exit )
       
   557         {
       
   558         if (status == KErrNone)
       
   559             {
       
   560             // To get Output format list devvideoplay requires to define output format first. 
       
   561             iDevVideoPlay->SetInputFormatL(iHwDeviceId, *iCompresedFormat, iDataUnitType, dataUnitEncapsulation, ETrue);
       
   562 
       
   563             // It's time to check input format support (since the plugin is loaded to the memory)
       
   564             iUncompressedFormat.iDataFormat = EYuvRawData;
       
   565             
       
   566             TUncompressedVideoFormat uncFormat;
       
   567             TBool found = EFalse;
       
   568             TInt pattern1, pattern2;
       
   569             TInt dataLayout;
       
   570                     
       
   571             switch (iOutputFormat.iDataType)
       
   572                 {
       
   573                 case CTRTranscoder::ETRYuvRawData420:
       
   574                     {
       
   575                     pattern1 = EYuv420Chroma1;
       
   576                     pattern2 = EYuv420Chroma2;
       
   577                     dataLayout = EYuvDataPlanar;
       
   578                     }
       
   579                     break;
       
   580 
       
   581                 case CTRTranscoder::ETRYuvRawData422:
       
   582                     {
       
   583                     pattern1 = EYuv422Chroma1;
       
   584                     pattern2 = EYuv422Chroma2;
       
   585                     dataLayout = EYuvDataInterleavedBE;
       
   586                     }
       
   587                     break;
       
   588                 
       
   589                 default:
       
   590                     {
       
   591                     // set 420 as a default
       
   592                     pattern1 = EYuv420Chroma1;
       
   593                     pattern2 = EYuv420Chroma2;
       
   594                     dataLayout = EYuvDataPlanar;
       
   595                     }
       
   596                 }
       
   597                 
       
   598             RArray<TUncompressedVideoFormat> supportedOutputFormats; 
       
   599             TRAP(status, iDevVideoPlay->GetOutputFormatListL( iHwDeviceId, supportedOutputFormats ));
       
   600             
       
   601             TInt formatCount = 0;
       
   602             if (status == KErrNone)
       
   603                 {
       
   604                 formatCount = supportedOutputFormats.Count();
       
   605                 PRINT((_L("CTRVideoDecoderClient::InitializeL(), formatCount[%d]"), formatCount ))
       
   606                 }
       
   607                 
       
   608             if (formatCount <= 0)
       
   609                 {
       
   610                 supportedOutputFormats.Close();
       
   611                 status = KErrAlreadyExists;
       
   612                 PRINT((_L("CTRVideoDecoderClient::InitializeL(), There are no supported output formats") ))
       
   613                 //User::Leave(KErrNotSupported);
       
   614                 }
       
   615             else
       
   616                 {
       
   617                 // Check the most important paramers
       
   618                 for ( TInt i = 0; i < formatCount; i ++ )
       
   619                     {
       
   620                     uncFormat = supportedOutputFormats[i];
       
   621                     PRINT((_L("CTRVideoDecoderClient::InitializeL(), pattern[%d]"), uncFormat.iYuvFormat.iPattern ))
       
   622                     
       
   623                     if ( (uncFormat.iDataFormat == iUncompressedFormat.iDataFormat) &&
       
   624                          (uncFormat.iYuvFormat.iDataLayout == dataLayout) &&
       
   625                          ( (uncFormat.iYuvFormat.iPattern == pattern1) || 
       
   626                            (uncFormat.iYuvFormat.iPattern == pattern2) ) )
       
   627                         {
       
   628                         // Assign the rest of parameters
       
   629                         iUncompressedFormat = uncFormat;
       
   630                         found = ETrue;
       
   631                         exit = ETrue;
       
   632                         supportedOutputFormats.Close();
       
   633                         break;
       
   634                         }
       
   635                     }
       
   636 
       
   637                 if (!found)
       
   638                     {
       
   639                     supportedOutputFormats.Close();
       
   640                     status = KErrAlreadyExists;
       
   641                     PRINT((_L("CTRVideoDecoderClient::SelectDecoderL(), Supported format was not found") ))
       
   642                     //User::Leave(KErrNotSupported);
       
   643                     }
       
   644                 }
       
   645             
       
   646             }
       
   647         else
       
   648             {
       
   649             if (iScalingInUse)
       
   650                 {
       
   651                 // We can't revert to fallback decoder here since scaling has been taken into use
       
   652                 // and we can't check here if the fallback decoder supports scaling nor
       
   653                 // disable scaling if it's not supported
       
   654                 PRINT((_L("CTRVideoDecoderClient::SelectDecoderL(), Failed to select decoder")))
       
   655                 User::Leave(KErrNotSupported);
       
   656                 }
       
   657                 
       
   658             // Try again with the fallback decoder if one exists
       
   659             if( (iFallbackUid != TUid::Null()) && (iFallbackUid.iUid != iUid.iUid) )
       
   660                 {
       
   661                 PRINT((_L("CTRVideoDecoderClient::SelectEncoderL(), Reverting to fallback decoder")))
       
   662                 iUid = iFallbackUid;
       
   663                 }
       
   664             else
       
   665                 {
       
   666                 PRINT((_L("CTRVideoDecoderClient::SelectDecoderL(), Failed to select decoder")))
       
   667                 User::Leave(KErrNotSupported);
       
   668                 }
       
   669                 
       
   670             TRAP( status, iAcceleratedCodecSelected = CheckCodecInfoL(iUid) );
       
   671             
       
   672             if (status != KErrNone)
       
   673                 {
       
   674                 PRINT((_L("CTRVideoDecoderClient::SelectDecoderL(), Failed to get codec info")))
       
   675                 User::Leave(KErrNotSupported);
       
   676                 }
       
   677               
       
   678             TRAP(status, iHwDeviceId = iDevVideoPlay->SelectDecoderL(iUid));
       
   679             
       
   680             if (status != KErrNone)
       
   681                 {
       
   682                 PRINT((_L("CTRVideoDecoderClient::SelectDecoderL(), Failed to select decoder")))
       
   683                 User::Leave(KErrNotSupported);
       
   684                 }
       
   685             }
       
   686         }
       
   687 
       
   688     PRINT((_L("CTRVideoDecoderClient::SelectDecoderL(), Out")))
       
   689     }
       
   690 
       
   691 
       
   692 // -----------------------------------------------------------------------------
       
   693 // CTRVideoDecoderClient::MdvpoInitComplete
       
   694 // Notifies for initialization complete with init status
       
   695 // (other items were commented in a header).
       
   696 // -----------------------------------------------------------------------------
       
   697 //
       
   698 void CTRVideoDecoderClient::MdvpoInitComplete(TInt aError)
       
   699     {
       
   700     if ((aError == KErrHardwareNotAvailable) || (aError == KErrNotSupported))
       
   701         {
       
   702         PRINT((_L("CTRVideoDecoderClient::MdvpoInitComplete(), Error in initialization")))
       
   703         
       
   704         // Map both error codes to the same
       
   705         aError = KErrNotSupported;
       
   706         
       
   707         // Try again with the fallback decoder if one exists
       
   708         while( (iFallbackUid != TUid::Null()) && (iFallbackUid.iUid != iUid.iUid) )
       
   709             {
       
   710             PRINT((_L("CTRVideoDecoderClient::MdvpoInitComplete(), Reverting to fallback decoder")))
       
   711             
       
   712             iUid = iFallbackUid;
       
   713             
       
   714             // Devvideo must be recreated from scratch
       
   715             if (iDevVideoPlay)
       
   716                 {
       
   717                 delete iDevVideoPlay;
       
   718                 iDevVideoPlay = NULL;
       
   719                 }
       
   720             
       
   721             TRAPD( status, iDevVideoPlay = CMMFDevVideoPlay::NewL(*this) );
       
   722             if (status != KErrNone)
       
   723                 {
       
   724                 // Something went wrong, let CTRTranscoderImp handle the error
       
   725                 PRINT((_L("CTRVideoDecoderClient::MdvpoInitComplete(), Failed to create DevVideoPlay")))
       
   726                 break;
       
   727                 }
       
   728                 
       
   729             TRAP( status, iAcceleratedCodecSelected = CheckCodecInfoL(iUid) );
       
   730             if (status != KErrNone)
       
   731                 {
       
   732                 // Fallback decoder can not be used, let CTRTranscoderImp handle the error
       
   733                 PRINT((_L("CTRVideoDecoderClient::MdvpoInitComplete(), Failed to get codec info")))
       
   734                 break;
       
   735                 }
       
   736             
       
   737             // We are now ready to reinitialize the decoder, let CTRTranscoderImp do it    
       
   738             aError = KErrHardwareNotAvailable;
       
   739             break;
       
   740             }
       
   741         }
       
   742     
       
   743     iObserver.MtrdvcoDecInitializeComplete(aError);
       
   744     }
       
   745 
       
   746 
       
   747 // -----------------------------------------------------------------------------
       
   748 // CTRVideoDecoderClient::StartL
       
   749 // Starts decoding
       
   750 // (other items were commented in a header).
       
   751 // -----------------------------------------------------------------------------
       
   752 //
       
   753 void CTRVideoDecoderClient::StartL()
       
   754     {
       
   755     PRINT((_L("CTRVideoDecoderClient::StartL(), In")))
       
   756 
       
   757     // Start decoding
       
   758     if (iFatalError == KErrNone)
       
   759         {
       
   760         iDevVideoPlay->Start();
       
   761         }
       
   762 
       
   763     if (!iInputBuffer)
       
   764         {
       
   765         // Get buffer from the decoder to fill
       
   766         iInputBuffer = iDevVideoPlay->GetBufferL(iBufferOptions.iMaxInputBufferSize);
       
   767         }
       
   768     
       
   769     // Reset iStop    
       
   770     iStop = EFalse;
       
   771     iPause = EFalse;
       
   772     
       
   773     // Reset ts monitor
       
   774     iLastTimestamp = -1;
       
   775 
       
   776     PRINT((_L("CTRVideoDecoderClient::StartL(), Out")))
       
   777     }
       
   778 
       
   779 // -----------------------------------------------------------------------------
       
   780 // CTRVideoDecoderClient::Pause
       
   781 // Pauses decoding
       
   782 // (other items were commented in a header).
       
   783 // -----------------------------------------------------------------------------
       
   784 //
       
   785 void CTRVideoDecoderClient::Pause()
       
   786     {
       
   787     PRINT((_L("CTRVideoDecoderClient::Pause(), In")))
       
   788 
       
   789     // Pause decoding
       
   790     iDevVideoPlay->Pause();
       
   791     
       
   792     // Return coded buffer to client since it can not be send to decoder now
       
   793     if (iCodedBuffer)
       
   794         {
       
   795         CCMRMediaBuffer* codedBuffer = iCodedBuffer;
       
   796         
       
   797         // Reset buffer ptr
       
   798         iCodedBuffer = NULL;
       
   799         
       
   800         iObserver.MtrdvcoReturnCodedBuffer(codedBuffer);
       
   801         }
       
   802     
       
   803     // Get all pictures from devvideoplay and return them to decoder
       
   804     TVideoPicture* picture = NULL;    
       
   805     TRAPD(status, picture = iDevVideoPlay->NextPictureL());
       
   806     
       
   807     while ((picture != NULL) && (status == KErrNone))
       
   808         {
       
   809         PRINT((_L("CTRVideoDecoderClient::Pause(), Sending picture [0x%x] back to decoder"), picture))
       
   810         
       
   811         iDevVideoPlay->ReturnPicture(picture);
       
   812         picture = NULL;
       
   813         
       
   814         TRAP(status, picture = iDevVideoPlay->NextPictureL());
       
   815         }
       
   816     
       
   817     // Input buffer is not valid anymore   
       
   818     iInputBuffer = NULL;    
       
   819         
       
   820     iPause = ETrue;
       
   821     
       
   822     PRINT((_L("CTRVideoDecoderClient::Pause(), Out")))
       
   823     }
       
   824 
       
   825 // -----------------------------------------------------------------------------
       
   826 // CTRVideoDecoderClient::ResumeL
       
   827 // Resumes decoding
       
   828 // (other items were commented in a header).
       
   829 // -----------------------------------------------------------------------------
       
   830 //
       
   831 void CTRVideoDecoderClient::ResumeL()
       
   832     {
       
   833     PRINT((_L("CTRVideoDecoderClient::ResumeL(), In")))
       
   834 
       
   835     // Start decoding
       
   836     if (iFatalError == KErrNone)
       
   837         {
       
   838         iDevVideoPlay->Resume();
       
   839         }
       
   840 
       
   841     if (!iInputBuffer)
       
   842         {
       
   843         // Get buffer from the decoder to fill
       
   844         iInputBuffer = iDevVideoPlay->GetBufferL(iBufferOptions.iMaxInputBufferSize);
       
   845         }
       
   846     
       
   847     // Reset ts monitor
       
   848     iLastTimestamp = -1;
       
   849     
       
   850     iPause = EFalse;
       
   851 
       
   852     PRINT((_L("CTRVideoDecoderClient::ResumeL(), Out")))
       
   853     }
       
   854 
       
   855 
       
   856 // -----------------------------------------------------------------------------
       
   857 // CTRVideoDecoderClient::MdvpoNewBuffers()
       
   858 // New buffers are available
       
   859 // (other items were commented in a header).
       
   860 // -----------------------------------------------------------------------------
       
   861 //
       
   862 void CTRVideoDecoderClient::MdvpoNewBuffers()
       
   863     {
       
   864     TInt status = KErrNone;
       
   865 
       
   866 
       
   867     if (iStop)
       
   868         {
       
   869         PRINT((_L("CTRVideoDecoderClient::MdvpoNewBuffers(), Stop was already called, nothing to do")))
       
   870         return;
       
   871         }
       
   872 
       
   873     // One or more new empty input buffers are available
       
   874     if (!iInputBuffer)
       
   875         {
       
   876         // Get buffer from the decoder to fill
       
   877         TRAP(status, iInputBuffer = iDevVideoPlay->GetBufferL(iBufferOptions.iMaxInputBufferSize));
       
   878         
       
   879         if (status != KErrNone)
       
   880             {
       
   881             PRINT((_L("CTRVideoDecoderClient::MdvpoNewBuffers(), GetBufferL status[%d]"), status))
       
   882             iObserver.MtrdvcoFatalError(status);
       
   883             return;
       
   884             }
       
   885 
       
   886         if (!iInputBuffer)
       
   887             {
       
   888             PRINT((_L("CTRVideoDecoderClient::MdvpoNewBuffers(), There are available buffer, but decoder returned NULL")))
       
   889             
       
   890             // Report an error or wait for the next MdvpoNewBuffers ?: Wait, GetBufferL is called when client send new coded buffer. 
       
   891             //iObserver.MtrdvcoFatalError(KErrAlreadyExists);
       
   892             return;
       
   893             }
       
   894         }
       
   895 
       
   896     if (iCodedBuffer)
       
   897         {
       
   898         CCMRMediaBuffer* codedBuffer = iCodedBuffer;
       
   899         
       
   900         // Reset buffer ptr
       
   901         iCodedBuffer = NULL;
       
   902         
       
   903         // Send coded buffer, since the client has already done request
       
   904         TRAP(status, this->SendBufferL(codedBuffer));
       
   905         if (status != KErrNone)
       
   906             {
       
   907             PRINT((_L("CTRVideoDecoderClient::MdvpoNewBuffers(), Send buffer error[%d]"), status))
       
   908             iObserver.MtrdvcoFatalError(status);
       
   909             return;
       
   910             }
       
   911         }
       
   912     }
       
   913 
       
   914 
       
   915 // -----------------------------------------------------------------------------
       
   916 // CTRVideoDecoderClient::WriteCodedBufferL
       
   917 // Writes coded data to decoder
       
   918 // (other items were commented in a header).
       
   919 // -----------------------------------------------------------------------------
       
   920 //
       
   921 void CTRVideoDecoderClient::WriteCodedBufferL(CCMRMediaBuffer* aBuffer)
       
   922     {
       
   923     PRINT((_L("CTRVideoDecoderClient::WriteCodedBufferL(), In")))
       
   924     CCMRMediaBuffer::TBufferType bufferType;
       
   925     
       
   926     if (!aBuffer)
       
   927         {
       
   928         PRINT((_L("CTRVideoDecoderClient::WriteCodedBufferL(), Input buffer is invalid, Leave")))
       
   929         User::Leave(KErrArgument);
       
   930         }
       
   931 
       
   932     if (iFatalError != KErrNone)
       
   933         {
       
   934         PRINT((_L("CTRVideoDecoderClient::WriteCodedBufferL(), FatalError was reported by decoder")))
       
   935         
       
   936         // Return coded buffer
       
   937         iObserver.MtrdvcoReturnCodedBuffer(aBuffer);
       
   938         return;
       
   939         }
       
   940     
       
   941     TTimeIntervalMicroSeconds ts = aBuffer->TimeStamp();
       
   942         
       
   943     if ( ts <= iLastTimestamp)
       
   944         {
       
   945         // Prevent propagation of the error now
       
   946         PRINT((_L("CTRVideoDecoderClient::WriteCodedBufferL(), Client sends invalid data (ts field), Leave")))
       
   947         User::Leave(KErrArgument);
       
   948         }
       
   949     else
       
   950         {
       
   951         iLastTimestamp = ts;
       
   952         }
       
   953     
       
   954     if (aBuffer->BufferSize() <= 0)
       
   955         {
       
   956         PRINT((_L("CTRVideoDecoderClient::WriteCodedBufferL(), Input data buffer is invalid (empty), Leave")))
       
   957         User::Leave(KErrArgument);
       
   958         }
       
   959         
       
   960     bufferType = aBuffer->Type();
       
   961         
       
   962     if ( ( bufferType != CCMRMediaBuffer::EVideoH263 ) && 
       
   963          ( bufferType != CCMRMediaBuffer::EVideoMPEG4 ) )   // : Add H264
       
   964         {
       
   965         PRINT((_L("CTRVideoDecoderClient::WriteCodedBufferL(), [%d] This data type is not supported, Leave"), aBuffer->Type() ))
       
   966         User::Leave(KErrNotSupported);
       
   967         }
       
   968 
       
   969     if (!iInputBuffer)
       
   970         {
       
   971         // Request new empty buffer
       
   972         iInputBuffer = iDevVideoPlay->GetBufferL(iBufferOptions.iMaxInputBufferSize);
       
   973         }
       
   974 
       
   975     if (iInputBuffer)
       
   976         {
       
   977         this->SendBufferL(aBuffer);
       
   978         }
       
   979     else
       
   980         {
       
   981         iCodedBuffer = aBuffer;
       
   982         }
       
   983 
       
   984     PRINT((_L("CTRVideoDecoderClient::WriteCodedBufferL(), Out")))
       
   985     }
       
   986 
       
   987 
       
   988 // -----------------------------------------------------------------------------
       
   989 // CTRVideoDecoderClient::SendBufferL
       
   990 // Sends buffer to decoder
       
   991 // (other items were commented in a header).
       
   992 // -----------------------------------------------------------------------------
       
   993 //
       
   994 void CTRVideoDecoderClient::SendBufferL(CCMRMediaBuffer* aBuffer)
       
   995     {
       
   996     PRINT((_L("CTRVideoDecoderClient::SendBufferL(), In")))
       
   997     
       
   998     if (iStop)
       
   999         {
       
  1000         PRINT((_L("CTRVideoDecoderClient::SendBufferL(), Stop was already called, nothing to do, out")))
       
  1001         iObserver.MtrdvcoReturnCodedBuffer(aBuffer);
       
  1002         return;
       
  1003         }
       
  1004 
       
  1005     PRINT((_L("CTRVideoDecoderClient::SendBufferL(), iInputBuffer[%d], aBuffer[%d]"), iInputBuffer->iData.MaxLength(), 
       
  1006                aBuffer->BufferSize() ))
       
  1007 
       
  1008     if ( iInputBuffer->iData.MaxLength() < aBuffer->BufferSize() )
       
  1009         {
       
  1010         PRINT((_L("CTRVideoDecoderClient::SendBufferL(), buffer length exceeds max length")))
       
  1011         User::Leave(KErrOverflow);
       
  1012         }
       
  1013 
       
  1014     iInputBuffer->iData.Copy( aBuffer->Data().Ptr(), aBuffer->BufferSize() );
       
  1015     iInputBuffer->iData.SetLength( aBuffer->BufferSize() );
       
  1016 
       
  1017     // Data unit presentation timestamp. Valid if EPresentationTimestamp is set in the options. 
       
  1018     // If the input bitstream does not contain timestamp information, this field should be valid, 
       
  1019     // otherwise pictures cannot be displayed at the correct time. If the input bitstream contains 
       
  1020     // timestamp information (such as the TR syntax element of H.263 bitstreams) and valid 
       
  1021     // iPresentationTimestamp is provided, the value of iPresentationTimestamp is used in playback.    
       
  1022     iInputBuffer->iOptions = TVideoInputBuffer::EPresentationTimestamp;
       
  1023     iInputBuffer->iPresentationTimestamp = aBuffer->TimeStamp();
       
  1024     /*Other data: TBC*/
       
  1025     
       
  1026     TVideoInputBuffer* inputBuffer = iInputBuffer;
       
  1027     
       
  1028     // Reset InputBuffer ptr
       
  1029     iInputBuffer = NULL;
       
  1030 
       
  1031     // Write data to decoder
       
  1032     iDevVideoPlay->WriteCodedDataL(inputBuffer);
       
  1033 
       
  1034     //  return buffer only after it's writtent to decoder (client could write next buffer synchronously from observer call)
       
  1035     // Return buffer to the client immediately after copying
       
  1036     iObserver.MtrdvcoReturnCodedBuffer(aBuffer);
       
  1037 
       
  1038     PRINT((_L("CTRVideoDecoderClient::SendBufferL(), Out")))
       
  1039     }
       
  1040 
       
  1041 
       
  1042 // -----------------------------------------------------------------------------
       
  1043 // CTRVideoDecoderClient::MdvpoNewPictures
       
  1044 // New decoded pictures available from decoder
       
  1045 // (other items were commented in a header).
       
  1046 // -----------------------------------------------------------------------------
       
  1047 //
       
  1048 void CTRVideoDecoderClient::MdvpoNewPictures()
       
  1049     {
       
  1050     PRINT((_L("CTRVideoDecoderClient::MdvpoNewPictures(), In")))
       
  1051     
       
  1052     TInt status = KErrNone;
       
  1053 
       
  1054     // 1 or more decoded pictures are available
       
  1055     if (!iDecodedPicture)
       
  1056         {
       
  1057         // Get new picture
       
  1058         TRAP(status, iDecodedPicture = iDevVideoPlay->NextPictureL());
       
  1059 
       
  1060         if (status != KErrNone)
       
  1061             {
       
  1062             PRINT((_L("CTRVideoDecoderClient::MdvpoNewPictures(), NextPicture status[%d]"), status))
       
  1063             iObserver.MtrdvcoFatalError(status);
       
  1064             return;
       
  1065             }
       
  1066 
       
  1067         if (!iDecodedPicture)
       
  1068             {
       
  1069             // Error: DevVideo notified of new buffers, but returns NULL
       
  1070             PRINT((_L("CTRVideoDecoderClient::MdvpoNewPictures(), DevVideo notified of new buffers, but returns NULL")))
       
  1071             iObserver.MtrdvcoFatalError(KErrAlreadyExists);
       
  1072             return;
       
  1073             }
       
  1074 
       
  1075         // Send new picture to the client
       
  1076         iObserver.MtrdvcoNewPicture(iDecodedPicture);
       
  1077         }
       
  1078     else
       
  1079         {
       
  1080         // Previous picture still was not returned by the client, nothing to do. 
       
  1081         //  SetActive();  // ???
       
  1082         }
       
  1083         
       
  1084     PRINT((_L("CTRVideoDecoderClient::MdvpoNewPictures(), Out")))
       
  1085     }
       
  1086 
       
  1087 
       
  1088 // -----------------------------------------------------------------------------
       
  1089 // CTRVideoDecoderClient::ReturnPicture
       
  1090 // Returns picture 
       
  1091 // (other items were commented in a header).
       
  1092 // -----------------------------------------------------------------------------
       
  1093 //
       
  1094 void CTRVideoDecoderClient::ReturnPicture(TVideoPicture* aPicture)
       
  1095     {
       
  1096     PRINT((_L("CTRVideoDecoderClient::ReturnPicture(), In")))
       
  1097     TInt status = KErrNone;
       
  1098 
       
  1099 
       
  1100     iDevVideoPlay->ReturnPicture(aPicture);
       
  1101 
       
  1102     // Reset decoded picture
       
  1103     iDecodedPicture = NULL;
       
  1104     
       
  1105     if (iPause)
       
  1106         {
       
  1107         // Nothing else to do when paused
       
  1108         PRINT((_L("CTRVideoDecoderClient::ReturnPicture(), Out")))
       
  1109         return;
       
  1110         }
       
  1111 
       
  1112     TRAP(status, iDecodedPicture = iDevVideoPlay->NextPictureL());
       
  1113 
       
  1114     if (status != KErrNone)
       
  1115         {
       
  1116         PRINT((_L("CTRVideoDecoderClient::ReturnPicture(), NextPicture status[%d]"), status))
       
  1117         iObserver.MtrdvcoFatalError(status);
       
  1118         return;
       
  1119         }
       
  1120 
       
  1121     if (iDecodedPicture)
       
  1122         {
       
  1123         // Send new picture to the client
       
  1124         iObserver.MtrdvcoNewPicture(iDecodedPicture);
       
  1125         }
       
  1126 
       
  1127     PRINT((_L("CTRVideoDecoderClient::ReturnPicture(), Out")))
       
  1128     }
       
  1129 
       
  1130 
       
  1131 // -----------------------------------------------------------------------------
       
  1132 // CTRVideoDecoderClient::StopL
       
  1133 // Stops decoding synchronously
       
  1134 // (other items were commented in a header).
       
  1135 // -----------------------------------------------------------------------------
       
  1136 //
       
  1137 void CTRVideoDecoderClient::StopL()
       
  1138     {
       
  1139     PRINT((_L("CTRVideoDecoderClient::StopL(), In")))
       
  1140     
       
  1141     iStop = ETrue;
       
  1142     iPause = EFalse;
       
  1143 
       
  1144     if (iFatalError == KErrNone)
       
  1145         {
       
  1146         iDevVideoPlay->Stop();
       
  1147         }
       
  1148         
       
  1149     PRINT((_L("CTRVideoDecoderClient::StopL(), Out")))
       
  1150     }
       
  1151 
       
  1152 
       
  1153 // -----------------------------------------------------------------------------
       
  1154 // CTRVideoDecoderClient::AsyncStopL
       
  1155 // Stops decoding asynchronously
       
  1156 // (other items were commented in a header).
       
  1157 // -----------------------------------------------------------------------------
       
  1158 //
       
  1159 void CTRVideoDecoderClient::AsyncStopL()
       
  1160     {
       
  1161     PRINT((_L("CTRVideoDecoderClient::StopL(), Async In")))
       
  1162 
       
  1163     if (iFatalError == KErrNone)
       
  1164         {
       
  1165         iDevVideoPlay->InputEnd();
       
  1166         }
       
  1167         
       
  1168     iStop = ETrue;
       
  1169 
       
  1170     PRINT((_L("CTRVideoDecoderClient::StopL(), Async Out")))
       
  1171     }
       
  1172 
       
  1173 
       
  1174 // -----------------------------------------------------------------------------
       
  1175 // CTRVideoDecoderClient::MdvpoStreamEnd
       
  1176 // Indicates when stream end is reached
       
  1177 // (other items were commented in a header).
       
  1178 // -----------------------------------------------------------------------------
       
  1179 //
       
  1180 void CTRVideoDecoderClient::MdvpoStreamEnd()
       
  1181     {
       
  1182     PRINT((_L("CTRVideoDecoderClient::MdvpoStreamEnd()")))
       
  1183     iObserver.MtrdvcoDecStreamEnd();
       
  1184     }
       
  1185 
       
  1186 // -----------------------------------------------------------------------------
       
  1187 // CTRVideoDecoderClient::MdvpoReturnPicture
       
  1188 // Returns a used input video picture back to the caller. The picture memory can be re-used or freed (only relevant to postprocessor)
       
  1189 // (other items were commented in a header).
       
  1190 // -----------------------------------------------------------------------------
       
  1191 //
       
  1192 void CTRVideoDecoderClient::MdvpoReturnPicture(TVideoPicture* /*aPicture*/)
       
  1193     {
       
  1194     PRINT((_L("CTRVideoDecoderClient::MdvpoReturnPicture()")))
       
  1195     }
       
  1196 
       
  1197 
       
  1198 // -----------------------------------------------------------------------------
       
  1199 // CTRVideoDecoderClient::MdvpoSupplementalInformation
       
  1200 // Sends SupplementalInformation
       
  1201 // (other items were commented in a header).
       
  1202 // -----------------------------------------------------------------------------
       
  1203 //
       
  1204 void CTRVideoDecoderClient::MdvpoSupplementalInformation(const TDesC8& /*aData*/, 
       
  1205                                                          const TTimeIntervalMicroSeconds& /*aTimestamp*/, 
       
  1206                                                          const TPictureId& /*aPictureId*/)
       
  1207     {
       
  1208     PRINT((_L("CTRVideoDecoderClient::MdvpoSupplementalInformation()")))
       
  1209     }
       
  1210 
       
  1211 
       
  1212 // -----------------------------------------------------------------------------
       
  1213 // CTRVideoDecoderClient::MdvpoPictureLoss
       
  1214 // Back channel information from the decoder, indicating a picture loss without specifying the lost picture
       
  1215 // (other items were commented in a header).
       
  1216 // -----------------------------------------------------------------------------
       
  1217 //
       
  1218 void CTRVideoDecoderClient::MdvpoPictureLoss()
       
  1219     {
       
  1220     PRINT((_L("CTRVideoDecoderClient::MdvpoPictureLoss(), report an error")))
       
  1221     iObserver.MtrdvcoFatalError(KErrAbort);
       
  1222     }
       
  1223 
       
  1224 
       
  1225 // -----------------------------------------------------------------------------
       
  1226 // CTRVideoDecoderClient::MdvpoPictureLoss
       
  1227 // Back channel information from the decoder, indicating the pictures that have been lost
       
  1228 // (other items were commented in a header).
       
  1229 // -----------------------------------------------------------------------------
       
  1230 //
       
  1231 void CTRVideoDecoderClient::MdvpoPictureLoss(const TArray< TPictureId >& /*aPictures*/)
       
  1232     {
       
  1233     PRINT((_L("CTRVideoDecoderClient::MdvpoPictureLoss(), pictureId: report an error")))
       
  1234     iObserver.MtrdvcoFatalError(KErrAbort);
       
  1235     }
       
  1236 
       
  1237 
       
  1238 // -----------------------------------------------------------------------------
       
  1239 // CTRVideoDecoderClient::MdvpoSliceLoss
       
  1240 // Reports that slice is lost
       
  1241 // (other items were commented in a header).
       
  1242 // -----------------------------------------------------------------------------
       
  1243 //
       
  1244 void CTRVideoDecoderClient::MdvpoSliceLoss(TUint /*aFirstMacroblock*/, TUint /*aNumMacroblocks*/, 
       
  1245                                            const TPictureId& /*aPicture*/)
       
  1246     {
       
  1247     PRINT((_L("CTRVideoDecoderClient::MdvpoSliceLoss()")))
       
  1248     // This error is not considered a s fatal for decoder or application, nothing to do
       
  1249     }
       
  1250 
       
  1251 
       
  1252 // -----------------------------------------------------------------------------
       
  1253 // CTRVideoDecoderClient::MdvpoReferencePictureSelection
       
  1254 // Back channel information from the decoder, indicating a reference picture selection request.
       
  1255 // (other items were commented in a header).
       
  1256 // -----------------------------------------------------------------------------
       
  1257 //
       
  1258 void CTRVideoDecoderClient::MdvpoReferencePictureSelection(const TDesC8& /*aSelectionData*/)
       
  1259     {
       
  1260     PRINT((_L("CTRVideoDecoderClient::MdvpoReferencePictureSelection()")))
       
  1261     }
       
  1262 
       
  1263 
       
  1264 // -----------------------------------------------------------------------------
       
  1265 // CTRVideoDecoderClient::MdvpoTimedSnapshotComplete
       
  1266 // Called when a timed snapshot request has been completed. 
       
  1267 // (other items were commented in a header).
       
  1268 // -----------------------------------------------------------------------------
       
  1269 //
       
  1270 void CTRVideoDecoderClient::MdvpoTimedSnapshotComplete(TInt /*aError*/, TPictureData* /*aPictureData*/, 
       
  1271                                                        const TTimeIntervalMicroSeconds& /*aPresentationTimestamp*/, 
       
  1272                                                        const TPictureId& /*aPictureId*/)
       
  1273     {
       
  1274     PRINT((_L("CTRVideoDecoderClient::MdvpoTimedSnapshotComplete()")))
       
  1275     }
       
  1276 
       
  1277 
       
  1278 // -----------------------------------------------------------------------------
       
  1279 // CTRVideoDecoderClient::MdvpoFatalError
       
  1280 // Reports the fatal error to the client
       
  1281 // (other items were commented in a header).
       
  1282 // -----------------------------------------------------------------------------
       
  1283 //
       
  1284 void CTRVideoDecoderClient::MdvpoFatalError(TInt aError)
       
  1285     {
       
  1286     PRINT((_L("CTRVideoDecoderClient::MdvpoFatalError(), error[%d]"), aError))
       
  1287     iFatalError = aError;
       
  1288     iObserver.MtrdvcoFatalError(iFatalError);
       
  1289     }
       
  1290 
       
  1291 
       
  1292 // -----------------------------------------------------------------------------
       
  1293 // CTRVideoDecoderClient::EstimateDecodeFrameTimeL
       
  1294 // Returns a time estimate on long it takes to decode one frame 
       
  1295 // (other items were commented in a header).
       
  1296 // -----------------------------------------------------------------------------
       
  1297 //    
       
  1298 TReal CTRVideoDecoderClient::EstimateDecodeFrameTimeL(const TTRVideoFormat& aInput, TInt aCodecType)
       
  1299     {
       
  1300     if (iUid == TUid::Null())
       
  1301         {
       
  1302         PRINT((_L("CTRVideoDecoderClient::EstimateDecodeFrameTimeL(), no decoder selected yet")))
       
  1303         User::Leave(KErrNotReady);
       
  1304         }
       
  1305     
       
  1306     TReal time = 0.0;    
       
  1307     
       
  1308     // Select the predefined constant using the current settings
       
  1309     if (aCodecType == EH263)
       
  1310         {
       
  1311         time = iAcceleratedCodecSelected ? KTRDecodeTimeFactorH263HW : KTRDecodeTimeFactorH263SW;
       
  1312         }
       
  1313     else if (aCodecType == EH264)
       
  1314         {
       
  1315         time = iAcceleratedCodecSelected ? KTRDecodeTimeFactorH264HW : KTRDecodeTimeFactorH264SW;
       
  1316         }
       
  1317     else
       
  1318         {
       
  1319         time = iAcceleratedCodecSelected ? KTRDecodeTimeFactorMPEG4HW : KTRDecodeTimeFactorMPEG4SW;
       
  1320         }
       
  1321     
       
  1322     // Multiply the time by the resolution of the input frame    
       
  1323     time *= static_cast<TReal>(aInput.iSize.iWidth + aInput.iSize.iHeight) * KTRTimeFactorScale;
       
  1324     
       
  1325     PRINT((_L("CTRVideoDecoderClient::EstimateDecodeFrameTimeL(), decode frame time: %.2f"), time))
       
  1326         
       
  1327     return time;
       
  1328     }
       
  1329 
       
  1330 // -----------------------------------------------------------------------------
       
  1331 // CTRVideoDecoderClient::SetDecoderScaling
       
  1332 // Checks if decoder supports scaling and enables scaling if supported
       
  1333 // (other items were commented in a header).
       
  1334 // -----------------------------------------------------------------------------
       
  1335 //    
       
  1336 TBool CTRVideoDecoderClient::SetDecoderScaling(TSize& aInputSize, TSize& aOutputSize)
       
  1337     {
       
  1338     PRINT((_L("CTRVideoDecoderClient::SetDecoderScaling(), In")))
       
  1339     
       
  1340     CPostProcessorInfo* ppInfo = NULL;
       
  1341     TBool scalingSupported = EFalse;
       
  1342     
       
  1343     // Check that the given sizes are valid
       
  1344     if( (aInputSize.iWidth == 0) || (aInputSize.iHeight == 0) ||
       
  1345         (aOutputSize.iWidth == 0) || (aOutputSize.iHeight == 0) )
       
  1346         {
       
  1347         PRINT((_L("CTRVideoDecoderClient::SetDecoderScaling(), invalid input/output size")))
       
  1348         return EFalse;
       
  1349         }
       
  1350         
       
  1351     iScalingInUse = EFalse;
       
  1352     iScalingWithDeblocking = EFalse;
       
  1353     
       
  1354     if( aInputSize == aOutputSize )
       
  1355         {
       
  1356         PRINT((_L("CTRVideoDecoderClient::SetDecoderScaling(), scaling disabled")))
       
  1357         return EFalse;
       
  1358         }
       
  1359        
       
  1360     // Get post processor info
       
  1361     TRAPD( status, ppInfo = iDevVideoPlay->PostProcessorInfoLC( iUid ); CleanupStack::Pop( ppInfo ) );
       
  1362 
       
  1363     if( (status != KErrNone) || !ppInfo )
       
  1364         {
       
  1365         PRINT((_L("CTRVideoDecoderClient::SetDecoderScaling(), getting info from [0x%x] failed"), iUid.iUid ))
       
  1366         return EFalse;
       
  1367         }
       
  1368         
       
  1369     if( ppInfo->SupportsArbitraryScaling() )
       
  1370         {
       
  1371         PRINT((_L("CTRVideoDecoderClient::SetDecoderScaling(), arbitrary scaling supported")))
       
  1372         scalingSupported = ETrue;
       
  1373         }
       
  1374     else if( (aInputSize.iWidth * aOutputSize.iHeight) != (aInputSize.iHeight * aOutputSize.iWidth) )
       
  1375         {
       
  1376         // Aspect ratio needs to be changed but decoder does not support arbitrary scaling => not supported
       
  1377         scalingSupported = EFalse;
       
  1378         }
       
  1379     else
       
  1380         {        
       
  1381         RArray<TScaleFactor> scaleFactors = ppInfo->SupportedScaleFactors();
       
  1382         
       
  1383         for( TInt i = 0; i < scaleFactors.Count(); ++i )
       
  1384             {
       
  1385             if( (aInputSize.iWidth * scaleFactors[i].iScaleNum) == (aOutputSize.iWidth * scaleFactors[i].iScaleDenom) )
       
  1386                 {
       
  1387                 PRINT((_L("CTRVideoDecoderClient::SetDecoderScaling(), supported scale factors found")))
       
  1388                 scalingSupported = ETrue;
       
  1389                 break;
       
  1390                 }
       
  1391             }
       
  1392         }
       
  1393     
       
  1394     if( scalingSupported )
       
  1395         {        
       
  1396         if( ppInfo->SupportsCombination( EPpScale | EPpDeblocking ) )
       
  1397             {
       
  1398             // Deblocking should be used with scaling if supported
       
  1399             PRINT((_L("CTRVideoDecoderClient::SetDecoderScaling(), deblocking supported")))
       
  1400             iScalingWithDeblocking = ETrue;
       
  1401             }
       
  1402 
       
  1403         iScalingInUse = ETrue;
       
  1404         iScaledOutputSize = aOutputSize;
       
  1405         }
       
  1406 
       
  1407     // Delete codec info
       
  1408     delete ppInfo;
       
  1409     
       
  1410     PRINT((_L("CTRVideoDecoderClient::SetDecoderScaling(), Out")))
       
  1411     
       
  1412     return scalingSupported;
       
  1413     }
       
  1414 
       
  1415 // -----------------------------------------------------------------------------
       
  1416 // CTRVideoDecoderClient::EnableResourceObserver
       
  1417 // Enable / Disable resourece observer
       
  1418 // (other items were commented in a header).
       
  1419 // -----------------------------------------------------------------------------
       
  1420 //     
       
  1421 void CTRVideoDecoderClient::EnableResourceObserver(TBool aEnable)
       
  1422     {
       
  1423     PRINT((_L("CTRVideoDecoderClient::EnableResourceObserver(), In")))
       
  1424     
       
  1425     iVideoResourceHandlerCI = (MMmfVideoResourceHandler*)iDevVideoPlay->CustomInterface( iHwDeviceId, KUidMmfVideoResourceManagement );
       
  1426     PRINT((_L("CTRVideoDecoderClient::EnableResourceObserver(), iVideoResourceHandlerCI[0x%x]"), iVideoResourceHandlerCI))
       
  1427 
       
  1428     if (iVideoResourceHandlerCI)
       
  1429         {
       
  1430         if (aEnable)
       
  1431             {
       
  1432             iVideoResourceHandlerCI->MmvrhSetObserver(this);
       
  1433             PRINT((_L("CTRVideoDecoderClient::EnableResourceObserver(), Enabled")))
       
  1434             }
       
  1435         else
       
  1436             {
       
  1437             iVideoResourceHandlerCI->MmvrhSetObserver(NULL);
       
  1438             }
       
  1439         }
       
  1440 
       
  1441     PRINT((_L("CTRVideoDecoderClient::EnableResourceObserver(), Out")))
       
  1442     }
       
  1443 
       
  1444 // -----------------------------------------------------------------------------
       
  1445 // CTRVideoDecoderClient::MmvroResourcesLost
       
  1446 // Indicates that a media device has lost its resources
       
  1447 // (other items were commented in a header).
       
  1448 // -----------------------------------------------------------------------------
       
  1449 //     
       
  1450 void CTRVideoDecoderClient::MmvroResourcesLost(TUid /*aMediaDevice*/)
       
  1451     {
       
  1452     iObserver.MtrdvcoResourcesLost(ETrue);
       
  1453     }
       
  1454         
       
  1455 
       
  1456 // -----------------------------------------------------------------------------
       
  1457 // CTRVideoDecoderClient::MmvroResourcesRestored
       
  1458 // Indicates that a media device has regained its resources
       
  1459 // (other items were commented in a header).
       
  1460 // -----------------------------------------------------------------------------
       
  1461 // 
       
  1462 void CTRVideoDecoderClient::MmvroResourcesRestored(TUid /*aMediaDevice*/)
       
  1463     {
       
  1464     iObserver.MtrdvcoResourcesRestored();
       
  1465     }
       
  1466 
       
  1467 
       
  1468 // End of file