videoeditorengine/vedengine/src/vedvideoconversionimp.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 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "vedvideoclip.h"
       
    21 #include "vedvideoconversionimp.h"
       
    22 
       
    23 // Print macro
       
    24 #ifdef _DEBUG
       
    25 #include <e32svr.h>
       
    26 #define PRINT(x) RDebug::Print x
       
    27 #else
       
    28 #define PRINT(x)
       
    29 #endif
       
    30 
       
    31 // An assertion macro wrapper to clean up the code a bit
       
    32 #define VCASSERT(x) __ASSERT_DEBUG(x, User::Panic(_L("CVideoConverterImp"), -10000 ))
       
    33 
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // NewL() of CVideoConverter
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 EXPORT_C CVideoConverter* CVideoConverter::NewL(MVideoConverterObserver& aObserver) 
       
    40     {
       
    41     PRINT(_L("CVideoConverter::NewL in"));
       
    42     
       
    43     CVideoConverterImp* self = (CVideoConverterImp*)NewLC(aObserver);
       
    44     CleanupStack::Pop(self);        
       
    45     PRINT(_L("CVideoConverter::NewL out"));
       
    46     
       
    47     return self;
       
    48     }
       
    49     
       
    50 // ---------------------------------------------------------------------------
       
    51 // NewLC() of CVideoConverter
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 EXPORT_C CVideoConverter* CVideoConverter::NewLC(MVideoConverterObserver& aObserver)
       
    55     {
       
    56     PRINT(_L("CVideoConverter::NewLC in"));
       
    57     
       
    58     CVideoConverterImp* self = new (ELeave) CVideoConverterImp(aObserver);
       
    59     CleanupStack::PushL(self);
       
    60     self->ConstructL();
       
    61 
       
    62     PRINT(_L("CVideoConverter::NewLC out"));
       
    63     return self;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // Constructor of CVideoConverter
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CVideoConverterImp::CVideoConverterImp(MVideoConverterObserver& aObserver) : iObserver(aObserver)
       
    71 {    
       
    72 }
       
    73 
       
    74     
       
    75 // ---------------------------------------------------------------------------
       
    76 // Destructor of CVideoConverter
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CVideoConverterImp::~CVideoConverterImp()
       
    80 {
       
    81     delete iMovie;
       
    82 }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // ConstructL() of CVideoConverter
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CVideoConverterImp::ConstructL()
       
    89 {   
       
    90     iMovie = CVedMovie::NewL(NULL);
       
    91  
       
    92     iMovie->RegisterMovieObserverL(this);
       
    93  
       
    94     // set quality to MMS   
       
    95     iMovie->SetQuality(CVedMovie::EQualityMMSInteroperability);
       
    96 }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // Insert file to be checked / converted
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 void CVideoConverterImp::InsertFileL(RFile* aFile)
       
   103 {
       
   104 
       
   105     if ( iMovie->VideoClipCount() != 0 )
       
   106         User::Leave(KErrAlreadyExists);
       
   107 
       
   108     iMovie->InsertVideoClipL(aFile, 0);
       
   109 }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // Check compatibility
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 TMMSCompatibility CVideoConverterImp::CheckMMSCompatibilityL(TInt aMaxSize)
       
   116 {
       
   117 
       
   118     VCASSERT( iMovie->VideoClipCount() == 1 );
       
   119     
       
   120     if ( iMovie->VideoClipCount() != 1 )
       
   121         User::Leave(KErrNotFound);
       
   122     
       
   123     CVedVideoClipInfo* info = iMovie->VideoClipInfo(0);
       
   124     
       
   125     // check file size
       
   126     RFile* file = info->FileHandle();
       
   127     
       
   128     TInt size = 0;
       
   129     User::LeaveIfError( file->Size(size) );
       
   130     
       
   131     TBool sizeOK = ( size <= aMaxSize );
       
   132     
       
   133     // check format
       
   134     TVedVideoFormat fileFormat = info->Format();
       
   135     TVedVideoType videoCodec = info->VideoType();
       
   136     TVedAudioType audioCodec = info->AudioType();
       
   137 
       
   138     TBool formatOK = ( fileFormat == EVedVideoFormat3GPP ) &&
       
   139                      ( videoCodec == EVedVideoTypeH263Profile0Level10 ) &&
       
   140                      ( audioCodec == EVedAudioTypeNoAudio || 
       
   141                        audioCodec == EVedAudioTypeAMR );
       
   142 
       
   143     if ( formatOK && sizeOK )
       
   144         return ECompatible;
       
   145     
       
   146     if ( sizeOK || (!sizeOK && !formatOK) )
       
   147     { 
       
   148          VCASSERT( !formatOK );
       
   149          // check estimated size after conversion
       
   150          // NOTE: This is checked also for sizeOK, because it's possible
       
   151          //       that size increases in conversion
       
   152         TInt sizeEstimate = iMovie->GetSizeEstimateL();
       
   153         
       
   154         if ( sizeEstimate <= aMaxSize )
       
   155             return EConversionNeeded;
       
   156         
       
   157         else
       
   158             return ECutNeeded;   
       
   159     } 
       
   160     
       
   161     // size not ok, format ok
       
   162     VCASSERT( !sizeOK && formatOK );
       
   163 
       
   164     return ECutNeeded;    
       
   165 
       
   166 }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // Get end time estimate on basis of target size and start time
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 void CVideoConverterImp::GetDurationEstimateL(TInt aTargetSize, TTimeIntervalMicroSeconds aStartTime, 
       
   173                                            TTimeIntervalMicroSeconds& aEndTime)
       
   174 {
       
   175  
       
   176     iMovie->GetDurationEstimateL(aTargetSize, aStartTime, aEndTime);
       
   177 
       
   178 }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // Start conversion
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 void CVideoConverterImp::ConvertL(RFile* aOutputFile, TInt aSizeLimit,
       
   185                                   TTimeIntervalMicroSeconds aCutInTime, 
       
   186                                   TTimeIntervalMicroSeconds aCutOutTime)
       
   187 {
       
   188 
       
   189     VCASSERT( iMovie && iMovie->VideoClipCount() == 1 );
       
   190     
       
   191     TTimeIntervalMicroSeconds temp = iMovie->VideoClipCutOutTime(0);
       
   192     
       
   193     iMovie->VideoClipSetCutInTime(0, aCutInTime);
       
   194     
       
   195     if ( aCutOutTime != KVedOriginalDuration )
       
   196         iMovie->VideoClipSetCutOutTime(0, aCutOutTime);
       
   197     
       
   198     iMovie->SetMovieSizeLimit(aSizeLimit);
       
   199     
       
   200     iMovie->ProcessL(aOutputFile, *this);
       
   201 
       
   202 }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // Cancel conversion
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 TInt CVideoConverterImp::CancelConversion()
       
   209 {
       
   210     iMovie->CancelProcessing();
       
   211     
       
   212     return KErrNone;
       
   213 }
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 // Reset to initial state
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 TInt CVideoConverterImp::Reset()
       
   220 {
       
   221     if (iMovie)
       
   222         iMovie->Reset();
       
   223     
       
   224     return KErrNone;
       
   225 }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // Implementation of clip added -callback
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 void CVideoConverterImp::NotifyVideoClipAdded(CVedMovie& /*aMovie*/, TInt /*aIndex*/)
       
   232 {
       
   233     iObserver.MvcoFileInserted(*this);
       
   234 }
       
   235 
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // Implementation of clip adding failed -callback
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CVideoConverterImp::NotifyVideoClipAddingFailed(CVedMovie& /*aMovie*/, TInt aError)
       
   242 {
       
   243     iObserver.MvcoFileInsertionFailed(*this, aError);
       
   244 }
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // Implementation of clip movie processing started -callback
       
   248 // ---------------------------------------------------------------------------
       
   249 //
       
   250 void CVideoConverterImp::NotifyMovieProcessingStartedL(CVedMovie& /*aMovie*/)
       
   251 {
       
   252     iObserver.MvcoConversionStartedL(*this);
       
   253 }
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // Implementation of clip movie processing progressed -callback
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 void CVideoConverterImp::NotifyMovieProcessingProgressed(CVedMovie& /*aMovie*/, TInt aPercentage)
       
   260 {
       
   261     iObserver.MvcoConversionProgressed(*this, aPercentage);
       
   262 }
       
   263 
       
   264 // ---------------------------------------------------------------------------
       
   265 // Implementation of clip movie processing completed -callback
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 void CVideoConverterImp::NotifyMovieProcessingCompleted(CVedMovie& /*aMovie*/, TInt aError)
       
   269 {
       
   270     iObserver.MvcoConversionCompleted(*this, aError);
       
   271 }
       
   272 
       
   273 void CVideoConverterImp::NotifyVideoClipRemoved(CVedMovie& /*aMovie*/, TInt /*aIndex*/){}
       
   274 void CVideoConverterImp::NotifyAudioClipAdded(CVedMovie& /*aMovie*/, TInt /*aIndex*/){}
       
   275 void CVideoConverterImp::NotifyAudioClipAddingFailed(CVedMovie& /*aMovie*/, TInt /*aError*/){}
       
   276 void CVideoConverterImp::NotifyVideoClipIndicesChanged(CVedMovie& /*aMovie*/, TInt /*aOldIndex*/, TInt /*aNewIndex*/){}
       
   277 void CVideoConverterImp::NotifyVideoClipTimingsChanged(CVedMovie& /*aMovie*/, TInt /*aIndex*/){}
       
   278 void CVideoConverterImp::NotifyVideoClipSettingsChanged(CVedMovie& /*aMovie*/, TInt /*aIndex*/){}
       
   279 void CVideoConverterImp::NotifyStartTransitionEffectChanged(CVedMovie& /*aMovie*/){}
       
   280 void CVideoConverterImp::NotifyMiddleTransitionEffectChanged(CVedMovie& /*aMovie*/, TInt /*aIndex*/){}
       
   281 void CVideoConverterImp::NotifyEndTransitionEffectChanged(CVedMovie& /*aMovie*/){}
       
   282 void CVideoConverterImp::NotifyAudioClipRemoved(CVedMovie& /*aMovie*/, TInt /*aIndex*/){}
       
   283 void CVideoConverterImp::NotifyAudioClipIndicesChanged(CVedMovie& /*aMovie*/, TInt /*aOldIndex*/, TInt /*aNewIndex*/){}
       
   284 void CVideoConverterImp::NotifyAudioClipTimingsChanged(CVedMovie& /*aMovie*/, TInt /*aIndex*/){}
       
   285 void CVideoConverterImp::NotifyMovieReseted(CVedMovie& /*aMovie*/){}
       
   286 void CVideoConverterImp::NotifyVideoClipGeneratorSettingsChanged(CVedMovie& /*aMovie*/, TInt /*aIndex*/) {} 
       
   287 void CVideoConverterImp::NotifyMovieOutputParametersChanged(CVedMovie& /*aMovie*/){}
       
   288 void CVideoConverterImp::NotifyVideoClipColorEffectChanged(CVedMovie& /*aMovie*/, TInt /*aIndex*/){}
       
   289 void CVideoConverterImp::NotifyVideoClipAudioSettingsChanged(CVedMovie& /*aMovie*/, TInt /*aIndex*/){}
       
   290 void CVideoConverterImp::NotifyVideoClipDescriptiveNameChanged(CVedMovie& /*aMovie*/, TInt /*aIndex*/){}
       
   291 void CVideoConverterImp::NotifyMovieQualityChanged(CVedMovie& /*aMovie*/){}
       
   292 void CVideoConverterImp::NotifyAudioClipDynamicLevelMarkInserted(CVedMovie& /*aMovie*/, TInt /*aClipIndex*/, TInt /*aMarkIndex*/){}
       
   293 void CVideoConverterImp::NotifyAudioClipDynamicLevelMarkRemoved(CVedMovie& /*aMovie*/, TInt /*aClipIndex*/, TInt /*aMarkIndex*/){}
       
   294 void CVideoConverterImp::NotifyVideoClipDynamicLevelMarkInserted(CVedMovie& /*aMovie*/, TInt /*aClipIndex*/, TInt /*aMarkIndex*/){}
       
   295 void CVideoConverterImp::NotifyVideoClipDynamicLevelMarkRemoved(CVedMovie& /*aMovie*/, TInt /*aClipIndex*/, TInt /*aMarkIndex*/){}