multimediacommscontroller/mmccshared/inc/streamformatter.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004-2005 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:    Formatter classes for encoding/decoding of a bit stream.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef STREAMFORMATTER_H
       
    21 #define STREAMFORMATTER_H
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32std.h>
       
    25 
       
    26 // CONSTS
       
    27 const TInt KBitsIn1Byte = 8;
       
    28 
       
    29 // CLASS DECLARATION
       
    30 
       
    31 /**
       
    32 * The formatter class that sequentially encodes a bit stream.
       
    33 *
       
    34 * @lib      Mccamrplformat.lib
       
    35 * @since    Series 60 3.0
       
    36 */
       
    37 class TStreamEncoder
       
    38     {
       
    39     public:
       
    40 
       
    41         /**
       
    42         * Constructor.
       
    43         */
       
    44         TStreamEncoder() : iBuffer( NULL ), iByteIndex( 0 ), iBitIndex( 0 )
       
    45             {   };
       
    46 
       
    47         /**
       
    48         * Destructor.
       
    49         */
       
    50         virtual ~TStreamEncoder() { iBuffer = NULL; };
       
    51 
       
    52     public:
       
    53 
       
    54         /**
       
    55         * Initialize the stream encoder.
       
    56         * This function must be called before calling any other functions.
       
    57         * @since Series 60 3.0
       
    58         * @param aBuffer - [input] Pointer to the bit-stream buffer.
       
    59         * @param aByteIndex - [input] Starting byte index ( starts from zero ).
       
    60         * @param aBitIndex - [input] Starting bit index ( starts from zero ).
       
    61         * @return void
       
    62         */
       
    63         void Initialize( TUint8* aBuffer, TInt aByteIndex, TInt aBitIndex );
       
    64 
       
    65         /**
       
    66         * Put a number of bit values ( up to 32 bits ) into the bit-stream 
       
    67         * buffer at current location. Bits are put starting from MSB of the
       
    68         * buffer byte and advancing to LSB.
       
    69         * @since    Series 60 3.0
       
    70         * @param    aValue - [input] Value to put.
       
    71         * @param    aBitCount - [input] Number of bits to put; between 1 and 32,
       
    72         *           both inclusive.
       
    73         */
       
    74         void Encode( TUint32 aValue, TInt aBitCount );
       
    75 
       
    76         /**
       
    77         * Put a number of bit values into the bit-stream buffer at current 
       
    78         * location.
       
    79         * @since    Series 60 3.0
       
    80         * @param    aFromBuffer - [input] Buffer to get byte values from.
       
    81         * @param    aByteIndex - [input] Starting byte index ( starts from
       
    82         *           zero ).
       
    83         * @param    aBitIndex - [input] Starting bit index ( starts from zero ).
       
    84         * @param    aBitCount - [input] Number of bits to put.
       
    85         */
       
    86         void Encode( const TUint8* aFromBuffer, TInt aFromByteIndex,
       
    87                 TInt aFromBitIndex, TInt aBitCount );
       
    88 
       
    89         /**
       
    90         * Get the current byte index value.
       
    91         * @since    Series 60 3.0
       
    92         * @return   TInt - Current byte index value.
       
    93         */
       
    94         inline TInt ByteIndex() const 
       
    95                 { return iByteIndex; };
       
    96 
       
    97         /**
       
    98         * Get the current bit index value.
       
    99         * @since    Series 60 3.0
       
   100         * @return   TInt - Current bit index value.
       
   101         */
       
   102         inline TInt BitIndex() const 
       
   103                 { return iBitIndex; };
       
   104 
       
   105         /**
       
   106         * Set the current byte index value.
       
   107         * @since    Series 60 3.0
       
   108         * @param    aByteIndex New byte index
       
   109         */
       
   110         inline void SetByteIndex( TInt aByteIndex ) 
       
   111                 { iByteIndex = aByteIndex; };
       
   112 
       
   113         /**
       
   114         * Set the current bit index value.
       
   115         * @since    Series 60 3.0
       
   116         * @param    aBitIndex New bit index
       
   117         */
       
   118         inline void SetBitIndex( TInt aBitIndex ) 
       
   119                 { iBitIndex = aBitIndex; };
       
   120 
       
   121     private:
       
   122     
       
   123         // Pointer to the bit-stream buffer.
       
   124         TUint8* iBuffer;
       
   125 
       
   126         // Current byte index ( starts from zero )
       
   127         TInt  iByteIndex;
       
   128         
       
   129         // Current bit index ( starts from zero )
       
   130         TInt  iBitIndex;
       
   131     };
       
   132 
       
   133 /**
       
   134 * The formatter class that sequentially decodes a bit stream.
       
   135 *
       
   136 * @lib      Mccamrplformat.lib
       
   137 * @since    Series 60 3.0
       
   138 */
       
   139 class TStreamDecoder
       
   140     {
       
   141     public:
       
   142 
       
   143         /**
       
   144         * Constructor.
       
   145         */
       
   146         TStreamDecoder() : iBuffer( NULL ), iByteIndex( 0 ), iBitIndex( 0 )
       
   147             {   };
       
   148 
       
   149         /**
       
   150         * Destructor.
       
   151         */
       
   152         virtual ~TStreamDecoder() { iBuffer = NULL; };
       
   153 
       
   154     public:
       
   155 
       
   156         /**
       
   157         * Initialize the stream decoder.
       
   158         * This function must be called before calling any other functions.
       
   159         * @since    Series 60 3.0
       
   160         * @param    aBuffer - [input] Pointer to the bit-stream buffer.
       
   161         * @param    aByteIndex - [input] Starting byte index ( starts from 
       
   162         *           zero ).
       
   163         * @param    aBitIndex - [input] Starting bit index ( starts from zero ).
       
   164         */
       
   165         void Initialize( const TUint8* aBuffer, TInt aByteIndex, 
       
   166                 TInt aBitIndex );
       
   167 
       
   168         /**
       
   169         * Get a number of bit values ( up to 32 bits ) from the bit-stream
       
   170         * buffer at current location. Bits are extracted starting from MSB of
       
   171         * the buffer byte and advancing to LSB.
       
   172         * Returned value: ( MSB )-> bit31, bit30 .... bit1, bit0 <-( LSB, full )
       
   173         * If aBitCount < 32, vacant MSB bits of the returned value are filled
       
   174         * with zeros.
       
   175         * @since    Series 60 3.0
       
   176         * @param    aBitCount - [input] Number of bits to get; between 1 and 32,
       
   177         *           both inclusive.
       
   178         * @return   TUint32 - Bit values extracted from the buffer; zero if
       
   179         *           aBitCount is out of range.
       
   180         */
       
   181         TUint32 Decode( TInt aBitCount );
       
   182 
       
   183         /**
       
   184         * Get a number of byte values from the bit-stream buffer at current
       
   185         * location.
       
   186         * @since Series 60 3.0
       
   187         * @param    aToBuffer - [output] Buffer to store byte values.
       
   188         * @param    aByteIndex - [input] Starting byte index ( starts from 
       
   189         *           zero ).
       
   190         * @param    aBitIndex - [input] Starting bit index ( starts from zero ).
       
   191         * @param    aBitCount - [input] Number of bits to put.
       
   192         */
       
   193         void Decode( TUint8* aToBuffer, TInt aToByteIndex, TInt aToBitIndex,
       
   194                 TInt aBitCount );
       
   195 
       
   196         /**
       
   197         * Get the current byte index value.
       
   198         * @since    Series 60 3.0
       
   199         * @return   TInt - Current byte index value.
       
   200         */
       
   201         inline TInt ByteIndex() const 
       
   202                 { return iByteIndex; };
       
   203 
       
   204         /**
       
   205         * Get the current bit index value.
       
   206         * @since    Series 60 3.0
       
   207         * @return   TInt - Current bit index value.
       
   208         */
       
   209         inline TInt BitIndex() const 
       
   210                 { return iBitIndex; };
       
   211 
       
   212         /**
       
   213         * Set the current byte index value.
       
   214         * @since    Series 60 3.0
       
   215         * @param    aByteIndex New byte index
       
   216         */
       
   217         inline void SetByteIndex( TInt aByteIndex ) 
       
   218                 { iByteIndex = aByteIndex; };
       
   219 
       
   220         /**
       
   221         * Set the current bit index value.
       
   222         * @since    Series 60 3.0
       
   223         * @param    aBitIndex New bit index
       
   224         */
       
   225         inline void SetBitIndex( TInt aBitIndex )
       
   226                 { iBitIndex = aBitIndex; };
       
   227 
       
   228     private:
       
   229     
       
   230         // Pointer to the bit-stream buffer.
       
   231         const TUint8* iBuffer;
       
   232         
       
   233         // Current byte index ( starts from zero )
       
   234         TInt  iByteIndex;
       
   235         
       
   236         // Current bit index ( starts from zero )
       
   237         TInt  iBitIndex;
       
   238     };
       
   239 
       
   240 #endif  // STREAMFORMATTER_H