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