1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 #ifndef PVAE_NODE_UTILITY_H_INCLUDED 19 #define PVAE_NODE_UTILTIY_H_INCLUDED 20 21 #ifndef OSCL_BASE_H_INCLUDED 22 #include "oscl_base.h" 23 #endif 24 #ifndef OSCL_SCHEDULER_AO_H_INCLUDED 25 #include "oscl_scheduler_ao.h" 26 #endif 27 #ifndef OSCL_VECTOR_H_INCLUDED 28 #include "oscl_vector.h" 29 #endif 30 #ifndef PVLOGGER_H_INCLUDED 31 #include "pvlogger.h" 32 #endif 33 #ifndef PV_ENGINE_TYPES_H_INCLUDED 34 #include "pv_engine_types.h" 35 #endif 36 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED 37 #include "pvmf_node_interface.h" 38 #endif 39 40 #define LOG_STACK_TRACE(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, m) 41 #define LOG_DEBUG(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, m) 42 #define LOG_ERR(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iLogger,PVLOGMSG_ERR,m) 43 44 /** Structure to contain a node and all ports and extensions associated to it */ 45 class PVAENodeContainer 46 { 47 public: PVAENodeContainer()48 PVAENodeContainer() 49 { 50 iNode = NULL; 51 iSessionId = 0; 52 iNodeCapConfigIF = NULL; 53 }; 54 55 PVMFNodeInterface* iNode; 56 PVMFSessionId iSessionId; 57 PVUuid iUuid; 58 Oscl_Vector<PVMFPortInterface*, OsclMemAllocator> iInputPorts; 59 Oscl_Vector<PVMFPortInterface*, OsclMemAllocator> iOutputPorts; 60 Oscl_Vector<PVInterface*, OsclMemAllocator> iExtensions; 61 Oscl_Vector<PVUuid, OsclMemAllocator> iExtensionUuids; 62 PVInterface* iNodeCapConfigIF; 63 }; 64 65 /** A vector of node container structures */ 66 typedef Oscl_Vector<PVAENodeContainer*, OsclMemAllocator> PVAENodeContainerVector; 67 68 /** Enumerated list of node commands */ 69 typedef enum 70 { 71 PVAENU_CMD_NONE, 72 PVAENU_CMD_CONNECT, 73 PVAENU_CMD_DISCONNECT, 74 PVAENU_CMD_QUERY_UUID, 75 PVAENU_CMD_QUERY_INTERFACE, 76 PVAENU_CMD_INIT, 77 PVAENU_CMD_PREPARE, 78 PVAENU_CMD_START, 79 PVAENU_CMD_STOP, 80 PVAENU_CMD_FLUSH, 81 PVAENU_CMD_PAUSE, 82 PVAENU_CMD_RESET, 83 } PVAENodeUtilCmdType; 84 85 /** Node utility command class */ 86 class PVAENodeUtilCmd 87 { 88 public: 89 PVAENodeUtilCmd()90 PVAENodeUtilCmd() : iType(PVAENU_CMD_NONE), iParam1(NULL), iParam2(NULL), iContext(NULL) {} PVAENodeUtilCmd(const PVAENodeUtilCmd & aCmd)91 PVAENodeUtilCmd(const PVAENodeUtilCmd& aCmd) 92 { 93 Copy(aCmd); 94 } 95 96 PVAENodeUtilCmd& operator=(const PVAENodeUtilCmd& aCmd) 97 { 98 Copy(aCmd); 99 return (*this); 100 } 101 102 // For most commands Construct(PVAENodeUtilCmdType aType,const PVAENodeContainerVector & aNodes,OsclAny * aContext)103 PVMFStatus Construct(PVAENodeUtilCmdType aType, const PVAENodeContainerVector& aNodes, OsclAny* aContext) 104 { 105 iType = aType; 106 iNodes = aNodes; 107 iContext = aContext; 108 return PVMFSuccess; 109 } 110 111 // For Connect ConstructConnect(PVAENodeContainer * aMasterNode,int32 aTag1,PVAENodeContainer * aSlaveNode,int32 aTag2,const PvmfMimeString & aMimeType,OsclAny * aContext)112 PVMFStatus ConstructConnect(PVAENodeContainer* aMasterNode, int32 aTag1, 113 PVAENodeContainer* aSlaveNode, int32 aTag2, 114 const PvmfMimeString& aMimeType, OsclAny* aContext) 115 { 116 iType = PVAENU_CMD_CONNECT; 117 iContext = aContext; 118 iParam1 = (OsclAny*)aTag1; 119 iParam2 = (OsclAny*)aTag2; 120 121 int32 err = 0; 122 OSCL_TRY(err, 123 iNodes.push_back(aMasterNode); 124 iNodes.push_back(aSlaveNode); 125 iMimeType = aMimeType; 126 ); 127 OSCL_FIRST_CATCH_ANY(err, return PVMFErrNoMemory;); 128 129 return PVMFSuccess; 130 } 131 ParseConnect(int32 & aTag1,int32 & aTag2,PvmfMimeString & aMimeType)132 PVMFStatus ParseConnect(int32& aTag1, int32& aTag2, PvmfMimeString& aMimeType) 133 { 134 if (iType != PVAENU_CMD_CONNECT) 135 return PVMFFailure; 136 137 aTag1 = (int32)iParam1; 138 aTag2 = (int32)iParam2; 139 aMimeType = iMimeType; 140 return PVMFSuccess; 141 } 142 ConstructDisconnect(PVAENodeContainer * aNodeContainer,OsclAny * aContext)143 PVMFStatus ConstructDisconnect(PVAENodeContainer* aNodeContainer, OsclAny* aContext) 144 { 145 iType = PVAENU_CMD_DISCONNECT; 146 iContext = aContext; 147 148 int32 err = 0; 149 OSCL_TRY(err, 150 iNodes.push_back(aNodeContainer); 151 ); 152 OSCL_FIRST_CATCH_ANY(err, return PVMFErrNoMemory;); 153 154 return PVMFSuccess; 155 } 156 ConstructQueryUUID(PVAENodeContainer * aNodeContainer,const PvmfMimeString & aMimeType,Oscl_Vector<PVUuid,OsclMemAllocator> & aUuids,bool aExactUuidsOnly,OsclAny * aContext)157 PVMFStatus ConstructQueryUUID(PVAENodeContainer* aNodeContainer, const PvmfMimeString& aMimeType, 158 Oscl_Vector<PVUuid, OsclMemAllocator>& aUuids, 159 bool aExactUuidsOnly, OsclAny* aContext) 160 { 161 iType = PVAENU_CMD_QUERY_UUID; 162 iContext = aContext; 163 iParam1 = (OsclAny*) & aUuids; 164 iParam2 = (OsclAny*)aExactUuidsOnly; 165 166 int32 err = 0; 167 OSCL_TRY(err, 168 iNodes.push_back(aNodeContainer); 169 iMimeType = aMimeType; 170 ); 171 OSCL_FIRST_CATCH_ANY(err, return PVMFErrNoMemory;); 172 173 return PVMFSuccess; 174 } 175 ParseQueryUUID(Oscl_Vector<PVUuid,OsclMemAllocator> * aUuids,bool & aExactUuidsOnly)176 PVMFStatus ParseQueryUUID(Oscl_Vector<PVUuid, OsclMemAllocator>* aUuids, bool& aExactUuidsOnly) 177 { 178 if (iType != PVAENU_CMD_QUERY_UUID) 179 return PVMFFailure; 180 181 aUuids = (Oscl_Vector<PVUuid, OsclMemAllocator>*)iParam1; 182 aExactUuidsOnly = (iParam2 != NULL); // iParam2 is a bool 183 return PVMFSuccess; 184 } 185 ConstructQueryInterface(PVAENodeContainer * aNodeContainer,const PVUuid & aUuid,PVInterface * & aInterfacePtr,OsclAny * aContext)186 PVMFStatus ConstructQueryInterface(PVAENodeContainer* aNodeContainer, 187 const PVUuid& aUuid, 188 PVInterface*& aInterfacePtr, 189 OsclAny* aContext) 190 { 191 iType = PVAENU_CMD_QUERY_INTERFACE; 192 iContext = aContext; 193 iParam1 = (OsclAny*) & aInterfacePtr; 194 iUuid = aUuid; 195 196 int32 err = 0; 197 OSCL_TRY(err, 198 iNodes.push_back(aNodeContainer); 199 ); 200 OSCL_FIRST_CATCH_ANY(err, return PVMFErrNoMemory;); 201 202 return PVMFSuccess; 203 } 204 ParseQueryInterface(PVInterface ** & aInterfacePtr)205 PVMFStatus ParseQueryInterface(PVInterface**& aInterfacePtr) 206 { 207 if (iType != PVAENU_CMD_QUERY_INTERFACE) 208 return PVMFFailure; 209 210 aInterfacePtr = (PVInterface**)iParam1; 211 return PVMFSuccess; 212 } 213 ConstructInit(PVAENodeContainer * aNodeContainer,OsclAny * aContext)214 PVMFStatus ConstructInit(PVAENodeContainer* aNodeContainer, OsclAny* aContext) 215 { 216 iType = PVAENU_CMD_INIT; 217 iContext = aContext; 218 219 int32 err = 0; 220 OSCL_TRY(err, 221 iNodes.push_back(aNodeContainer); 222 ); 223 OSCL_FIRST_CATCH_ANY(err, return PVMFErrNoMemory;); 224 225 return PVMFSuccess; 226 } 227 228 PVAENodeUtilCmdType iType; 229 PVAENodeContainerVector iNodes; 230 OSCL_HeapString<OsclMemAllocator> iMimeType; 231 PVUuid iUuid; // For QueryInterface 232 OsclAny* iParam1; 233 OsclAny* iParam2; 234 OsclAny* iContext; 235 236 private: Copy(const PVAENodeUtilCmd & aCmd)237 void Copy(const PVAENodeUtilCmd& aCmd) 238 { 239 iType = aCmd.iType; 240 iNodes = aCmd.iNodes; 241 iMimeType = aCmd.iMimeType; 242 iUuid = aCmd.iUuid; 243 iParam1 = aCmd.iParam1; 244 iParam2 = aCmd.iParam2; 245 iContext = aCmd.iContext; 246 } 247 }; 248 249 /** Observer class to listen for utility command completion events */ 250 class PVAENodeUtilObserver 251 { 252 public: 253 virtual void NodeUtilCommandCompleted(const PVMFCmdResp& aResponse) = 0; 254 virtual void NodeUtilErrorEvent(const PVMFAsyncEvent& aEvent) = 0; ~PVAENodeUtilObserver()255 virtual ~PVAENodeUtilObserver() {} 256 }; 257 258 /** 259 * Utility class to connect two nodes and handle node commands to multiple 260 * nodes. Users of this utility must provide PVMFNodeCmdStatusObserver, 261 * PVMFNodeErrorEventObserver and PVMFNodeInfoEventObserver in order to 262 * receive callbacks for results of command issued to this utility. 263 * 264 * While this utility is processing a command, it will change the nodes' 265 * observers to this utility. Therefore there must be no pending commands 266 * in the node before this method is called. Other users of the node must not 267 * change the observers until this command is completed. Also, no additional commands 268 * should be made to these nodes until the command is completed. When the 269 * command is complete, the observers of the node will be set to the observers 270 * of this utility. 271 */ 272 class PVAuthorEngineNodeUtility : public OsclTimerObject, 273 public PVMFNodeCmdStatusObserver 274 { 275 public: 276 PVAuthorEngineNodeUtility(); 277 virtual ~PVAuthorEngineNodeUtility(); 278 279 /** 280 * Sets command status observer. After a utility 281 * command is completed, the command status observer for the nodes 282 * will be sent to the observer set here. 283 * 284 * @param aObserver Command status observer 285 */ SetObserver(const PVAENodeUtilObserver & aObserver)286 void SetObserver(const PVAENodeUtilObserver& aObserver) 287 { 288 iObserver = (PVAENodeUtilObserver*) & aObserver; 289 } 290 291 /** 292 * Connect two nodes. An output port will be requested from the specified 293 * input node, and an input port will be requested from the specified output 294 * node. The two ports will then be connected to establish a connection 295 * between the two nodes. This utility will callback to report status of 296 * the command after the connection is complete and will return the newly 297 * requested and connected ports will be added to the iInPorts or iOutPorts 298 * vector in the PVAENodeContainer objects passed in. 299 * 300 * @param aInputNode Container of input node of the connection. The newly requested 301 * port will be added to the iOutPorts vector of the node container. 302 * @param aOutputNode Container of output node of the connection. The newly requested 303 * port will be added to the iInPorts vector of the node container. 304 * @param aContext Optional opaque data to be passed back to user with the command response 305 * @returns Completion status 306 */ 307 PVMFStatus Connect(PVAENodeContainer* aMasterNode, int32 aTag1, 308 PVAENodeContainer* aSlaveNode, int32 aTag2, 309 const PvmfMimeString& aMimeType, 310 OsclAny* aContext = NULL); 311 312 /** 313 * Disconnect and release all ports of a node. 314 * 315 * @param aNodeContainer Container for node which ports will be disonnected and released 316 * @param aContext Optional opaque data to be passed back to user with the command response 317 * @returns Completion status 318 */ 319 PVMFStatus Disconnect(PVAENodeContainer* aNodeContainer, OsclAny* aContext = NULL); 320 321 /** 322 * Query UUIDs supported by the specified node. 323 * 324 * @param aNodeContainer Container for node to which this query is made 325 * @param aMimeType The MIME type of the desired interfaces 326 * @param aUuids A vector to hold the discovered UUIDs 327 * @param aExactUuidsOnly Turns on/off the retrival of UUIDs with aMimeType as a base type 328 * @param aContext Optional opaque data to be passed back to user with the command response 329 * @returns Completion status 330 */ 331 PVMFStatus QueryUUID(PVAENodeContainer* aNodeContainer, 332 const PvmfMimeString& aMimeType, 333 Oscl_Vector<PVUuid, OsclMemAllocator>& aUuids, 334 bool aExactUuidsOnly = false, 335 OsclAny* aContext = NULL); 336 337 /** 338 * Query for interface of specified Uuid from the specified node. The queried interface 339 * object will be added to the iExtensions vector and stored in the interface pointer 340 * provided by user. Also, Uuid of the queried interface will be added to the 341 * iExtensionsUuid vector. 342 * 343 * @param aNodeContainer Container for node to which this query is made 344 * @param aUuid The UUID of the desired interface 345 * @param aInterfacePtr Optional interface pointer to store the requested interface 346 * @param aContext Optional opaque data to be passed back to user with the command response 347 * @returns Completion status 348 */ 349 PVMFStatus QueryInterface(PVAENodeContainer* aNodeContainer, 350 const PVUuid& aUuid, 351 PVInterface*& aInterfacePtr, 352 OsclAny* aContext = NULL); 353 354 /** 355 * Initialize a node 356 * 357 * @param aNode Node container containing the node to be initialized. 358 * @param aContext Optional opaque data to be passed back to user with the command response 359 * @returns Completion status 360 */ 361 PVMFStatus Init(const PVAENodeContainer* aNode, OsclAny* aContext = NULL); 362 363 /** 364 * Initialize all nodes in the vector. 365 * 366 * @param aNodes Vector of nodes to be initialized 367 * @param aContext Optional opaque data to be passed back to user with the command response 368 * @returns Completion status 369 */ 370 PVMFStatus Init(const PVAENodeContainerVector& aNodes, OsclAny* aContext = NULL); 371 372 /** 373 * Prepare all nodes in the vector. 374 * 375 * @param aNodes Vector of nodes to be prepared 376 * @param aContext Optional opaque data to be passed back to user with the command response 377 * @returns Completion status 378 */ 379 PVMFStatus Prepare(const PVAENodeContainerVector& aNodes, OsclAny* aContext = NULL); 380 381 /** 382 * Start all ports of all nodes in the vector. 383 * 384 * @param aNodes Vector of nodes to be started 385 * @param aContext Optional opaque data to be passed back to user with the command response 386 * @returns Completion status 387 */ 388 PVMFStatus Start(const PVAENodeContainerVector& aNodes, OsclAny* aContext = NULL); 389 390 /** 391 * Pause all ports of all nodes in the vector. 392 * 393 * @param aNodes Vector of nodes to be paused 394 * @param aContext Optional opaque data to be passed back to user with the command response 395 * @returns Completion status 396 */ 397 PVMFStatus Pause(const PVAENodeContainerVector& aNodes, OsclAny* aContext = NULL); 398 399 /** 400 * Stop all ports of all nodes in the vector. 401 * 402 * @param aNodes Vector of nodes to be stopped 403 * @param aContext Optional opaque data to be passed back to user with the command response 404 * @returns Completion status 405 */ 406 PVMFStatus Stop(const PVAENodeContainerVector& aNodes, OsclAny* aContext = NULL); 407 408 /** 409 * Flush all ports of all nodes in the vector. 410 * 411 * @param aNodes Vector of nodes to be flushed 412 * @param aContext Optional opaque data to be passed back to user with the command response 413 * @returns Completion status 414 */ 415 PVMFStatus Flush(const PVAENodeContainerVector& aNodes, OsclAny* aContext = NULL); 416 417 /** 418 * Start all ports of all nodes in the vector. 419 * 420 * @param aNodes Vector of nodes to be reset 421 * @param aContext Optional opaque data to be passed back to user with the command response 422 * @returns Completion status 423 */ 424 PVMFStatus Reset(const PVAENodeContainerVector& aNodes, OsclAny* aContext = NULL); 425 426 /** 427 * Provides the size of command queue 428 * 429 * @returns Number of pending commands in command queue 430 */ 431 uint32 GetCommandQueueSize(); 432 433 // Implement pure virtual method of PVMFNodeCmdStatusObserver 434 void NodeCommandCompleted(const PVMFCmdResp& aResponse); 435 436 private: 437 void Run(); 438 439 // Command queue routines 440 PVMFStatus AddCmdToQueue(PVAENodeUtilCmd& aCmd); 441 void CompleteUtilityCmd(const PVAENodeUtilCmd& aCmd, PVMFStatus aStatus); 442 443 // Command processing routines 444 PVMFStatus DoConnect(const PVAENodeUtilCmd& aCmd); 445 PVMFStatus CompleteConnect(const PVAENodeUtilCmd& aCmd, const PVMFCmdResp& aResponse); 446 PVMFStatus DoDisconnect(const PVAENodeUtilCmd& aCmd); 447 PVMFStatus DoQueryUuid(const PVAENodeUtilCmd& aCmd); 448 PVMFStatus DoQueryInterface(const PVAENodeUtilCmd& aCmd); 449 PVMFStatus CompleteQueryInterface(const PVAENodeUtilCmd& aCmd); 450 PVMFStatus DoInit(const PVAENodeUtilCmd& aCmd); 451 PVMFStatus DoPrepare(const PVAENodeUtilCmd& aCmd); 452 PVMFStatus DoStart(const PVAENodeUtilCmd& aCmd); 453 PVMFStatus DoPause(const PVAENodeUtilCmd& aCmd); 454 PVMFStatus DoStop(const PVAENodeUtilCmd& aCmd); 455 PVMFStatus DoFlush(const PVAENodeUtilCmd& aCmd); 456 PVMFStatus DoReset(const PVAENodeUtilCmd& aCmd); 457 PVMFStatus CompleteStateTransition(const PVAENodeUtilCmd& aCmd, TPVMFNodeInterfaceState aState); 458 PVMFStatus ReleasePort(PVAENodeContainer*&, PVMFPortInterface*&); 459 // Observer 460 PVAENodeUtilObserver* iObserver; 461 462 // Command queue 463 Oscl_Vector<PVAENodeUtilCmd, OsclMemAllocator> iCmdQueue; 464 465 PVLogger* iLogger; 466 }; 467 468 #endif // PVAE_NODE_UTILTIY_H_INCLUDED 469