multimediacommscontroller/mmccredpayloadformat/src/mccredencdecbase.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005-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:    Base class for redundancy payload encoder and decoder
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include    <mmf/server/mmfdatabuffer.h>
       
    24 #include    "mccredencdecbase.h"
       
    25 #include    "mccredpayloadformatdefs.h"
       
    26 
       
    27 // ============================= LOCAL FUNCTIONS ===============================
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CMccRedEncDecBase::CMccRedEncDecBase
       
    33 // C++ default constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CMccRedEncDecBase::CMccRedEncDecBase()
       
    38     :
       
    39     iRedBlockCount( KDefRedCount )
       
    40     {
       
    41     DP_RED_ENCODE( "CMccRedEncDecBase::CMccRedEncDecBase" )
       
    42     }
       
    43 
       
    44 // Destructor
       
    45 CMccRedEncDecBase::~CMccRedEncDecBase()
       
    46     {
       
    47     DP_RED_ENCODE( "CMccRedEncDecBase::~CMccRedEncDecBase" )
       
    48     iEncodings.DeleteAll();
       
    49     delete iRTPPayload;
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CMccRedEncDecBase::SetEncodingBlockL
       
    54 // Set encoding, which is wanted to encode/decode.
       
    55 // SetMaxPayloadSizeL() MUST be called before coming here.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 void CMccRedEncDecBase::SetEncodingBlockL( TMccRedEncoding aEncoding,
       
    59                                            TDesC8& aEncodingBuf )
       
    60     {
       
    61     DP_RED_ENCODE2( "CMccRedEncDecBase::SetEncodingBlock() - \
       
    62         PARAMBUF SIZE: %d", aEncodingBuf.Size() )
       
    63     
       
    64     if ( EMccRTPPayload == aEncoding )
       
    65         {
       
    66         __ASSERT_ALWAYS( iRTPPayload, User::Leave( KErrNotReady ) );
       
    67         
       
    68         DP_RED_ENCODE2( "MAX RTP Payload SIZE to ACCEPT: %d", \
       
    69             iRTPPayload->Data().MaxSize() )
       
    70         
       
    71         TDes8& rtpPayload = iRTPPayload->Data();
       
    72         rtpPayload.Copy( aEncodingBuf );
       
    73         }
       
    74     else
       
    75         {
       
    76         __ASSERT_ALWAYS( aEncoding < iEncodings.Count(), 
       
    77             User::Leave( KErrArgument ) );
       
    78         __ASSERT_ALWAYS( iEncodings[ aEncoding ], User::Leave( KErrNotReady ) );
       
    79         
       
    80         TDes8& encoding = iEncodings[ aEncoding ]->Data();
       
    81         DP_RED_ENCODE2( "MAX Encoding SIZE to ACCEPT: %d", \
       
    82             encoding.MaxSize() )
       
    83         
       
    84         encoding.Copy( aEncodingBuf );
       
    85         }
       
    86     }
       
    87   
       
    88 // -----------------------------------------------------------------------------
       
    89 // CMccRedEncDecBase::GetEncodingBlockL
       
    90 // Get encoding specified with parameter.
       
    91 // -----------------------------------------------------------------------------
       
    92 //                                   
       
    93 void CMccRedEncDecBase::GetEncodingBlockL( TMccRedEncoding aEncoding, 
       
    94                                            TDes8& aToBuffer )
       
    95     {
       
    96     DP_RED_ENCODE2( "CMccRedEncDecBase::GetEncodingBlock() - \
       
    97         PARAMBUFSIZE: %d", aToBuffer.MaxSize() )
       
    98     
       
    99     if ( EMccRTPPayload == aEncoding )
       
   100         {
       
   101         __ASSERT_ALWAYS( iRTPPayload, User::Leave( KErrNotReady ) );
       
   102         DP_RED_ENCODE2( "RTP Payload SIZE: %d", iRTPPayload->Data().Size() )
       
   103         aToBuffer.Copy( iRTPPayload->Data() );
       
   104         }
       
   105     else
       
   106         {
       
   107         __ASSERT_ALWAYS( aEncoding < iEncodings.Count(), 
       
   108             User::Leave( KErrArgument ) );
       
   109         
       
   110         DP_RED_ENCODE2( "Encoding SIZE: %d", \
       
   111             iEncodings[ aEncoding ]->Data().Size() )
       
   112         
       
   113         aToBuffer.Copy( iEncodings[ aEncoding ]->Data() );
       
   114         }        
       
   115     }
       
   116         
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CMccRedEncDecBase::SetPayloadTypes
       
   120 // Set payload types to wait for. Issue payload not defined values for unused
       
   121 // encodings.
       
   122 // -----------------------------------------------------------------------------
       
   123 //        
       
   124 TInt CMccRedEncDecBase::SetPayloadTypes( RArray<TUint>& aPayloadTypes )
       
   125     {
       
   126     TInt ptCount( aPayloadTypes.Count() );
       
   127     
       
   128     DP_RED_ENCODE2( "CMccRedEncDecBase::SetPayloadTypes() - PTs: %d",
       
   129         ptCount )
       
   130         
       
   131     TInt maxNumOfPTs( iPayloadTypes.Count() );
       
   132     
       
   133     if ( ptCount && ptCount <= maxNumOfPTs )
       
   134         {
       
   135         TInt payloadInd( 0 );
       
   136         
       
   137         for ( ; payloadInd < ptCount; payloadInd++ )
       
   138             {
       
   139             iPayloadTypes[payloadInd] = 
       
   140                 static_cast<TUint8>( aPayloadTypes[payloadInd] );
       
   141             }
       
   142 
       
   143         for ( ; payloadInd < maxNumOfPTs; payloadInd++ )
       
   144             {
       
   145             iPayloadTypes[payloadInd] = KPayloadNotDefined;
       
   146             }
       
   147         
       
   148         return KErrNone;
       
   149         }
       
   150     else
       
   151         {
       
   152         return KErrArgument;    
       
   153         }
       
   154     }
       
   155 
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CMccRedEncDecBase::InitializeL
       
   159 // Reserve space for buffers and reset variables.
       
   160 // -----------------------------------------------------------------------------
       
   161 //  
       
   162 void CMccRedEncDecBase::InitializeL( TInt aRedBlockCount, TInt aMaxPayloadSize,
       
   163     TInt aNumOfEncodings )
       
   164     {
       
   165     DP_RED_ENCODE4( "CMccRedEncDecBase::InitializeL - RedBC: %d, MaxPS: %d, \
       
   166     NumOfEncs: %d", aRedBlockCount, aMaxPayloadSize, aNumOfEncodings )
       
   167     __ASSERT_ALWAYS( aNumOfEncodings <= iEncodings.Count(), 
       
   168         User::Leave( KErrArgument ) );
       
   169         
       
   170     TInt redHeadersSize( aRedBlockCount * KRedHeaderSize + KFinalHeaderSize );
       
   171     iMaxPayloadSize 
       
   172         = ( aRedBlockCount + 1 ) * ( aMaxPayloadSize ) + redHeadersSize;
       
   173             
       
   174     // Reserve space for RTP payload, which includes redundancy
       
   175     delete iRTPPayload;
       
   176     iRTPPayload = NULL;
       
   177     iRTPPayload = CMMFDataBuffer::NewL( iMaxPayloadSize );
       
   178     DP_RED_ENCODE2( "Redundancy payload MAX size: %d", iMaxPayloadSize )
       
   179     
       
   180     // Reserve memory for payload for number of encodings used
       
   181     TUint encBufSize( aMaxPayloadSize * ( aRedBlockCount + 1 ) );
       
   182     for ( TInt i = 0; i < aNumOfEncodings; i++ )
       
   183         {
       
   184         if ( iEncodings[i] )
       
   185             {
       
   186             if ( iEncodings[i]->BufferSize() < encBufSize )
       
   187                 {
       
   188                 delete iEncodings[i];
       
   189                 iEncodings[i] = NULL;
       
   190                 iEncodings[i] = CMMFDataBuffer::NewL( encBufSize );
       
   191                 }
       
   192             }
       
   193         else
       
   194             {
       
   195             iEncodings[i] = CMMFDataBuffer::NewL( encBufSize );
       
   196             }            
       
   197         }
       
   198 
       
   199     return DoInitializeL( aRedBlockCount, aMaxPayloadSize, aNumOfEncodings );
       
   200     }
       
   201 
       
   202 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   203 
       
   204 
       
   205 //  End of File