sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1997-2002 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "MMFImaAdStereoPcmToPcm16Codec.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
|
sl@0
|
23 |
// __________________________________________________________________________
|
sl@0
|
24 |
// Implementation
|
sl@0
|
25 |
|
sl@0
|
26 |
CMMFCodec* CMMFImaAdStereoPcmPcm16Codec::NewL(TAny* aInitParams)
|
sl@0
|
27 |
{
|
sl@0
|
28 |
CMMFImaAdStereoPcmPcm16Codec* self=new(ELeave) CMMFImaAdStereoPcmPcm16Codec();
|
sl@0
|
29 |
CleanupStack::PushL(self);
|
sl@0
|
30 |
self->ConstructL(aInitParams);
|
sl@0
|
31 |
CleanupStack::Pop(self);
|
sl@0
|
32 |
return STATIC_CAST( CMMFCodec*, self );
|
sl@0
|
33 |
}
|
sl@0
|
34 |
|
sl@0
|
35 |
CMMFImaAdStereoPcmPcm16Codec::~CMMFImaAdStereoPcmPcm16Codec()
|
sl@0
|
36 |
{
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
CMMFImaAdStereoPcmPcm16Codec::CMMFImaAdStereoPcmPcm16Codec() : iImaAdpcmTo16Pcm(2)
|
sl@0
|
40 |
{
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
void CMMFImaAdStereoPcmPcm16Codec::ConstructL(TAny* /*aInitParams*/)
|
sl@0
|
44 |
{
|
sl@0
|
45 |
iTempSrcBufferPtr = iTempSrcBuffer;
|
sl@0
|
46 |
iTempSrcBufferCount = 0;
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
/*************************************************************
|
sl@0
|
50 |
CMMFImaAdStereoPcmPcm16Codec::ProcessL
|
sl@0
|
51 |
|
sl@0
|
52 |
This function converts IMA ADPCM stereo samples to PCM samples
|
sl@0
|
53 |
in blocks of KImaAdpcmBlockAlign (256) bytes. 256
|
sl@0
|
54 |
source bytes are required to fill a 996 byte block.
|
sl@0
|
55 |
**************************************************************/
|
sl@0
|
56 |
TCodecProcessResult CMMFImaAdStereoPcmPcm16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
TCodecProcessResult result;
|
sl@0
|
59 |
result.iStatus = TCodecProcessResult::EProcessIncomplete;
|
sl@0
|
60 |
|
sl@0
|
61 |
//convert from generic CMMFBuffer to CMMFDataBuffer
|
sl@0
|
62 |
iSrc = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
|
sl@0
|
63 |
iDst = STATIC_CAST(CMMFDataBuffer*, &aDst);
|
sl@0
|
64 |
|
sl@0
|
65 |
const TUint srcLen = iSrc->Data().Length();
|
sl@0
|
66 |
const TUint dstMaxLen = iDst->Data().MaxLength();
|
sl@0
|
67 |
const TUint sourceRemain = srcLen - iSrc->Position();
|
sl@0
|
68 |
|
sl@0
|
69 |
if (dstMaxLen < (KImaAdpcmStereoSamplesPerBlock*4))
|
sl@0
|
70 |
User::Leave(KErrArgument);
|
sl@0
|
71 |
|
sl@0
|
72 |
//reset data if not a consecutive frame number
|
sl@0
|
73 |
if ((iSrc->FrameNumber() != iLastFrameNumber) && (iSrc->FrameNumber() != (iLastFrameNumber+1)))
|
sl@0
|
74 |
{
|
sl@0
|
75 |
iTempSrcBufferPtr = iTempSrcBuffer;
|
sl@0
|
76 |
iTempSrcBufferCount = 0;
|
sl@0
|
77 |
}
|
sl@0
|
78 |
iLastFrameNumber = iSrc->FrameNumber();
|
sl@0
|
79 |
|
sl@0
|
80 |
TUint dstRemain = (dstMaxLen - iDst->Position());
|
sl@0
|
81 |
TUint srcToFillTempBuffer = 0;
|
sl@0
|
82 |
|
sl@0
|
83 |
//take account of src to be added to temporary buffer
|
sl@0
|
84 |
if (iTempSrcBufferCount > 0)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
srcToFillTempBuffer = KImaAdpcmBlockAlign - iTempSrcBufferCount;
|
sl@0
|
87 |
|
sl@0
|
88 |
if (srcToFillTempBuffer<sourceRemain) //enough source to fill temporary buffer
|
sl@0
|
89 |
dstRemain -= (KImaAdpcmStereoSamplesPerBlock*4);
|
sl@0
|
90 |
else //not enough source to fill the temporary buffer
|
sl@0
|
91 |
srcToFillTempBuffer = sourceRemain;
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
//calculate how much source is required to fill the destination buffer
|
sl@0
|
95 |
TUint blocksRemaining = dstRemain/(KImaAdpcmStereoSamplesPerBlock*4);
|
sl@0
|
96 |
TUint maxUsableDst = blocksRemaining * KImaAdpcmSamplesPerBlock * 4;
|
sl@0
|
97 |
TUint srcToUse = blocksRemaining * KImaAdpcmBlockAlign;
|
sl@0
|
98 |
|
sl@0
|
99 |
srcToUse += srcToFillTempBuffer;
|
sl@0
|
100 |
srcToUse = (srcToUse<sourceRemain ? srcToUse : sourceRemain);
|
sl@0
|
101 |
|
sl@0
|
102 |
//we need to cast away CONST even on the source, as the TClass needs a TUint8*
|
sl@0
|
103 |
TUint8* pSrc = CONST_CAST(TUint8*,iSrc->Data().Ptr());
|
sl@0
|
104 |
pSrc += iSrc->Position();
|
sl@0
|
105 |
TUint8* pDst = CONST_CAST(TUint8*,iDst->Data().Ptr());
|
sl@0
|
106 |
pDst += iDst->Position();
|
sl@0
|
107 |
|
sl@0
|
108 |
TUint dstBytesAdded = 0;
|
sl@0
|
109 |
TUint srcLeft = srcToUse;
|
sl@0
|
110 |
|
sl@0
|
111 |
//convert remaining source from previous call to ProcessL
|
sl@0
|
112 |
if (iTempSrcBufferCount > 0)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
//Fill temp buffer from source buffer
|
sl@0
|
115 |
while((iTempSrcBufferCount < KImaAdpcmBlockAlign) && (srcLeft))
|
sl@0
|
116 |
{
|
sl@0
|
117 |
*iTempSrcBufferPtr++ = *pSrc++;
|
sl@0
|
118 |
iTempSrcBufferCount++;
|
sl@0
|
119 |
srcLeft--;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
if(iTempSrcBufferCount == KImaAdpcmBlockAlign)
|
sl@0
|
123 |
{
|
sl@0
|
124 |
//reset
|
sl@0
|
125 |
iTempSrcBufferCount = 0;
|
sl@0
|
126 |
iTempSrcBufferPtr = iTempSrcBuffer;
|
sl@0
|
127 |
|
sl@0
|
128 |
iImaAdpcmTo16Pcm.Convert(iTempSrcBufferPtr, pDst, KImaAdpcmStereoSamplesPerBlock);
|
sl@0
|
129 |
|
sl@0
|
130 |
pDst += (KImaAdpcmStereoSamplesPerBlock*4);
|
sl@0
|
131 |
dstBytesAdded += (KImaAdpcmStereoSamplesPerBlock*4);
|
sl@0
|
132 |
}
|
sl@0
|
133 |
}
|
sl@0
|
134 |
|
sl@0
|
135 |
//convert full blocks
|
sl@0
|
136 |
while (srcLeft >= KImaAdpcmBlockAlign)
|
sl@0
|
137 |
{
|
sl@0
|
138 |
iImaAdpcmTo16Pcm.Convert(pSrc, pDst, KImaAdpcmStereoSamplesPerBlock);
|
sl@0
|
139 |
|
sl@0
|
140 |
pSrc += KImaAdpcmBlockAlign;
|
sl@0
|
141 |
pDst += (KImaAdpcmStereoSamplesPerBlock*4);
|
sl@0
|
142 |
|
sl@0
|
143 |
dstBytesAdded += (KImaAdpcmStereoSamplesPerBlock*4);
|
sl@0
|
144 |
srcLeft -= KImaAdpcmBlockAlign;
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
while (srcLeft)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
*iTempSrcBufferPtr++ = *pSrc++;
|
sl@0
|
150 |
iTempSrcBufferCount++;
|
sl@0
|
151 |
srcLeft--;
|
sl@0
|
152 |
}
|
sl@0
|
153 |
|
sl@0
|
154 |
//if the source buffer is consumed
|
sl@0
|
155 |
if ((srcLen == srcToUse + iSrc->Position()))
|
sl@0
|
156 |
{
|
sl@0
|
157 |
if (dstBytesAdded < maxUsableDst)
|
sl@0
|
158 |
result.iStatus = TCodecProcessResult::EDstNotFilled;
|
sl@0
|
159 |
else
|
sl@0
|
160 |
result.iStatus = TCodecProcessResult::EProcessComplete;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
result.iSrcBytesProcessed = srcToUse;
|
sl@0
|
164 |
result.iDstBytesAdded = dstBytesAdded;
|
sl@0
|
165 |
|
sl@0
|
166 |
iDst->Data().SetLength( iDst->Position() + result.iDstBytesAdded);
|
sl@0
|
167 |
|
sl@0
|
168 |
return result;
|
sl@0
|
169 |
}
|