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