multimediacommscontroller/mmccamrpayloadformat/src/amrpayloadheader.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 27 Apr 2010 17:02:55 +0300
branchRCL_3
changeset 14 5bf83dc720b3
parent 0 1bce908db942
permissions -rw-r--r--
Revision: 201015 Kit: 201017

/*
* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:    PayloadFormat plugin capable to read RTP payload containing
*                Amr audio.
*
*/




// INCLUDE FILES
#include "amrpayloadheader.h"
#include "streamformatter.h"

// CONSTANTS


// ============================= LOCAL FUNCTIONS ===============================

// ============================ MEMBER FUNCTIONS ===============================

// ---------------------------------------------------------------------------
// CAmrPayloadHeader::CAmrPayloadHeader
// C++ default constructor can NOT contain any code, that
// might leave.
// ---------------------------------------------------------------------------
//
CAmrPayloadHeader::CAmrPayloadHeader() :iCmr( EAmrModeReqNone )
    {
    DP_AMR_ENCODE( "CAmrPayloadHeader::CAmrPayloadHeader" );        
    }


// ---------------------------------------------------------------------------
// CAmrPayloadHeader::NewL
// Two-phased constructor.
// ---------------------------------------------------------------------------
//
CAmrPayloadHeader* CAmrPayloadHeader::NewL()
    {
    DP_AMR_ENCODE( "CAmrPayloadHeader::NewL" );
    
    CAmrPayloadHeader* self = new( ELeave ) CAmrPayloadHeader( );
    
    return self;
    }


// Destructor
CAmrPayloadHeader::~CAmrPayloadHeader()
    {
    DP_AMR_ENCODE( "CAmrPayloadHeader::~CAmrPayloadHeader" );
    }


// ---------------------------------------------------------------------------
// CAmrPayloadHeader::Encode
// Encode the payload header fields into a given buffer at the given position.
// ---------------------------------------------------------------------------
//
void CAmrPayloadHeader::Encode( TUint8* aBuffer,
        TInt& aByteIndex, TInt& aBitIndex )
    {
    DP_AMR_ENCODE( "CAmrPayloadHeader::Encode" );
        
    TStreamEncoder encoder;
    encoder.Initialize( aBuffer, aByteIndex, aBitIndex );
    
    //In bandwidth-efficient mode, the payload header simply consists of a
    //4 bit codec mode request:
    //  0 1 2 3
    // +-+-+-+-+
    // |  CMR  |
    // +-+-+-+-+
    encoder.Encode( iCmr, KCMRFieldBits );

    // Update Byte and Bit positions
    aByteIndex = encoder.ByteIndex( ); 
    aBitIndex = encoder.BitIndex( );
    }


// ---------------------------------------------------------------------------
// CAmrPayloadHeader::Decode
// Decode the payload header from a given buffer at the given position.
// ---------------------------------------------------------------------------
//
void CAmrPayloadHeader::Decode( const TUint8* aBuffer,
        TInt& aByteIndex, TInt& aBitIndex )
    {
    DP_AMR_ENCODE( "CAmrPayloadHeader::Decode" );
    
    TStreamDecoder decoder;
    decoder.Initialize( aBuffer, aByteIndex, aBitIndex );
    iCmr = TAmrModeRequest( decoder.Decode( KCMRFieldBits ) );

    // Update Byte and Bit positions
    aByteIndex = decoder.ByteIndex( );
    aBitIndex = decoder.BitIndex( );
    }