|
1 // Copyright (c) 2005-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 // MmfBtMulawToPcm16HwDevice.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include "MmfBtAudioCodec.h" |
|
19 #include <mmfpaniccodes.h> |
|
20 #include "MmfBtPcm16SwapEndianHwDevice.h" |
|
21 #include "../../MmfBtFileDependencyUtil.h" |
|
22 |
|
23 /** |
|
24 * |
|
25 * NewL |
|
26 * @return 'CMMFPcm16SwapEndianHwDevice*' |
|
27 * |
|
28 */ |
|
29 CMMFPcm16SwapEndianHwDevice* CMMFPcm16SwapEndianHwDevice::NewL() |
|
30 { |
|
31 CMMFPcm16SwapEndianHwDevice* self=new(ELeave) CMMFPcm16SwapEndianHwDevice(); |
|
32 CleanupStack::PushL(self); |
|
33 self->ConstructL(); |
|
34 CleanupStack::Pop(self); |
|
35 return self; |
|
36 } |
|
37 |
|
38 /** |
|
39 * |
|
40 * ~CMMFPcm16SwapEndianHwDevice |
|
41 */ |
|
42 CMMFPcm16SwapEndianHwDevice::~CMMFPcm16SwapEndianHwDevice() |
|
43 { |
|
44 } |
|
45 |
|
46 /** |
|
47 * |
|
48 * ConstructL |
|
49 * |
|
50 */ |
|
51 void CMMFPcm16SwapEndianHwDevice::ConstructL() |
|
52 { |
|
53 iCodec = new (ELeave)CMMFPcm16SwapEndianCodec(); |
|
54 } |
|
55 |
|
56 /** |
|
57 * |
|
58 * Codec |
|
59 * |
|
60 */ |
|
61 CMMFSwCodec &CMMFPcm16SwapEndianHwDevice::Codec() |
|
62 { |
|
63 return *iCodec; |
|
64 } |
|
65 |
|
66 /** |
|
67 * |
|
68 * ProcessL |
|
69 * @param aSrc |
|
70 * @param aDst |
|
71 * @return 'CMMFSwCodec::TCodecProcessResult' |
|
72 * |
|
73 */ |
|
74 CMMFSwCodec::TCodecProcessResult CMMFPcm16SwapEndianCodec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst) |
|
75 { |
|
76 CMMFSwCodec::TCodecProcessResult result; |
|
77 result.iCodecProcessStatus = result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete; |
|
78 |
|
79 //convert from generic CMMFBuffer to CMMFDataBuffer |
|
80 const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSrc); |
|
81 CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst); |
|
82 |
|
83 //[ check the preconditions ] |
|
84 if( !CheckPreconditions( src, dst )) |
|
85 { |
|
86 //[ precondition violation ] |
|
87 User::Leave( KErrArgument ); |
|
88 } |
|
89 |
|
90 TInt srcUse = src->Data().Length(); |
|
91 |
|
92 //we need to cast away CONST even on the source, as the TClass needs a TUint8* |
|
93 TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr()); |
|
94 TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr()); |
|
95 |
|
96 TInt noSamples = srcUse / 2; //divide by TWO as 2 bytes are equal to 1 sample |
|
97 iPcm16EndianSwap.Convert(pSrc, pDst, noSamples ); |
|
98 |
|
99 result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete; |
|
100 result.iSrcBytesProcessed = srcUse; |
|
101 result.iDstBytesAdded = srcUse; |
|
102 |
|
103 dst->Data().SetLength(srcUse); |
|
104 |
|
105 //[ check post conditions ] |
|
106 __ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); |
|
107 __ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); |
|
108 __ASSERT_DEBUG( src->Data().Length() == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); |
|
109 __ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // pcm output |
|
110 |
|
111 return result; |
|
112 } |
|
113 |
|
114 /** |
|
115 * |
|
116 * Preconditions |
|
117 * This methos tests the preconditions of the ProcessL method |
|
118 * @return TBool ETrue for sucess and EFalse for failure of the preconditions |
|
119 * |
|
120 **/ |
|
121 TBool CMMFPcm16SwapEndianCodec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer ) |
|
122 { |
|
123 TBool result = EFalse; |
|
124 |
|
125 if(! aSrcBuffer ) |
|
126 { |
|
127 return result; |
|
128 } |
|
129 |
|
130 if( ! aDestBuffer ) |
|
131 { |
|
132 return result; |
|
133 } |
|
134 |
|
135 // Check position of src and dest are 0 |
|
136 if( aSrcBuffer->Position() ) |
|
137 { |
|
138 return result; |
|
139 } |
|
140 |
|
141 // Check position of src and dest are 0 |
|
142 if( aDestBuffer->Position() ) |
|
143 { |
|
144 return result; |
|
145 } |
|
146 |
|
147 // check there are sufficient bytes in the output to consume the input |
|
148 if( ( aSrcBuffer->Data().Length() > aDestBuffer->Data().MaxLength() ) || |
|
149 ( aSrcBuffer->Data().Length() % 2 != 0 )) |
|
150 { |
|
151 return result; |
|
152 } |
|
153 |
|
154 result = ETrue; // preconditions have been satisfied |
|
155 |
|
156 return result; |
|
157 } |