|
1 /* |
|
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Display Sink subsystem for Display Posting. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "CDisplaySinkDP.h" |
|
22 #include "vtyuvconverter.h" |
|
23 |
|
24 // MACROS |
|
25 |
|
26 #ifdef _DEBUG |
|
27 #include <e32debug.h> |
|
28 #define PRINT RDebug::Print |
|
29 #define _IFDBG(a) a |
|
30 #else |
|
31 #define PRINT |
|
32 #define _IFDBG(a) |
|
33 #endif |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CDisplaySinkDP::NewL |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CDisplaySinkDP* CDisplaySinkDP::NewL( TDisplaySinkParams& aParams, |
|
40 const TDesC8& aInitData ) |
|
41 { |
|
42 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::NewL()<"), RThread().Id().operator TUint())); |
|
43 CDisplaySinkDP* self = new ( ELeave ) CDisplaySinkDP(); |
|
44 CleanupStack::PushL( self ); |
|
45 self->ConstructL( aParams, aInitData ); |
|
46 CleanupStack::Pop(); // self |
|
47 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::NewL()>"), RThread().Id().operator TUint())); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CDisplaySinkDP::CDisplaySinkDP |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CDisplaySinkDP::CDisplaySinkDP() |
|
56 { |
|
57 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::Ctor<"), RThread().Id().operator TUint())); |
|
58 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::Ctor>"), RThread().Id().operator TUint())); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CDisplaySinkDP::~CDisplaySinkDP |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CDisplaySinkDP::~CDisplaySinkDP() |
|
66 { |
|
67 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::~<"), RThread().Id().operator TUint())); |
|
68 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::~>"), RThread().Id().operator TUint())); |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CDisplaySinkDP::BaseConstructL |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 void CDisplaySinkDP::BaseConstructL( TDisplaySinkParams& aParams, |
|
76 const TDesC8& ) |
|
77 { |
|
78 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseConstructL()<"), RThread().Id().operator TUint())); |
|
79 iNewParams = static_cast< const TDisplaySinkParamsDP& >( aParams ); |
|
80 if ( !iNewParams.iPostingBuffer1 || !iNewParams.iPostingBuffer2 ) |
|
81 { |
|
82 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseConstructL() posting buffer is NULL!"))); |
|
83 User::Leave( KErrArgument ); |
|
84 } |
|
85 iBitmapTable[EFirstBitmap].iBuffer = iNewParams.iPostingBuffer1; |
|
86 iBitmapTable[ESecondBitmap].iBuffer = iNewParams.iPostingBuffer2; |
|
87 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseConstructL()>"), RThread().Id().operator TUint())); |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CDisplaySinkDP::BaseConvert |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 TBool CDisplaySinkDP::BaseConvert( const TVtMMFDataBuffer& aBuffer ) |
|
95 { |
|
96 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseConvert()<"), RThread().Id().operator TUint())); |
|
97 |
|
98 TBool consumed( ETrue ); |
|
99 TBitmapNo bitmapNo( iBitmapTable[ EFirstBitmap ].iIsFree ? EFirstBitmap : ESecondBitmap ); |
|
100 if ( iBitmapTable[ bitmapNo ].iIsFree && |
|
101 !iReleased && |
|
102 ( *iRequestStatusPtr == KRequestPending ) ) |
|
103 { |
|
104 CPostingSurface::TPostingBuff* postingBuffer = |
|
105 *iBitmapTable[ bitmapNo ].iBuffer; |
|
106 |
|
107 TInt bufferLength( |
|
108 postingBuffer->GetSize().iHeight * postingBuffer->GetStride() ); |
|
109 |
|
110 TPtr8 ptrBuffer( |
|
111 static_cast< TUint8* >( postingBuffer->GetBuffer() ), |
|
112 bufferLength, |
|
113 bufferLength |
|
114 ); |
|
115 |
|
116 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseConvert(): buffer %d: $%x %d bytes"), RThread().Id().operator TUint(), bitmapNo, postingBuffer->GetBuffer(), bufferLength)); |
|
117 |
|
118 // Determine wether to convert or copy (420 will be just copied) |
|
119 if ( iNewParams.iPostingFormat == |
|
120 CPostingSurface::EYuv422LeBt601Range0 ) |
|
121 { |
|
122 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseConvert(): converting to 422"), RThread().Id().operator TUint())); |
|
123 VtYuvConverter::ConvertFrom420PlanarTo422Interleaved( |
|
124 aBuffer.Data(), |
|
125 aBuffer.GetFrameSize(), |
|
126 ptrBuffer, |
|
127 postingBuffer->GetStride() ); |
|
128 } |
|
129 else |
|
130 { |
|
131 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseConvert(): copying as 420"), RThread().Id().operator TUint())); |
|
132 ptrBuffer = aBuffer.Data(); |
|
133 } |
|
134 |
|
135 iBitmapTable[ bitmapNo ].iIsFree = EFalse; |
|
136 TRequestStatus* statusP = iRequestStatusPtr; |
|
137 iThread.RequestComplete( statusP, bitmapNo ); |
|
138 } |
|
139 else |
|
140 { |
|
141 consumed = EFalse; |
|
142 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseConvert(): could not find free buffer"), RThread().Id().operator TUint())); |
|
143 } |
|
144 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseConvert()>"), RThread().Id().operator TUint())); |
|
145 return consumed; |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CDisplaySinkDP::BaseSinkThreadLogonL |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 void CDisplaySinkDP::BaseSinkThreadLogonL() |
|
153 { |
|
154 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseSinkThreadLogonL()<"), RThread().Id().operator TUint())); |
|
155 UpdateExpectedFrameSizeL(); |
|
156 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseSinkThreadLogonL()>"), RThread().Id().operator TUint())); |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // CDisplaySinkDP::BaseSinkThreadLogoff |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 void CDisplaySinkDP::BaseSinkThreadLogoff() |
|
164 { |
|
165 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseSinkThreadLogoff()<"), RThread().Id().operator TUint())); |
|
166 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseSinkThreadLogoff()>"), RThread().Id().operator TUint())); |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CDisplaySinkDP::BaseUpdateSinkParamsL |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void CDisplaySinkDP::BaseUpdateSinkParamsL( const TDisplaySinkParams& aParams ) |
|
174 { |
|
175 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseUpdateSinkParamsL()<"), RThread().Id().operator TUint())); |
|
176 iNewParams = static_cast< const TDisplaySinkParamsDP& >( aParams ); |
|
177 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseUpdateSinkParamsL()>"), RThread().Id().operator TUint())); |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CDisplaySinkDP::BaseDoUpdateParamsL |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CDisplaySinkDP::BaseDoUpdateParamsL() |
|
185 { |
|
186 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseDoUpdateParamsL()<"), RThread().Id().operator TUint())); |
|
187 iBitmapTable[ EFirstBitmap ].iBuffer = iNewParams.iPostingBuffer1; |
|
188 iBitmapTable[ ESecondBitmap ].iBuffer = iNewParams.iPostingBuffer2; |
|
189 UpdateExpectedFrameSizeL(); |
|
190 if( iNewParams.iFrameRateLimit != iFrameRateInterval ) |
|
191 { |
|
192 SetFrameRateLimit( iNewParams.iFrameRateLimit ); |
|
193 ResetFrameRateLimitter(); |
|
194 } |
|
195 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseDoUpdateParamsL()>"), RThread().Id().operator TUint())); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CDisplaySinkDP::BaseSetVideoFrameSizeL |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 void CDisplaySinkDP::BaseSetVideoFrameSizeL( const TSize& ) |
|
203 { |
|
204 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseSetVideoFrameSizeL()<"), RThread().Id().operator TUint())); |
|
205 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseSetVideoFrameSizeL()>"), RThread().Id().operator TUint())); |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CDisplaySinkDP::BaseSizesMatch |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 TBool CDisplaySinkDP::BaseSizesMatch( const TSize& aSize ) |
|
213 { |
|
214 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseSizesMatch()<"), RThread().Id().operator TUint())); |
|
215 TBool sizesMatch( iExpectedFrameSize == aSize ); |
|
216 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseSizesMatch() %d>"), RThread().Id().operator TUint(), sizesMatch)); |
|
217 return sizesMatch; |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CDisplaySinkDP::BitmapEntry |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 CDisplaySink::TBitmapEntry& CDisplaySinkDP::BitmapEntry( TInt aIndex ) |
|
225 { |
|
226 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BitmapEntry(%d)<"), RThread().Id().operator TUint(), aIndex)); |
|
227 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BitmapEntry()>"), RThread().Id().operator TUint())); |
|
228 return iBitmapTable[ aIndex ]; |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CDisplaySinkDP::BaseEmptyBufferL |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CDisplaySinkDP::BaseEmptyBufferL( TVtMMFDataBuffer& aVTMMFBuffer ) |
|
236 { |
|
237 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseEmptyBufferL()<"), RThread().Id().operator TUint())); |
|
238 if ( BaseConvert( aVTMMFBuffer ) ) |
|
239 { |
|
240 CleanupStack::PopAndDestroy(); // iBitmapCS.Signal(); |
|
241 iSupplier->BufferEmptiedL( iBuffer ); |
|
242 } |
|
243 else |
|
244 { |
|
245 if ( iVideoFrameQueue->IsStored() || !IsOkToSendFrame() ) |
|
246 { |
|
247 CleanupStack::PopAndDestroy(); // iBitmapCS.Signal(); |
|
248 iSupplier->BufferEmptiedL( iBuffer ); |
|
249 } |
|
250 else |
|
251 { |
|
252 iVideoFrameQueue->Store( *iSupplier, static_cast<CMMFDataBuffer*>(aVTMMFBuffer.GetMMFBuffer()), aVTMMFBuffer.GetFrameSize(), aVTMMFBuffer.Data() ); |
|
253 CleanupStack::PopAndDestroy(); // iBitmapCS.Signal(); |
|
254 } |
|
255 } |
|
256 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseEmptyBufferL()>"), RThread().Id().operator TUint())); |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CDisplaySinkDP::BaseSetBitmapAvailable( TBitmapNo aBitmapNo ) |
|
261 // ----------------------------------------------------------------------------- |
|
262 // |
|
263 void CDisplaySinkDP::BaseSetBitmapAvailable( TBitmapNo ) |
|
264 { |
|
265 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseSetBitmapAvailable()<"), RThread().Id().operator TUint())); |
|
266 NextFrame(); |
|
267 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseSetBitmapAvailable()>"), RThread().Id().operator TUint())); |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CDisplaySinkDP::BaseVideoFrameSizeChangedL( const TSize& ) |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 void CDisplaySinkDP::BaseVideoFrameSizeChangedL( const TSize& ) |
|
275 { |
|
276 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseVideoFrameSizeChangedL()<"), RThread().Id().operator TUint())); |
|
277 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::BaseVideoFrameSizeChangedL()>"), RThread().Id().operator TUint())); |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CDisplaySinkDP::NextFrame |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 void CDisplaySinkDP::NextFrame() |
|
285 { |
|
286 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::NextFrame()<"), RThread().Id().operator TUint())); |
|
287 if ( iVideoFrameQueue->IsStored() ) |
|
288 { |
|
289 if ( IsOkToSendFrame() ) |
|
290 { |
|
291 BaseConvert( iVideoFrameQueue->Buffer() ); |
|
292 } |
|
293 iVideoFrameQueue->Release(); |
|
294 } |
|
295 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::NextFrame()>"), RThread().Id().operator TUint())); |
|
296 } |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // CDisplaySinkDP::UpdateExpectedFrameSizeL() |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 void CDisplaySinkDP::UpdateExpectedFrameSizeL() |
|
303 { |
|
304 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::UpdateExpectedFrameSizeL()<"), RThread().Id().operator TUint())); |
|
305 iExpectedFrameSize = iNewParams.iFrameSize; |
|
306 _IFDBG(PRINT(_L("VideoSource[%d]: CDisplaySinkDP::UpdateExpectedFrameSizeL()>"), RThread().Id().operator TUint())); |
|
307 } |
|
308 |
|
309 // End of File |