omxil_generic/omxilcomplib/src/omxilcallbackmanager.h
changeset 0 0e4a32b9112d
child 5 fb6faddbb212
equal deleted inserted replaced
-1:000000000000 0:0e4a32b9112d
       
     1 // Copyright (c) 2008-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 
       
    17 /**
       
    18  @file
       
    19  @internalComponent
       
    20 */
       
    21 
       
    22 #ifndef OMXILCALLBACKMANAGER_H
       
    23 #define OMXILCALLBACKMANAGER_H
       
    24 
       
    25 #include <e32base.h>
       
    26 
       
    27 #include "omxilcallbackmanagerif.h"
       
    28 #include "omxilcallbackmanagerifimpl.h"
       
    29 #include "primsgqueue.h"
       
    30 
       
    31 
       
    32 /**
       
    33    Call Back Manager Panic category
       
    34 */
       
    35 _LIT(KOmxILCallbackManagerPanicCategory, "OmxILCallbackManager");
       
    36 
       
    37 
       
    38 /**
       
    39    OpenMAX IL call backs and buffer marks manager. This is an asynchronous
       
    40    implementation of MOmxILCallbackManagerIf.  It keeps and manages the IL
       
    41    Client callback information as well as the buffer mark propagation info.
       
    42 
       
    43  */
       
    44 NONSHARABLE_CLASS(COmxILCallbackManager) :
       
    45 	public CActive,
       
    46 	public MOmxILCallbackManagerIf,
       
    47 	private XOmxILCallbackManagerIfImpl
       
    48 	{
       
    49 
       
    50 	// Declaration of nested private command classes
       
    51 	class CCallbackCommand;
       
    52 	class CCompHandleRegistrationCommand;
       
    53 	class CClientCallbacksRegistrationCommand;
       
    54 	class CTunnelCallbackRegistrationCommand;
       
    55 	class CBufferMarkPropagationRegistrationCommand;
       
    56 	class CBufferRemovalCommand;
       
    57 	class CEventCallbackCommand;
       
    58 	class CBufferDoneCallbackCommand;
       
    59 	class CPortSettingsChangeCommand;
       
    60 #ifdef _OMXIL_COMMON_IL516C_ON
       
    61 	class CEjectBuffersRequestCommand;
       
    62 #endif
       
    63 	// Note that the following friends don't break COmxILCallbackManager's
       
    64 	// interface as all friends below are COmxILCallbackManager's private
       
    65 	// nested classes and therefore they are logically part of
       
    66 	// COmxILCallbackManager implementation
       
    67 	friend class CCompHandleRegistrationCommand;
       
    68 	friend class CClientCallbacksRegistrationCommand;
       
    69 	friend class CTunnelCallbackRegistrationCommand;
       
    70 	friend class CBufferMarkPropagationRegistrationCommand;
       
    71 	friend class CBufferRemovalCommand;
       
    72 	friend class CEventCallbackCommand;
       
    73 	friend class CBufferDoneCallbackCommand;
       
    74 	friend class CPortSettingsChangeCommand;
       
    75 #ifdef _OMXIL_COMMON_IL516C_ON
       
    76 	friend class CEjectBuffersRequestCommand;
       
    77 #endif
       
    78 
       
    79 public:
       
    80 
       
    81 	static COmxILCallbackManager* NewL(
       
    82 		OMX_HANDLETYPE apComponentHandle,
       
    83 		OMX_PTR apAppData,
       
    84 		OMX_CALLBACKTYPE* apCallbacks);
       
    85 
       
    86 	~COmxILCallbackManager();
       
    87 
       
    88 	void SetPortManager(MOmxILPortManagerIf& apPortManager);
       
    89 
       
    90 	void SetFsm(COmxILFsm& apFsm);
       
    91 
       
    92 
       
    93 	//
       
    94 	// Methods for Callback Registration (from MOmxILCallbackManagerIf)
       
    95 	//
       
    96 
       
    97 	OMX_ERRORTYPE RegisterComponentHandle(
       
    98 		OMX_HANDLETYPE aComponentHandle);
       
    99 
       
   100 	OMX_ERRORTYPE RegisterILClientCallbacks(
       
   101 		const OMX_CALLBACKTYPE* apCallbacks,
       
   102 		const OMX_PTR apAppData);
       
   103 
       
   104 	OMX_ERRORTYPE RegisterTunnelCallback(
       
   105 		OMX_U32 aLocalPortIndex,
       
   106 		OMX_DIRTYPE aLocalPortDirection,
       
   107 		OMX_HANDLETYPE aTunnelledComponentHandle,
       
   108 		OMX_U32 aTunnelledPortIndex
       
   109 		);
       
   110 
       
   111 	OMX_ERRORTYPE DeregisterTunnelCallback(
       
   112 		OMX_U32 aLocalPortIndex);
       
   113 
       
   114 	OMX_ERRORTYPE RegisterBufferMarkPropagationPort(
       
   115 		OMX_U32 aPortIndex,
       
   116 		OMX_U32 aPropagationPortIndex);
       
   117 
       
   118 	TBool BufferRemovalIndication(
       
   119 		OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   120 		OMX_DIRTYPE aDirection);
       
   121 
       
   122 
       
   123 	//
       
   124 	// Methods for Callback Notification (from MOmxILCallbackManagerIf)
       
   125 	//
       
   126 
       
   127 	OMX_ERRORTYPE TransitionCompleteNotification(
       
   128 		OMX_STATETYPE aOmxState);
       
   129 
       
   130 	OMX_ERRORTYPE CommandCompleteNotification(
       
   131 		OMX_COMMANDTYPE aOmxCommand,
       
   132 		OMX_U32 aOmxPortIndex);
       
   133 
       
   134 #ifdef _OMXIL_COMMON_IL516C_ON
       
   135 	OMX_ERRORTYPE EjectBuffersRequest(
       
   136 		OMX_U32 aLocalOmxPortIndex);
       
   137 #endif
       
   138 
       
   139 	//
       
   140 	// Methods for Callback Notification (from MOmxILCallbackManagerIf)
       
   141 	//
       
   142 
       
   143 	OMX_ERRORTYPE ErrorEventNotification(
       
   144 		OMX_ERRORTYPE aOmxError);
       
   145 
       
   146 	OMX_ERRORTYPE EventNotification(
       
   147 		OMX_EVENTTYPE aEvent,
       
   148 		TUint32 aData1,
       
   149 		TUint32 aData2,
       
   150 		OMX_STRING aExtraInfo);
       
   151 
       
   152 	OMX_ERRORTYPE BufferDoneNotification(
       
   153 		OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   154 		OMX_U32 aLocalPortIndex,
       
   155 		OMX_DIRTYPE aLocalPortDirection);
       
   156 
       
   157 	OMX_ERRORTYPE ClockBufferDoneNotification(
       
   158 		OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   159 		OMX_U32 aLocalPortIndex,
       
   160 		OMX_DIRTYPE aLocalPortDirection);
       
   161 
       
   162 	OMX_ERRORTYPE PortSettingsChangeNotification(
       
   163 		OMX_U32 aLocalPortIndex,
       
   164 		TUint aPortSettingsIndex,
       
   165 		const TDesC8& aPortSettings);
       
   166 
       
   167 	//
       
   168 	// From CActive
       
   169 	//
       
   170 private:	
       
   171 	void RunL();
       
   172 	void DoCancel();
       
   173 
       
   174 private:
       
   175 
       
   176 	// Convenience typedef
       
   177 	typedef RPriMsgQueue<CCallbackCommand*> RCbCmdPriQue;
       
   178 
       
   179 	/**
       
   180 	   COmxILCallbackManager's priority-based command queue.
       
   181 
       
   182 	   This queue is based on RPriMsgQueue but it is specialized to support the
       
   183 	   search and deletion of Buffer Done Callback Commands using some specific
       
   184 	   search criteria like buffer headers or port indexes.
       
   185 	 */
       
   186 	class RCallbackManagerQueue : public RCbCmdPriQue
       
   187 		{
       
   188 
       
   189 	public:
       
   190 
       
   191 		TBool RemoveBufferDoneCbCommandsByBufferHeader(
       
   192 			COmxILCallbackManager& aCbMgr,
       
   193 			const OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   194 			OMX_DIRTYPE aDirection);
       
   195 
       
   196 		TBool RemoveBufferDoneCbCommandsByPortIndex(
       
   197 			COmxILCallbackManager& aCbMgr,
       
   198 			OMX_U32 aLocalPortIndex);
       
   199 
       
   200 		TBool ExecuteBufferDoneCbCommandsByPortIndex(
       
   201 			COmxILCallbackManager& aCbMgr,
       
   202 			OMX_U32 aLocalPortIndex);
       
   203 
       
   204 
       
   205     };
       
   206 
       
   207 private:
       
   208 
       
   209 	static const TInt KMaxMsgQueueEntries = 30;
       
   210 
       
   211 private:
       
   212 
       
   213 	COmxILCallbackManager(OMX_HANDLETYPE apComponentHandle,
       
   214 						  OMX_PTR apAppData,
       
   215 						  OMX_CALLBACKTYPE* apCallbacks);
       
   216 	void ConstructL();
       
   217 
       
   218 
       
   219 	OMX_ERRORTYPE SendBufferDoneNotification(
       
   220 		OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   221 		OMX_U32 aLocalPortIndex,
       
   222 		OMX_DIRTYPE aLocalPortDirection,
       
   223 		TInt aPriority);
       
   224 
       
   225 	void ProcessQueue(RCallbackManagerQueue& aQueue);
       
   226 
       
   227 	void CleanUpQueue(RCallbackManagerQueue& aQueue);
       
   228 	
       
   229 	OMX_ERRORTYPE EventNotificationImpl(
       
   230 		OMX_EVENTTYPE aEvent,
       
   231 		TUint32 aData1,
       
   232 		TUint32 aData2,
       
   233 		OMX_STRING aExtraInfo);
       
   234 
       
   235 private:
       
   236 
       
   237 	// COmxILCallbackManager priority queue.
       
   238 	RCallbackManagerQueue iCommandQueue;
       
   239 
       
   240 	// Queue of buffer done notifications that need to be queued during
       
   241 	// OMX_StatePaused state
       
   242 	RCallbackManagerQueue iPendingQueue;
       
   243 
       
   244 	// Flag to enable unconditional flushing of buffer done notifications
       
   245 	TBool iFlushPendingQueue;
       
   246 
       
   247 	OMX_STATETYPE iCurrentState;
       
   248 	OMX_STATETYPE iPreviousState;
       
   249 
       
   250 	};
       
   251 
       
   252 
       
   253 //
       
   254 // COmxILCallbackManager nested classes
       
   255 //
       
   256 
       
   257 /**
       
   258   Abstract Callback Manager's command class.
       
   259  */
       
   260 class COmxILCallbackManager::CCallbackCommand : public CBase
       
   261 	{
       
   262 
       
   263 public:
       
   264 
       
   265 	enum TCommandPriority
       
   266 		{
       
   267 		EPriorityLow,
       
   268 		EPriorityNormal,
       
   269 		EPriorityHigh,
       
   270 		EPriorityVeryHigh
       
   271 		};
       
   272 
       
   273 public:
       
   274 
       
   275 	inline CCallbackCommand(TInt aPriority);
       
   276 
       
   277 	/**
       
   278 	   Operator() method that must be implemented to perform the specific
       
   279 	   command logic.
       
   280 
       
   281 	   @param [in] aCbMgr The Callback Manager object used as context to the
       
   282 	   command operation
       
   283 	*/
       
   284 	virtual void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred) = 0;
       
   285 
       
   286 	virtual TBool DoRemoveBufferDoneCbCommandByBufferHeader(
       
   287 		COmxILCallbackManager& aCbMgr,
       
   288 		const OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   289 		OMX_DIRTYPE aDirection);
       
   290 
       
   291 	virtual TBool DoRemoveBufferDoneCbCommandByPortIndex(
       
   292 		COmxILCallbackManager& aCbMgr,
       
   293 		OMX_U32 aLocalPortIndex);
       
   294 
       
   295 	virtual TBool DoExecuteBufferDoneCbCommandByPortIndex(
       
   296 		COmxILCallbackManager& aCbMgr,
       
   297 		OMX_U32 aLocalPortIndex);
       
   298 
       
   299 	inline TInt Priority();
       
   300 
       
   301 public:
       
   302 
       
   303 	TInt iPriority;
       
   304 
       
   305 	};
       
   306 
       
   307 /**
       
   308   Callback Manager's command class for registering component handles.
       
   309  */
       
   310 class COmxILCallbackManager::CCompHandleRegistrationCommand :
       
   311 	public COmxILCallbackManager::CCallbackCommand
       
   312 	{
       
   313 
       
   314 public:
       
   315 
       
   316 	inline CCompHandleRegistrationCommand(OMX_HANDLETYPE aComponentHandle);
       
   317 
       
   318 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   319 
       
   320 private:
       
   321 
       
   322 	OMX_COMPONENTTYPE* ipHandle; // Not owned
       
   323 
       
   324 	};
       
   325 
       
   326 /**
       
   327   Callback Manager's command class for registering IL Client callbacks .
       
   328  */
       
   329 class COmxILCallbackManager::CClientCallbacksRegistrationCommand :
       
   330 	public COmxILCallbackManager::CCallbackCommand
       
   331 	{
       
   332 
       
   333 public:
       
   334 
       
   335 	inline CClientCallbacksRegistrationCommand(
       
   336 		const OMX_CALLBACKTYPE*& apCallbacks,
       
   337 		const OMX_PTR& apAppData);
       
   338 
       
   339 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   340 
       
   341 private:
       
   342 
       
   343 	const OMX_CALLBACKTYPE* ipCallbacks; // not owned
       
   344 	const OMX_PTR ipAppData; // not owned
       
   345 
       
   346 	};
       
   347 
       
   348 /**
       
   349   Callback Manager's command class for registering tunnel callbacks.
       
   350  */
       
   351 class COmxILCallbackManager::CTunnelCallbackRegistrationCommand :
       
   352 	public COmxILCallbackManager::CCallbackCommand
       
   353 	{
       
   354 
       
   355 public:
       
   356 
       
   357 	inline CTunnelCallbackRegistrationCommand(
       
   358 		OMX_U32 aLocalPortIndex,
       
   359 		OMX_DIRTYPE aLocalPortDirection,
       
   360 		OMX_HANDLETYPE aTunnelledComponentHandle,
       
   361 		OMX_U32 aTunnelledPortIndex);
       
   362 
       
   363 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   364 
       
   365 
       
   366 public:
       
   367 
       
   368 	TTunnelRegistrationInfo iTunnelInfo;
       
   369 
       
   370 	};
       
   371 
       
   372 /**
       
   373   Callback Manager's command class for registering buffer marks info .
       
   374  */
       
   375 class COmxILCallbackManager::CBufferMarkPropagationRegistrationCommand :
       
   376 	public COmxILCallbackManager::CCallbackCommand
       
   377 	{
       
   378 
       
   379 public:
       
   380 
       
   381 	inline CBufferMarkPropagationRegistrationCommand(
       
   382 		OMX_U32 aPortIndex,
       
   383 		OMX_U32 aPropagationPortIndex);
       
   384 
       
   385 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   386 
       
   387 public:
       
   388 
       
   389 	TBufferMarkPropagationInfo iMarkPropagationInfo;
       
   390 
       
   391 	};
       
   392 
       
   393 /**
       
   394   Callback Manager's command class for buffer header removal.
       
   395  */
       
   396 class COmxILCallbackManager::CBufferRemovalCommand :
       
   397 	public COmxILCallbackManager::CCallbackCommand
       
   398 	{
       
   399 
       
   400 public:
       
   401 
       
   402 	inline CBufferRemovalCommand(
       
   403 		OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   404 		OMX_DIRTYPE aDirection);
       
   405 
       
   406 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   407 
       
   408 public:
       
   409 
       
   410 	OMX_BUFFERHEADERTYPE* ipBufferHeader;
       
   411 	OMX_DIRTYPE iDirection;
       
   412 
       
   413 	};
       
   414 
       
   415 /**
       
   416   Callback Manager's command class for notification of OpenMAX IL events .
       
   417  */
       
   418 class COmxILCallbackManager::CEventCallbackCommand :
       
   419 	public COmxILCallbackManager::CCallbackCommand
       
   420 	{
       
   421 
       
   422 public:
       
   423 
       
   424 	inline CEventCallbackCommand(OMX_EVENTTYPE aEvent,
       
   425 								 TUint32 aData1,
       
   426 								 TUint32 aData2,
       
   427 								 OMX_STRING aExtraInfo);
       
   428 
       
   429 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   430 
       
   431 private:
       
   432 
       
   433 	OMX_EVENTTYPE iEvent;
       
   434 	TUint32 iData1;
       
   435 	TUint32 iData2;
       
   436 	OMX_STRING iExtraInfo;
       
   437 
       
   438 	};
       
   439 
       
   440 /**
       
   441   Callback Manager's command class for notification of buffer done events .
       
   442  */
       
   443 class COmxILCallbackManager::CBufferDoneCallbackCommand :
       
   444 	public COmxILCallbackManager::CCallbackCommand
       
   445 	{
       
   446 
       
   447 public:
       
   448 
       
   449 	inline CBufferDoneCallbackCommand(OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   450 									  OMX_U32 aLocalPortIndex,
       
   451 									  OMX_DIRTYPE aLocalPortDirection,
       
   452 									  TInt aPriority = CCallbackCommand::EPriorityNormal);
       
   453 
       
   454 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   455 
       
   456 	TBool DoRemoveBufferDoneCbCommandByBufferHeader(
       
   457 		COmxILCallbackManager& aCbMgr,
       
   458 		const OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   459 		OMX_DIRTYPE aDirection);
       
   460 
       
   461 	TBool DoRemoveBufferDoneCbCommandByPortIndex(
       
   462 		COmxILCallbackManager& aCbMgr,
       
   463 		OMX_U32 aLocalPortIndex);
       
   464 
       
   465 	TBool DoExecuteBufferDoneCbCommandByPortIndex(
       
   466 		COmxILCallbackManager& aCbMgr,
       
   467 		OMX_U32 aLocalPortIndex);
       
   468 
       
   469 private:
       
   470 
       
   471 	OMX_BUFFERHEADERTYPE* ipBufferHeader; // not owned
       
   472 	OMX_U32 iLocalPortIndex;
       
   473 	OMX_DIRTYPE iLocalPortDirection;
       
   474 
       
   475 	};
       
   476 
       
   477 /**
       
   478   Callback Manager's command class for notification of port settings change
       
   479   events .
       
   480  */
       
   481 class COmxILCallbackManager::CPortSettingsChangeCommand :
       
   482 	public COmxILCallbackManager::CCallbackCommand
       
   483 	{
       
   484 
       
   485 public:
       
   486 
       
   487 	inline CPortSettingsChangeCommand(OMX_U32 aLocalPortIndex,
       
   488 									  TUint aPortSettingsIndex,
       
   489 									  HBufC8*& apPortSettings);
       
   490 
       
   491 	~CPortSettingsChangeCommand();
       
   492 
       
   493 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   494 
       
   495 private:
       
   496 
       
   497 	OMX_U32 iLocalPortIndex;
       
   498 	TUint iPortSettingsIndex;
       
   499 	HBufC8* ipPortSettings; // This is owned by this class
       
   500 
       
   501 	};
       
   502 
       
   503 #ifdef _OMXIL_COMMON_IL516C_ON
       
   504 /**
       
   505   Callback Manager's command class for requesting buffer ejection from tunnelled component.
       
   506  */
       
   507 class COmxILCallbackManager::CEjectBuffersRequestCommand :
       
   508 	public COmxILCallbackManager::CCallbackCommand
       
   509 	{
       
   510 
       
   511 public:
       
   512 
       
   513 	inline CEjectBuffersRequestCommand(OMX_U32 aLocalOmxPortIndex);
       
   514 
       
   515 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   516 
       
   517 private:
       
   518 
       
   519 	OMX_U32 iLocalOmxPortIndex;
       
   520 
       
   521 	};
       
   522 #endif
       
   523 
       
   524 
       
   525 #include "omxilcallbackmanager.inl"
       
   526 
       
   527 #endif // OMXILCALLBACKMANAGER_H