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