|
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: DisplaySink subsystem. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef CDISPLAYSINK_H |
|
22 #define CDISPLAYSINK_H |
|
23 |
|
24 // INCLUDE FILES |
|
25 |
|
26 #include <bldvariant.hrh> |
|
27 #include <e32base.h> |
|
28 #include <mmfutilities.h> |
|
29 #include <mmfdatasource.h> |
|
30 #include <mmfdatasink.h> |
|
31 #include <fbs.h> |
|
32 #include <mvtprotocolhandler.h> |
|
33 |
|
34 #include "mdisplaysink.h" |
|
35 |
|
36 // CONSTANTS |
|
37 |
|
38 // QCIF size |
|
39 #define QCIF TSize( 176, 144 ) |
|
40 |
|
41 // Number of bitmap sets (big/small) in array |
|
42 const TInt KBitmapTableCount = 2; |
|
43 |
|
44 // FORWARD DECLARATIONS |
|
45 |
|
46 class CDisplaySink; |
|
47 class CVTYUVFbsBitmapConverter; |
|
48 class CVtCallback; |
|
49 class CVtImageIYUV; |
|
50 class CMMFDataBuffer; |
|
51 class CVtFrameQueue; |
|
52 |
|
53 // CLASS DECLARATION |
|
54 |
|
55 /** |
|
56 * CVtFrameQueue |
|
57 * |
|
58 * Storage class for DisplaySink. Used in situations where EmptyBufferL() is |
|
59 * called and there's no available bitmaps (or buffers). This class will |
|
60 * hold one buffer until next SetBitmapAvailable() is called. Instance operates |
|
61 * in protocol thread's active scheduler. |
|
62 * |
|
63 * @lib DisplaySink.lib |
|
64 */ |
|
65 NONSHARABLE_CLASS( CVtFrameQueue ) : public CActive |
|
66 { |
|
67 |
|
68 public: // new methods |
|
69 /** |
|
70 * C++ constructor. |
|
71 */ |
|
72 CVtFrameQueue(); |
|
73 |
|
74 /** |
|
75 * Adds this to protocol thread's active scheduler. |
|
76 */ |
|
77 TInt ThreadLogon(); |
|
78 |
|
79 /** |
|
80 * Releases stored buffer, when sink is stopped. |
|
81 */ |
|
82 void SinkStoppedL(); |
|
83 |
|
84 /** |
|
85 * Deques from protocol thread's active scheduler. |
|
86 */ |
|
87 void ThreadLogoff(); |
|
88 |
|
89 /** |
|
90 * Stores buffer & supplier. |
|
91 */ |
|
92 void Store( MVTVideoSource& aSupplier, CMMFDataBuffer* aBuffer, TSize aFrameSize, TPtr8& aPtr ); |
|
93 |
|
94 /** |
|
95 * Returns ETrue if buffer is being stored, EFalse otherwise. |
|
96 */ |
|
97 TBool IsStored() const; |
|
98 |
|
99 /** |
|
100 * Returns stored buffer. |
|
101 */ |
|
102 TVtMMFDataBuffer Buffer(); |
|
103 |
|
104 /** |
|
105 * Releases stored buffer. Supplier's BufferEmptiedL() is called. Call |
|
106 * is executed in protocol thread's context. |
|
107 */ |
|
108 void Release(); |
|
109 |
|
110 private: |
|
111 |
|
112 /** |
|
113 * Calls BufferEmptiedL() for supplier. This call always happens in protocol |
|
114 * thread context. |
|
115 * @param aBuffer Pointer reference to a buffer to be released. |
|
116 */ |
|
117 void DoReleaseBufferL( CMMFDataBuffer*& aBuffer ); |
|
118 |
|
119 private: // from CActive |
|
120 /** |
|
121 * @see CActive::RunL |
|
122 */ |
|
123 void RunL(); |
|
124 |
|
125 /** |
|
126 * @see CActive::DoCancel |
|
127 */ |
|
128 void DoCancel(); |
|
129 |
|
130 private: |
|
131 // Stored supplier |
|
132 MVTVideoSource* iSupplier; |
|
133 // Stored buffer |
|
134 CMMFDataBuffer* iBuffer; |
|
135 |
|
136 TSize iFrameSize; |
|
137 TPtr8* iPtr; |
|
138 // Pre-opened thread object that is used for signalling the delayed |
|
139 // BufferEmptiedL() call |
|
140 RThread iThread; |
|
141 // Buffer to be released on next RunL() |
|
142 CMMFDataBuffer* iReleaseBuffer; |
|
143 }; |
|
144 |
|
145 /** |
|
146 * CVtCallback |
|
147 * |
|
148 * |
|
149 * @lib DisplaySink.lib |
|
150 */ |
|
151 NONSHARABLE_CLASS( CVtCallback ) : public CActive |
|
152 { |
|
153 |
|
154 private: |
|
155 |
|
156 /** |
|
157 * Callback type. Currently only size changes are supported. If new callback |
|
158 * types are needed, add them here. |
|
159 */ |
|
160 enum TCallBackType |
|
161 { |
|
162 EVideoFrameSizeChanged |
|
163 }; |
|
164 |
|
165 public: |
|
166 |
|
167 /** |
|
168 * C++ constructor. |
|
169 */ |
|
170 CVtCallback( MDisplaySinkObserver& aObserver ); |
|
171 |
|
172 /** |
|
173 * C++ destructor. |
|
174 */ |
|
175 ~CVtCallback(); |
|
176 |
|
177 /** |
|
178 * Video frame size has been changed. Old and new size are given as |
|
179 * parameter. |
|
180 */ |
|
181 void VideoFrameSizeChangedL( const TSize& aFrom, const TSize& aTo ); |
|
182 |
|
183 /** |
|
184 * Returns callback result. |
|
185 */ |
|
186 TInt Result() const; |
|
187 |
|
188 /** |
|
189 * Boolean variable that tells wether or not call back has been served. |
|
190 */ |
|
191 TBool Completed() const; |
|
192 |
|
193 private: |
|
194 |
|
195 /** |
|
196 * Issues callback. Because callback receiver can be in same or different |
|
197 * thread this is made as own function that checks whether or not other |
|
198 * thread needs to be signalled. |
|
199 */ |
|
200 void IssueCallbackL(); |
|
201 |
|
202 private: // from CActive |
|
203 |
|
204 /** |
|
205 * See CActive documentation. |
|
206 */ |
|
207 void RunL(); |
|
208 |
|
209 /** |
|
210 * See CActive documentation. |
|
211 */ |
|
212 void DoCancel(); |
|
213 |
|
214 /** |
|
215 * See CActive documentation. |
|
216 */ |
|
217 TInt RunError( TInt aError ); |
|
218 |
|
219 private: |
|
220 |
|
221 // Owner thread's id |
|
222 TThreadId iOwnThreadId; |
|
223 |
|
224 // Pointer to observer |
|
225 MDisplaySinkObserver* iObserver; |
|
226 |
|
227 // Callback type |
|
228 TCallBackType iCallBackType; |
|
229 |
|
230 // Old size |
|
231 TSize iFrom; |
|
232 |
|
233 // New size |
|
234 TSize iTo; |
|
235 |
|
236 // Callback result |
|
237 TInt iResult; |
|
238 |
|
239 // Has callback been completed? |
|
240 TBool iCompleted; |
|
241 }; |
|
242 |
|
243 |
|
244 /** |
|
245 * MVTVideoSink interface implementation |
|
246 * |
|
247 * @lib DisplaySink.lib |
|
248 */ |
|
249 NONSHARABLE_CLASS( CDisplaySink ) : public CBase, public MDisplaySink, |
|
250 public MVTVideoSink |
|
251 { |
|
252 protected: // inner classes |
|
253 |
|
254 // Structure containing bitmap related data |
|
255 class TBitmapEntry |
|
256 { |
|
257 public: // data |
|
258 |
|
259 // ETrue if this bitmap entry is free |
|
260 TBool iIsFree; |
|
261 }; |
|
262 |
|
263 private: // from MDisplaySink |
|
264 |
|
265 /** |
|
266 * @see MDisplaySink::Destroy |
|
267 */ |
|
268 void Destroy(); |
|
269 |
|
270 /** |
|
271 * @see MDisplaySink::SetBitmapAvailable |
|
272 */ |
|
273 void SetBitmapAvailable( TBitmapNo aBitmapNo ); |
|
274 |
|
275 /** |
|
276 * @see MDisplaySink::Release |
|
277 */ |
|
278 void Release(); |
|
279 |
|
280 /** |
|
281 * @see MDisplaySink::UpdateSinkParamsL |
|
282 */ |
|
283 void UpdateSinkParamsL( const TDisplaySinkParams& aParams, TBool& aUpdated ); |
|
284 |
|
285 /** |
|
286 * @see MDisplaySink::Pause |
|
287 */ |
|
288 void Pause(); |
|
289 |
|
290 /** |
|
291 * @see MDisplaySink::Resume |
|
292 */ |
|
293 void Resume(); |
|
294 |
|
295 /** |
|
296 * @see MDisplaySink::operator MVTVideoSink& |
|
297 */ |
|
298 operator MVTVideoSink&(); |
|
299 |
|
300 /** |
|
301 * @see MDisplaySink::NextFrame |
|
302 */ |
|
303 void NextFrame(); |
|
304 |
|
305 private: // from MVTVideoSink |
|
306 /** |
|
307 * From MVTVideoOutput. See MVTVideoOutput for description. |
|
308 */ |
|
309 virtual void SetFormatL( const TDesC8& aFormat ); |
|
310 |
|
311 /** |
|
312 * From MVTVideoOutput. See MVTVideoOutput for description. |
|
313 */ |
|
314 virtual void SetVideoFrameSizeL( const TSize& aSize ); |
|
315 |
|
316 /** |
|
317 * From MVTVideoOutput. See MVTVideoOutput for description. |
|
318 */ |
|
319 virtual void GetVideoFrameSizeL( TSize& aSize ) const; |
|
320 |
|
321 /** |
|
322 * From MVTVideoSink. See MVTVideoSink for description. |
|
323 */ |
|
324 virtual void EmptyBufferL( |
|
325 TVtMMFDataBuffer aDataBuffer, |
|
326 MVTVideoSource* aSupplier, |
|
327 TMediaId aMediaId ); |
|
328 |
|
329 /** |
|
330 * From MVTVideoSink. See MVTVideoSink for description. |
|
331 */ |
|
332 virtual void BufferFilledL( CMMFBuffer* aBuffer ); |
|
333 |
|
334 /** |
|
335 * From MVTVideoSink. See MVTVideoSink for description. |
|
336 */ |
|
337 virtual TBool CanCreateSinkBuffer(); |
|
338 |
|
339 /** |
|
340 * From MVTVideoSink. See MVTVideoSink for description. |
|
341 */ |
|
342 virtual CMMFBuffer* CreateSinkBufferL( |
|
343 TMediaId aMediaId, |
|
344 TBool &aReference ); |
|
345 |
|
346 /** |
|
347 * From MVTVideoSink. See MVTVideoSink for description. |
|
348 */ |
|
349 virtual TInt SinkThreadLogon( MAsyncEventHandler& aEventHandler ); |
|
350 |
|
351 /** |
|
352 * From MVTVideoSink. See MVTVideoSink for description. |
|
353 */ |
|
354 virtual void SinkThreadLogoff(); |
|
355 |
|
356 /** |
|
357 * From MVTVideoSink. See MVTVideoSink for description. |
|
358 */ |
|
359 virtual TInt SinkPrimeL(); |
|
360 |
|
361 /** |
|
362 * From MVTVideoSink. See MVTVideoSink for description. |
|
363 */ |
|
364 virtual TInt SinkPlayL(); |
|
365 |
|
366 /** |
|
367 * From MVTVideoSink. See MVTVideoSink for description. |
|
368 */ |
|
369 virtual TInt SinkPauseL(); |
|
370 |
|
371 /** |
|
372 * From MVTVideoSink. See MVTVideoSink for description. |
|
373 */ |
|
374 virtual TInt SinkStopL(); |
|
375 |
|
376 private: |
|
377 const RArray<TDesC8* >& GetMultimediaTypesL() const; |
|
378 |
|
379 |
|
380 protected: // Constructors and destructor |
|
381 |
|
382 /** |
|
383 * C++ default constructor. |
|
384 */ |
|
385 CDisplaySink(); |
|
386 |
|
387 /** |
|
388 * Destructor. |
|
389 */ |
|
390 ~CDisplaySink(); |
|
391 |
|
392 protected: // New functions |
|
393 |
|
394 /** |
|
395 * By default Symbian 2nd phase constructor is private. |
|
396 * @param "aParams" Initialization parameters. |
|
397 * @param "aInitData" Initialization parameters. Not used. |
|
398 * @exception Can leave with one of the system wide error codes. |
|
399 */ |
|
400 void ConstructL( TDisplaySinkParams& aParams, const TDesC8& aInitData ); |
|
401 |
|
402 /** |
|
403 * Thread logon that may leave. This will be trapped and possible |
|
404 * error code is returned to the caller of SinkThreadLogon(). |
|
405 * @exception Can leave with one of the system wide error codes. |
|
406 */ |
|
407 void SinkThreadLogonL(); |
|
408 |
|
409 /** |
|
410 * Sets limit for displaysink frame rate. |
|
411 */ |
|
412 void SetFrameRateLimit( |
|
413 TDisplaySinkParams::TFrameRateLimit aFrameRateLimit ); |
|
414 |
|
415 /** |
|
416 * Resets frame rate limitter. |
|
417 */ |
|
418 void ResetFrameRateLimitter(); |
|
419 |
|
420 /** |
|
421 * Does frame rate limitter validation and also checks if sink is paused. |
|
422 */ |
|
423 TBool IsOkToSendFrame(); |
|
424 |
|
425 /** |
|
426 * Opens fbs session and sets flag, if open succeeds. |
|
427 */ |
|
428 void FbsConnectL(); |
|
429 |
|
430 /** |
|
431 * Opens VT engine thread. |
|
432 */ |
|
433 void ThreadOpenL(); |
|
434 |
|
435 /** |
|
436 * Closes fbs session (if open succeeded earlier). |
|
437 */ |
|
438 void FbsDisconnect(); |
|
439 |
|
440 /** |
|
441 * Closes VT thread (if open succeeded earlier). |
|
442 */ |
|
443 void ThreadClose(); |
|
444 |
|
445 /** |
|
446 * Cleanup operation for SinkThradLogon. |
|
447 */ |
|
448 static void SinkThreadLogonCleanup( TAny* aPtr ); |
|
449 |
|
450 private: // new methods implemented in derived classes |
|
451 |
|
452 /** |
|
453 * Called from ConstructL() to allow inherited classes to do their own |
|
454 * construction. |
|
455 */ |
|
456 virtual void BaseConstructL( TDisplaySinkParams& aParams, |
|
457 const TDesC8& aInitData ) = 0; |
|
458 |
|
459 /** |
|
460 * Converts image. Calls DoConvertL() to do the task. |
|
461 * @return KErrNone or one of the system wide error codes. |
|
462 */ |
|
463 virtual TBool BaseConvert( const TVtMMFDataBuffer& aBuffer ) = 0; |
|
464 |
|
465 /** |
|
466 * Called from SinkThreadLogonL(). |
|
467 */ |
|
468 virtual void BaseSinkThreadLogonL() = 0; |
|
469 |
|
470 /** |
|
471 * Called from SinkThreadLogogg(). |
|
472 */ |
|
473 virtual void BaseSinkThreadLogoff() = 0; |
|
474 |
|
475 /** |
|
476 * Called from UpdateSinkParamsL(). |
|
477 */ |
|
478 virtual void BaseUpdateSinkParamsL( const TDisplaySinkParams& aParams ) = 0; |
|
479 |
|
480 /** |
|
481 * Updates sink params. |
|
482 * @exception May leave with one of the system wide error codes (e.g. in |
|
483 * out of memory situaton). |
|
484 */ |
|
485 virtual void BaseDoUpdateParamsL() = 0; |
|
486 |
|
487 /** |
|
488 * Called when video frame size is set. |
|
489 * @exception May leave with one of the system wide error codes (e.g. in |
|
490 * out of memory situaton). |
|
491 */ |
|
492 virtual void BaseSetVideoFrameSizeL( const TSize& aSize ) = 0; |
|
493 |
|
494 /** |
|
495 * Returns ETrue if given frame size matches with expected frame size. |
|
496 * Implemented in derived classes because in some cases (e.g. when rotation |
|
497 * is enabled), size calculation is more complicated. |
|
498 */ |
|
499 virtual TBool BaseSizesMatch( const TSize& aSize ) = 0; |
|
500 |
|
501 /** |
|
502 * Returns reference to TBitmapEntry. |
|
503 */ |
|
504 virtual TBitmapEntry& BitmapEntry( TInt aIndex ) = 0; |
|
505 |
|
506 /** |
|
507 * EmptyBuffer handling. |
|
508 */ |
|
509 virtual void BaseEmptyBufferL( TVtMMFDataBuffer& aVTMMFBuffer ) = 0; |
|
510 |
|
511 /** |
|
512 * Bitmap availability handling. |
|
513 */ |
|
514 virtual void BaseSetBitmapAvailable( TBitmapNo aBitmapNo ) = 0; |
|
515 |
|
516 /** |
|
517 * Called when source frame size changes. |
|
518 */ |
|
519 virtual void BaseVideoFrameSizeChangedL( const TSize& aNewSize ) = 0; |
|
520 |
|
521 protected: // Data |
|
522 |
|
523 // Video source that provides buffer filled with video frame(s) |
|
524 MVTVideoSource* iSupplier; |
|
525 |
|
526 // Event handler to notify events |
|
527 MAsyncEventHandler* iEventHandler; |
|
528 |
|
529 // Buffer containing video frame(s) and to be converted |
|
530 CMMFBuffer* iBuffer; |
|
531 |
|
532 // Sink data type code as fourCC code |
|
533 TFourCC iSinkFourCC; |
|
534 |
|
535 // Sink state enumeration |
|
536 enum TState |
|
537 { |
|
538 EStopped, |
|
539 EPrimed, |
|
540 EPlaying |
|
541 }; |
|
542 |
|
543 // Sink state |
|
544 TState iState; |
|
545 |
|
546 // Array of MIME types supported by sink |
|
547 RArray<TDesC8* > iVTMimeTypes; |
|
548 |
|
549 // Video frame size |
|
550 TSize iFrameSize; |
|
551 |
|
552 // Thread ID of thread to notify after video frame is converted |
|
553 TThreadId iThreadId; |
|
554 |
|
555 // Handle to thread to notify after video frame is converted |
|
556 RThread iThread; |
|
557 |
|
558 // Pointer to iStatus member of the Active Object to notify |
|
559 // after video frame is converted |
|
560 TRequestStatus* iRequestStatusPtr; |
|
561 |
|
562 // Critical section to serialize access to iBitmapTable |
|
563 RCriticalSection iBitmapCS; |
|
564 |
|
565 // Semaphore to force thread context switch after video frame |
|
566 // is converted |
|
567 RSemaphore iSync; |
|
568 |
|
569 |
|
570 // This is set to ETrue when new params are set, this pointer |
|
571 // is also used as flag when parameter update is requested. |
|
572 TBool* iParamsUpdated; |
|
573 |
|
574 // This flag variable will be set to ETrue when sink parameters |
|
575 // need to be updated (e.g. when frame size changes from QCIF |
|
576 // to Sub QCIF or vice versa) |
|
577 TBool iWaitingForUpdate; |
|
578 |
|
579 // Contains expected frame size (this is taken from given bitmaps). |
|
580 TSize iExpectedFrameSize; |
|
581 |
|
582 // Active object that will call callbacks to VT engine in VT |
|
583 // engine's thread context. |
|
584 CVtCallback* iVTSignaller; |
|
585 |
|
586 // If ETrue, sink does not convert data that is given to it |
|
587 TBool iReleased; |
|
588 |
|
589 // Output MIME type holder |
|
590 TBuf8< 128 > iYuv420PlanarDesc; |
|
591 |
|
592 // Frame rate interval in milliseconds |
|
593 TInt iFrameRateInterval; |
|
594 |
|
595 // Time since last frame was sent (in milliseconds) |
|
596 TInt iMilliSecondsSinceLastFrame; |
|
597 |
|
598 // Time stamp for last frame sent |
|
599 TTime iLastFrameTime; |
|
600 |
|
601 // When paused remote video will no be sent to VT engine |
|
602 TBool iPaused; |
|
603 |
|
604 // DisplaySink params flags |
|
605 TUint32 iDSFlags; |
|
606 |
|
607 // Is set to ETrue when SinkThreadLogon() is called. |
|
608 TUint32 iInitFlags; |
|
609 |
|
610 // Initialization flags |
|
611 enum TInitFlags |
|
612 { |
|
613 // This flag is set, when SinkThreadLogon() is called |
|
614 ESinkThreadLogonCalled = ( 1 << 0 ), |
|
615 |
|
616 // This flag is set, when FbsSession has been connected |
|
617 EFbsSessionConnected = ( 1 << 1 ), |
|
618 |
|
619 // This flag is set, when handle to Sink Thread has been opened |
|
620 EThreadOpened = ( 1 << 2 ) |
|
621 }; |
|
622 |
|
623 // Frame queue for holding for holding frames until target conversion |
|
624 // buffer is ready. |
|
625 CVtFrameQueue* iVideoFrameQueue; |
|
626 |
|
627 // friend classes |
|
628 |
|
629 |
|
630 }; |
|
631 |
|
632 /** |
|
633 * Safe cleanup for synchronization primitives. |
|
634 * |
|
635 * @lib DisplaySink.lib |
|
636 */ |
|
637 template < class T > |
|
638 class CleanupSignal |
|
639 { |
|
640 public: |
|
641 static void PushL( T& aPtr ); |
|
642 private: |
|
643 static void Signal( TAny *aPtr ); |
|
644 }; |
|
645 |
|
646 template < class T > |
|
647 void CleanupSignal< T >::PushL( T& aRef ) |
|
648 { |
|
649 CleanupStack::PushL( TCleanupItem( &Signal, &aRef ) ); |
|
650 } |
|
651 |
|
652 template < class T > |
|
653 void CleanupSignal< T >::Signal( TAny *aPtr ) |
|
654 { |
|
655 static_cast< T* >( aPtr )->Signal(); |
|
656 } |
|
657 |
|
658 /** |
|
659 * Pushes signalable object into cleanup stack. |
|
660 */ |
|
661 template < class T > |
|
662 void CleanupSignalPushL( T& aRef ) |
|
663 { |
|
664 CleanupSignal< T >::PushL( aRef ); |
|
665 } |
|
666 |
|
667 #endif // CDISPLAYSINK_H |
|
668 |
|
669 // End of File |
|
670 |
|
671 |