mmserv/thumbnailengine/TneProcessorSrc/TNEDecoderWrap.cpp
changeset 0 71ca22bcf22a
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     1 /*
       
     2 * Copyright (c) 2006 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:   TNE decoder wrapper
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <devvideoconstants.h>
       
    23 #include "TNEDecoderWrap.h"
       
    24 #include "ctrsettings.h"
       
    25 
       
    26 // MACROS
       
    27 #define TRASSERT(x) __ASSERT_DEBUG(x, User::Panic(_L("CTRANSCODERVIDEODECODERCLIENT"), -10010))
       
    28 
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CTNEDecoderWrap::NewL
       
    34 // Two-phased constructor.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CTNEDecoderWrap* CTNEDecoderWrap::NewL(MThumbnailObserver* aObserver)
       
    38 {
       
    39     PRINT((_L("CTNEDecoderWrap::NewL(), In")))
       
    40     CTNEDecoderWrap* self = new (ELeave) CTNEDecoderWrap(aObserver);
       
    41     CleanupStack::PushL(self);
       
    42     self->ConstructL();
       
    43     CleanupStack::Pop();
       
    44 
       
    45     PRINT((_L("CTNEDecoderWrap::NewL(), Out")))
       
    46     return self;
       
    47 }
       
    48 
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CTNEDecoderWrap::CTNEDecoderWrap
       
    52 // C++ default constructor can NOT contain any code, that
       
    53 // might leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CTNEDecoderWrap::CTNEDecoderWrap(MThumbnailObserver* aObserver)
       
    57 {    
       
    58     iObserver = aObserver;
       
    59     iDevVideoPlay = NULL;
       
    60     iCompresedFormat = NULL;
       
    61     iClockSource = NULL;
       
    62     iUid = TUid::Null();
       
    63     iHwDeviceId = THwDeviceId(0);
       
    64     iInputBuffer = NULL;
       
    65     iCodedBuffer = NULL;
       
    66     iDecodedPicture = NULL;
       
    67     iFatalError = KErrNone;
       
    68     iDataUnitType = EDuCodedPicture;
       
    69     iStop = EFalse;
       
    70     iState = ETRNone;
       
    71     iLastTimestamp = -1;
       
    72 }
       
    73 
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CTNEDecoderWrap::ConstructL
       
    77 // Symbian 2nd phase constructor can leave.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CTNEDecoderWrap::ConstructL()
       
    81 {
       
    82     iDevVideoPlay = CMMFDevVideoPlay::NewL(*this);
       
    83     
       
    84     // Support for AVC
       
    85    	iClockSource = CSystemClockSource::NewL();
       
    86    	iInputFrameNum = 1;	
       
    87 }
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // CTNEDecoderWrap::~CTNEDecoderWrap()
       
    92 // Destructor
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 CTNEDecoderWrap::~CTNEDecoderWrap()
       
    96 {
       
    97     PRINT((_L("CTNEDecoderWrap::~CTNEDecoderWrap(), In")))
       
    98 
       
    99     if (iDevVideoPlay)
       
   100     {
       
   101         delete iDevVideoPlay;
       
   102         iDevVideoPlay = NULL;
       
   103     }
       
   104 
       
   105     iInputBuffer = NULL;
       
   106     
       
   107     if (iClockSource)
       
   108     {
       
   109     	delete iClockSource;
       
   110     	iClockSource = 0;
       
   111     }
       
   112      
       
   113     
       
   114     if (iCompresedFormat)
       
   115     {
       
   116         delete iCompresedFormat;
       
   117     }
       
   118         
       
   119     iAcceleratedDecoders.Reset();
       
   120     iAcceleratedDecoders.Close();
       
   121 
       
   122     PRINT((_L("CTNEDecoderWrap::~CTNEDecoderWrap(), Out")))
       
   123 }
       
   124 
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CTNEDecoderWrap::SupportsCodec
       
   128 // Checks whether this coded is supported
       
   129 // (other items were commented in a header).
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 TBool CTNEDecoderWrap::SupportsCodec(const TDesC8& aFormat, const TDesC8& aShortFormat)
       
   133 {
       
   134     TBool supports = EFalse;
       
   135     TBuf8<256> mime;
       
   136     
       
   137     if (iDevVideoPlay)
       
   138     {
       
   139         RArray<TUid> decoders;
       
   140         
       
   141         TRAPD( status, iDevVideoPlay->FindDecodersL(aShortFormat, 0/*aPreProcType*/, decoders, EFalse/*aExactMatch*/) );
       
   142 
       
   143         if( ( status != KErrNone ) || ( decoders.Count() <= 0 ) )
       
   144         {
       
   145             PRINT((_L("CTNEDecoderWrap::SupportsCodec(), status[%d]"), status))
       
   146             supports = EFalse;
       
   147         }
       
   148         else
       
   149         {
       
   150             // Keep mime type given by codec fo future use
       
   151             iMimeType = aFormat;
       
   152             iShortMimeType = aShortFormat;
       
   153             supports = ETrue;
       
   154         }
       
   155 
       
   156         decoders.Reset();
       
   157         decoders.Close();
       
   158     }
       
   159 
       
   160     return supports;
       
   161 }
       
   162 
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CTNEDecoderWrap::SetDecoderParametersL
       
   166 // Sets codec parameters
       
   167 // (other items were commented in a header).
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 void CTNEDecoderWrap::SetDecoderParametersL(TInt aDecoderLevel, const TTRVideoFormat& aFormat)
       
   171 {
       
   172     PRINT((_L("CTNEDecoderWrap::SetDecoderParametersL(), In")))
       
   173     RArray<TUid> decoders;
       
   174     TBool codecAcceleration = EFalse;
       
   175     TInt status = KErrNone;
       
   176     iCodecLevel = aDecoderLevel;
       
   177     iFormat = aFormat;
       
   178 
       
   179 	// Find the list of decoders 
       
   180     iDevVideoPlay->FindDecodersL(iShortMimeType, 0/*aPreProcType*/, decoders, EFalse/*aExactMatch*/);
       
   181 
       
   182     // Input format
       
   183     if (!iCompresedFormat)
       
   184     {
       
   185         TRAP(status, iCompresedFormat = CCompressedVideoFormat::NewL( iMimeType ));
       
   186         
       
   187         if (status != KErrNone)
       
   188         {
       
   189             // Reset decoder's list
       
   190             decoders.Reset();
       
   191             decoders.Close();
       
   192             User::Leave(status);
       
   193         }
       
   194     }
       
   195 
       
   196     // get decoder info
       
   197     for ( TInt i = 0; i < decoders.Count(); i ++ )
       
   198     {
       
   199         TRAP( status, codecAcceleration = CheckDecoderInfoL(decoders[i]) );
       
   200 
       
   201         if (status == KErrNone)
       
   202         {
       
   203             if (codecAcceleration != KTRAccelerationPriorityDecoder) 
       
   204             {
       
   205                 // Use the first available software decoder
       
   206                 iUid = decoders[i];
       
   207 
       
   208                 // Keep the list of non-checked codecs for future use
       
   209                 i = i + 1;
       
   210                 for (; i < decoders.Count(); i ++)
       
   211                 {
       
   212                     iCheckDecoders.Insert(decoders[i], iCheckDecoders.Count() );
       
   213                 }
       
   214 
       
   215                 break;
       
   216             }
       
   217             else
       
   218             {
       
   219                 // Keep track of accelerated decoder to the list of "good" decoders
       
   220                 iAcceleratedDecoders.Insert( decoders[i], iAcceleratedDecoders.Count() );
       
   221             }
       
   222         }
       
   223     }
       
   224         
       
   225     decoders.Reset();
       
   226     decoders.Close();
       
   227         
       
   228     if (iUid == TUid::Null())
       
   229     {
       
   230         // Check others "good"
       
   231         if ( iAcceleratedDecoders.Count() <= 0 )
       
   232         {
       
   233             PRINT((_L("CTNEDecoderWrap::SetDecoderParametersL(), No suitable decoders found")))
       
   234             User::Leave(KErrNotSupported);
       
   235         }
       
   236         else
       
   237         {
       
   238             // Select the accelerated as no ARM decoder is available
       
   239             iUid = iAcceleratedDecoders[0];
       
   240             iAcceleratedDecoders.Remove(0);
       
   241         }
       
   242     }
       
   243 
       
   244     PRINT((_L("CTNEDecoderWrap::SetDecoderParametersL(), Out")))
       
   245 }
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // CTNEDecoderWrap::CheckDecoderInfoL
       
   249 // Checks coded info
       
   250 // (other items were commented in a header).
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 TBool CTNEDecoderWrap::CheckDecoderInfoL(TUid aUid)
       
   254 {
       
   255     CVideoDecoderInfo* decoderInfo = NULL; // Decoder info for retrieving capabilities
       
   256     TInt status = KErrNone;
       
   257     TBool accelerated = EFalse;
       
   258 
       
   259     // Check decoder
       
   260     PRINT((_L("CTNEDecoderWrap::CheckDecoderInfoL(), getting info from [0x%x]"), aUid.iUid ))
       
   261     decoderInfo = iDevVideoPlay->VideoDecoderInfoLC( aUid );
       
   262 
       
   263     if (!decoderInfo)
       
   264 	{
       
   265         PRINT((_L("CTNEDecoderWrap::CheckDecoderInfoL(), getting info from [0x%x] failed[%d]"), aUid.iUid, status ))
       
   266         User::Leave(KErrNotSupported);
       
   267 	}
       
   268     else 
       
   269 	{
       
   270         // Check max rate for requested image format
       
   271         TSize maxSize = decoderInfo->MaxPictureSize();
       
   272 
       
   273         if ( (iFormat.iSize.iWidth > maxSize.iWidth) || (iFormat.iSize.iHeight > maxSize.iHeight) )
       
   274         {
       
   275             PRINT((_L("CTNEDecoderWrap::CheckDecoderInfoL(), Picture size is not supported")))
       
   276             status = KErrNotSupported;
       
   277         }
       
   278 	}
       
   279         
       
   280     accelerated = decoderInfo->Accelerated();
       
   281 
       
   282     // Delete codec info
       
   283     CleanupStack::PopAndDestroy(decoderInfo);
       
   284 
       
   285     if (status != KErrNone)
       
   286     {
       
   287         User::Leave(status);
       
   288     }
       
   289 
       
   290     return accelerated;
       
   291 }
       
   292 
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CTNEDecoderWrap::InitializeL
       
   296 // Initializes decoder
       
   297 // (other items were commented in a header).
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 void CTNEDecoderWrap::InitializeL()
       
   301     {
       
   302     PRINT((_L("CTNEDecoderWrap::InitializeL(), In")))
       
   303     TUint maxBufferSize = 0;
       
   304     TInt status = KErrNone;
       
   305 
       
   306 	iState = ETRInitializing;
       
   307 
       
   308     switch(iFormat.iDataType)
       
   309         {
       
   310         case ETRDuCodedPicture:
       
   311             {
       
   312             iDataUnitType = EDuCodedPicture;
       
   313             break;
       
   314             }
       
   315 
       
   316         case ETRDuVideoSegment:
       
   317             {
       
   318             iDataUnitType = EDuVideoSegment;
       
   319             break;
       
   320             }
       
   321 
       
   322         default:
       
   323             {
       
   324             // Should never happend. Decoder does not support uncompressed input format. 
       
   325             TRASSERT(0);
       
   326             }
       
   327         }
       
   328 
       
   329     iBufferOptions.iMinNumInputBuffers = KTRDecoderMinNumberOfBuffers;
       
   330 
       
   331     // Select decoder first
       
   332     this->SelectDecoderL();
       
   333 
       
   334     // Set now output format for this device    
       
   335     TRAP(status, iDevVideoPlay->SetOutputFormatL(iHwDeviceId, iUncompressedFormat));
       
   336     
       
   337     // 3. Buffer options
       
   338     iBufferOptions.iPreDecodeBufferSize = 0;            // "0" - use default decoder value
       
   339     iBufferOptions.iMaxPostDecodeBufferSize = 0;        // No limitations
       
   340     iBufferOptions.iPreDecoderBufferPeriod = 0;
       
   341     iBufferOptions.iPostDecoderBufferPeriod = 0;
       
   342     
       
   343     // Check max coded picture size for specified codec level
       
   344     switch(iCodecLevel)
       
   345         {
       
   346         case KTRH263CodecLevel10:
       
   347             {
       
   348             maxBufferSize = KTRMaxBufferSizeLevel10;
       
   349             break;
       
   350             }
       
   351 
       
   352         case KTRH263CodecLevel20:
       
   353             {
       
   354             maxBufferSize = KTRMaxBufferSizeLevel20;
       
   355             break;
       
   356             }
       
   357 
       
   358         case KTRH263CodecLevel30:
       
   359             {
       
   360             maxBufferSize = KTRMaxBufferSizeLevel30;
       
   361             break;
       
   362             }
       
   363 
       
   364         case KTRH263CodecLevel40:
       
   365             {
       
   366             maxBufferSize = KTRMaxBufferSizeLevel40;
       
   367             break;
       
   368             }
       
   369 
       
   370         case KTRH263CodecLevel50:
       
   371             {
       
   372             maxBufferSize = KTRMaxBufferSizeLevel50;
       
   373             break;
       
   374             }
       
   375 
       
   376         case KTRH263CodecLevel60:
       
   377             {
       
   378             maxBufferSize = KTRMaxBufferSizeLevel60;
       
   379             break;
       
   380             }
       
   381 
       
   382         case KTRH263CodecLevel70:
       
   383             {
       
   384             maxBufferSize = KTRMaxBufferSizeLevel70;
       
   385             break;
       
   386             }
       
   387 
       
   388         case KTRMPEG4CodecLevel0:
       
   389             {
       
   390             maxBufferSize = KTRMaxBufferSizeLevel0;
       
   391             break;
       
   392             }
       
   393             
       
   394         case KTRMPEG4CodecLevel1:
       
   395             {
       
   396             maxBufferSize = KTRMaxBufferSizeLevel1;
       
   397             break;
       
   398             }
       
   399             
       
   400         case KTRMPEG4CodecLevel2:
       
   401             {
       
   402             maxBufferSize = KTRMaxBufferSizeLevel2;
       
   403             break;
       
   404             }
       
   405             
       
   406         case KTRMPEG4CodecLevel3:
       
   407             {
       
   408             maxBufferSize = KTRMaxBufferSizeLevel3;
       
   409             break;
       
   410             }
       
   411 
       
   412         case KTRMPEG4CodecLevel0b:
       
   413             {
       
   414             maxBufferSize = KTRMaxBufferSizeLevel0b;
       
   415             break;
       
   416             }
       
   417 
       
   418         case KTRMPEG4CodecLevel4a:
       
   419             {
       
   420             maxBufferSize = KTRMaxBufferSizeLevel4a;
       
   421             break;
       
   422             }
       
   423 
       
   424         default:
       
   425             {
       
   426             maxBufferSize = KTRMaxBufferSizeLevel0;
       
   427             break;
       
   428             }
       
   429         }
       
   430 
       
   431     iBufferOptions.iMaxInputBufferSize = maxBufferSize;
       
   432     
       
   433     PRINT((_L("CTNEDecoderWrap::InitializeL(), InputBufferSize[%d], NumberOfBuffers[%d]"), 
       
   434                iBufferOptions.iMaxInputBufferSize, iBufferOptions.iMinNumInputBuffers ))
       
   435 
       
   436     iDevVideoPlay->SetBufferOptionsL(iBufferOptions);
       
   437 
       
   438     // Initialize devVideoPlay
       
   439     iDevVideoPlay->Initialize();
       
   440 
       
   441     PRINT((_L("CTNEDecoderWrap::InitializeL(), Out")))
       
   442     }
       
   443 
       
   444 
       
   445 // -----------------------------------------------------------------------------
       
   446 // CTNEDecoderWrap::SelectDecoderL
       
   447 // Selects decoder
       
   448 // (other items were commented in a header).
       
   449 // -----------------------------------------------------------------------------
       
   450 //
       
   451 void CTNEDecoderWrap::SelectDecoderL()
       
   452 {
       
   453     PRINT(( _L("CTNEDecoderWrap::SelectDecoderL(), In") ))
       
   454     TInt status = KErrNone;
       
   455     TBool accelerated = EFalse;
       
   456     TBool exit = EFalse;
       
   457 
       
   458 
       
   459     if (iUid != TUid::Null())
       
   460 	{
       
   461         TRAP( status, iHwDeviceId = iDevVideoPlay->SelectDecoderL(iUid) );
       
   462 	}
       
   463     else
       
   464 	{
       
   465         // Most likely an error exists, if iUid == NULL; 
       
   466         status = KErrAlreadyExists;
       
   467 	}
       
   468 
       
   469     while ( !exit )
       
   470 	{
       
   471         if (status == KErrNone)
       
   472 		{
       
   473             // To get Output format list devvideoplay requires to define output format first. 
       
   474             iDevVideoPlay->SetInputFormatL(iHwDeviceId, *iCompresedFormat, iDataUnitType, EDuElementaryStream, ETrue);
       
   475 
       
   476             // It's time to check input format support (since the plugin is loaded to the memory)
       
   477             iUncompressedFormat.iDataFormat = EYuvRawData;
       
   478             
       
   479             TUncompressedVideoFormat uncFormat;
       
   480             TBool found = EFalse;
       
   481             TInt pattern1, pattern2;
       
   482                     
       
   483             pattern1 = EYuv420Chroma1;
       
   484             pattern2 = EYuv420Chroma2;
       
   485                 
       
   486             RArray<TUncompressedVideoFormat> supportedOutputFormats; 
       
   487             TRAP(status, iDevVideoPlay->GetOutputFormatListL( iHwDeviceId, supportedOutputFormats ));
       
   488             
       
   489             TInt formatCount = 0;
       
   490             if (status == KErrNone)
       
   491             {
       
   492                 formatCount = supportedOutputFormats.Count();
       
   493                 PRINT((_L("CTNEDecoderWrap::InitializeL(), formatCount[%d]"), formatCount ))
       
   494             }
       
   495                 
       
   496             if (formatCount <= 0)
       
   497             {
       
   498                 supportedOutputFormats.Close();
       
   499                 status = KErrAlreadyExists;
       
   500                 PRINT((_L("CTNEDecoderWrap::InitializeL(), There are no supported output formats") ))
       
   501                 //User::Leave(KErrNotSupported);
       
   502             }
       
   503             else
       
   504             {
       
   505                 // Check the most important paramers
       
   506                 for ( TInt i = 0; i < formatCount; i ++ )
       
   507                 {
       
   508                     uncFormat = supportedOutputFormats[i];
       
   509                     PRINT((_L("CTNEDecoderWrap::InitializeL(), pattern[%d]"), uncFormat.iYuvFormat.iPattern ))
       
   510                     
       
   511                     if ( (uncFormat.iDataFormat == iUncompressedFormat.iDataFormat) && 
       
   512                          ( (uncFormat.iYuvFormat.iPattern == pattern1) || 
       
   513                            (uncFormat.iYuvFormat.iPattern == pattern2) ) )
       
   514                         {
       
   515                         // Assign the rest of parameters
       
   516                         iUncompressedFormat = uncFormat;
       
   517                         found = ETrue;
       
   518                         exit = ETrue;
       
   519                         supportedOutputFormats.Close();
       
   520                         break;
       
   521                         }
       
   522                 }
       
   523 
       
   524                 if (!found)
       
   525                 {
       
   526                     supportedOutputFormats.Close();
       
   527                     PRINT((_L("CTNEDecoderWrap::InitializeL(), Supported format is not found") ))
       
   528                     //User::Leave(KErrNotSupported);
       
   529                 }
       
   530             }
       
   531         }
       
   532         else
       
   533         {
       
   534             // Take another codec and try again
       
   535             // Reset Uid
       
   536             iUid = TUid::Null();
       
   537 
       
   538             // Check codecs
       
   539             for ( TInt i = 0; i < iCheckDecoders.Count(); i ++ )
       
   540             {
       
   541             	TRAP( status, accelerated = CheckDecoderInfoL(iCheckDecoders[i]) );
       
   542 
       
   543             	if (status == KErrNone)
       
   544                 {
       
   545                 	if (accelerated != KTRAccelerationPriorityDecoder) // The rule is defined based on study
       
   546                 	{
       
   547                      	// pick the first ARM decoder
       
   548                     	iUid = iCheckDecoders[i];
       
   549                     	iCheckDecoders.Remove(i);
       
   550                             
       
   551                      	// Keep the list of non-checked codecs for future use
       
   552                      	// nothing to do, they are already are in the list
       
   553                     	break;
       
   554                 	}
       
   555                  	else
       
   556                 	{
       
   557                     	// its a DSP based decoder add it to the accelerated decoder array 
       
   558                     	iAcceleratedDecoders.Insert( iAcceleratedDecoders[i], iAcceleratedDecoders.Count() );
       
   559                     }
       
   560                 }
       
   561             }
       
   562                 
       
   563             if ( iUid == TUid::Null() )
       
   564             {
       
   565                 // There are no ARM decoders in the system, use the accelerated ones
       
   566                 if (iAcceleratedDecoders.Count() > 0)
       
   567                 {
       
   568                     // decoders were already checked, take the first from the list
       
   569                     iUid = iAcceleratedDecoders[0];
       
   570                     iAcceleratedDecoders.Remove(0);
       
   571                 }
       
   572                 else
       
   573                 {
       
   574                     PRINT((_L("CTNEDecoderWrap::SelectDecoderL(), No suitable accelerated decoders found")))
       
   575                     User::Leave(KErrNotSupported);
       
   576                 }
       
   577             }
       
   578                 
       
   579             status = KErrNone;
       
   580             TRAP(status, iHwDeviceId = iDevVideoPlay->SelectDecoderL(iUid));
       
   581         }
       
   582     }
       
   583 
       
   584     PRINT((_L("CTNEDecoderWrap::SelectDecoderL(), Out")))
       
   585 }
       
   586 
       
   587 // -----------------------------------------------------------------------------
       
   588 // CTNEDecoderWrap::MdvpoInitComplete
       
   589 // Notifies for initialization complete with init status
       
   590 // (other items were commented in a header).
       
   591 // -----------------------------------------------------------------------------
       
   592 //
       
   593 void CTNEDecoderWrap::MdvpoInitComplete(TInt /*aError*/)
       
   594     {
       
   595 		iState = ETRInitialized;
       
   596     }
       
   597 
       
   598 
       
   599 // -----------------------------------------------------------------------------
       
   600 // CTNEDecoderWrap::StartL
       
   601 // Starts decoding
       
   602 // (other items were commented in a header).
       
   603 // -----------------------------------------------------------------------------
       
   604 //
       
   605 void CTNEDecoderWrap::StartL()
       
   606     {
       
   607     PRINT((_L("CTNEDecoderWrap::StartL(), In")))
       
   608 
       
   609     // Start decoding
       
   610     if (iFatalError == KErrNone)
       
   611         {
       
   612         iDevVideoPlay->Start();
       
   613         }
       
   614 
       
   615     if (!iInputBuffer)
       
   616         {
       
   617         // Get buffer from the decoder to fill
       
   618         iInputBuffer = iDevVideoPlay->GetBufferL(iBufferOptions.iMaxInputBufferSize);
       
   619         }
       
   620     
       
   621     // Reset iStop    
       
   622     iStop = EFalse;
       
   623     iState = ETRRunning;
       
   624     
       
   625     // Reset ts monitor
       
   626     iLastTimestamp = -1;
       
   627 
       
   628     PRINT((_L("CTNEDecoderWrap::StartL(), Out")))
       
   629     }
       
   630 
       
   631 
       
   632 // -----------------------------------------------------------------------------
       
   633 // CTNEDecoderWrap::MdvpoNewBuffers()
       
   634 // New buffers are available
       
   635 // (other items were commented in a header).
       
   636 // -----------------------------------------------------------------------------
       
   637 //
       
   638 void CTNEDecoderWrap::MdvpoNewBuffers()
       
   639     {
       
   640     TInt status = KErrNone;
       
   641 
       
   642 
       
   643     if (iStop)
       
   644         {
       
   645         PRINT((_L("CTNEDecoderWrap::MdvpoNewBuffers(), Stop was already called, nothing to do")))
       
   646         return;
       
   647         }
       
   648 
       
   649     // One or more new empty input buffers are available
       
   650     if (!iInputBuffer)
       
   651         {
       
   652         // Get buffer from the decoder to fill
       
   653         TRAP(status, iInputBuffer = iDevVideoPlay->GetBufferL(iBufferOptions.iMaxInputBufferSize));
       
   654         
       
   655         if (status != KErrNone)
       
   656             {
       
   657             PRINT((_L("CTNEDecoderWrap::MdvpoNewBuffers(), GetBufferL status[%d]"), status))
       
   658             iObserver->MNotifyThumbnailReady(status);
       
   659             return;
       
   660             }
       
   661 
       
   662         if (!iInputBuffer)
       
   663             {
       
   664             PRINT((_L("CTNEDecoderWrap::MdvpoNewBuffers(), There are available buffer, but decoder returned NULL")))
       
   665             return;
       
   666             }
       
   667         }
       
   668 
       
   669     if (iCodedBuffer)
       
   670         {
       
   671         // Send coded buffer, since the client has already done request
       
   672         TRAP(status, this->SendBufferL(iCodedBuffer));
       
   673 
       
   674         // Reset buffer
       
   675         iCodedBuffer = NULL;
       
   676 
       
   677         if (status != KErrNone)
       
   678             {
       
   679             PRINT((_L("CTNEDecoderWrap::MdvpoNewBuffers(), Send buffer error[%d]"), status))
       
   680             iObserver->MNotifyThumbnailReady(status);
       
   681             return;
       
   682             }
       
   683         }
       
   684         
       
   685     if ((iInputBuffer) && (iState == ETRRunning))
       
   686     	{
       
   687 			// If InputBuffer is available send 
       
   688 			// more encoded packets to the decoder
       
   689             iObserver->MSendEncodedBuffer();
       
   690     	}
       
   691     
       
   692     }
       
   693 
       
   694 
       
   695 // -----------------------------------------------------------------------------
       
   696 // CTNEDecoderWrap::WriteCodedBufferL
       
   697 // Writes coded data to decoder
       
   698 // (other items were commented in a header).
       
   699 // -----------------------------------------------------------------------------
       
   700 //
       
   701 void CTNEDecoderWrap::WriteCodedBufferL(TVideoBuffer* aBuffer)
       
   702     {
       
   703     PRINT((_L("CTNEDecoderWrap::WriteCodedBufferL(), In")))
       
   704     TVideoBuffer::TBufferType bufferType;
       
   705     
       
   706     if (!aBuffer)
       
   707         {
       
   708         PRINT((_L("CTNEDecoderWrap::WriteCodedBufferL(), Input buffer is invalid, Leave")))
       
   709         User::Leave(KErrArgument);
       
   710         }
       
   711 
       
   712     if (iFatalError != KErrNone)
       
   713         {
       
   714         PRINT((_L("CTNEDecoderWrap::WriteCodedBufferL(), FatalError was reported by decoder")))
       
   715         
       
   716         // Return coded buffer
       
   717         iObserver->MReturnCodedBuffer(aBuffer);
       
   718         return;
       
   719         }
       
   720     
       
   721     TTimeIntervalMicroSeconds ts = aBuffer->TimeStamp();
       
   722         
       
   723     if ( ts <= iLastTimestamp)
       
   724         {
       
   725         // Prevent propagation of the error now
       
   726         PRINT((_L("CTNEDecoderWrap::WriteCodedBufferL(), Client sends invalid data (ts field), Leave")))
       
   727         User::Leave(KErrArgument);
       
   728         }
       
   729     else
       
   730         {
       
   731         iLastTimestamp = ts;
       
   732         }
       
   733     
       
   734     if (aBuffer->BufferSize() <= 0)
       
   735         {
       
   736         PRINT((_L("CTNEDecoderWrap::WriteCodedBufferL(), Input data buffer is invalid (empty), Leave")))
       
   737         User::Leave(KErrArgument);
       
   738         }
       
   739         
       
   740     bufferType = aBuffer->Type();
       
   741         
       
   742     if ( ( bufferType != TVideoBuffer::EVideoH263 ) && 
       
   743          ( bufferType != TVideoBuffer::EVideoMPEG4 ) )
       
   744         {
       
   745         PRINT((_L("CTNEDecoderWrap::WriteCodedBufferL(), [%d] This data type is not supported, Leave"), aBuffer->Type() ))
       
   746         User::Leave(KErrNotSupported);
       
   747         }
       
   748 
       
   749     if (!iInputBuffer)
       
   750         {
       
   751         // Request new empty buffer
       
   752         iInputBuffer = iDevVideoPlay->GetBufferL(iBufferOptions.iMaxInputBufferSize);
       
   753         }
       
   754 
       
   755     if (iInputBuffer)
       
   756         {
       
   757         this->SendBufferL(aBuffer);
       
   758         }
       
   759     else
       
   760         {
       
   761         iCodedBuffer = aBuffer;
       
   762         }
       
   763 
       
   764     PRINT((_L("CTNEDecoderWrap::WriteCodedBufferL(), Out")))
       
   765     }
       
   766 
       
   767 
       
   768 // -----------------------------------------------------------------------------
       
   769 // CTNEDecoderWrap::SendBufferL
       
   770 // Sends buffer to decoder
       
   771 // (other items were commented in a header).
       
   772 // -----------------------------------------------------------------------------
       
   773 //
       
   774 void CTNEDecoderWrap::SendBufferL(TVideoBuffer* aBuffer)
       
   775     {
       
   776     PRINT((_L("CTNEDecoderWrap::SendBufferL(), In")))
       
   777 
       
   778     PRINT((_L("CTNEDecoderWrap::SendBufferL(), iInputBuffer[%d], aBuffer[%d]"), iInputBuffer->iData.MaxLength(), 
       
   779                aBuffer->BufferSize() ))
       
   780 
       
   781     if ( iInputBuffer->iData.MaxLength() < aBuffer->BufferSize() )
       
   782         {
       
   783         PRINT((_L("CTNEDecoderWrap::SendBufferL(), buffer length exceeds max length")))
       
   784         User::Leave(KErrOverflow);
       
   785         }
       
   786 
       
   787     iInputBuffer->iData.Copy( aBuffer->Data().Ptr(), aBuffer->BufferSize() );
       
   788     iInputBuffer->iData.SetLength( aBuffer->BufferSize() );
       
   789 
       
   790     // Data unit presentation timestamp. Valid if EPresentationTimestamp is set in the options. 
       
   791     // If the input bitstream does not contain timestamp information, this field should be valid, 
       
   792     // otherwise pictures cannot be displayed at the correct time. If the input bitstream contains 
       
   793     // timestamp information (such as the TR syntax element of H.263 bitstreams) and valid 
       
   794     // iPresentationTimestamp is provided, the value of iPresentationTimestamp is used in playback.    
       
   795     iInputBuffer->iOptions = TVideoInputBuffer::EPresentationTimestamp;
       
   796     iInputBuffer->iPresentationTimestamp = aBuffer->TimeStamp();
       
   797  
       
   798  // @@ HARI AVC
       
   799     iInputBuffer->iSequenceNumber = iInputFrameNum;
       
   800     iInputFrameNum++;
       
   801     iInputBuffer->iDecodingTimestamp = aBuffer->TimeStamp();
       
   802     iInputBuffer->iPresentationTimestamp  = TTimeIntervalMicroSeconds(iClockSource->Time().Int64() + 1000000);
       
   803 
       
   804  
       
   805     /*Other data: TBC*/
       
   806 
       
   807     // Write data to decoder
       
   808     iDevVideoPlay->WriteCodedDataL(iInputBuffer);
       
   809 
       
   810     // Reset InputBuffer ptr
       
   811     iInputBuffer = NULL;
       
   812 
       
   813     // FIXME return buffer only after it's writtent to decoder (client could write next buffer synchronously from observer call)
       
   814     // Return buffer to the client immediately after copying
       
   815     iObserver->MReturnCodedBuffer(aBuffer);
       
   816 
       
   817     PRINT((_L("CTNEDecoderWrap::SendBufferL(), Out")))
       
   818     }
       
   819 
       
   820 
       
   821 // -----------------------------------------------------------------------------
       
   822 // CTNEDecoderWrap::MdvpoNewPictures
       
   823 // New decoded pictures available from decoder
       
   824 // (other items were commented in a header).
       
   825 // -----------------------------------------------------------------------------
       
   826 //
       
   827 void CTNEDecoderWrap::MdvpoNewPictures()
       
   828     {
       
   829     TInt status = KErrNone;
       
   830 
       
   831 
       
   832     // 1 or more decoded pictures are available
       
   833     if (!iDecodedPicture)
       
   834         {
       
   835         // Get new picture
       
   836         TRAP(status, iDecodedPicture = iDevVideoPlay->NextPictureL());
       
   837 
       
   838         if (status != KErrNone)
       
   839             {
       
   840             PRINT((_L("CTNEDecoderWrap::MdvpoNewPictures(), NextPicture status[%d]"), status))
       
   841             iObserver->MNotifyThumbnailReady(status);
       
   842             return;
       
   843             }
       
   844 
       
   845         if (!iDecodedPicture)
       
   846             {
       
   847             // Error: DevVideo notified of new buffers, but returns NULL
       
   848             PRINT((_L("CTNEDecoderWrap::MdvpoNewPictures(), DevVideo notified of new buffers, but returns NULL")))
       
   849             iObserver->MNotifyThumbnailReady(KErrAlreadyExists);
       
   850             return;
       
   851             }
       
   852 
       
   853         // Send new picture to the client
       
   854         iObserver->MPictureFromDecoder(iDecodedPicture);
       
   855         }
       
   856     else
       
   857         {
       
   858         // Previous picture still was not returned by the client, nothing to do. 
       
   859         // FIXME SetActive();
       
   860         }
       
   861     }
       
   862 
       
   863 
       
   864 // -----------------------------------------------------------------------------
       
   865 // CTNEDecoderWrap::ReturnPicture
       
   866 // Returns picture 
       
   867 // (other items were commented in a header).
       
   868 // -----------------------------------------------------------------------------
       
   869 //
       
   870 void CTNEDecoderWrap::ReturnPicture(TVideoPicture* aPicture)
       
   871     {
       
   872     PRINT((_L("CTNEDecoderWrap::ReturnPicture(), In")))
       
   873     TInt status = KErrNone;
       
   874 
       
   875 
       
   876     iDevVideoPlay->ReturnPicture(aPicture);
       
   877 
       
   878     // Reset decoded picture
       
   879     iDecodedPicture = NULL;
       
   880 
       
   881     TRAP(status, iDecodedPicture = iDevVideoPlay->NextPictureL());
       
   882 
       
   883     if (status != KErrNone)
       
   884         {
       
   885         PRINT((_L("CTNEDecoderWrap::ReturnPicture(), NextPicture status[%d]"), status))
       
   886         iObserver->MNotifyThumbnailReady(status);
       
   887         return;
       
   888         }
       
   889 
       
   890     if (iDecodedPicture)
       
   891         {
       
   892         // Send new picture to the client
       
   893         iObserver->MPictureFromDecoder(iDecodedPicture);
       
   894         }
       
   895 
       
   896     PRINT((_L("CTNEDecoderWrap::ReturnPicture(), Out")))
       
   897     }
       
   898 
       
   899 
       
   900 // -----------------------------------------------------------------------------
       
   901 // CTNEDecoderWrap::StopL
       
   902 // Stops decoding synchronously
       
   903 // (other items were commented in a header).
       
   904 // -----------------------------------------------------------------------------
       
   905 //
       
   906 void CTNEDecoderWrap::StopL()
       
   907     {
       
   908     PRINT((_L("CTNEDecoderWrap::StopL(), In")))
       
   909 
       
   910     if (iFatalError == KErrNone)
       
   911         {
       
   912         iDevVideoPlay->Stop();
       
   913         }
       
   914         
       
   915     iStop = ETrue;
       
   916     iState = ETRStopped;
       
   917         
       
   918     PRINT((_L("CTNEDecoderWrap::StopL(), Out")))
       
   919     }
       
   920 
       
   921 
       
   922 // -----------------------------------------------------------------------------
       
   923 // CTNEDecoderWrap::AsyncStopL
       
   924 // Stops decoding asynchronously
       
   925 // (other items were commented in a header).
       
   926 // -----------------------------------------------------------------------------
       
   927 //
       
   928 void CTNEDecoderWrap::AsyncStopL()
       
   929     {
       
   930     PRINT((_L("CTNEDecoderWrap::StopL(), Async In")))
       
   931 
       
   932     if (iFatalError == KErrNone)
       
   933         {
       
   934         iDevVideoPlay->InputEnd();
       
   935         }
       
   936         
       
   937     iStop = ETrue;
       
   938     iState = ETRStopped;
       
   939 
       
   940     PRINT((_L("CTNEDecoderWrap::StopL(), Async Out")))
       
   941     }
       
   942 
       
   943 // -----------------------------------------------------------------------------
       
   944 // CTNEDecoderWrap::GetNumInputFreeBuffers
       
   945 // returns the number of buffers that can be sent to 
       
   946 // decoder
       
   947 // (other items were commented in a header).
       
   948 // -----------------------------------------------------------------------------
       
   949 //
       
   950 TUint CTNEDecoderWrap::GetNumInputFreeBuffers()
       
   951 {
       
   952 	TUint inputFreeBuffers = iDevVideoPlay->NumFreeBuffers();
       
   953 	
       
   954 	return inputFreeBuffers;
       
   955 }
       
   956 
       
   957 
       
   958 // -----------------------------------------------------------------------------
       
   959 // CTNEDecoderWrap::MdvpoStreamEnd
       
   960 // Indicates when stream end is reached
       
   961 // (other items were commented in a header).
       
   962 // -----------------------------------------------------------------------------
       
   963 //
       
   964 void CTNEDecoderWrap::MdvpoStreamEnd()
       
   965     {
       
   966     PRINT((_L("CTNEDecoderWrap::MdvpoStreamEnd()")))    
       
   967     }
       
   968 
       
   969 // -----------------------------------------------------------------------------
       
   970 // CTNEDecoderWrap::MdvpoReturnPicture
       
   971 // Returns a used input video picture back to the caller. The picture memory can be re-used or freed (only relevant to postprocessor)
       
   972 // (other items were commented in a header).
       
   973 // -----------------------------------------------------------------------------
       
   974 //
       
   975 void CTNEDecoderWrap::MdvpoReturnPicture(TVideoPicture* /*aPicture*/)
       
   976     {
       
   977     PRINT((_L("CTNEDecoderWrap::MdvpoReturnPicture()")))
       
   978     }
       
   979 
       
   980 
       
   981 // -----------------------------------------------------------------------------
       
   982 // CTNEDecoderWrap::MdvpoSupplementalInformation
       
   983 // Sends SupplementalInformation
       
   984 // (other items were commented in a header).
       
   985 // -----------------------------------------------------------------------------
       
   986 //
       
   987 void CTNEDecoderWrap::MdvpoSupplementalInformation(const TDesC8& /*aData*/, 
       
   988                                                          const TTimeIntervalMicroSeconds& /*aTimestamp*/, 
       
   989                                                          const TPictureId& /*aPictureId*/)
       
   990     {
       
   991     PRINT((_L("CTNEDecoderWrap::MdvpoSupplementalInformation()")))
       
   992     }
       
   993 
       
   994 
       
   995 // -----------------------------------------------------------------------------
       
   996 // CTNEDecoderWrap::MdvpoPictureLoss
       
   997 // Back channel information from the decoder, indicating a picture loss without specifying the lost picture
       
   998 // (other items were commented in a header).
       
   999 // -----------------------------------------------------------------------------
       
  1000 //
       
  1001 void CTNEDecoderWrap::MdvpoPictureLoss()
       
  1002     {
       
  1003     PRINT((_L("CTNEDecoderWrap::MdvpoPictureLoss(), report an error")))
       
  1004     iObserver->MNotifyThumbnailReady(KErrAbort);
       
  1005     }
       
  1006 
       
  1007 
       
  1008 // -----------------------------------------------------------------------------
       
  1009 // CTNEDecoderWrap::MdvpoPictureLoss
       
  1010 // Back channel information from the decoder, indicating the pictures that have been lost
       
  1011 // (other items were commented in a header).
       
  1012 // -----------------------------------------------------------------------------
       
  1013 //
       
  1014 void CTNEDecoderWrap::MdvpoPictureLoss(const TArray< TPictureId >& /*aPictures*/)
       
  1015     {
       
  1016     PRINT((_L("CTNEDecoderWrap::MdvpoPictureLoss(), pictureId: report an error")))
       
  1017     iObserver->MNotifyThumbnailReady(KErrAbort);
       
  1018     }
       
  1019 
       
  1020 
       
  1021 // -----------------------------------------------------------------------------
       
  1022 // CTNEDecoderWrap::MdvpoSliceLoss
       
  1023 // Reports that slice is lost
       
  1024 // (other items were commented in a header).
       
  1025 // -----------------------------------------------------------------------------
       
  1026 //
       
  1027 void CTNEDecoderWrap::MdvpoSliceLoss(TUint /*aFirstMacroblock*/, TUint /*aNumMacroblocks*/, 
       
  1028                                            const TPictureId& /*aPicture*/)
       
  1029     {
       
  1030     PRINT((_L("CTNEDecoderWrap::MdvpoSliceLoss()")))
       
  1031     // This error is not considered a s fatal for decoder or application, nothing to do
       
  1032     }
       
  1033 
       
  1034 
       
  1035 // -----------------------------------------------------------------------------
       
  1036 // CTNEDecoderWrap::MdvpoReferencePictureSelection
       
  1037 // Back channel information from the decoder, indicating a reference picture selection request.
       
  1038 // (other items were commented in a header).
       
  1039 // -----------------------------------------------------------------------------
       
  1040 //
       
  1041 void CTNEDecoderWrap::MdvpoReferencePictureSelection(const TDesC8& /*aSelectionData*/)
       
  1042     {
       
  1043     PRINT((_L("CTNEDecoderWrap::MdvpoReferencePictureSelection()")))
       
  1044     }
       
  1045 
       
  1046 
       
  1047 // -----------------------------------------------------------------------------
       
  1048 // CTNEDecoderWrap::MdvpoTimedSnapshotComplete
       
  1049 // Called when a timed snapshot request has been completed. 
       
  1050 // (other items were commented in a header).
       
  1051 // -----------------------------------------------------------------------------
       
  1052 //
       
  1053 void CTNEDecoderWrap::MdvpoTimedSnapshotComplete(TInt /*aError*/, TPictureData* /*aPictureData*/, 
       
  1054                                                        const TTimeIntervalMicroSeconds& /*aPresentationTimestamp*/, 
       
  1055                                                        const TPictureId& /*aPictureId*/)
       
  1056     {
       
  1057     PRINT((_L("CTNEDecoderWrap::MdvpoTimedSnapshotComplete()")))
       
  1058     }
       
  1059 
       
  1060 
       
  1061 // -----------------------------------------------------------------------------
       
  1062 // CTNEDecoderWrap::MdvpoFatalError
       
  1063 // Reports the fatal error to the client
       
  1064 // (other items were commented in a header).
       
  1065 // -----------------------------------------------------------------------------
       
  1066 //
       
  1067 void CTNEDecoderWrap::MdvpoFatalError(TInt aError)
       
  1068     {
       
  1069     PRINT((_L("CTNEDecoderWrap::MdvpoFatalError(), error[%d]"), aError))
       
  1070     iFatalError = aError;
       
  1071     iObserver->MNotifyThumbnailReady(iFatalError);
       
  1072     }
       
  1073 
       
  1074 
       
  1075 
       
  1076 
       
  1077 // End of file