|
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 "MMFpcmU8ToPcm16HwDevice.h" |
|
17 |
|
18 /** |
|
19 * |
|
20 * Returns the created hw device for unsigned pcm8 to signed pcm16 audio. |
|
21 * |
|
22 * @return "CMMFPcmU8ToPcm16HwDevice" |
|
23 * |
|
24 */ |
|
25 CMMFPcmU8ToPcm16HwDevice* CMMFPcmU8ToPcm16HwDevice::NewL() |
|
26 { |
|
27 CMMFPcmU8ToPcm16HwDevice* self = new (ELeave) CMMFPcmU8ToPcm16HwDevice(); |
|
28 CleanupStack::PushL(self); |
|
29 self->ConstructL(); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 /** |
|
35 * |
|
36 * Second phase constructor. |
|
37 * |
|
38 */ |
|
39 void CMMFPcmU8ToPcm16HwDevice::ConstructL() |
|
40 { |
|
41 iCodec = new (ELeave) CMMFPcmU8ToPcm16Codec(); |
|
42 } |
|
43 |
|
44 /** |
|
45 * |
|
46 * ~CMMFPcmU8ToPcm16HwDevice |
|
47 * |
|
48 */ |
|
49 CMMFPcmU8ToPcm16HwDevice::~CMMFPcmU8ToPcm16HwDevice() |
|
50 { |
|
51 //The codec is deleted in the base class CMMFSwCodecWrapper |
|
52 } |
|
53 |
|
54 /** |
|
55 * |
|
56 * Codec |
|
57 * @return 'CMMFSwCodec&' |
|
58 * |
|
59 */ |
|
60 CMMFSwCodec& CMMFPcmU8ToPcm16HwDevice::Codec() |
|
61 { |
|
62 return *iCodec; |
|
63 } |
|
64 |
|
65 /** |
|
66 * |
|
67 * ProcessL |
|
68 * @param aSource |
|
69 * @param aDst |
|
70 * @return 'CMMFSwCodec::TCodecProcessResult' |
|
71 * |
|
72 */ |
|
73 CMMFSwCodec::TCodecProcessResult CMMFPcmU8ToPcm16Codec::ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest) |
|
74 { |
|
75 TCodecProcessResult result; |
|
76 result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete; |
|
77 |
|
78 //convert from generic CMMFBuffer to CMMFDataBuffer |
|
79 const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSource); |
|
80 CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDest); |
|
81 |
|
82 //[ check preconditions ] |
|
83 if( !CheckPreconditions( src, dst )) |
|
84 { |
|
85 //[ precondition violation ] |
|
86 User::Leave( KErrArgument ); |
|
87 } |
|
88 |
|
89 //we need to cast away CONST even on the source, as the TClass needs a TUint8* |
|
90 TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr()); |
|
91 TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr()); |
|
92 |
|
93 TInt srcUse = src->Data().Length(); |
|
94 TInt noSamples = srcUse; |
|
95 iAudioU8ToS16Pcm.Convert(pSrc, pDst, noSamples ); |
|
96 |
|
97 TInt dstBytesAdded = srcUse * 2; |
|
98 result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete; |
|
99 result.iSrcBytesProcessed = srcUse; |
|
100 result.iDstBytesAdded = dstBytesAdded; |
|
101 |
|
102 dst->Data().SetLength(dstBytesAdded); |
|
103 |
|
104 //[ check post conditions ] |
|
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() == dst->Data().Length()/2, TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // 2 here signifies sizeof TInt16 |
|
108 __ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // pcm output |
|
109 |
|
110 return result; |
|
111 } |
|
112 |
|
113 /** |
|
114 * |
|
115 * Preconditions |
|
116 * This methos tests the preconditions of the ProcessL method |
|
117 * @return TBool ETrue for sucess and EFalse for failure of the preconditions |
|
118 * |
|
119 **/ |
|
120 TBool CMMFPcmU8ToPcm16Codec::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 { |
|
149 return result; |
|
150 } |
|
151 |
|
152 result = ETrue; // preconditions have been satisfied |
|
153 |
|
154 return result; |
|
155 } |