multimediacommscontroller/mmccamrpayloadformat/src/amrtocentry.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:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "amrtocentry.h"
       
    23 #include "amrpayloadformatter.h"
       
    24 #include "streamformatter.h"
       
    25 
       
    26 // CONSTANTS
       
    27 const TUint KFTFieldBits = 4;
       
    28 const TUint KFrameFollowedBits = 1;
       
    29 const TUint KQualityIndBits = 1;
       
    30 
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // CAmrTocEntry::CAmrTocEntry
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CAmrTocEntry::CAmrTocEntry() : iFrameFollowed( 1 ),
       
    39     iFrameType( EAmrFrame5_15 ), iFrameQualityInd( 1 ) 
       
    40     {
       
    41     DP_AMR_ENCODE( "CAmrTocEntry::CAmrTocEntry" );        
       
    42     }
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CAmrTocEntry::NewL
       
    47 // Two-phased constructor.
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CAmrTocEntry* CAmrTocEntry::NewL()
       
    51     {
       
    52     DP_AMR_ENCODE( "CAmrTocEntry::NewL" );   
       
    53     CAmrTocEntry* self = new( ELeave ) CAmrTocEntry( );    
       
    54     return self;
       
    55     }
       
    56 
       
    57 
       
    58 // Destructor
       
    59 CAmrTocEntry::~CAmrTocEntry()
       
    60     {
       
    61     DP_AMR_ENCODE( "CAmrTocEntry::~CAmrTocEntry" );
       
    62     }
       
    63 
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CAmrTocEntry::Encode
       
    67 // Encode the `table of contents' ( TOC ) entry fields into a given buffer.
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void CAmrTocEntry::Encode( TUint8* aBuffer,
       
    71         TInt& aByteIndex, TInt& aBitIndex )
       
    72     {
       
    73     DP_AMR_ENCODE( "CAmrTocEntry::Encode" );
       
    74         
       
    75     TStreamEncoder encoder;
       
    76     encoder.Initialize( aBuffer, aByteIndex, aBitIndex );
       
    77     
       
    78     // In bandwidth-efficient mode, a TOC entry takes the following format
       
    79     //   0 1 2 3 4 5
       
    80     //  +-+-+-+-+-+-+
       
    81     //  |F|  FT   |Q|
       
    82     //  +-+-+-+-+-+-+
       
    83     encoder.Encode( iFrameFollowed, KFrameFollowedBits );
       
    84     encoder.Encode( iFrameType, KFTFieldBits );
       
    85     encoder.Encode( iFrameQualityInd, KQualityIndBits );
       
    86 
       
    87     // Update Byte and Bit positions
       
    88     aByteIndex = encoder.ByteIndex( );
       
    89     aBitIndex = encoder.BitIndex( );
       
    90     }
       
    91 
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CAmrTocEntry::Decode
       
    95 // Decode the `table of contents' ( TOC ) entry fields from a given buffer at
       
    96 // the given position.
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CAmrTocEntry::Decode( const TUint8* aBuffer, 
       
   100         TInt& aByteIndex, TInt& aBitIndex )
       
   101     {
       
   102     DP_AMR_ENCODE( "CAmrTocEntry::Decode" );
       
   103         
       
   104     TStreamDecoder decoder;
       
   105     decoder.Initialize( aBuffer, aByteIndex, aBitIndex );
       
   106 
       
   107     // In bandwidth-efficient mode, a TOC entry takes the following format
       
   108     //   0 1 2 3 4 5
       
   109     //  +-+-+-+-+-+-+
       
   110     //  |F|  FT   |Q|
       
   111     //  +-+-+-+-+-+-+
       
   112     iFrameFollowed = TUint8( decoder.Decode( KFrameFollowedBits ) );
       
   113     iFrameType = TAmrFrameType( decoder.Decode( KFTFieldBits ) );
       
   114     iFrameQualityInd = TUint8( decoder.Decode( KQualityIndBits ) );
       
   115 
       
   116     // Update Byte and Bit positions
       
   117     aByteIndex = decoder.ByteIndex( );
       
   118     aBitIndex = decoder.BitIndex( );
       
   119     }