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