omxil/omxilcomponentcommon/src/common/omxilcallbackmanager.h
changeset 56 b6488ac24ddc
parent 47 481b3bce574a
child 57 1cbb0d5bf7f2
equal deleted inserted replaced
47:481b3bce574a 56:b6488ac24ddc
     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 private:
       
   161 	void RunL();
       
   162 	void DoCancel();
       
   163 
       
   164 private:
       
   165 
       
   166 	// Convenience typedef
       
   167 	typedef RPriMsgQueue<CCallbackCommand*> RCbCmdPriQue;
       
   168 
       
   169 	/**
       
   170 	   COmxILCallbackManager's priority-based command queue.
       
   171 
       
   172 	   This queue is based on RPriMsgQueue but it is specialized to support the
       
   173 	   search and deletion of Buffer Done Callback Commands using some specific
       
   174 	   search criteria like buffer headers or port indexes.
       
   175 	 */
       
   176 	class RCallbackManagerQueue : public RCbCmdPriQue
       
   177 		{
       
   178 
       
   179 	public:
       
   180 
       
   181 		TBool RemoveBufferDoneCbCommandsByBufferHeader(
       
   182 			COmxILCallbackManager& aCbMgr,
       
   183 			const OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   184 			OMX_DIRTYPE aDirection);
       
   185 
       
   186 		TBool RemoveBufferDoneCbCommandsByPortIndex(
       
   187 			COmxILCallbackManager& aCbMgr,
       
   188 			OMX_U32 aLocalPortIndex);
       
   189 
       
   190 		TBool ExecuteBufferDoneCbCommandsByPortIndex(
       
   191 			COmxILCallbackManager& aCbMgr,
       
   192 			OMX_U32 aLocalPortIndex);
       
   193 
       
   194 
       
   195     };
       
   196 
       
   197 private:
       
   198 
       
   199 	static const TInt KMaxMsgQueueEntries = 30;
       
   200 
       
   201 private:
       
   202 
       
   203 	COmxILCallbackManager(OMX_HANDLETYPE apComponentHandle,
       
   204 						  OMX_PTR apAppData,
       
   205 						  OMX_CALLBACKTYPE* apCallbacks);
       
   206 	void ConstructL();
       
   207 
       
   208 
       
   209 	OMX_ERRORTYPE SendBufferDoneNotification(
       
   210 		OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   211 		OMX_U32 aLocalPortIndex,
       
   212 		OMX_DIRTYPE aLocalPortDirection,
       
   213 		TInt aPriority);
       
   214 
       
   215 	void ProcessQueue(RCallbackManagerQueue& aQueue);
       
   216 
       
   217 	void CleanUpQueue(RCallbackManagerQueue& aQueue);
       
   218 	
       
   219 	OMX_ERRORTYPE EventNotificationImpl(
       
   220 		OMX_EVENTTYPE aEvent,
       
   221 		TUint32 aData1,
       
   222 		TUint32 aData2,
       
   223 		OMX_STRING aExtraInfo);
       
   224 
       
   225 private:
       
   226 
       
   227 	// COmxILCallbackManager priority queue.
       
   228 	RCallbackManagerQueue iCommandQueue;
       
   229 
       
   230 	// Queue of buffer done notifications that need to be queued during
       
   231 	// OMX_StatePaused state
       
   232 	RCallbackManagerQueue iPendingQueue;
       
   233 
       
   234 	// Flag to enable unconditional flushing of buffer done notifications
       
   235 	TBool iFlushPendingQueue;
       
   236 
       
   237 	OMX_STATETYPE iCurrentState;
       
   238 	OMX_STATETYPE iPreviousState;
       
   239 
       
   240 	};
       
   241 
       
   242 
       
   243 //
       
   244 // COmxILCallbackManager nested classes
       
   245 //
       
   246 
       
   247 /**
       
   248   Abstract Callback Manager's command class.
       
   249  */
       
   250 class COmxILCallbackManager::CCallbackCommand : public CBase
       
   251 	{
       
   252 
       
   253 public:
       
   254 
       
   255 	enum TCommandPriority
       
   256 		{
       
   257 		EPriorityLow,
       
   258 		EPriorityNormal,
       
   259 		EPriorityHigh,
       
   260 		EPriorityVeryHigh
       
   261 		};
       
   262 
       
   263 public:
       
   264 
       
   265 	inline CCallbackCommand(TInt aPriority);
       
   266 
       
   267 	/**
       
   268 	   Operator() method that must be implemented to perform the specific
       
   269 	   command logic.
       
   270 
       
   271 	   @param [in] aCbMgr The Callback Manager object used as context to the
       
   272 	   command operation
       
   273 	*/
       
   274 	virtual void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred) = 0;
       
   275 
       
   276 	virtual TBool DoRemoveBufferDoneCbCommandByBufferHeader(
       
   277 		COmxILCallbackManager& aCbMgr,
       
   278 		const OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   279 		OMX_DIRTYPE aDirection);
       
   280 
       
   281 	virtual TBool DoRemoveBufferDoneCbCommandByPortIndex(
       
   282 		COmxILCallbackManager& aCbMgr,
       
   283 		OMX_U32 aLocalPortIndex);
       
   284 
       
   285 	virtual TBool DoExecuteBufferDoneCbCommandByPortIndex(
       
   286 		COmxILCallbackManager& aCbMgr,
       
   287 		OMX_U32 aLocalPortIndex);
       
   288 
       
   289 	inline TInt Priority();
       
   290 
       
   291 public:
       
   292 
       
   293 	TInt iPriority;
       
   294 
       
   295 	};
       
   296 
       
   297 /**
       
   298   Callback Manager's command class for registering component handles.
       
   299  */
       
   300 class COmxILCallbackManager::CCompHandleRegistrationCommand :
       
   301 	public COmxILCallbackManager::CCallbackCommand
       
   302 	{
       
   303 
       
   304 public:
       
   305 
       
   306 	inline CCompHandleRegistrationCommand(OMX_HANDLETYPE aComponentHandle);
       
   307 
       
   308 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   309 
       
   310 private:
       
   311 
       
   312 	OMX_COMPONENTTYPE* ipHandle; // Not owned
       
   313 
       
   314 	};
       
   315 
       
   316 /**
       
   317   Callback Manager's command class for registering IL Client callbacks .
       
   318  */
       
   319 class COmxILCallbackManager::CClientCallbacksRegistrationCommand :
       
   320 	public COmxILCallbackManager::CCallbackCommand
       
   321 	{
       
   322 
       
   323 public:
       
   324 
       
   325 	inline CClientCallbacksRegistrationCommand(
       
   326 		const OMX_CALLBACKTYPE*& apCallbacks,
       
   327 		const OMX_PTR& apAppData);
       
   328 
       
   329 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   330 
       
   331 private:
       
   332 
       
   333 	const OMX_CALLBACKTYPE* ipCallbacks; // not owned
       
   334 	const OMX_PTR ipAppData; // not owned
       
   335 
       
   336 	};
       
   337 
       
   338 /**
       
   339   Callback Manager's command class for registering tunnel callbacks.
       
   340  */
       
   341 class COmxILCallbackManager::CTunnelCallbackRegistrationCommand :
       
   342 	public COmxILCallbackManager::CCallbackCommand
       
   343 	{
       
   344 
       
   345 public:
       
   346 
       
   347 	inline CTunnelCallbackRegistrationCommand(
       
   348 		OMX_U32 aLocalPortIndex,
       
   349 		OMX_DIRTYPE aLocalPortDirection,
       
   350 		OMX_HANDLETYPE aTunnelledComponentHandle,
       
   351 		OMX_U32 aTunnelledPortIndex);
       
   352 
       
   353 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   354 
       
   355 
       
   356 public:
       
   357 
       
   358 	TTunnelRegistrationInfo iTunnelInfo;
       
   359 
       
   360 	};
       
   361 
       
   362 /**
       
   363   Callback Manager's command class for registering buffer marks info .
       
   364  */
       
   365 class COmxILCallbackManager::CBufferMarkPropagationRegistrationCommand :
       
   366 	public COmxILCallbackManager::CCallbackCommand
       
   367 	{
       
   368 
       
   369 public:
       
   370 
       
   371 	inline CBufferMarkPropagationRegistrationCommand(
       
   372 		OMX_U32 aPortIndex,
       
   373 		OMX_U32 aPropagationPortIndex);
       
   374 
       
   375 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   376 
       
   377 public:
       
   378 
       
   379 	TBufferMarkPropagationInfo iMarkPropagationInfo;
       
   380 
       
   381 	};
       
   382 
       
   383 /**
       
   384   Callback Manager's command class for buffer header removal.
       
   385  */
       
   386 class COmxILCallbackManager::CBufferRemovalCommand :
       
   387 	public COmxILCallbackManager::CCallbackCommand
       
   388 	{
       
   389 
       
   390 public:
       
   391 
       
   392 	inline CBufferRemovalCommand(
       
   393 		OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   394 		OMX_DIRTYPE aDirection);
       
   395 
       
   396 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   397 
       
   398 public:
       
   399 
       
   400 	OMX_BUFFERHEADERTYPE* ipBufferHeader;
       
   401 	OMX_DIRTYPE iDirection;
       
   402 
       
   403 	};
       
   404 
       
   405 /**
       
   406   Callback Manager's command class for notification of OpenMAX IL events .
       
   407  */
       
   408 class COmxILCallbackManager::CEventCallbackCommand :
       
   409 	public COmxILCallbackManager::CCallbackCommand
       
   410 	{
       
   411 
       
   412 public:
       
   413 
       
   414 	inline CEventCallbackCommand(OMX_EVENTTYPE aEvent,
       
   415 								 TUint32 aData1,
       
   416 								 TUint32 aData2,
       
   417 								 OMX_STRING aExtraInfo);
       
   418 
       
   419 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   420 
       
   421 private:
       
   422 
       
   423 	OMX_EVENTTYPE iEvent;
       
   424 	TUint32 iData1;
       
   425 	TUint32 iData2;
       
   426 	OMX_STRING iExtraInfo;
       
   427 
       
   428 	};
       
   429 
       
   430 /**
       
   431   Callback Manager's command class for notification of buffer done events .
       
   432  */
       
   433 class COmxILCallbackManager::CBufferDoneCallbackCommand :
       
   434 	public COmxILCallbackManager::CCallbackCommand
       
   435 	{
       
   436 
       
   437 public:
       
   438 
       
   439 	inline CBufferDoneCallbackCommand(OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   440 									  OMX_U32 aLocalPortIndex,
       
   441 									  OMX_DIRTYPE aLocalPortDirection,
       
   442 									  TInt aPriority = CCallbackCommand::EPriorityNormal);
       
   443 
       
   444 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   445 
       
   446 	TBool DoRemoveBufferDoneCbCommandByBufferHeader(
       
   447 		COmxILCallbackManager& aCbMgr,
       
   448 		const OMX_BUFFERHEADERTYPE* apBufferHeader,
       
   449 		OMX_DIRTYPE aDirection);
       
   450 
       
   451 	TBool DoRemoveBufferDoneCbCommandByPortIndex(
       
   452 		COmxILCallbackManager& aCbMgr,
       
   453 		OMX_U32 aLocalPortIndex);
       
   454 
       
   455 	TBool DoExecuteBufferDoneCbCommandByPortIndex(
       
   456 		COmxILCallbackManager& aCbMgr,
       
   457 		OMX_U32 aLocalPortIndex);
       
   458 
       
   459 private:
       
   460 
       
   461 	OMX_BUFFERHEADERTYPE* ipBufferHeader; // not owned
       
   462 	OMX_U32 iLocalPortIndex;
       
   463 	OMX_DIRTYPE iLocalPortDirection;
       
   464 
       
   465 	};
       
   466 
       
   467 /**
       
   468   Callback Manager's command class for notification of port settings change
       
   469   events .
       
   470  */
       
   471 class COmxILCallbackManager::CPortSettingsChangeCommand :
       
   472 	public COmxILCallbackManager::CCallbackCommand
       
   473 	{
       
   474 
       
   475 public:
       
   476 
       
   477 	inline CPortSettingsChangeCommand(OMX_U32 aLocalPortIndex,
       
   478 									  TUint aPortSettingsIndex,
       
   479 									  HBufC8*& apPortSettings);
       
   480 
       
   481 	~CPortSettingsChangeCommand();
       
   482 
       
   483 	void operator()(COmxILCallbackManager& aCbMgr, TBool& aHasBeenDeferred);
       
   484 
       
   485 private:
       
   486 
       
   487 	OMX_U32 iLocalPortIndex;
       
   488 	TUint iPortSettingsIndex;
       
   489 	HBufC8* ipPortSettings; // This is owned by this class
       
   490 
       
   491 	};
       
   492 
       
   493 #include "omxilcallbackmanager.inl"
       
   494 
       
   495 #endif // OMXILCALLBACKMANAGER_H