os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/Gsm610/BtGsm610.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // * INCLUDE FILES:
    15 // 
    16 //
    17 
    18 // Standard includes
    19 #include <e32std.h>
    20 #include <mmfbtswcodecwrapper.h>
    21 
    22 #include <ecom/implementationproxy.h>
    23 #include "BtGsm610.h"
    24 #include "gsm610fr.h"
    25 #include <ecom/ecom.h>
    26 #include <e32def.h>
    27 #include <mmfbthwdeviceimplementationuids.hrh>
    28 #include "../../../MmfBtFileDependencyUtil.h"
    29 
    30 /**
    31 *
    32 * NewL
    33 * @return CMmfGsm610ToPcm16HwDevice*
    34 *
    35 */
    36 CMmfGsm610ToPcm16HwDevice* CMmfGsm610ToPcm16HwDevice::NewL()
    37 	{
    38 	CMmfGsm610ToPcm16HwDevice* self=new(ELeave) CMmfGsm610ToPcm16HwDevice();
    39 	CleanupStack::PushL(self);
    40 	self->ConstructL();
    41 	CleanupStack::Pop(self);
    42 	return self;
    43 	}
    44 
    45 /**
    46 *
    47 * Codec
    48 *
    49 */
    50 CMMFSwCodec& CMmfGsm610ToPcm16HwDevice::Codec()
    51 	{						  
    52 	return *iCodec;
    53 	}
    54 
    55 /**
    56 *
    57 * CMmfGsm610ToPcm16HwDevice
    58 *
    59 */
    60 CMmfGsm610ToPcm16HwDevice::~CMmfGsm610ToPcm16HwDevice()
    61 	{
    62 	}
    63 
    64 
    65 /**
    66 *
    67 * ConstructL
    68 *
    69 */
    70 void CMmfGsm610ToPcm16HwDevice::ConstructL()
    71 	{
    72 	CMMFGsm610ToPcm16Codec* ptr= new(ELeave)CMMFGsm610ToPcm16Codec();
    73 	CleanupStack::PushL(ptr); 
    74 	ptr->ConstructL();
    75 	iCodec = ptr;
    76 	CleanupStack::Pop(ptr);
    77 	}
    78 
    79 /**
    80 *
    81 * CMmfPcm16ToGsm610HwDevice
    82 *
    83 */
    84 CMmfPcm16ToGsm610HwDevice* CMmfPcm16ToGsm610HwDevice::NewL()
    85 	{
    86 	CMmfPcm16ToGsm610HwDevice* self=new(ELeave) CMmfPcm16ToGsm610HwDevice();
    87 	CleanupStack::PushL(self);
    88 	self->ConstructL();
    89 	CleanupStack::Pop(self);
    90 	return self;
    91 	}
    92 
    93 /**
    94 *
    95 * Codec
    96 * @return CMMFSwCodec&
    97 *
    98 */
    99 CMMFSwCodec& CMmfPcm16ToGsm610HwDevice::Codec()
   100 	{
   101 	return *iCodec;
   102 	}
   103 
   104 /**
   105 *
   106 * ~CMmfPcm16ToGsm610HwDevice
   107 *
   108 */
   109 CMmfPcm16ToGsm610HwDevice::~CMmfPcm16ToGsm610HwDevice()
   110 	{
   111 	}
   112 
   113 /**
   114 *
   115 * ConstructL
   116 *
   117 */
   118 void CMmfPcm16ToGsm610HwDevice::ConstructL()
   119 	{
   120 	CMMFPcm16ToGsm610Codec* ptr =new(ELeave) CMMFPcm16ToGsm610Codec();
   121 	CleanupStack::PushL(ptr); 
   122 	ptr->ConstructL();
   123 	iCodec = ptr;
   124 	CleanupStack::Pop(ptr);
   125 	}
   126 
   127 /**
   128 *
   129 * CMMFGsm610ToPcm16Codec
   130 *
   131 */
   132 CMMFGsm610ToPcm16Codec::CMMFGsm610ToPcm16Codec()
   133 	{	
   134 	}
   135 
   136 /**
   137 *
   138 * ConstructL
   139 *
   140 */
   141 void CMMFGsm610ToPcm16Codec::ConstructL()
   142 	{
   143     iGsmDecoder = new (ELeave) CGSM610FR_Decoder;
   144 	iGsmDecoder->ConstructL();
   145 	iGsmDecoder->StartL();
   146 	}
   147 
   148 /**
   149 *
   150 * NewL
   151 *
   152 */
   153 CMMFGsm610ToPcm16Codec*  CMMFGsm610ToPcm16Codec::NewL()
   154 	{
   155 	CMMFGsm610ToPcm16Codec* self=new(ELeave) CMMFGsm610ToPcm16Codec();
   156 	CleanupStack::PushL(self);
   157 	self->ConstructL();
   158 	CleanupStack::Pop(self);
   159 	return self;
   160 	}
   161 
   162 /**
   163 *
   164 * ~CMMFGsm610ToPcm16Codec
   165 *
   166 */
   167 CMMFGsm610ToPcm16Codec::~CMMFGsm610ToPcm16Codec()
   168 	{
   169 	delete iGsmDecoder;
   170 	}
   171 
   172 /**
   173 *
   174 * ProcessL
   175 * @param aSource
   176 * @param aDest
   177 * @pre input buffer length is mod 65
   178 * @pre output buffer has sufficient space for coded input
   179 *
   180 */
   181 CMMFSwCodec::TCodecProcessResult CMMFGsm610ToPcm16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDest)
   182 	{
   183 	CMMFSwCodec::TCodecProcessResult result;
   184 	result.iCodecProcessStatus =	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
   185 
   186 	//convert from generic CMMFBuffer to CMMFDataBuffer
   187 	CMMFBuffer* pSrcBuffer =const_cast<CMMFBuffer*>(&aSrc);
   188 	if( !pSrcBuffer )
   189 		{
   190 		User::Leave( KErrArgument );
   191 		}
   192 
   193 	CMMFDataBuffer* src = static_cast<CMMFDataBuffer*>( pSrcBuffer );
   194     if( !src )
   195 		{
   196 		User::Leave( KErrArgument );
   197 		}
   198 
   199 	CMMFDataBuffer* dst = static_cast<CMMFDataBuffer*>(&aDest);
   200 	if( !dst )
   201 		{
   202 		User::Leave( KErrArgument );
   203 		}
   204 
   205 	if(!CheckInputBuffers( *src, *dst ))
   206 		{
   207 		User::Leave( KErrArgument );
   208 		}
   209 
   210 	TInt numBuffersToProcess = NumBuffersToProcess( *src );
   211 	TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
   212 	TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
   213 	
   214 	for( TInt count = 0; count < numBuffersToProcess; count++ )
   215 		{
   216 		// Encode two frames of gsm data
   217 		iGsmDecoder->ExecuteL( pSrc, pDst );
   218 		pSrc                      += KGsmFrameSize;;
   219 		pDst                      += KPcmDataForGsmFrame;
   220 		result.iSrcBytesProcessed += KGsmFrameSize;
   221 		result.iDstBytesAdded     += KPcmDataForGsmFrame;
   222 		}
   223 
   224     dst->Data().SetLength( result.iDstBytesAdded );
   225 	__ASSERT_DEBUG( ProcessPostCondition( result ), TMmfGsmCodecPanicsNameSpace::Panic( TMmfGsmCodecPanicsNameSpace::EPostConditionViolation ));
   226 	return result;
   227 	}
   228 
   229 /**
   230 *
   231 * CheckInputBuffers
   232 * @param aSrc
   233 * @param aDest
   234 * @return TBool
   235 * This function returns ETrue if the preconditions of processL are met
   236 *
   237 */
   238 TBool CMMFGsm610ToPcm16Codec::CheckInputBuffers( CMMFDataBuffer& aSrc, CMMFDataBuffer& aDest )
   239 	{
   240 	TBool result = ETrue;    
   241     TInt numInputSubFrames     = aSrc.Data().Length() / KGsmFrameSize;
   242 	TInt numOutputSubFrames    = aDest.Data().MaxLength() / KPcmDataForGsmFrame;
   243 	TBool validInputDataLength = (aSrc.Data().Length() % KGsmFrameSize == 0);
   244     
   245 	if( (numInputSubFrames > numOutputSubFrames) ||  // sufficient space in the output for the input
   246         (aSrc.Position() > 0 )  ||                   // position must be zero since we can eat all the data
   247 		(aDest.Position() > 0 ) ||
   248 		(!validInputDataLength))                         //position must be zero
   249 		{
   250 		result = EFalse;
   251 		}
   252 
   253 	return result;
   254 	}
   255 
   256 /**
   257 *
   258 * NumBuffersToProcess
   259 * @param aSrc
   260 * @return TBool
   261 * This method returns the number of buffers to process
   262 *
   263 */
   264 TInt CMMFGsm610ToPcm16Codec::NumBuffersToProcess( const CMMFDataBuffer& aSrc )
   265 	{
   266     TInt numBuffers = (aSrc.Data().Length() / KGsmFrameSize );
   267 	return numBuffers;
   268 	}
   269 
   270 /**
   271 *
   272 * ProcessPostCondition
   273 * @param aResult
   274 * @return TBool Etrue if the post condition is satisfied
   275 *
   276 **/
   277 TBool CMMFGsm610ToPcm16Codec::ProcessPostCondition( const CMMFSwCodec::TCodecProcessResult& aResult )
   278 	{
   279      TBool status = ETrue;
   280 	 if( (aResult.iSrcBytesProcessed / KGsmFrameSize ) != (aResult.iDstBytesAdded / KPcmDataForGsmFrame ) )
   281 		 {
   282 		 status = EFalse;
   283 		 }
   284 	 return status;
   285 	}
   286 
   287 /************************>----------------------------------<*****************************/
   288 
   289 /**
   290 *
   291 * CMMFPcm16ToGsm610Codec
   292 *
   293 */
   294 CMMFPcm16ToGsm610Codec::CMMFPcm16ToGsm610Codec()
   295 	{	
   296 	}
   297 
   298 /**
   299 *
   300 * ConstructL
   301 *
   302 */
   303 void CMMFPcm16ToGsm610Codec::ConstructL()
   304 	{
   305 	iGsmEncoder = new (ELeave) CGSM610FR_Encoder;
   306 	iGsmEncoder->ConstructL();
   307 	iGsmEncoder->StartL();
   308 	}
   309 
   310 /**
   311 *
   312 * NewL
   313 *
   314 */
   315 CMMFPcm16ToGsm610Codec* CMMFPcm16ToGsm610Codec::NewL()
   316 	{
   317 	CMMFPcm16ToGsm610Codec* self=new(ELeave) CMMFPcm16ToGsm610Codec();
   318 	CleanupStack::PushL(self);
   319 	self->ConstructL();
   320 	CleanupStack::Pop(self);
   321 	return self;
   322 	}
   323 
   324 /**
   325 *
   326 * CMMFPcm16ToGsm610Codec
   327 *
   328 */
   329 CMMFPcm16ToGsm610Codec::~CMMFPcm16ToGsm610Codec()
   330 	{
   331 	delete iGsmEncoder;
   332 	}
   333 
   334 /**
   335 *
   336 * ProcessL
   337 * @param aSource
   338 * @param aDest TCodecProcessResult
   339 * @return
   340 * @pre input buffer length is mod 320
   341 * @pre output buffer has sufficient space for coded input
   342 */
   343 CMMFSwCodec::TCodecProcessResult CMMFPcm16ToGsm610Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDest)
   344 	{
   345 	CMMFSwCodec::TCodecProcessResult result;
   346 	result.iCodecProcessStatus = 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
   347 
   348 	//convert from generic CMMFBuffer to CMMFDataBuffer
   349 	CMMFBuffer* pSrcBuffer =const_cast<CMMFBuffer*>(&aSrc);
   350 	if( !pSrcBuffer )
   351 		{
   352 		User::Leave( KErrArgument );
   353 		}
   354 
   355 	CMMFDataBuffer* src = static_cast<CMMFDataBuffer*>( pSrcBuffer );
   356     if( !src )
   357 		{
   358 		User::Leave( KErrArgument );
   359 		}
   360 
   361 	CMMFDataBuffer* dst = static_cast<CMMFDataBuffer*>(&aDest);
   362 	if( !dst )
   363 		{
   364 		User::Leave( KErrArgument );
   365 		}
   366 
   367 
   368 	if(!CheckInputBuffers( *src, *dst ))
   369 		{
   370 		User::Leave( KErrArgument );
   371 		}
   372 
   373 	TInt numBuffersToProcess = NumBuffersToProcess( *src );
   374 	TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
   375 	TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
   376 	
   377 	for( TInt count = 0; count < numBuffersToProcess; count++ )
   378 		{
   379 		// Encode two frames of gsm data
   380 		iGsmEncoder->ExecuteL (pSrc, pDst);
   381 		pSrc                      += KPcmDataForGsmFrame;
   382 		pDst                      += KGsmFrameSize;
   383 		result.iSrcBytesProcessed += KPcmDataForGsmFrame;
   384 		result.iDstBytesAdded     += KGsmFrameSize;
   385 		}
   386 
   387     dst->Data().SetLength( result.iDstBytesAdded ); 
   388 
   389 	__ASSERT_DEBUG( ProcessPostCondition(result), TMmfGsmCodecPanicsNameSpace::Panic( TMmfGsmCodecPanicsNameSpace::EPostConditionViolation ));
   390 
   391     return result ;
   392 	}
   393 
   394 /**
   395 *
   396 * CheckInputBuffers
   397 * @param aSrc
   398 * @param aDest
   399 * @return TBool
   400 * This function returns ETrue if there is sufficient space
   401 * in the output buffer for the coded input and
   402 * the position of both input buffers is zero
   403 *
   404 */
   405 TBool CMMFPcm16ToGsm610Codec::CheckInputBuffers( CMMFDataBuffer& aSrc, CMMFDataBuffer& aDest )
   406 	{
   407 	TBool result = ETrue;    
   408     TInt numInputSubFrames     = aSrc.Data().Length() / KPcmDataForGsmFrame;
   409 	TInt numOutputSubFrames    = aDest.Data().MaxLength() / KGsmFrameSize;
   410 	TBool validInputDataLength = (aSrc.Data().Length() % KPcmDataForGsmFrame == 0);
   411     
   412 	if( (numInputSubFrames > numOutputSubFrames) ||  // sufficient space in the output for the input
   413         (aSrc.Position() > 0 )  ||                   // position must be zero since we can eat all the data
   414 		(aDest.Position() > 0 ) ||
   415 		(!validInputDataLength))                         //position must be zero
   416 		{
   417 		result = EFalse;
   418 		}
   419 
   420 	return result;
   421 	}
   422 
   423 /**
   424 *
   425 * NumBuffersToProcess
   426 * @param aSrc
   427 * @return TBool
   428 * This method returns the number of buffers to process
   429 *
   430 */
   431 TInt CMMFPcm16ToGsm610Codec::NumBuffersToProcess( const CMMFDataBuffer& aSrc )
   432 	{
   433 	TInt numBuffers = ( aSrc.Data().Length() / KPcmDataForGsmFrame );
   434 	return numBuffers;
   435 	}
   436