How to Pack and Unpack the AMR Encoded Data

How to Pack the AMR Encoded Data

The user gets the AMR encoded data in aAmrData. It then attaches the AMR payload header to it and returns the packed data in aPackedData. The following code describes the CStreamFormatter::Pack() function.

// Call the Pack function
TInt Pack(const TDesC8& aAmrData,RBuf8& aPackedData)

It is the responsibility of the user to free the memory allocated to aPackedData descriptor. The following return values are returned by the function, depending on the availability of memory:

  • KErrNone if successful

  • KErrArgument if an argument is out of range

  • KErrNoMemory if there is insufficient memory.

The following code shows how to use the CStreamFormatter::Pack() API:

 // Create an instance of AMR Payload Formatter by passing KAmrFormatterUid
CStreamFormatter * aStreamFormatter =  CStreamFormatter::NewL(TUid::Uid(KAmrFormatterUid)); 
// Call the pack function 
TInt8 ret = aStreamFormatter->Pack(pPacket,modifiableBuf);

How to Unpack the AMR Encoded Data

The user gets the AMR encoded data in aAmrData. It then detaches AMR payload header from it and returns the actual encoded AMR data in aUnPackedData. The following code describes the CStreamFormatter::Unpack function.

// Call the Unpack function 
TInt Unpack(const TDesC8& aAmrData,RBuf8& aUnPackedData)

It is the responsibility of the user to free the memory allocated to aUnPackedData descriptor. The following return values are returned by the function, depending on the availability of memory:

  • KErrNone if successful

  • KErrArgument if an argument is out of range

  • KErrNoMemory if there is insufficient memory.

The following code shows how to use the CStreamFormatter::Unpack() API:

// Create an instance of AMR Payload Formatter by passing KAmrFormatterUid
CStreamFormatter * aStreamFormatter =  CStreamFormatter::NewL(TUid::Uid(KAmrFormatterUid)); 
//Call the Unpack function 
TInt8 ret = aStreamFormatter->UnPack(pPacket,modifiableBuf);