|
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 "MmfBtPcm16ToAlawHwDevice.h" |
|
17 #include "../../MmfBtFileDependencyUtil.h" |
|
18 |
|
19 /** |
|
20 * |
|
21 * NewL |
|
22 * |
|
23 */ |
|
24 CMMFPcm16ToAlawHwDevice* CMMFPcm16ToAlawHwDevice::NewL() |
|
25 { |
|
26 CMMFPcm16ToAlawHwDevice* self=new(ELeave) CMMFPcm16ToAlawHwDevice(); |
|
27 CleanupStack::PushL(self); |
|
28 self->ConstructL(); |
|
29 CleanupStack::Pop(self); |
|
30 return self; |
|
31 } |
|
32 |
|
33 /** |
|
34 * |
|
35 * ~CMMFPcm16ToAlawHwDevice |
|
36 * |
|
37 */ |
|
38 CMMFPcm16ToAlawHwDevice::~CMMFPcm16ToAlawHwDevice() |
|
39 { |
|
40 } |
|
41 |
|
42 /** |
|
43 * |
|
44 * ConstructL |
|
45 * |
|
46 */ |
|
47 void CMMFPcm16ToAlawHwDevice::ConstructL() |
|
48 { |
|
49 iCodec = new (ELeave) CMMFPcm16ToALawCodec(); |
|
50 } |
|
51 |
|
52 |
|
53 /** |
|
54 * |
|
55 * Codec |
|
56 * |
|
57 */ |
|
58 CMMFSwCodec &CMMFPcm16ToAlawHwDevice::Codec() |
|
59 { |
|
60 return *iCodec; |
|
61 } |
|
62 |
|
63 /** |
|
64 * |
|
65 * ProcessL |
|
66 * @param aSrc |
|
67 * @param aDst |
|
68 * @pre position of buffer aSrc is 0 |
|
69 * @pre position of buffer aDst is 0 |
|
70 * @pre sufficient bytes in output to consume input |
|
71 * @return TCodecProcessResult |
|
72 * |
|
73 */ |
|
74 CMMFSwCodec::TCodecProcessResult CMMFPcm16ToALawCodec::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 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 pSrc += src->Position(); |
|
92 TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr()); |
|
93 pDst += dst->Position(); |
|
94 |
|
95 TUint destUse = src->Data().Length()/2; |
|
96 |
|
97 //compress TWO bytes (16-bit PCM word) into a to 1 byte sample |
|
98 iPcm16ToALaw.Convert(pSrc, pDst, destUse ); |
|
99 |
|
100 result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete; |
|
101 result.iSrcBytesProcessed = src->Data().Length(); |
|
102 result.iDstBytesAdded = destUse; |
|
103 |
|
104 dst->Data().SetLength(result.iDstBytesAdded); |
|
105 |
|
106 //[ post condition evaluation here ] |
|
107 __ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); |
|
108 __ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); |
|
109 __ASSERT_DEBUG( src->Data().Length()/2 == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); |
|
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 CMMFPcm16ToALawCodec::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()/2 > 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 } |