sl@0
|
1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <fbs.h>
|
sl@0
|
17 |
#include <mmf/server/mmfdatabuffer.h>
|
sl@0
|
18 |
#include "mdfvideodecoderbuffermanager.h"
|
sl@0
|
19 |
|
sl@0
|
20 |
#define MDFVIDEODECODERBUFFERMANAGER_DEBUG 1
|
sl@0
|
21 |
|
sl@0
|
22 |
#if defined (SYMBIAN_MDFVIDEODECODERBUFFERMANAGER_DEBUG)
|
sl@0
|
23 |
#define DEBUG_PRINT( x ) ( RDebug::Print( x ) )
|
sl@0
|
24 |
#define DEBUG_PRINT2( x,y ) ( RDebug::Print( x,y ) )
|
sl@0
|
25 |
#define DEBUG_PRINT3( x,y,z ) ( RDebug::Print( x,y,z ) )
|
sl@0
|
26 |
|
sl@0
|
27 |
#else
|
sl@0
|
28 |
#define DEBUG_PRINT( x )
|
sl@0
|
29 |
#define DEBUG_PRINT2( x,y )
|
sl@0
|
30 |
#define DEBUG_PRINT3( x,y,z )
|
sl@0
|
31 |
#endif // defined (SYMBIAN_MDFVIDEODECODERBUFFERMANAGER_DEBUG)
|
sl@0
|
32 |
|
sl@0
|
33 |
CVideoDataBuffer::CVideoDataBuffer()
|
sl@0
|
34 |
{
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
TUint CVideoDataBuffer::Length()
|
sl@0
|
38 |
{
|
sl@0
|
39 |
return iSize;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
CVideoDataBuffer* CVideoDataBuffer::NewL(TUint aSize)
|
sl@0
|
43 |
{
|
sl@0
|
44 |
CVideoDataBuffer* self = new (ELeave) CVideoDataBuffer;
|
sl@0
|
45 |
CleanupStack::PushL(self);
|
sl@0
|
46 |
self->ConstructL(aSize);
|
sl@0
|
47 |
CleanupStack::Pop(self);
|
sl@0
|
48 |
return self;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
void CVideoDataBuffer::ConstructL(TUint aBufferSize)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
iSize = aBufferSize;
|
sl@0
|
54 |
CMMFDescriptorBuffer* buffer = CMMFDescriptorBuffer::NewL(aBufferSize);
|
sl@0
|
55 |
TDes8& des = buffer->Data();
|
sl@0
|
56 |
TUint8* ptr = const_cast<TUint8*>(des.Ptr());
|
sl@0
|
57 |
iVideoInputBuffer.iData.Set(ptr, des.Length(), des.MaxLength());
|
sl@0
|
58 |
iMmfBuffer = buffer;
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
CVideoDataBuffer::operator CMMFBuffer*()
|
sl@0
|
62 |
{
|
sl@0
|
63 |
return iMmfBuffer;
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
CVideoDataBuffer::operator TVideoInputBuffer&()
|
sl@0
|
67 |
{
|
sl@0
|
68 |
return iVideoInputBuffer;
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
|
sl@0
|
72 |
|
sl@0
|
73 |
TBool CVideoDataBuffer::operator== (const CMMFBuffer* aBuffer) const
|
sl@0
|
74 |
{
|
sl@0
|
75 |
return (aBuffer == iMmfBuffer);
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
TBool CVideoDataBuffer::operator== (const TVideoInputBuffer& aVideoInputBuffer) const
|
sl@0
|
79 |
{
|
sl@0
|
80 |
// compare the data pointers
|
sl@0
|
81 |
return iVideoInputBuffer.iData == aVideoInputBuffer.iData;
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
CVideoDataBuffer::~CVideoDataBuffer()
|
sl@0
|
85 |
{
|
sl@0
|
86 |
delete iMmfBuffer;
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
|
sl@0
|
90 |
CVideoFrameBuffer::CVideoFrameBuffer(TSize aFrameSize,
|
sl@0
|
91 |
TUncompressedVideoFormat aFormat,
|
sl@0
|
92 |
TDisplayMode aDisplayMode)
|
sl@0
|
93 |
: iRawPtr(0,0),
|
sl@0
|
94 |
iFrameSize(aFrameSize),
|
sl@0
|
95 |
iVideoFormat(aFormat),
|
sl@0
|
96 |
iDisplayMode(aDisplayMode)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
CVideoFrameBuffer* CVideoFrameBuffer::NewL(TSize aFrameSize,
|
sl@0
|
102 |
TUncompressedVideoFormat aFormat,
|
sl@0
|
103 |
TDisplayMode aDisplayMode)
|
sl@0
|
104 |
{
|
sl@0
|
105 |
CVideoFrameBuffer* self = new (ELeave) CVideoFrameBuffer(aFrameSize, aFormat, aDisplayMode);
|
sl@0
|
106 |
CleanupStack::PushL(self);
|
sl@0
|
107 |
self->ConstructL();
|
sl@0
|
108 |
CleanupStack::Pop(self);
|
sl@0
|
109 |
return self;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
void CVideoFrameBuffer::SetLastBuffer(TBool aLastBuffer)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
iLastBuffer = aLastBuffer;
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
TBool CVideoFrameBuffer::LastBuffer()
|
sl@0
|
118 |
{
|
sl@0
|
119 |
return iLastBuffer;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
void CVideoFrameBuffer::ConstructL()
|
sl@0
|
123 |
{
|
sl@0
|
124 |
iFrameBufferSize = CFbsBitmap::ScanLineLength(iFrameSize.iWidth, iDisplayMode) *
|
sl@0
|
125 |
iFrameSize.iHeight;
|
sl@0
|
126 |
Mem::FillZ(&iVideoPicture, sizeof(TVideoPicture));
|
sl@0
|
127 |
if(iVideoFormat.iDataFormat == ERgbFbsBitmap)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
iBitmap = new(ELeave)CFbsBitmap;
|
sl@0
|
130 |
User::LeaveIfError(iBitmap->Create(iFrameSize, iDisplayMode));
|
sl@0
|
131 |
DEBUG_PRINT2(_L("BufferManager: Created bitmap at 0x%08x"), iBitmap);
|
sl@0
|
132 |
|
sl@0
|
133 |
iVideoPicture.iData.iRgbBitmap = iBitmap;
|
sl@0
|
134 |
iBitmap->LockHeap();
|
sl@0
|
135 |
TRAPD(err, iMmfBuffer = CMMFPtrBuffer::NewL(TPtr8(reinterpret_cast<TUint8*>(iBitmap->DataAddress()),
|
sl@0
|
136 |
iFrameBufferSize,
|
sl@0
|
137 |
iFrameBufferSize)) );
|
sl@0
|
138 |
iBitmap->UnlockHeap();
|
sl@0
|
139 |
User::LeaveIfError(err);
|
sl@0
|
140 |
}
|
sl@0
|
141 |
else if((iVideoFormat.iDataFormat == ERgbRawData) || (iVideoFormat.iDataFormat == EYuvRawData))
|
sl@0
|
142 |
{
|
sl@0
|
143 |
iRawBuffer = HBufC8::NewMaxL(iFrameBufferSize);
|
sl@0
|
144 |
iRawPtr.Set(iRawBuffer->Des());
|
sl@0
|
145 |
iMmfBuffer = CMMFPtrBuffer::NewL(iRawPtr);
|
sl@0
|
146 |
iVideoPicture.iData.iRawData = &iRawPtr;
|
sl@0
|
147 |
}
|
sl@0
|
148 |
iVideoPicture.iData.iDataFormat = iVideoFormat.iDataFormat;
|
sl@0
|
149 |
iVideoPicture.iData.iDataSize = iFrameSize;
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
CVideoFrameBuffer::operator CMMFBuffer*()
|
sl@0
|
153 |
{
|
sl@0
|
154 |
return iMmfBuffer;
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
CVideoFrameBuffer::operator TVideoPicture&()
|
sl@0
|
158 |
{
|
sl@0
|
159 |
return iVideoPicture;
|
sl@0
|
160 |
}
|
sl@0
|
161 |
|
sl@0
|
162 |
CVideoFrameBuffer::operator CMMFBuffer&()
|
sl@0
|
163 |
{
|
sl@0
|
164 |
return *iMmfBuffer;
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
CVideoFrameBuffer::operator TVideoPicture*()
|
sl@0
|
168 |
{
|
sl@0
|
169 |
return &iVideoPicture;
|
sl@0
|
170 |
}
|
sl@0
|
171 |
|
sl@0
|
172 |
void CVideoFrameBuffer::LockFrameBufferHeap()
|
sl@0
|
173 |
{
|
sl@0
|
174 |
iBitmap->LockHeap();
|
sl@0
|
175 |
iHeapLocked = ETrue;
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
void CVideoFrameBuffer::UnlockFrameBufferHeap()
|
sl@0
|
179 |
{
|
sl@0
|
180 |
if (iHeapLocked)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
iBitmap->UnlockHeap();
|
sl@0
|
183 |
iHeapLocked = EFalse;
|
sl@0
|
184 |
}
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
|
sl@0
|
188 |
TBool CVideoFrameBuffer::operator== (const CMMFBuffer* aBuffer) const
|
sl@0
|
189 |
{
|
sl@0
|
190 |
return (aBuffer == iMmfBuffer);
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
TBool CVideoFrameBuffer::operator== (const TVideoPicture& aVideoInputBuffer) const
|
sl@0
|
194 |
{
|
sl@0
|
195 |
// compare the data pointers - cheat, it is the same pointer for the bitmap and
|
sl@0
|
196 |
// raw data
|
sl@0
|
197 |
return iVideoPicture.iData.iRawData == aVideoInputBuffer.iData.iRawData;
|
sl@0
|
198 |
}
|
sl@0
|
199 |
|
sl@0
|
200 |
CVideoFrameBuffer::~CVideoFrameBuffer()
|
sl@0
|
201 |
{
|
sl@0
|
202 |
UnlockFrameBufferHeap();
|
sl@0
|
203 |
delete iMmfBuffer;
|
sl@0
|
204 |
delete iBitmap;
|
sl@0
|
205 |
delete iRawBuffer;
|
sl@0
|
206 |
}
|
sl@0
|
207 |
|
sl@0
|
208 |
|
sl@0
|
209 |
/**
|
sl@0
|
210 |
Constructs a new instance of CMDFVideoDecoderBufferManager.
|
sl@0
|
211 |
@return "CMDFVideoDecoderBufferManager*"
|
sl@0
|
212 |
A pointer to the newly constructed CMDFVideoDecoderBufferManager
|
sl@0
|
213 |
*/
|
sl@0
|
214 |
CMdfVideoDecoderBufferManager* CMdfVideoDecoderBufferManager::NewL()
|
sl@0
|
215 |
{
|
sl@0
|
216 |
CMdfVideoDecoderBufferManager* s = new(ELeave) CMdfVideoDecoderBufferManager;
|
sl@0
|
217 |
CleanupStack::PushL(s);
|
sl@0
|
218 |
s->ConstructL();
|
sl@0
|
219 |
CleanupStack::Pop(s);
|
sl@0
|
220 |
return (static_cast<CMdfVideoDecoderBufferManager*>(s));
|
sl@0
|
221 |
}
|
sl@0
|
222 |
|
sl@0
|
223 |
CMdfVideoDecoderBufferManager::CMdfVideoDecoderBufferManager()
|
sl@0
|
224 |
{
|
sl@0
|
225 |
}
|
sl@0
|
226 |
void CMdfVideoDecoderBufferManager::ConstructL()
|
sl@0
|
227 |
{
|
sl@0
|
228 |
RFbsSession::Connect();
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
/**
|
sl@0
|
232 |
Default destructor
|
sl@0
|
233 |
*/
|
sl@0
|
234 |
CMdfVideoDecoderBufferManager::~CMdfVideoDecoderBufferManager()
|
sl@0
|
235 |
{
|
sl@0
|
236 |
// get rid of input buffers
|
sl@0
|
237 |
delete iInputBuffer;
|
sl@0
|
238 |
// cleanup frame buffer arrays
|
sl@0
|
239 |
iEmptyFrameBuffers.ResetAndDestroy();
|
sl@0
|
240 |
iFilledFrameBuffers.ResetAndDestroy();
|
sl@0
|
241 |
iFrameBuffersInUse.ResetAndDestroy();
|
sl@0
|
242 |
RFbsSession::Disconnect();
|
sl@0
|
243 |
|
sl@0
|
244 |
DEBUG_PRINT(_L("BufferManager: Closing down"));
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
/**
|
sl@0
|
248 |
Initializes the decoder buffer manager.
|
sl@0
|
249 |
@param "const TUncompressedVideoFormat& aFormat"
|
sl@0
|
250 |
The image format to decode into
|
sl@0
|
251 |
*/
|
sl@0
|
252 |
void CMdfVideoDecoderBufferManager::Init(const TUncompressedVideoFormat& aFormat)
|
sl@0
|
253 |
{
|
sl@0
|
254 |
DEBUG_PRINT(_L("BufferManager: Initializing"));
|
sl@0
|
255 |
|
sl@0
|
256 |
iFormat = aFormat;
|
sl@0
|
257 |
// The actual frame size will come from the VOL headers.
|
sl@0
|
258 |
// Set an initial value for iFrameBufferSize so we can get
|
sl@0
|
259 |
// the VOL headers themselves.
|
sl@0
|
260 |
// Also ensure we allow one free output buffer.
|
sl@0
|
261 |
iFrameBufferSize = 1024; // 1k
|
sl@0
|
262 |
iMaxFrameBuffers = 1;
|
sl@0
|
263 |
|
sl@0
|
264 |
iInputBufferInUse = EFalse;
|
sl@0
|
265 |
}
|
sl@0
|
266 |
|
sl@0
|
267 |
/**
|
sl@0
|
268 |
Creates a new empty input buffer.
|
sl@0
|
269 |
@param "TUint aBufferSize"
|
sl@0
|
270 |
The requested buffer size.
|
sl@0
|
271 |
@return "TVideoInputBuffer&"
|
sl@0
|
272 |
An empty input buffer.
|
sl@0
|
273 |
@leave May leave with KErrInUse if no input buffer is available, or with KErrNoMemory
|
sl@0
|
274 |
if a buffer cannot be created or adjusted.
|
sl@0
|
275 |
*/
|
sl@0
|
276 |
CVideoDataBuffer& CMdfVideoDecoderBufferManager::CreateDataBufferL(TUint aBufferSize)
|
sl@0
|
277 |
{
|
sl@0
|
278 |
// We use one input buffer and one overflow buffer.
|
sl@0
|
279 |
|
sl@0
|
280 |
// If the app requests another buffer before this one has been processed, then leave.
|
sl@0
|
281 |
if(iInputBufferInUse)
|
sl@0
|
282 |
{
|
sl@0
|
283 |
User::Leave(KErrInUse);
|
sl@0
|
284 |
}
|
sl@0
|
285 |
|
sl@0
|
286 |
if(aBufferSize < 1)
|
sl@0
|
287 |
{
|
sl@0
|
288 |
User::Leave(KErrArgument);
|
sl@0
|
289 |
}
|
sl@0
|
290 |
|
sl@0
|
291 |
// Create or adjust the input buffer
|
sl@0
|
292 |
|
sl@0
|
293 |
if(!iInputBuffer)
|
sl@0
|
294 |
{
|
sl@0
|
295 |
iInputBuffer = CVideoDataBuffer::NewL(aBufferSize);
|
sl@0
|
296 |
}
|
sl@0
|
297 |
else if(iInputBuffer->Length() != aBufferSize)
|
sl@0
|
298 |
{
|
sl@0
|
299 |
// NB don't use ReAllocL() as it will panic if the buffer is shrinking
|
sl@0
|
300 |
// Use temp variable
|
sl@0
|
301 |
CVideoDataBuffer* tempBuffer = CVideoDataBuffer::NewL(aBufferSize);
|
sl@0
|
302 |
|
sl@0
|
303 |
// Coverity reports a leave_without_push error here because
|
sl@0
|
304 |
// CVideoDataBuffer contains a frame buffer member which could contain
|
sl@0
|
305 |
// a CFbsBitmap member which can panic during its destructor. The panic
|
sl@0
|
306 |
// has a trapped leave and for some reason coverity does not recognise it.
|
sl@0
|
307 |
// Mark as false positive
|
sl@0
|
308 |
// coverity[leave_without_push : FALSE]
|
sl@0
|
309 |
delete iInputBuffer;
|
sl@0
|
310 |
iInputBuffer = NULL;
|
sl@0
|
311 |
iInputBuffer = tempBuffer;
|
sl@0
|
312 |
}
|
sl@0
|
313 |
return *iInputBuffer;
|
sl@0
|
314 |
}
|
sl@0
|
315 |
|
sl@0
|
316 |
void CMdfVideoDecoderBufferManager::ReturnDataBufferL(TVideoInputBuffer& aInputBuffer)
|
sl@0
|
317 |
{
|
sl@0
|
318 |
if (!iInputBuffer)
|
sl@0
|
319 |
{
|
sl@0
|
320 |
User::Leave(KErrNotFound);
|
sl@0
|
321 |
}
|
sl@0
|
322 |
// if this buffer isn't the input buffer, leave
|
sl@0
|
323 |
if(! (*iInputBuffer == aInputBuffer) )
|
sl@0
|
324 |
{
|
sl@0
|
325 |
User::Leave(KErrNotFound);
|
sl@0
|
326 |
}
|
sl@0
|
327 |
// if the buffer is not in use, leave
|
sl@0
|
328 |
if(!iInputBufferInUse)
|
sl@0
|
329 |
{
|
sl@0
|
330 |
User::Leave(KErrInUse);
|
sl@0
|
331 |
}
|
sl@0
|
332 |
|
sl@0
|
333 |
// finished with input buffer - mark it unused
|
sl@0
|
334 |
iInputBufferInUse = EFalse;
|
sl@0
|
335 |
}
|
sl@0
|
336 |
|
sl@0
|
337 |
CVideoDataBuffer& CMdfVideoDecoderBufferManager::GetDataBufferL()
|
sl@0
|
338 |
{
|
sl@0
|
339 |
if (!iInputBuffer)
|
sl@0
|
340 |
{
|
sl@0
|
341 |
User::Leave(KErrNotFound);
|
sl@0
|
342 |
}
|
sl@0
|
343 |
if (iInputBufferInUse)
|
sl@0
|
344 |
{
|
sl@0
|
345 |
User::Leave(KErrInUse);
|
sl@0
|
346 |
}
|
sl@0
|
347 |
iInputBufferInUse = ETrue;
|
sl@0
|
348 |
return *iInputBuffer;
|
sl@0
|
349 |
}
|
sl@0
|
350 |
|
sl@0
|
351 |
/**
|
sl@0
|
352 |
Gets the number of available input buffers.
|
sl@0
|
353 |
@return "TInt"
|
sl@0
|
354 |
The number of available input buffers.
|
sl@0
|
355 |
*/
|
sl@0
|
356 |
TInt CMdfVideoDecoderBufferManager::DataBuffersAvailable() const
|
sl@0
|
357 |
{
|
sl@0
|
358 |
// this plugin has one input buffer. if it is in use (i.e. the client hasn't been
|
sl@0
|
359 |
// notified with MdvppNewBuffers()) then return 0.
|
sl@0
|
360 |
return ((iInputBufferInUse) ? 0 : 1);
|
sl@0
|
361 |
}
|
sl@0
|
362 |
|
sl@0
|
363 |
/**
|
sl@0
|
364 |
Sets the frame size.
|
sl@0
|
365 |
@param "const TSize& aSize"
|
sl@0
|
366 |
The frame size.
|
sl@0
|
367 |
*/
|
sl@0
|
368 |
void CMdfVideoDecoderBufferManager::SetFrameSize(const TSize& aSize)
|
sl@0
|
369 |
{
|
sl@0
|
370 |
iFrameSize = aSize;
|
sl@0
|
371 |
}
|
sl@0
|
372 |
|
sl@0
|
373 |
/**
|
sl@0
|
374 |
Gets the frame size.
|
sl@0
|
375 |
@return "const TSize&"
|
sl@0
|
376 |
The frame size.
|
sl@0
|
377 |
*/
|
sl@0
|
378 |
const TSize& CMdfVideoDecoderBufferManager::FrameSize() const
|
sl@0
|
379 |
{
|
sl@0
|
380 |
return iFrameSize;
|
sl@0
|
381 |
}
|
sl@0
|
382 |
|
sl@0
|
383 |
/**
|
sl@0
|
384 |
Sets the frame buffer size.
|
sl@0
|
385 |
@param "TInt aSize"
|
sl@0
|
386 |
The frame buffer size.
|
sl@0
|
387 |
*/
|
sl@0
|
388 |
void CMdfVideoDecoderBufferManager::SetFrameBufferSize(TInt aSize)
|
sl@0
|
389 |
{
|
sl@0
|
390 |
iFrameBufferSize = aSize;
|
sl@0
|
391 |
}
|
sl@0
|
392 |
|
sl@0
|
393 |
/**
|
sl@0
|
394 |
Gets the frame buffer size.
|
sl@0
|
395 |
@return "TInt"
|
sl@0
|
396 |
The frame buffer size.
|
sl@0
|
397 |
*/
|
sl@0
|
398 |
TInt CMdfVideoDecoderBufferManager::FrameBufferSize() const
|
sl@0
|
399 |
{
|
sl@0
|
400 |
return iFrameBufferSize;
|
sl@0
|
401 |
}
|
sl@0
|
402 |
|
sl@0
|
403 |
/**
|
sl@0
|
404 |
Gets the maximum number of frame buffers.
|
sl@0
|
405 |
@return "TInt"
|
sl@0
|
406 |
The maximum number of frame buffers.
|
sl@0
|
407 |
*/
|
sl@0
|
408 |
TInt CMdfVideoDecoderBufferManager::MaxFrameBuffers() const
|
sl@0
|
409 |
{
|
sl@0
|
410 |
return iMaxFrameBuffers;
|
sl@0
|
411 |
}
|
sl@0
|
412 |
|
sl@0
|
413 |
/**
|
sl@0
|
414 |
Gets the number of available pictures (full output buffers).
|
sl@0
|
415 |
@return "TInt"
|
sl@0
|
416 |
The number of available pictures.
|
sl@0
|
417 |
*/
|
sl@0
|
418 |
TInt CMdfVideoDecoderBufferManager::FilledFrameBuffersAvailable() const
|
sl@0
|
419 |
{
|
sl@0
|
420 |
return ((iFilledFrameBuffers.Count() > 0) ? 1 : 0);
|
sl@0
|
421 |
}
|
sl@0
|
422 |
|
sl@0
|
423 |
/**
|
sl@0
|
424 |
Gets the number of available frame buffers.
|
sl@0
|
425 |
@return "TInt"
|
sl@0
|
426 |
The number of available frame buffers.
|
sl@0
|
427 |
*/
|
sl@0
|
428 |
TInt CMdfVideoDecoderBufferManager::EmptyFrameBuffersAvailable() const
|
sl@0
|
429 |
{
|
sl@0
|
430 |
return ((iEmptyFrameBuffers.Count() < iMaxFrameBuffers) ? 1 : 0);
|
sl@0
|
431 |
}
|
sl@0
|
432 |
|
sl@0
|
433 |
|
sl@0
|
434 |
/**
|
sl@0
|
435 |
Gets the first available framebuffer
|
sl@0
|
436 |
@return "TVideoPicture&"
|
sl@0
|
437 |
A picture.
|
sl@0
|
438 |
@leave May leave with KErrNotReady if no picture is available.
|
sl@0
|
439 |
*/
|
sl@0
|
440 |
CVideoFrameBuffer& CMdfVideoDecoderBufferManager::GetEmptyFrameBufferL(TBool aLockHeap)
|
sl@0
|
441 |
{
|
sl@0
|
442 |
DEBUG_PRINT2(_L("Get Empty Frame Buffer avail: %d"),iEmptyFrameBuffers.Count());
|
sl@0
|
443 |
|
sl@0
|
444 |
if(iEmptyFrameBuffers.Count() == 0)
|
sl@0
|
445 |
{
|
sl@0
|
446 |
User::Leave(KErrNotReady);
|
sl@0
|
447 |
}
|
sl@0
|
448 |
CVideoFrameBuffer* frameBuf = iEmptyFrameBuffers[0];
|
sl@0
|
449 |
iFrameBuffersInUse.AppendL(frameBuf);
|
sl@0
|
450 |
iEmptyFrameBuffers.Remove(0);
|
sl@0
|
451 |
if (aLockHeap)
|
sl@0
|
452 |
{
|
sl@0
|
453 |
frameBuf->LockFrameBufferHeap();
|
sl@0
|
454 |
}
|
sl@0
|
455 |
return *frameBuf;
|
sl@0
|
456 |
}
|
sl@0
|
457 |
|
sl@0
|
458 |
|
sl@0
|
459 |
|
sl@0
|
460 |
/**
|
sl@0
|
461 |
Gets the first available picture (full frame buffer).
|
sl@0
|
462 |
@return "TVideoPicture&"
|
sl@0
|
463 |
A picture.
|
sl@0
|
464 |
@leave May leave with KErrNotReady if no picture is available.
|
sl@0
|
465 |
*/
|
sl@0
|
466 |
CVideoFrameBuffer& CMdfVideoDecoderBufferManager::GetFilledFrameBufferL(TBool aLockHeap)
|
sl@0
|
467 |
{
|
sl@0
|
468 |
DEBUG_PRINT2(_L("Get Filled Frame Buffer avail: %d"),iFilledFrameBuffers.Count());
|
sl@0
|
469 |
|
sl@0
|
470 |
if(iFilledFrameBuffers.Count() == 0)
|
sl@0
|
471 |
{
|
sl@0
|
472 |
User::Leave(KErrNotReady);
|
sl@0
|
473 |
}
|
sl@0
|
474 |
CVideoFrameBuffer* frameBuf = iFilledFrameBuffers[0];
|
sl@0
|
475 |
iFilledFrameBuffers.Remove(0);
|
sl@0
|
476 |
iFrameBuffersInUse.AppendL(frameBuf);
|
sl@0
|
477 |
|
sl@0
|
478 |
if (aLockHeap)
|
sl@0
|
479 |
{
|
sl@0
|
480 |
frameBuf->LockFrameBufferHeap();
|
sl@0
|
481 |
}
|
sl@0
|
482 |
return *frameBuf;
|
sl@0
|
483 |
}
|
sl@0
|
484 |
|
sl@0
|
485 |
/**
|
sl@0
|
486 |
Gets the last displayed picture.
|
sl@0
|
487 |
Used by Direct Screen Access to redraw.
|
sl@0
|
488 |
@return "TPictureData&"
|
sl@0
|
489 |
The last displayed picture.
|
sl@0
|
490 |
@leave May leave with KErrNotReady if no picture is available.
|
sl@0
|
491 |
*/
|
sl@0
|
492 |
const TPictureData& CMdfVideoDecoderBufferManager::LastPictureL() const
|
sl@0
|
493 |
{
|
sl@0
|
494 |
// it's a union, so we can check either iRgbBitmap or iRawData
|
sl@0
|
495 |
if(!iLastDisplayedFrame.iRgbBitmap)
|
sl@0
|
496 |
{
|
sl@0
|
497 |
User::Leave(KErrNotReady);
|
sl@0
|
498 |
}
|
sl@0
|
499 |
return iLastDisplayedFrame;
|
sl@0
|
500 |
}
|
sl@0
|
501 |
|
sl@0
|
502 |
/**
|
sl@0
|
503 |
Gets a new empty frame buffer.
|
sl@0
|
504 |
@param aDisplayMode
|
sl@0
|
505 |
The display mode of the bitmap to be created.
|
sl@0
|
506 |
@return "TVideoPicture&"
|
sl@0
|
507 |
A frame buffer.
|
sl@0
|
508 |
@leave May leave with KErrNotReady if no frame buffer is available, or if there
|
sl@0
|
509 |
is no memory to create a new one.
|
sl@0
|
510 |
*/
|
sl@0
|
511 |
CVideoFrameBuffer& CMdfVideoDecoderBufferManager::CreateFrameBufferL(TDisplayMode aDisplayMode)
|
sl@0
|
512 |
{
|
sl@0
|
513 |
CVideoFrameBuffer* frameBuffer = CVideoFrameBuffer::NewL(iFrameSize, iFormat, aDisplayMode);
|
sl@0
|
514 |
CleanupStack::PushL(frameBuffer);
|
sl@0
|
515 |
iEmptyFrameBuffers.AppendL(frameBuffer);
|
sl@0
|
516 |
CleanupStack::Pop(frameBuffer);
|
sl@0
|
517 |
|
sl@0
|
518 |
DEBUG_PRINT2(_L("BufferManager: Created frame buffer; %d buffers in use"), iEmptyFrameBuffers.Count());
|
sl@0
|
519 |
return *frameBuffer;
|
sl@0
|
520 |
}
|
sl@0
|
521 |
|
sl@0
|
522 |
/**
|
sl@0
|
523 |
Returns a used picture to the buffer manager for disposal.
|
sl@0
|
524 |
@param "TVideoPicture* aFrameBuffer"
|
sl@0
|
525 |
A used picture.
|
sl@0
|
526 |
@param "TBool aSaveLast"
|
sl@0
|
527 |
Save this picture as the last displayed (for redraw).
|
sl@0
|
528 |
@leave May leave with KErrNotFound if the picture does not exist.
|
sl@0
|
529 |
*/
|
sl@0
|
530 |
void CMdfVideoDecoderBufferManager::ReturnFrameBufferL(TVideoPicture& aFrameBuffer, CVideoFrameBuffer::TFrameBufferState aState)
|
sl@0
|
531 |
{
|
sl@0
|
532 |
DEBUG_PRINT(_L("Return Frame Buffer from TVideoPicture"));
|
sl@0
|
533 |
|
sl@0
|
534 |
TInt bufIndex;
|
sl@0
|
535 |
User::LeaveIfError(bufIndex = FindFrameBuffer(aFrameBuffer));
|
sl@0
|
536 |
// remove from the list of avaible buffers
|
sl@0
|
537 |
CVideoFrameBuffer* frameBuf = iFrameBuffersInUse[bufIndex];
|
sl@0
|
538 |
frameBuf->UnlockFrameBufferHeap();
|
sl@0
|
539 |
if (aState == CVideoFrameBuffer::EEmptied)
|
sl@0
|
540 |
{
|
sl@0
|
541 |
DEBUG_PRINT(_L("Added to empty pool"));
|
sl@0
|
542 |
iEmptyFrameBuffers.AppendL(frameBuf);
|
sl@0
|
543 |
}
|
sl@0
|
544 |
else
|
sl@0
|
545 |
{
|
sl@0
|
546 |
DEBUG_PRINT(_L("Added to filled pool"));
|
sl@0
|
547 |
iFilledFrameBuffers.AppendL(frameBuf);
|
sl@0
|
548 |
}
|
sl@0
|
549 |
iFrameBuffersInUse.Remove(bufIndex);
|
sl@0
|
550 |
|
sl@0
|
551 |
}
|
sl@0
|
552 |
|
sl@0
|
553 |
void CMdfVideoDecoderBufferManager::ReturnFrameBufferL(CMMFBuffer* aBuffer,
|
sl@0
|
554 |
CVideoFrameBuffer::TFrameBufferState aState,
|
sl@0
|
555 |
TBool aLastBuffer)
|
sl@0
|
556 |
{
|
sl@0
|
557 |
DEBUG_PRINT(_L("Return Frame buffer from CMMFBuffer"));
|
sl@0
|
558 |
TInt bufIndex;
|
sl@0
|
559 |
User::LeaveIfError(bufIndex = FindFrameBuffer(aBuffer));
|
sl@0
|
560 |
// remove from the list of avaible buffers
|
sl@0
|
561 |
CVideoFrameBuffer* frameBuf = iFrameBuffersInUse[bufIndex];
|
sl@0
|
562 |
frameBuf->SetLastBuffer(aLastBuffer);
|
sl@0
|
563 |
frameBuf->UnlockFrameBufferHeap();
|
sl@0
|
564 |
if (aState == CVideoFrameBuffer::EEmptied)
|
sl@0
|
565 |
{
|
sl@0
|
566 |
DEBUG_PRINT(_L("Added to empty pool"));
|
sl@0
|
567 |
iEmptyFrameBuffers.AppendL(frameBuf);
|
sl@0
|
568 |
}
|
sl@0
|
569 |
else
|
sl@0
|
570 |
{
|
sl@0
|
571 |
DEBUG_PRINT(_L("Added to filled pool"));
|
sl@0
|
572 |
iFilledFrameBuffers.AppendL(frameBuf);
|
sl@0
|
573 |
}
|
sl@0
|
574 |
iFrameBuffersInUse.Remove(bufIndex);
|
sl@0
|
575 |
|
sl@0
|
576 |
}
|
sl@0
|
577 |
|
sl@0
|
578 |
// private methods
|
sl@0
|
579 |
|
sl@0
|
580 |
TInt CMdfVideoDecoderBufferManager::FindFrameBuffer(const TVideoPicture& aFrameBuffer) const
|
sl@0
|
581 |
{
|
sl@0
|
582 |
TInt theCount = iFrameBuffersInUse.Count();
|
sl@0
|
583 |
TInt found = KErrNotFound;
|
sl@0
|
584 |
for(TInt i = 0; i < theCount; i++)
|
sl@0
|
585 |
{
|
sl@0
|
586 |
if(*iFrameBuffersInUse[i] == aFrameBuffer)
|
sl@0
|
587 |
{
|
sl@0
|
588 |
found = i;
|
sl@0
|
589 |
break;
|
sl@0
|
590 |
}
|
sl@0
|
591 |
}
|
sl@0
|
592 |
return found;
|
sl@0
|
593 |
}
|
sl@0
|
594 |
|
sl@0
|
595 |
|
sl@0
|
596 |
TInt CMdfVideoDecoderBufferManager::FindFrameBuffer(const CMMFBuffer* aBuffer) const
|
sl@0
|
597 |
{
|
sl@0
|
598 |
TInt theCount = iFrameBuffersInUse.Count();
|
sl@0
|
599 |
TInt found = KErrNotFound;
|
sl@0
|
600 |
for(TInt i = 0; i < theCount; i++)
|
sl@0
|
601 |
{
|
sl@0
|
602 |
if(*iFrameBuffersInUse[i] == aBuffer)
|
sl@0
|
603 |
{
|
sl@0
|
604 |
found = i;
|
sl@0
|
605 |
break;
|
sl@0
|
606 |
}
|
sl@0
|
607 |
}
|
sl@0
|
608 |
return found;
|
sl@0
|
609 |
}
|
sl@0
|
610 |
|
sl@0
|
611 |
// end
|