videoeditorengine/vedengine/videoprocessor/src/audioprocessor.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 * Implementation of audio processor class.                
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 //  Include Files
       
    22 #include "movieprocessorimpl.h"
       
    23 #include "AudSong.h"
       
    24 #include "audioprocessor.h"
       
    25 
       
    26 #ifdef _DEBUG
       
    27 #include <e32svr.h>
       
    28 #define PRINT(x) RDebug::Print x;
       
    29 #else
       
    30 #define PRINT(x)
       
    31 #endif
       
    32 
       
    33 // Macros
       
    34 #define APASSERT(x) __ASSERT_DEBUG(x, User::Panic(_L("CAudioProcessor"), -30000))
       
    35 
       
    36 const TUint KNumFramesInOneRun = 20;
       
    37 
       
    38 
       
    39 // ================= MEMBER FUNCTIONS =======================
       
    40 
       
    41 
       
    42 // ---------------------------------------------------------
       
    43 // CAudioProcessor::NewL
       
    44 // Two-phased constructor.
       
    45 // ---------------------------------------------------------
       
    46 //
       
    47 CAudioProcessor* CAudioProcessor::NewL(CMovieProcessorImpl *aMovieProcessor, CAudSong* aSong)
       
    48 {
       
    49     CAudioProcessor* self = NewLC(aMovieProcessor, aSong);
       
    50     CleanupStack::Pop(self);
       
    51     return self;
       
    52 }
       
    53 
       
    54 CAudioProcessor* CAudioProcessor::NewLC(CMovieProcessorImpl *aMovieProcessor, CAudSong* aSong)
       
    55 {
       
    56     CAudioProcessor* self = new (ELeave) CAudioProcessor(aMovieProcessor, aSong);
       
    57     CleanupStack::PushL(self);
       
    58     self->ConstructL();
       
    59     return self;
       
    60 }
       
    61 
       
    62 
       
    63 // ---------------------------------------------------------
       
    64 // CAudioProcessor::NewL
       
    65 // C++ default constructor
       
    66 // ---------------------------------------------------------
       
    67 //
       
    68 CAudioProcessor::CAudioProcessor(CMovieProcessorImpl *aMovieProcessor, CAudSong* aSong) : CActive(EPriorityNormal)
       
    69 {
       
    70     iMovieProcessor = aMovieProcessor;
       
    71     iSong = aSong;	
       
    72     iProcessing = EFalse;
       
    73 }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CAudioProcessor::ConstructL
       
    77 // Symbian 2nd phase constructor 
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CAudioProcessor::ConstructL()
       
    81 {
       
    82 
       
    83     if(!iSong)
       
    84     {
       
    85         User::Leave(KErrArgument);	
       
    86     }     	
       
    87 
       
    88     SetPriority( EPriorityNormal );
       
    89     // Add to active scheduler
       
    90     CActiveScheduler::Add(this);
       
    91     
       
    92     // Make us active
       
    93     SetActive();
       
    94     iStatus = KRequestPending;
       
    95   
       
    96 }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CAudioProcessor::~CAudioProcessor
       
   100 // Destructor
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 CAudioProcessor::~CAudioProcessor()
       
   104 {
       
   105     PRINT((_L("CAudioProcessor::~CAudioProcessor() begin")));
       
   106 
       
   107     Cancel();
       
   108 
       
   109     PRINT((_L("CAudioProcessor::~CAudioProcessor() end")));
       
   110 }
       
   111 
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CAudioProcessor::DoCancel()
       
   115 // DoCancel for AO framework
       
   116 // (other items were commented in a header).
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CAudioProcessor::DoCancel()
       
   120 {
       
   121     // Cancel our internal request
       
   122     if ( iStatus == KRequestPending )
       
   123     {
       
   124         PRINT((_L("CAudioProcessor::DoCancel() cancel request")))
       
   125         TRequestStatus *status = &iStatus;
       
   126         User::RequestComplete(status, KErrCancel);
       
   127     }
       
   128 }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CAudioProcessor::RunL()
       
   132 // Running method of AO framework
       
   133 // (other items were commented in a header).
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CAudioProcessor::RunL()
       
   137 {
       
   138 
       
   139     if (!iProcessing)
       
   140         return;
       
   141     
       
   142     ProcessFramesL();
       
   143         
       
   144 }
       
   145 
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CAudioProcessor::ProcessFramesL()
       
   149 // Process audio frames
       
   150 // (other items were commented in a header).
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void CAudioProcessor::ProcessFramesL()
       
   154 {
       
   155 
       
   156     TInt progress = 0;
       
   157     HBufC8* frame = 0;
       
   158     TPtr8 ptr(0,0);	
       
   159     TTimeIntervalMicroSeconds time(0);
       
   160     
       
   161     TBool gotFrame = ETrue; // true indicates end of sequence
       
   162     
       
   163     TInt framesProcessed = 0;
       
   164     
       
   165     do
       
   166     {	    
       
   167         gotFrame = iSong->SyncProcessFrameL(frame,progress,time); 
       
   168 
       
   169         if(gotFrame)
       
   170         {
       
   171             break;		
       
   172         }
       
   173 
       
   174         if (frame == NULL || frame->Size() == 0)
       
   175         {
       
   176             continue;
       
   177         }
       
   178 		
       
   179         CleanupStack::PushL(frame);
       
   180 
       
   181         TInt duration = I64INT(time.Int64()); 
       
   182 
       
   183         ptr.Set((TUint8*)frame->Ptr(),frame->Length(),frame->Length());
       
   184 
       
   185         User::LeaveIfError(iMovieProcessor->WriteAllAudioFrames((TDesC8&)ptr,duration));			
       
   186 
       
   187         CleanupStack::Pop();
       
   188 
       
   189         if(frame != 0)
       
   190         {
       
   191             delete frame;		
       
   192             frame = 0;
       
   193         }
       
   194 
       
   195         // Increment the frame number
       
   196         framesProcessed++;
       
   197 
       
   198         if (framesProcessed >= KNumFramesInOneRun)
       
   199         {
       
   200             iStatus = KRequestPending;
       
   201             SetActive();
       
   202             TRequestStatus *tmp = &iStatus;
       
   203             User::RequestComplete( tmp, KErrNone );
       
   204             return;
       
   205         }			
       
   206 		
       
   207 	} while(!gotFrame);
       
   208 	
       
   209     if(frame!=0)
       
   210     {
       
   211         delete frame;
       
   212         frame = 0;
       
   213     }
       
   214 
       
   215     // finished
       
   216     iProcessing = EFalse;
       
   217 
       
   218     iMovieProcessor->AudioProcessingComplete(KErrNone);	
       
   219 	
       
   220 }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CAudioProcessor::RunError()
       
   224 // RunError method of AO framework
       
   225 // (other items were commented in a header).
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 TInt CAudioProcessor::RunError(TInt aError)
       
   229 {
       
   230     iProcessing = EFalse;
       
   231 
       
   232     iMovieProcessor->AudioProcessingComplete(aError);
       
   233 
       
   234     return KErrNone;
       
   235 }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CAudioProcessor::StartL()
       
   239 // Stops audio processing
       
   240 // (other items were commented in a header).
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 void CAudioProcessor::StartL()
       
   244 {
       
   245     PRINT((_L("CAudioProcessor::StartL() begin")));
       
   246     
       
   247     if ( iProcessing )
       
   248         return;
       
   249     
       
   250     if (iSong->ClipCount(KAllTrackIndices) == 0)
       
   251     {
       
   252         iMovieProcessor->AudioProcessingComplete(KErrNone);
       
   253         return;    	
       
   254     }
       
   255 
       
   256     iSong->SyncStartProcessingL();
       
   257     
       
   258     TRequestStatus *status = &iStatus;
       
   259     User::RequestComplete(status, KErrNone);
       
   260     
       
   261     iProcessing = ETrue;    
       
   262 
       
   263     PRINT((_L("CAudioProcessor::StartL() end")));
       
   264 }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CAudioProcessor::StopL()
       
   268 // Stops audio processing
       
   269 // (other items were commented in a header).
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 void CAudioProcessor::StopL()
       
   273 {
       
   274     PRINT((_L("CAudioProcessor::StopL() begin")));
       
   275     
       
   276     if ( !iProcessing )
       
   277         return;
       
   278 
       
   279     Cancel();
       
   280     
       
   281     iSong->SyncCancelProcess();
       
   282 
       
   283     iMovieProcessor->AudioProcessingComplete(KErrNone);
       
   284 
       
   285     iProcessing = EFalse;
       
   286     
       
   287     PRINT((_L("CAudioProcessor::StopL() end")));
       
   288 }
       
   289 
       
   290 // End of file
       
   291