multimediacommscontroller/mmccamrpayloadformat/src/amrpayloadheader.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 "amrpayloadheader.h"
       
    24 #include "streamformatter.h"
       
    25 
       
    26 // CONSTANTS
       
    27 
       
    28 
       
    29 // ============================= LOCAL FUNCTIONS ===============================
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CAmrPayloadHeader::CAmrPayloadHeader
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CAmrPayloadHeader::CAmrPayloadHeader() :iCmr( EAmrModeReqNone )
       
    40     {
       
    41     DP_AMR_ENCODE( "CAmrPayloadHeader::CAmrPayloadHeader" );        
       
    42     }
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CAmrPayloadHeader::NewL
       
    47 // Two-phased constructor.
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CAmrPayloadHeader* CAmrPayloadHeader::NewL()
       
    51     {
       
    52     DP_AMR_ENCODE( "CAmrPayloadHeader::NewL" );
       
    53     
       
    54     CAmrPayloadHeader* self = new( ELeave ) CAmrPayloadHeader( );
       
    55     
       
    56     return self;
       
    57     }
       
    58 
       
    59 
       
    60 // Destructor
       
    61 CAmrPayloadHeader::~CAmrPayloadHeader()
       
    62     {
       
    63     DP_AMR_ENCODE( "CAmrPayloadHeader::~CAmrPayloadHeader" );
       
    64     }
       
    65 
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CAmrPayloadHeader::Encode
       
    69 // Encode the payload header fields into a given buffer at the given position.
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void CAmrPayloadHeader::Encode( TUint8* aBuffer,
       
    73         TInt& aByteIndex, TInt& aBitIndex )
       
    74     {
       
    75     DP_AMR_ENCODE( "CAmrPayloadHeader::Encode" );
       
    76         
       
    77     TStreamEncoder encoder;
       
    78     encoder.Initialize( aBuffer, aByteIndex, aBitIndex );
       
    79     
       
    80     //In bandwidth-efficient mode, the payload header simply consists of a
       
    81     //4 bit codec mode request:
       
    82     //  0 1 2 3
       
    83     // +-+-+-+-+
       
    84     // |  CMR  |
       
    85     // +-+-+-+-+
       
    86     encoder.Encode( iCmr, KCMRFieldBits );
       
    87 
       
    88     // Update Byte and Bit positions
       
    89     aByteIndex = encoder.ByteIndex( ); 
       
    90     aBitIndex = encoder.BitIndex( );
       
    91     }
       
    92 
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CAmrPayloadHeader::Decode
       
    96 // Decode the payload header from a given buffer at the given position.
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CAmrPayloadHeader::Decode( const TUint8* aBuffer,
       
   100         TInt& aByteIndex, TInt& aBitIndex )
       
   101     {
       
   102     DP_AMR_ENCODE( "CAmrPayloadHeader::Decode" );
       
   103     
       
   104     TStreamDecoder decoder;
       
   105     decoder.Initialize( aBuffer, aByteIndex, aBitIndex );
       
   106     iCmr = TAmrModeRequest( decoder.Decode( KCMRFieldBits ) );
       
   107 
       
   108     // Update Byte and Bit positions
       
   109     aByteIndex = decoder.ByteIndex( );
       
   110     aBitIndex = decoder.BitIndex( );
       
   111     }
       
   112