|
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 "mmfpcmS16PcmS8HwDevice.h" |
|
17 |
|
18 /** |
|
19 * |
|
20 * Returns the created hw device for passing audio through audio. |
|
21 * for the wins implementation this would always be pcm16 although |
|
22 * this is effectively a null hw device that will pass any datatype through |
|
23 * @return "CMMFPcm16ToPcmU16BEHwDevice" |
|
24 * |
|
25 */ |
|
26 CMMFPcmS16ToPcmS8HwDevice* CMMFPcmS16ToPcmS8HwDevice::NewL() |
|
27 { |
|
28 CMMFPcmS16ToPcmS8HwDevice* self = new (ELeave) CMMFPcmS16ToPcmS8HwDevice(); |
|
29 CleanupStack::PushL(self); |
|
30 self->ConstructL(); |
|
31 CleanupStack::Pop(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 /** |
|
36 * |
|
37 * ~CMMFPcmS16ToPcmS8HwDevice |
|
38 */ |
|
39 CMMFPcmS16ToPcmS8HwDevice::~CMMFPcmS16ToPcmS8HwDevice() |
|
40 { |
|
41 } |
|
42 |
|
43 /** |
|
44 * |
|
45 * ConstructL |
|
46 * |
|
47 */ |
|
48 void CMMFPcmS16ToPcmS8HwDevice::ConstructL() |
|
49 { |
|
50 iCodec = new (ELeave) CMMFPcmS16ToPcmS8Codec(); |
|
51 } |
|
52 |
|
53 /** |
|
54 * |
|
55 * Codec |
|
56 * @return 'CMMFSwCodec&' |
|
57 * |
|
58 */ |
|
59 CMMFSwCodec& CMMFPcmS16ToPcmS8HwDevice::Codec() |
|
60 { |
|
61 return *iCodec; |
|
62 } |
|
63 |
|
64 /** |
|
65 * |
|
66 * ProcessL |
|
67 * @param aSrc |
|
68 * @param aDst |
|
69 * @param aSamples |
|
70 * |
|
71 */ |
|
72 CMMFSwCodec::TCodecProcessResult CMMFPcmS16ToPcmS8Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst) |
|
73 { |
|
74 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 //[Check Preconditions] |
|
82 if( !CheckPreconditions( src, dst )) |
|
83 { |
|
84 //[ precondition violation ] |
|
85 User::Leave( KErrArgument ); |
|
86 } |
|
87 |
|
88 //we need to cast away CONST even on the source, as the TClass needs a TUint8* |
|
89 TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr()); |
|
90 TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr()); |
|
91 |
|
92 TInt srcUse = src->Data().Length(); |
|
93 TInt noSamples = srcUse/2; |
|
94 |
|
95 //compress TWO bytes (16-bit PCM word) into a to 1 byte sample |
|
96 iAudioPcmS16ToPcmS8.Convert(pSrc, pDst, noSamples ); |
|
97 |
|
98 result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete; |
|
99 result.iSrcBytesProcessed = srcUse; |
|
100 result.iDstBytesAdded = srcUse/2; |
|
101 |
|
102 dst->Data().SetLength(result.iDstBytesAdded); |
|
103 |
|
104 //[ post conditions |
|
105 // srcbytes/2 == destbytes added |
|
106 // pos src == 0 |
|
107 // pos dest == 0 ] |
|
108 __ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); |
|
109 __ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); |
|
110 __ASSERT_DEBUG( src->Data().Length()/2 == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); |
|
111 |
|
112 return result; |
|
113 } |
|
114 |
|
115 /** |
|
116 * |
|
117 * Preconditions |
|
118 * This methos tests the preconditions of the ProcessL method |
|
119 * @return TBool ETrue for sucess and EFalse for failure of the preconditions |
|
120 * |
|
121 **/ |
|
122 TBool CMMFPcmS16ToPcmS8Codec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer ) |
|
123 { |
|
124 TBool result = EFalse; |
|
125 |
|
126 if(! aSrcBuffer ) |
|
127 { |
|
128 return result; |
|
129 } |
|
130 |
|
131 if( ! aDestBuffer ) |
|
132 { |
|
133 return result; |
|
134 } |
|
135 |
|
136 // Check position of src and dest are 0 |
|
137 if( aSrcBuffer->Position() ) |
|
138 { |
|
139 return result; |
|
140 } |
|
141 |
|
142 // Check position of src and dest are 0 |
|
143 if( aDestBuffer->Position() ) |
|
144 { |
|
145 return result; |
|
146 } |
|
147 |
|
148 // check there are sufficient bytes in the output to consume the input |
|
149 if( ( aSrcBuffer->Data().Length()/2 > aDestBuffer->Data().MaxLength() ) && |
|
150 ( aSrcBuffer->Data().Length() % 2 == 0 ) ) // must have pcm16 samples on input |
|
151 { |
|
152 return result; |
|
153 } |
|
154 |
|
155 result = ETrue; // preconditions have been satisfied |
|
156 |
|
157 return result; |
|
158 } |
|
159 |