multimediacommscontroller/mmccamrpayloadformat/src/AmrPayloadEncoderOA.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     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:    PayloadFormat plugin capable to read RTP payload containing
       
    15 *                Amr audio.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include "amrpayloadencoderoa.h"
       
    24 #include "amrpayloadheaderoa.h"
       
    25 #include "amrtocentryoa.h"
       
    26 
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS =============================
       
    29   
       
    30 // ---------------------------------------------------------------------------
       
    31 // CAmrPayloadEncoderOA::CAmrPayloadEncoderOA
       
    32 // C++ default constructor can NOT contain any code, that
       
    33 // might leave.
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CAmrPayloadEncoderOA::CAmrPayloadEncoderOA( TBool aIsNb )
       
    37     : CAmrPayloadEncoder( aIsNb )
       
    38     {
       
    39     DP_AMR_ENCODE( "CAmrPayloadEncoderOA::CAmrPayloadEncoderOA" );
       
    40         
       
    41     CAmrPayloadEncoderOA::InitializeFrameEncoder( );
       
    42     }
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CAmrPayloadEncoderOA::ConstructL
       
    47 // Symbian 2nd phase constructor can leave.
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 void CAmrPayloadEncoderOA::ConstructL()
       
    51     {
       
    52     DP_AMR_ENCODE( "CAmrPayloadEncoderOA::ConstructL" );
       
    53 
       
    54     // Allocate memory for iHeaderEncoder and iTocEntryEncoder and set them
       
    55     // to NULL to avoid codescanner errors
       
    56     delete iHeaderEncoder;
       
    57     iHeaderEncoder = NULL;
       
    58     delete iTocEntryEncoder;
       
    59     iTocEntryEncoder = NULL;
       
    60     
       
    61     iHeaderEncoder = CAmrPayloadHeaderOA::NewL();
       
    62     iTocEntryEncoder = CAmrTocEntryOA::NewL();
       
    63     }
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CAmrPayloadEncoder::NewL
       
    68 // Two-phased constructor.
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CAmrPayloadEncoderOA* CAmrPayloadEncoderOA::NewL( TBool aIsNb )
       
    72     {
       
    73     DP_AMR_ENCODE( "CAmrPayloadEncoderOA::NewL" );
       
    74         
       
    75     CAmrPayloadEncoderOA* self = new( ELeave ) CAmrPayloadEncoderOA( aIsNb );
       
    76     
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL( );
       
    79     CleanupStack::Pop( self );
       
    80 
       
    81     return self;
       
    82     }
       
    83 
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // CAmrPayloadEncoderOA::~CAmrPayloadEncoderOA
       
    87 // Destructor
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 CAmrPayloadEncoderOA::~CAmrPayloadEncoderOA()
       
    91     {
       
    92     DP_AMR_ENCODE( "CAmrPayloadEncoderOA::~CAmrPayloadEncoderOA" );
       
    93     }
       
    94 
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CAmrPayloadEncoderOA::EncodeFrame
       
    98 // Encode a received Amr frame into the payload buffer.
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 TBool CAmrPayloadEncoderOA::EncodeFrame( TInt aChannel,
       
   102                                          TAmrFrameType aFrameType,
       
   103                                          TUint8 aFrameQualityInd,
       
   104                                          const TDes8& aFrameData )
       
   105     {
       
   106     DP_AMR_ENCODE( "CAmrPayloadEncoderOA::EncodeFrame" );
       
   107         
       
   108     TBool ret = CAmrPayloadEncoder::EncodeFrame( aChannel, aFrameType, 
       
   109                                                  aFrameQualityInd, aFrameData );
       
   110     if ( EFalse == ret )
       
   111         {
       
   112         // Encoding a frame data only. Payload Header and TOCs haven't been filled
       
   113         // Padding frame data to Byte boundary.
       
   114         if ( iFrameEncoder.BitIndex( ) != 0 )
       
   115             {
       
   116             iFrameEncoder.Encode( 0, ( KBitsIn1Byte - iFrameEncoder.BitIndex( ) ) );
       
   117             }
       
   118         }
       
   119     else
       
   120         {
       
   121         InitializeFrameEncoder();
       
   122         }
       
   123 
       
   124     return ret;
       
   125     }
       
   126 
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // CAmrPayloadEncoderOA::SetChannelCount
       
   130 // Set number of audio channels.
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 TInt CAmrPayloadEncoderOA::SetChannelCount( TInt aChannelCount )
       
   134     {
       
   135     DP_AMR_ENCODE( "CAmrPayloadEncoderOA::SetChannelCount" );
       
   136         
       
   137     TInt ret = CAmrPayloadFormatter::SetChannelCount( aChannelCount );
       
   138     InitializeFrameEncoder( );
       
   139     return ret;
       
   140     }
       
   141 
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CAmrPayloadEncoderOA::SetFrameBlockCount
       
   145 // Set number of Amr frame blocks included in one RTP packet.
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 TInt CAmrPayloadEncoderOA::SetFrameBlockCount( TInt aFrameblockCount )
       
   149     {
       
   150     DP_AMR_ENCODE( "CAmrPayloadEncoderOA::SetFrameBlockCount" );
       
   151         
       
   152     TInt ret = CAmrPayloadFormatter::SetFrameBlockCount( aFrameblockCount );
       
   153     InitializeFrameEncoder();
       
   154     return ret;
       
   155     }
       
   156 
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CAmrPayloadEncoderOA::InitializeFrameEncoder
       
   160 // Initialize frame encoder ( Stream Encoder ). Starting position of first 
       
   161 // AMR frame data is calculated. Refer to RFC3267 4.4.
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void CAmrPayloadEncoderOA::InitializeFrameEncoder()
       
   165     {
       
   166     DP_AMR_ENCODE( "CAmrPayloadEncoderOA::InitializeFrameEncoder" );    
       
   167 
       
   168     // Total number of TOCs: iFrameCount = iChannelCount * iFrameBlockCount
       
   169     // In OA mode, Bit Index always equals to Zero.
       
   170     TInt numOfRedFrames( 0 );
       
   171     if ( iRedIntervalCollected )
       
   172         {
       
   173         numOfRedFrames = iFrameDatas.Count();
       
   174         }
       
   175 
       
   176     TInt frameByteIndex = ( KHeaderBitsOA 
       
   177         + KTOCFieldBitsOA * ( iFrameCount + numOfRedFrames ) ) / KBitsIn1Byte;
       
   178 
       
   179     iFrameEncoder.Initialize( iPayload, frameByteIndex, 0 );
       
   180     }