|
1 // Copyright (c) 1997-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 // |
|
15 |
|
16 #include "MMFPcm16ToMuLawCodec.h" |
|
17 |
|
18 |
|
19 // __________________________________________________________________________ |
|
20 // Implementation |
|
21 |
|
22 CMMFCodec* CMMFPcm16MulawCodec::NewL(TAny* aInitParams) |
|
23 { |
|
24 CMMFPcm16MulawCodec* self=new(ELeave) CMMFPcm16MulawCodec(); |
|
25 CleanupStack::PushL(self); |
|
26 self->ConstructL(aInitParams); |
|
27 CleanupStack::Pop(self); |
|
28 return STATIC_CAST( CMMFCodec*, self ); |
|
29 } |
|
30 |
|
31 CMMFPcm16MulawCodec::~CMMFPcm16MulawCodec() |
|
32 { |
|
33 } |
|
34 |
|
35 CMMFPcm16MulawCodec::CMMFPcm16MulawCodec() |
|
36 { |
|
37 } |
|
38 |
|
39 void CMMFPcm16MulawCodec::ConstructL(TAny* /*aInitParams*/) |
|
40 { |
|
41 } |
|
42 |
|
43 |
|
44 //this codec converts 2 bytes into 1 |
|
45 TCodecProcessResult CMMFPcm16MulawCodec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst) |
|
46 { |
|
47 |
|
48 TCodecProcessResult result; |
|
49 result.iStatus = TCodecProcessResult::EProcessIncomplete; |
|
50 |
|
51 //convert from generic CMMFBuffer to CMMFDataBuffer |
|
52 iSrc = STATIC_CAST(const CMMFDataBuffer*, &aSrc); |
|
53 iDst = STATIC_CAST(CMMFDataBuffer*, &aDst); |
|
54 |
|
55 const TUint dstMaxLen = iDst->Data().MaxLength(); |
|
56 |
|
57 if (!dstMaxLen) |
|
58 User::Leave(KErrArgument); |
|
59 |
|
60 //don't scribble Destination (pDst) by only consuming enough source to fill pDst |
|
61 TUint srcUse = (dstMaxLen - iDst->Position()) * 2; |
|
62 const TUint srcLen = iSrc->Data().Length(); |
|
63 const TUint sourceRemain = srcLen - iSrc->Position(); |
|
64 |
|
65 //make sure we don't blow source by checking against remaining |
|
66 //and clipping to minimum remaining if necessary |
|
67 srcUse = (srcUse<sourceRemain ? srcUse : sourceRemain); |
|
68 |
|
69 //we need to cast away CONST even on the source, as the TClass needs a TUint8* |
|
70 TUint8* pSrc = CONST_CAST(TUint8*,iSrc->Data().Ptr()); |
|
71 pSrc += iSrc->Position(); |
|
72 TUint8* pDst = CONST_CAST(TUint8*,iDst->Data().Ptr()); |
|
73 pDst += iDst->Position(); |
|
74 |
|
75 //compress TWO bytes (16-bit PCM word) into a to 1 byte sample |
|
76 i16PcmToMulaw.Convert(pSrc, pDst, srcUse / 2); |
|
77 |
|
78 TUint dstBytesAdded = srcUse / 2; |
|
79 |
|
80 if (dstBytesAdded + iDst->Position() < dstMaxLen) |
|
81 result.iStatus = TCodecProcessResult::EDstNotFilled; |
|
82 |
|
83 else if (srcUse + iSrc->Position() >= srcLen) |
|
84 result.iStatus = TCodecProcessResult::EProcessComplete; |
|
85 |
|
86 result.iSrcBytesProcessed = srcUse; |
|
87 result.iDstBytesAdded = dstBytesAdded; |
|
88 |
|
89 iDst->Data().SetLength(iDst->Position() + result.iDstBytesAdded); |
|
90 |
|
91 return result; |
|
92 |
|
93 } |