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