videoeditorengine/vedengine/src/VedVideoClipInfoImp.cpp
branchRCL_3
changeset 3 e0b5df5c0969
parent 0 951a5db380a0
child 7 4c409de21d23
equal deleted inserted replaced
0:951a5db380a0 3:e0b5df5c0969
     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 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "VedVideoClipInfoImp.h"
       
    23 #include "movieprocessor.h"
       
    24 #include <fbs.h>
       
    25 #include <ecom/ecom.h>
       
    26 #include "audclipinfo.h"
       
    27 #include "audcommon.h"
       
    28 #include "VedVideoClip.h"
       
    29 
       
    30 // Print macro
       
    31 #ifdef _DEBUG
       
    32 #include <e32svr.h>
       
    33 #define PRINT(x) RDebug::Print x
       
    34 #else
       
    35 #define PRINT(x)
       
    36 #endif
       
    37 
       
    38 
       
    39 EXPORT_C CVedVideoClipInfo* CVedVideoClipInfo::NewL(const TDesC& aFileName,
       
    40                                                     MVedVideoClipInfoObserver& aObserver)
       
    41     {
       
    42     PRINT(_L("CVedVideoClipInfo::NewL"));
       
    43 
       
    44     CVedVideoClipInfoImp* self = (CVedVideoClipInfoImp*)NewLC(aFileName, aObserver);
       
    45     self->iVideoClipIsStandalone = ETrue;
       
    46     CleanupStack::Pop(self);
       
    47     PRINT(_L("CVedVideoClipInfo::NewL out"));
       
    48     return self;
       
    49     }
       
    50     
       
    51 EXPORT_C CVedVideoClipInfo* CVedVideoClipInfo::NewLC(const TDesC& aFileName,
       
    52                                                      MVedVideoClipInfoObserver& aObserver)
       
    53     {
       
    54     PRINT(_L("CVedVideoClipInfo::NewLC in"));
       
    55 
       
    56     CVedVideoClipInfoImp* self = new (ELeave) CVedVideoClipInfoImp(NULL);
       
    57     CleanupStack::PushL(self);
       
    58     self->ConstructL(aFileName, aObserver);
       
    59 
       
    60     PRINT(_L("CVedVideoClipInfo::NewLC out"));
       
    61     return self;
       
    62     }
       
    63 
       
    64 EXPORT_C CVedVideoClipInfo* CVedVideoClipInfo::NewL(RFile* aFileHandle,
       
    65                                                     MVedVideoClipInfoObserver& aObserver)
       
    66     {
       
    67     PRINT(_L("CVedVideoClipInfo::NewL"));
       
    68 
       
    69     CVedVideoClipInfoImp* self = (CVedVideoClipInfoImp*)NewLC(aFileHandle, aObserver);
       
    70     self->iVideoClipIsStandalone = ETrue;
       
    71     CleanupStack::Pop(self);
       
    72     PRINT(_L("CVedVideoClipInfo::NewL out"));
       
    73     return self;
       
    74     }
       
    75     
       
    76 EXPORT_C CVedVideoClipInfo* CVedVideoClipInfo::NewLC(RFile* aFileHandle,
       
    77                                                      MVedVideoClipInfoObserver& aObserver)
       
    78     {
       
    79     PRINT(_L("CVedVideoClipInfo::NewLC in"));
       
    80 
       
    81     CVedVideoClipInfoImp* self = new (ELeave) CVedVideoClipInfoImp(NULL);
       
    82     CleanupStack::PushL(self);
       
    83     self->ConstructL(aFileHandle, aObserver);
       
    84 
       
    85     PRINT(_L("CVedVideoClipInfo::NewLC out"));
       
    86     return self;
       
    87     }
       
    88 
       
    89 
       
    90 CVedVideoClipInfo* CVedVideoClipInfoImp::NewL(CAudClipInfo* aAudClipInfo, 
       
    91                                               const TDesC& aFileName, MVedVideoClipInfoObserver& aObserver)
       
    92     {
       
    93     CVedVideoClipInfoImp* self = new (ELeave) CVedVideoClipInfoImp(aAudClipInfo);
       
    94     CleanupStack::PushL(self);
       
    95     if (aAudClipInfo) 
       
    96         {
       
    97         self->ConstructL(aAudClipInfo->FileName(), aObserver);
       
    98         }
       
    99     else
       
   100         {
       
   101         self->ConstructL(aFileName, aObserver);
       
   102         }
       
   103     self->iVideoClipIsStandalone = EFalse;
       
   104     CleanupStack::Pop(self);
       
   105     return self;
       
   106     }
       
   107     
       
   108 CVedVideoClipInfo* CVedVideoClipInfoImp::NewL(CAudClipInfo* aAudClipInfo, 
       
   109                                               RFile* aFileHandle, MVedVideoClipInfoObserver& aObserver)
       
   110     {
       
   111     CVedVideoClipInfoImp* self = new (ELeave) CVedVideoClipInfoImp(aAudClipInfo);
       
   112     CleanupStack::PushL(self);
       
   113     if (aAudClipInfo) 
       
   114         {
       
   115         self->ConstructL(aAudClipInfo->FileHandle(), aObserver);
       
   116         }
       
   117     else
       
   118         {
       
   119         self->ConstructL(aFileHandle, aObserver);
       
   120         }
       
   121     self->iVideoClipIsStandalone = EFalse;
       
   122     CleanupStack::Pop(self);
       
   123     return self;
       
   124     }
       
   125     
       
   126 
       
   127 CVedVideoClipInfoImp::CVedVideoClipInfoImp(CAudClipInfo* aAudClipInfo)
       
   128         : iReady(EFalse), iAudClipInfoOwnedByVideoClipInfo(EFalse), iAudClipInfo(aAudClipInfo)
       
   129     {
       
   130     }
       
   131 
       
   132 
       
   133 void CVedVideoClipInfoImp::ConstructL(const TDesC& aFileName,
       
   134                                    MVedVideoClipInfoObserver& aObserver)
       
   135     {
       
   136     PRINT(_L("CVedVideoClipInfo::ConstructL in"));
       
   137 
       
   138     iFileName = HBufC::NewL(aFileName.Length());
       
   139     *iFileName = aFileName;
       
   140 
       
   141     iFrameOperation = CVedVideoClipFrameOperation::NewL(this);
       
   142 
       
   143     iInfoOperation = CVedVideoClipInfoOperation::NewL(this, aObserver);
       
   144     
       
   145     PRINT(_L("CVedVideoClipInfo::ConstructL out"));
       
   146     }
       
   147     
       
   148 void CVedVideoClipInfoImp::ConstructL(RFile* aFileHandle,
       
   149                                    MVedVideoClipInfoObserver& aObserver)
       
   150     {
       
   151     PRINT(_L("CVedVideoClipInfo::ConstructL in"));
       
   152 
       
   153     iFileName = HBufC::NewL(1);
       
   154     iFileHandle = aFileHandle;
       
   155 
       
   156     iFrameOperation = CVedVideoClipFrameOperation::NewL(this);
       
   157 
       
   158     iInfoOperation = CVedVideoClipInfoOperation::NewL(this, aObserver);
       
   159     
       
   160     PRINT(_L("CVedVideoClipInfo::ConstructL out"));
       
   161     }
       
   162     
       
   163 
       
   164 CVedVideoClipInfoImp::~CVedVideoClipInfoImp()
       
   165     {
       
   166     PRINT(_L("CVedVideoClipInfo::~CVedVideoClipInfoImp in"));
       
   167 
       
   168     delete iInfoOperation;
       
   169     delete iFrameOperation;
       
   170 
       
   171     User::Free(iVideoFrameInfoArray);
       
   172     delete iFileName;
       
   173 
       
   174     REComSession::FinalClose();
       
   175 
       
   176     if (iAudClipInfoOwnedByVideoClipInfo) 
       
   177         {
       
   178         delete iAudClipInfo;
       
   179         }
       
   180 
       
   181     PRINT(_L("CVedVideoClipInfo::~CVedVideoClipInfoImp out"));
       
   182     }
       
   183 
       
   184 
       
   185 TPtrC CVedVideoClipInfoImp::DescriptiveName() const 
       
   186     {
       
   187     return *iFileName;
       
   188     }
       
   189 
       
   190 CVedVideoClipGenerator* CVedVideoClipInfoImp::Generator() const
       
   191     {
       
   192     // Always panic
       
   193     TVedPanic::Panic(TVedPanic::EVideoClipInfoNoGeneratorAssociated);
       
   194     
       
   195     // This will never be reached.
       
   196     return NULL;
       
   197     }
       
   198 
       
   199 
       
   200 TVedVideoClipClass CVedVideoClipInfoImp::Class() const 
       
   201     {
       
   202     return EVedVideoClipClassFile;
       
   203     }
       
   204 
       
   205 
       
   206 TInt CVedVideoClipInfoImp::GenerateVideoFrameInfoArrayL() 
       
   207     {
       
   208     PRINT(_L("CVedVideoClipInfoImp::GenerateVideoFrameInfoArrayL in"));
       
   209 
       
   210     __ASSERT_ALWAYS(iReady, 
       
   211                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   212 
       
   213     TInt error = KErrNone;
       
   214 
       
   215     if ( !iVideoFrameInfoArrayReady )
       
   216         {
       
   217         CMovieProcessor* processor = CMovieProcessor::NewL();
       
   218         CleanupStack::PushL(processor);
       
   219         TRAP( error, processor->GenerateVideoFrameInfoArrayL(*iFileName, iFileHandle, iVideoFrameInfoArray));
       
   220         CleanupStack::PopAndDestroy(processor);
       
   221 
       
   222         if ( (error == KErrNone) && iVideoFrameInfoArray )
       
   223             {
       
   224             iVideoFrameInfoArrayReady = ETrue;            
       
   225             }
       
   226         else
       
   227             {
       
   228             PRINT((_L("CVedVideoClipInfoImp::GenerateVideoFrameInfoArrayL Error=%d"), error));
       
   229             }
       
   230         }
       
   231 
       
   232     PRINT(_L("CVedVideoClipInfoImp::GenerateVideoFrameInfoArrayL out"));
       
   233     return error;
       
   234     }
       
   235 
       
   236 
       
   237 TInt CVedVideoClipInfoImp::GetVideoFrameIndexL(TTimeIntervalMicroSeconds aTime)
       
   238     {
       
   239     PRINT(_L("CVedVideoClipInfoImp::GetVideoFrameIndex in"));
       
   240 
       
   241     __ASSERT_ALWAYS(iReady, 
       
   242                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   243     __ASSERT_ALWAYS((aTime >= TTimeIntervalMicroSeconds(0)) && (aTime <= Duration()), 
       
   244                     TVedPanic::Panic(TVedPanic::EVideoClipInfoIllegalVideoFrameTime));
       
   245 
       
   246     /* Use binary search to find the right frame. */
       
   247 
       
   248     TInt start = 0;
       
   249     TInt end = iVideoFrameCount - 1;
       
   250     TInt index = -1;
       
   251     TBool always = ETrue;
       
   252 
       
   253     while( always )
       
   254         {
       
   255         index = start + ((end - start) / 2);
       
   256 
       
   257         TTimeIntervalMicroSeconds startTime = VideoFrameStartTimeL(index);
       
   258         TTimeIntervalMicroSeconds endTime = VideoFrameEndTimeL(index);
       
   259         if (index < (VideoFrameCount() - 1))
       
   260             {
       
   261             endTime = TTimeIntervalMicroSeconds(endTime.Int64() - 1);
       
   262             }
       
   263 
       
   264         if (aTime < startTime)
       
   265             {
       
   266             end = index - 1;
       
   267             }
       
   268         else if (aTime > endTime)
       
   269             {
       
   270             start = index + 1;
       
   271             }
       
   272         else
       
   273             {
       
   274             always = EFalse;
       
   275             }
       
   276         }
       
   277 
       
   278     PRINT(_L("CVedVideoClipInfoImp::GetVideoFrameIndex out"));
       
   279     return index;
       
   280     }
       
   281 
       
   282 
       
   283 void CVedVideoClipInfoImp::GetFrameL(MVedVideoClipFrameObserver& aObserver, 
       
   284                                      TInt aIndex,
       
   285                                      TSize* const aResolution,
       
   286                                      TDisplayMode aDisplayMode,
       
   287                                      TBool aEnhance,
       
   288                                      TInt aPriority)
       
   289     {
       
   290     PRINT(_L("CVedVideoClipInfoImp::GetFrameL in"));
       
   291 
       
   292     __ASSERT_ALWAYS(iReady, 
       
   293                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   294 
       
   295     iFrameOperation->StartL(aObserver, aIndex, aResolution, aDisplayMode, aEnhance, aPriority);
       
   296     
       
   297     PRINT(_L("CVedVideoClipInfoImp::GetFrameL out"));
       
   298     }
       
   299 
       
   300 
       
   301 void CVedVideoClipInfoImp::CancelFrame()
       
   302     {
       
   303     PRINT(_L("CVedVideoClipInfoImp::CancelFrame in"));
       
   304 
       
   305     if ( !iReady )
       
   306         {
       
   307         PRINT(_L("CVedVideoClipInfoImp::CancelFrame not even info ready yet, cancel it and get out"));
       
   308         iInfoOperation->Cancel();
       
   309         return;
       
   310         }
       
   311 
       
   312     iFrameOperation->Cancel();
       
   313 
       
   314     PRINT(_L("CVedVideoClipInfoImp::CancelFrame out"));
       
   315     }
       
   316 
       
   317 
       
   318 
       
   319 
       
   320 TPtrC CVedVideoClipInfoImp::FileName() const
       
   321     {
       
   322     __ASSERT_ALWAYS(iReady, 
       
   323                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   324 
       
   325     return *iFileName;
       
   326     }
       
   327     
       
   328 RFile* CVedVideoClipInfoImp::FileHandle() const
       
   329     {
       
   330     __ASSERT_ALWAYS(iReady, 
       
   331                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   332 
       
   333     return iFileHandle;
       
   334     }
       
   335 
       
   336 
       
   337 TVedVideoFormat CVedVideoClipInfoImp::Format() const
       
   338     {
       
   339     __ASSERT_ALWAYS(iReady, 
       
   340                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   341 
       
   342     return iFormat;
       
   343     }
       
   344 
       
   345 
       
   346 TVedVideoType CVedVideoClipInfoImp::VideoType() const
       
   347     {
       
   348     __ASSERT_ALWAYS(iReady, 
       
   349                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   350 
       
   351     return iVideoType;
       
   352     }
       
   353 
       
   354 
       
   355 TSize CVedVideoClipInfoImp::Resolution() const
       
   356     {
       
   357     __ASSERT_ALWAYS(iReady, 
       
   358                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   359 
       
   360     return iResolution;
       
   361     }
       
   362 
       
   363 
       
   364 TBool CVedVideoClipInfoImp::HasAudio() const
       
   365     {
       
   366     
       
   367     if (!iReady)  
       
   368         {
       
   369         if (iVideoClipIsStandalone)
       
   370             return EFalse;
       
   371         }
       
   372 
       
   373     if (iAudClipInfo == 0) 
       
   374         {
       
   375         return EFalse;
       
   376         }
       
   377     return ((iAudClipInfo->Properties().iAudioType != EAudTypeUnrecognized)
       
   378         && (iAudClipInfo->Properties().iAudioType != EAudNoAudio));
       
   379     }
       
   380 
       
   381 
       
   382 TVedAudioType CVedVideoClipInfoImp::AudioType() const
       
   383     {
       
   384     __ASSERT_ALWAYS(iReady, 
       
   385                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   386 
       
   387     if (iAudClipInfo == 0) 
       
   388         {
       
   389         return EVedAudioTypeNoAudio;
       
   390         }
       
   391 
       
   392     TVedAudioType vedAudioType = EVedAudioTypeUnrecognized;
       
   393     if (iAudClipInfo->Properties().iAudioType == EAudAMR)
       
   394         {
       
   395         vedAudioType = EVedAudioTypeAMR;
       
   396         }
       
   397     else if (iAudClipInfo->Properties().iAudioType == EAudAMRWB)
       
   398         {
       
   399         vedAudioType = EVedAudioTypeAMRWB;
       
   400         }
       
   401     else if (iAudClipInfo->Properties().iAudioType == EAudMP3)
       
   402         {
       
   403         vedAudioType = EVedAudioTypeMP3;
       
   404         }
       
   405     else if (iAudClipInfo->Properties().iAudioType == EAudAAC_MPEG4 )
       
   406         {
       
   407         vedAudioType = EVedAudioTypeAAC_LC;
       
   408         }
       
   409     else if (iAudClipInfo->Properties().iAudioType == EAudWAV)
       
   410         {
       
   411         vedAudioType = EVedAudioTypeWAV;
       
   412         }
       
   413     else if (iAudClipInfo->Properties().iAudioType == EAudNoAudio)
       
   414     	{
       
   415     	vedAudioType = EVedAudioTypeNoAudio;
       
   416     	}
       
   417         
       
   418     return vedAudioType;
       
   419     }
       
   420 
       
   421 TVedAudioChannelMode CVedVideoClipInfoImp::AudioChannelMode() const
       
   422     {
       
   423     __ASSERT_ALWAYS(iReady, 
       
   424                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   425 
       
   426     if (iAudClipInfo == 0) 
       
   427         {
       
   428         return EVedAudioChannelModeUnrecognized;
       
   429         }
       
   430 
       
   431     TVedAudioChannelMode vedChannelMode = EVedAudioChannelModeUnrecognized;
       
   432     if (iAudClipInfo->Properties().iChannelMode == EAudStereo)
       
   433         {
       
   434         vedChannelMode = EVedAudioChannelModeStereo;
       
   435         }
       
   436     else if (iAudClipInfo->Properties().iChannelMode == EAudSingleChannel)
       
   437         {
       
   438         vedChannelMode = EVedAudioChannelModeSingleChannel;
       
   439         }
       
   440     else if (iAudClipInfo->Properties().iChannelMode == EAudDualChannel)
       
   441         {
       
   442         vedChannelMode = EVedAudioChannelModeDualChannel;
       
   443         }
       
   444 
       
   445     return vedChannelMode;
       
   446     }
       
   447 
       
   448 TInt CVedVideoClipInfoImp::AudioSamplingRate() const
       
   449     {
       
   450     __ASSERT_ALWAYS(iReady, 
       
   451                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   452 
       
   453     if (iAudClipInfo == 0) 
       
   454         {
       
   455         return 0;
       
   456         }
       
   457 
       
   458     return iAudClipInfo->Properties().iSamplingRate;
       
   459     }
       
   460 
       
   461 
       
   462 TTimeIntervalMicroSeconds CVedVideoClipInfoImp::Duration() const
       
   463     {
       
   464     __ASSERT_ALWAYS(iReady, 
       
   465                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   466 
       
   467     return iDuration;
       
   468     }
       
   469 
       
   470 
       
   471 TInt CVedVideoClipInfoImp::VideoFrameCount() const
       
   472     {
       
   473     __ASSERT_ALWAYS(iReady, 
       
   474                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   475 
       
   476     return iVideoFrameCount;
       
   477     }
       
   478 
       
   479 
       
   480 TTimeIntervalMicroSeconds CVedVideoClipInfoImp::VideoFrameStartTimeL(TInt aIndex)
       
   481     {
       
   482     __ASSERT_ALWAYS(iReady, 
       
   483                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   484     __ASSERT_ALWAYS(((aIndex >= 0) && (aIndex < iVideoFrameCount)),
       
   485                     TVedPanic::Panic(TVedPanic::EVideoClipInfoIllegalVideoFrameIndex));
       
   486 
       
   487     if ( !iVideoFrameInfoArrayReady )
       
   488         {
       
   489         User::LeaveIfError(GenerateVideoFrameInfoArrayL());
       
   490         }
       
   491 
       
   492     TInt64 startTime = TInt64(iVideoFrameInfoArray[aIndex].iStartTime) * TInt64(1000);
       
   493     return TTimeIntervalMicroSeconds(startTime);
       
   494     }
       
   495 
       
   496 
       
   497 TTimeIntervalMicroSeconds CVedVideoClipInfoImp::VideoFrameEndTimeL(TInt aIndex)
       
   498     {
       
   499     __ASSERT_ALWAYS(iReady, 
       
   500                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   501     __ASSERT_ALWAYS(((aIndex >= 0) && (aIndex < iVideoFrameCount)),
       
   502                     TVedPanic::Panic(TVedPanic::EVideoClipInfoIllegalVideoFrameIndex));
       
   503 
       
   504     if ( !iVideoFrameInfoArrayReady )
       
   505         {
       
   506         User::LeaveIfError(GenerateVideoFrameInfoArrayL());
       
   507         }
       
   508 
       
   509     if (aIndex < (iVideoFrameCount - 1))
       
   510         {
       
   511         return (TInt64(iVideoFrameInfoArray[aIndex + 1].iStartTime) * TInt64(1000));
       
   512         }
       
   513     else
       
   514         {
       
   515         return iDuration;
       
   516         }
       
   517     }
       
   518 
       
   519 
       
   520 TTimeIntervalMicroSeconds CVedVideoClipInfoImp::VideoFrameDurationL(TInt aIndex)
       
   521     {
       
   522     __ASSERT_ALWAYS(iReady, 
       
   523                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   524     __ASSERT_ALWAYS(((aIndex >= 0) && (aIndex < iVideoFrameCount)),
       
   525                     TVedPanic::Panic(TVedPanic::EVideoClipInfoIllegalVideoFrameIndex));
       
   526 
       
   527     if ( !iVideoFrameInfoArrayReady )
       
   528         {
       
   529         User::LeaveIfError(GenerateVideoFrameInfoArrayL());
       
   530         }
       
   531 
       
   532 
       
   533     TInt64 duration = - (TInt64(iVideoFrameInfoArray[aIndex].iStartTime) * TInt64(1000));
       
   534     if (aIndex < (iVideoFrameCount - 1))
       
   535         {
       
   536         duration += TInt64(iVideoFrameInfoArray[aIndex + 1].iStartTime) * TInt64(1000);
       
   537         }
       
   538     else
       
   539         {
       
   540         duration += iDuration.Int64();
       
   541         }
       
   542 
       
   543     return TTimeIntervalMicroSeconds(duration);
       
   544     }
       
   545 
       
   546 
       
   547 TInt CVedVideoClipInfoImp::VideoFrameSizeL(TInt aIndex)
       
   548     {
       
   549     __ASSERT_ALWAYS(iReady, 
       
   550                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   551     __ASSERT_ALWAYS(((aIndex >= 0) && (aIndex < iVideoFrameCount)),
       
   552                     TVedPanic::Panic(TVedPanic::EVideoClipInfoIllegalVideoFrameIndex));
       
   553 
       
   554     if ( !iVideoFrameInfoArrayReady )
       
   555         {
       
   556         User::LeaveIfError(GenerateVideoFrameInfoArrayL());
       
   557         }
       
   558 
       
   559 
       
   560     return iVideoFrameInfoArray[aIndex].iSize;
       
   561     }
       
   562 
       
   563 
       
   564 TBool CVedVideoClipInfoImp::VideoFrameIsIntraL(TInt aIndex)
       
   565     {
       
   566     __ASSERT_ALWAYS(iReady, 
       
   567                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   568     __ASSERT_ALWAYS(((aIndex >= 0) && (aIndex < iVideoFrameCount)),
       
   569                     TVedPanic::Panic(TVedPanic::EVideoClipInfoIllegalVideoFrameIndex));
       
   570 
       
   571     if ( !iVideoFrameInfoArrayReady )
       
   572         {
       
   573         User::LeaveIfError(GenerateVideoFrameInfoArrayL());
       
   574         }
       
   575 
       
   576     if (iVideoFrameInfoArray[aIndex].iFlags & KVedVideoFrameInfoFlagIntra)
       
   577         {
       
   578         return ETrue;
       
   579         }
       
   580     else
       
   581         {
       
   582         return EFalse;
       
   583         }
       
   584     }
       
   585 
       
   586 void CVedVideoClipInfoImp::SetTranscodeFactor(TVedTranscodeFactor aFactor)
       
   587     {
       
   588     iTimeFactor.iStreamType = aFactor.iStreamType;
       
   589     iTimeFactor.iTRes = aFactor.iTRes;
       
   590     }
       
   591 
       
   592 TVedTranscodeFactor CVedVideoClipInfoImp::TranscodeFactor()
       
   593     {
       
   594     return iTimeFactor;
       
   595     }
       
   596 
       
   597 TBool CVedVideoClipInfoImp::IsMMSCompatible()
       
   598     {
       
   599     __ASSERT_ALWAYS(iReady, 
       
   600                     TVedPanic::Panic(TVedPanic::EVideoClipInfoNotReady));
       
   601 
       
   602     TAudType audioType;
       
   603     if (iAudClipInfo == 0) 
       
   604         {
       
   605         audioType = EAudNoAudio;
       
   606         }
       
   607     else
       
   608         {
       
   609         audioType = iAudClipInfo->Properties().iAudioType;
       
   610         }
       
   611 
       
   612     return ( ( iFormat == EVedVideoFormat3GPP ) &&
       
   613              ( iVideoType == EVedVideoTypeH263Profile0Level10 ) &&
       
   614              ( audioType == EAudAMR ) );
       
   615     }
       
   616 
       
   617 
       
   618 CVedVideoClipInfoOperation* CVedVideoClipInfoOperation::NewL(CVedVideoClipInfoImp* aInfo,
       
   619                                                              MVedVideoClipInfoObserver& aObserver)
       
   620     {
       
   621     PRINT(_L("CVedVideoClipInfoOperation::NewL in"));
       
   622 
       
   623     CVedVideoClipInfoOperation* self = 
       
   624         new (ELeave) CVedVideoClipInfoOperation(aInfo, aObserver);
       
   625     CleanupStack::PushL(self);
       
   626     self->ConstructL();
       
   627     CleanupStack::Pop(self);
       
   628 
       
   629     PRINT(_L("CVedVideoClipInfoOperation::NewL out"));
       
   630     return self;
       
   631     }
       
   632 
       
   633 
       
   634 CVedVideoClipInfoOperation::CVedVideoClipInfoOperation(CVedVideoClipInfoImp* aInfo,
       
   635                                                        MVedVideoClipInfoObserver& aObserver)
       
   636         : CActive(EPriorityStandard), iInfo(aInfo), iMovieProcessorError(KErrNone)
       
   637     {
       
   638     PRINT(_L("CVedVideoClipInfoOperation::CVedVideoClipInfoOperation in"));
       
   639 
       
   640     iObserver = &aObserver;
       
   641     CActiveScheduler::Add(this);
       
   642 
       
   643     PRINT(_L("CVedVideoClipInfoOperation::CVedVideoClipInfoOperation out"));
       
   644     }
       
   645 
       
   646 
       
   647 void CVedVideoClipInfoOperation::ConstructL()
       
   648     {
       
   649     PRINT(_L("CVedVideoClipInfoOperation::ConstructL in"));
       
   650 
       
   651     iGettingAudio = EFalse;
       
   652 
       
   653     SetActive();
       
   654     TRequestStatus* status = &iStatus;
       
   655     User::RequestComplete(status, KErrNone);
       
   656 
       
   657     PRINT(_L("CVedVideoClipInfoOperation::ConstructL out"));
       
   658     }
       
   659 
       
   660 
       
   661 CVedVideoClipInfoOperation::~CVedVideoClipInfoOperation()
       
   662     {
       
   663     Cancel();
       
   664     }
       
   665 
       
   666 
       
   667 void CVedVideoClipInfoOperation::RunL()
       
   668     {
       
   669     PRINT(_L("CVedVideoClipInfoOperation::RunL in"));    
       
   670  
       
   671     if (iGettingAudio) 
       
   672         {
       
   673         if (iMovieProcessorError == KErrNone || iMovieProcessorError == KErrNoAudio) 
       
   674             {
       
   675             iInfo->iReady = ETrue;
       
   676             iMovieProcessorError = KErrNone;
       
   677             }
       
   678         iObserver->NotifyVideoClipInfoReady(*iInfo, iMovieProcessorError);
       
   679         }
       
   680     else
       
   681         {
       
   682         CMovieProcessor* processor = CMovieProcessor::NewL();
       
   683         TVedAudioType audioType = EVedAudioTypeUnrecognized;
       
   684         TVedAudioChannelMode audioChannelMode = EVedAudioChannelModeUnrecognized;
       
   685         TInt audioSamplingRate;
       
   686         TRAP(iMovieProcessorError,
       
   687              processor->GetVideoClipPropertiesL(*iInfo->iFileName, 
       
   688                                                 iInfo->iFileHandle,
       
   689                                                 iInfo->iFormat,
       
   690                                                 iInfo->iVideoType,
       
   691                                                 iInfo->iResolution,
       
   692                                                 audioType,
       
   693                                                 iInfo->iDuration,
       
   694                                                 iInfo->iVideoFrameCount,
       
   695                                                 audioSamplingRate,
       
   696                                                 audioChannelMode));    
       
   697         delete processor;
       
   698         processor = 0;                
       
   699         
       
   700         if (iMovieProcessorError != KErrNone) 
       
   701             {
       
   702             iObserver->NotifyVideoClipInfoReady(*iInfo, iMovieProcessorError);
       
   703             }
       
   704         else if (iInfo->iAudClipInfo || !iInfo->iVideoClipIsStandalone)
       
   705             {
       
   706             if (iMovieProcessorError == KErrNone) 
       
   707                 {
       
   708                 iInfo->iReady = ETrue;
       
   709                 }
       
   710             iObserver->NotifyVideoClipInfoReady(*iInfo, iMovieProcessorError);
       
   711             }
       
   712         else
       
   713             {
       
   714             
       
   715             if (iInfo->iFileHandle)
       
   716                 iInfo->iAudClipInfo = CAudClipInfo::NewL(iInfo->iFileHandle, *this);
       
   717             else
       
   718                 iInfo->iAudClipInfo = CAudClipInfo::NewL(*iInfo->iFileName, *this);
       
   719             
       
   720             iInfo->iAudClipInfoOwnedByVideoClipInfo = ETrue;
       
   721             iGettingAudio = ETrue;
       
   722             }
       
   723         }
       
   724     PRINT(_L("CVedVideoClipInfoOperation::RunL out"));
       
   725     }
       
   726 
       
   727 void CVedVideoClipInfoOperation::NotifyClipInfoReady(CAudClipInfo& /*aInfo*/, TInt aError)
       
   728     {
       
   729     SetActive();
       
   730     TRequestStatus* status = &iStatus;
       
   731     User::RequestComplete(status, KErrNone);
       
   732     
       
   733     iMovieProcessorError = aError;
       
   734     }
       
   735 
       
   736 void CVedVideoClipInfoOperation::DoCancel()
       
   737     {
       
   738     }
       
   739 
       
   740 
       
   741 CVedVideoClipFrameOperation* CVedVideoClipFrameOperation::NewL(CVedVideoClipInfoImp* aInfo)
       
   742     {
       
   743     PRINT(_L("CVedVideoClipFrameOperation::NewL in"));
       
   744 
       
   745     CVedVideoClipFrameOperation* self = 
       
   746         new (ELeave) CVedVideoClipFrameOperation(aInfo);
       
   747     CleanupStack::PushL(self);
       
   748     self->ConstructL();
       
   749     CleanupStack::Pop(self);
       
   750 
       
   751     PRINT(_L("CVedVideoClipFrameOperation::NewL out"));
       
   752     return self;
       
   753     }
       
   754 
       
   755 
       
   756 CVedVideoClipFrameOperation::CVedVideoClipFrameOperation(CVedVideoClipInfoImp* aInfo)
       
   757         : CActive(EPriorityIdle), iInfo(aInfo)
       
   758     {
       
   759     PRINT(_L("CVedVideoClipFrameOperation::CVedVideoClipFrameOperation in"));
       
   760     CActiveScheduler::Add(this);
       
   761     PRINT(_L("CVedVideoClipFrameOperation::CVedVideoClipFrameOperation out"));
       
   762     }
       
   763 
       
   764 
       
   765 void CVedVideoClipFrameOperation::ConstructL()
       
   766     {
       
   767     }
       
   768 
       
   769 
       
   770 CVedVideoClipFrameOperation::~CVedVideoClipFrameOperation()
       
   771     {
       
   772     Cancel();
       
   773     }
       
   774 
       
   775 
       
   776 void CVedVideoClipFrameOperation::StartL(MVedVideoClipFrameObserver& aObserver,
       
   777                                          TInt aIndex,
       
   778                                          TSize* const aResolution, 
       
   779                                          TDisplayMode aDisplayMode,
       
   780                                          TBool aEnhance,
       
   781                                          TInt aPriority)
       
   782     {
       
   783     PRINT(_L("CVedVideoClipFrameOperation::StartL in"));
       
   784 
       
   785     __ASSERT_ALWAYS(!IsActive(), 
       
   786         TVedPanic::Panic(TVedPanic::EVideoClipInfoFrameOperationAlreadyRunning));
       
   787     __ASSERT_DEBUG(iProcessor == 0, TVedPanic::Panic(TVedPanic::EInternal));
       
   788 
       
   789     TSize resolution;
       
   790     if (aResolution != 0)
       
   791         {
       
   792         __ASSERT_ALWAYS(aResolution->iWidth > 0, 
       
   793             TVedPanic::Panic(TVedPanic::EVideoClipInfoIllegalFrameResolution));
       
   794         __ASSERT_ALWAYS(aResolution->iHeight > 0, 
       
   795             TVedPanic::Panic(TVedPanic::EVideoClipInfoIllegalFrameResolution));
       
   796 
       
   797         resolution = *aResolution;
       
   798         }
       
   799     else
       
   800         {
       
   801         resolution = iInfo->Resolution();
       
   802         }
       
   803 
       
   804     __ASSERT_ALWAYS(((aIndex >= 0) && (iInfo->VideoFrameCount() == 0) || 
       
   805                                       (aIndex < iInfo->VideoFrameCount()) || 
       
   806                                       (aIndex == KFrameIndexBestThumb) ), 
       
   807             TVedPanic::Panic(TVedPanic::EVideoClipInfoIllegalVideoFrameIndex));
       
   808 
       
   809     iIndex = aIndex;
       
   810     
       
   811     iFactor.iStreamType = EVedVideoBitstreamModeUnknown;
       
   812     iFactor.iTRes = 0;
       
   813 
       
   814     CMovieProcessor* processor = CMovieProcessor::NewLC();  
       
   815 
       
   816     processor->StartThumbL(iInfo->FileName(), iInfo->FileHandle(), aIndex, resolution, aDisplayMode,
       
   817                            aEnhance);
       
   818 
       
   819     /* Initialization OK. This method cannot leave any more. Start processing. */
       
   820 
       
   821     CleanupStack::Pop(processor);
       
   822 
       
   823     iProcessor = processor;
       
   824     iObserver = &aObserver;
       
   825 
       
   826     SetPriority(aPriority);
       
   827     SetActive();
       
   828     TRequestStatus* status = &iStatus;
       
   829     User::RequestComplete(status, KErrNone);
       
   830 
       
   831     PRINT(_L("CVedVideoClipFrameOperation::StartL out"));
       
   832     }
       
   833 
       
   834 
       
   835 void CVedVideoClipFrameOperation::RunL()
       
   836     {
       
   837     PRINT(_L("CVedVideoClipFrameOperation::RunL in"));
       
   838 
       
   839     __ASSERT_DEBUG(iProcessor != 0, TVedPanic::Panic(TVedPanic::EInternal));
       
   840     __ASSERT_DEBUG(iObserver != 0, TVedPanic::Panic(TVedPanic::EInternal));
       
   841     
       
   842     TInt err = KErrNone;
       
   843     
       
   844     if (!iThumbRequestPending)
       
   845         TRAP(err, iProcessor->ProcessThumbL(iStatus, &iFactor));
       
   846     
       
   847     if (err != KErrNone)
       
   848         {
       
   849         delete iProcessor;
       
   850         iProcessor = 0;
       
   851         
       
   852         MVedVideoClipFrameObserver* observer = iObserver;
       
   853         iObserver = 0;
       
   854         observer->NotifyVideoClipFrameCompleted(*iInfo, err, NULL);
       
   855         return;
       
   856         }
       
   857         
       
   858     if (!iThumbRequestPending)
       
   859     {        
       
   860         iInfo->SetTranscodeFactor(iFactor);
       
   861         iThumbRequestPending = ETrue;
       
   862         iStatus = KRequestPending;
       
   863         SetActive();        
       
   864         return;
       
   865     }
       
   866     else
       
   867     {
       
   868         MVedVideoClipFrameObserver* observer = iObserver;
       
   869         iObserver = 0;
       
   870                 
       
   871         if (iStatus == KErrNone)
       
   872         {
       
   873             CFbsBitmap* frame = 0;
       
   874             iProcessor->FetchThumb(frame);
       
   875             observer->NotifyVideoClipFrameCompleted(*iInfo, KErrNone, frame);            
       
   876         }
       
   877         else
       
   878         {
       
   879             observer->NotifyVideoClipFrameCompleted(*iInfo, iStatus.Int(), NULL);            
       
   880         }
       
   881         iThumbRequestPending = EFalse;
       
   882         delete iProcessor;
       
   883         iProcessor = 0;
       
   884     }      
       
   885         
       
   886     PRINT(_L("CVedVideoClipFrameOperation::RunL out"));
       
   887     }
       
   888 
       
   889 
       
   890 void CVedVideoClipFrameOperation::DoCancel()
       
   891     {
       
   892     if (iProcessor != 0)
       
   893         {
       
   894         delete iProcessor;
       
   895         iProcessor = 0;
       
   896         
       
   897         // Cancel our internal request
       
   898         if ( iStatus == KRequestPending )
       
   899         {
       
   900             PRINT((_L("CVedVideoClipFrameOperation::DoCancel() cancel request")));
       
   901             TRequestStatus *status = &iStatus;
       
   902             User::RequestComplete(status, KErrCancel);
       
   903         }
       
   904         iThumbRequestPending = EFalse;
       
   905 
       
   906         MVedVideoClipFrameObserver* observer = iObserver;
       
   907         iObserver = 0;
       
   908         observer->NotifyVideoClipFrameCompleted(*iInfo, KErrCancel, NULL);
       
   909         }
       
   910     }
       
   911