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 PVMF_SM_FSP_BASE_TYPES_H_INCLUDED 19 #define PVMF_SM_FSP_BASE_TYPES_H_INCLUDED 20 21 #ifndef PVMF_NODE_UTILS_H_INCLUDED 22 #include "pvmf_node_utils.h" 23 #endif 24 25 class PVMFDataSourcePositionParams; 26 class PVMFTimebase; 27 /* 28 * Structure to contain a node and all ports and extensions associated to it 29 */ 30 enum PVMFSMFSPChildNodeCmdState 31 { 32 PVMFSMFSP_NODE_CMD_IDLE, 33 PVMFSMFSP_NODE_CMD_PENDING, 34 PVMFSMFSP_NODE_CMD_CANCEL_PENDING 35 }; 36 37 typedef PVMFGenericNodeCommand <OsclMemAllocator> PVMFSMFSPBaseNodeCommandBase; 38 class PVMFSMFSPBaseNodeCommand : public PVMFSMFSPBaseNodeCommandBase 39 { 40 public: 41 void Construct(PVMFSessionId s, 42 int32 cmd, 43 int32 arg1, 44 int32 arg2, 45 int32& arg3, 46 const OsclAny*aContext) 47 { 48 PVMFSMFSPBaseNodeCommandBase::Construct(s, cmd, aContext); 49 iParam1 = (OsclAny*)arg1; 50 iParam2 = (OsclAny*)arg2; 51 iParam3 = (OsclAny*) & arg3; 52 } 53 54 void Parse(int32&arg1, int32&arg2, int32*&arg3) 55 { 56 arg1 = (int32)iParam1; 57 arg2 = (int32)iParam2; 58 arg3 = (int32*)iParam3; 59 } 60 61 /* Constructor and parser for SetDataSourcePosition */ 62 void Construct(PVMFSessionId s, 63 int32 cmd, 64 PVMFTimestamp aTargetNPT, 65 PVMFTimestamp* aActualNPT, 66 PVMFTimestamp* aActualMediaDataTS, 67 bool aSeekToSyncPoint, 68 uint32 aStreamID, 69 const OsclAny*aContext) 70 { 71 PVMFSMFSPBaseNodeCommandBase::Construct(s, cmd, aContext); 72 iParam1 = (OsclAny*)aTargetNPT; 73 iParam2 = (OsclAny*)aActualNPT; 74 iParam3 = (OsclAny*)aActualMediaDataTS; 75 iParam4 = (OsclAny*)aSeekToSyncPoint; 76 iParam5 = (OsclAny*)aStreamID; 77 } 78 79 void Parse(PVMFTimestamp& aTargetNPT, 80 PVMFTimestamp* &aActualNPT, 81 PVMFTimestamp* &aActualMediaDataTS, 82 bool& aSeekToSyncPoint, 83 uint32& aStreamID) 84 { 85 aTargetNPT = (PVMFTimestamp)iParam1; 86 aActualNPT = (PVMFTimestamp*)iParam2; 87 aActualMediaDataTS = (PVMFTimestamp*)iParam3; 88 aSeekToSyncPoint = (iParam4 ? true : false); 89 aStreamID = (uint32)iParam5; 90 } 91 92 /* Constructor and parser for SetDataSourcePosition - Playlist */ 93 void Construct(PVMFSessionId s, 94 int32 cmd, 95 PVMFDataSourcePositionParams* aParams, 96 const OsclAny*aContext) 97 { 98 PVMFSMFSPBaseNodeCommandBase::Construct(s, cmd, aContext); 99 iParam1 = (OsclAny*)aParams; 100 iParam2 = NULL; 101 iParam3 = NULL; 102 iParam4 = NULL; 103 iParam5 = NULL; 104 } 105 106 void Parse(PVMFDataSourcePositionParams*& aParams) 107 { 108 aParams = (PVMFDataSourcePositionParams*)iParam1; 109 } 110 111 112 /* Constructor and parser for QueryDataSourcePosition */ 113 void Construct(PVMFSessionId s, 114 int32 cmd, 115 PVMFTimestamp aTargetNPT, 116 PVMFTimestamp* aActualNPT, 117 bool aSeekToSyncPoint, 118 const OsclAny*aContext) 119 { 120 PVMFSMFSPBaseNodeCommandBase::Construct(s, cmd, aContext); 121 iParam1 = (OsclAny*)aTargetNPT; 122 iParam2 = (OsclAny*)aActualNPT; 123 iParam3 = (OsclAny*)aSeekToSyncPoint; 124 iParam4 = NULL; 125 iParam5 = NULL; 126 } 127 128 void Construct(PVMFSessionId s, 129 int32 cmd, 130 PVMFTimestamp aTargetNPT, 131 PVMFTimestamp* aSeekPointBeforeTargetNPT, 132 PVMFTimestamp* aSeekPointAfterTargetNPT, 133 const OsclAny*aContext, 134 bool aSeekToSyncPoint 135 ) 136 { 137 PVMFSMFSPBaseNodeCommandBase::Construct(s, cmd, aContext); 138 iParam1 = (OsclAny*)aTargetNPT; 139 iParam3 = (OsclAny*)aSeekToSyncPoint; 140 iParam4 = aSeekPointBeforeTargetNPT; 141 iParam5 = aSeekPointAfterTargetNPT; 142 } 143 144 void Parse(PVMFTimestamp& aTargetNPT, 145 PVMFTimestamp* &aActualNPT, 146 bool& aSeekToSyncPoint) 147 { 148 aTargetNPT = (PVMFTimestamp)iParam1; 149 aActualNPT = (PVMFTimestamp*)iParam2; 150 aSeekToSyncPoint = (iParam3 ? true : false); 151 } 152 153 void Parse(PVMFTimestamp& aTargetNPT, 154 PVMFTimestamp*& aSeekPointBeforeTargetNPT, 155 bool& aSeekToSyncPoint, 156 PVMFTimestamp*& aSeekPointAfterTargetNPT) 157 158 { 159 aTargetNPT = (PVMFTimestamp)iParam1; 160 aSeekToSyncPoint = (iParam3) ? true : false; 161 aSeekPointBeforeTargetNPT = (PVMFTimestamp*)iParam4; 162 aSeekPointAfterTargetNPT = (PVMFTimestamp*)iParam5; 163 } 164 165 166 /* Constructor and parser for SetDataSourceRate */ 167 void Construct(PVMFSessionId s, 168 int32 cmd, 169 int32 aRate, 170 PVMFTimebase* aTimebase, 171 const OsclAny* aContext) 172 { 173 PVMFSMFSPBaseNodeCommandBase::Construct(s, cmd, aContext); 174 iParam1 = (OsclAny*)aRate; 175 iParam2 = (OsclAny*)aTimebase; 176 iParam3 = NULL; 177 iParam4 = NULL; 178 iParam5 = NULL; 179 }; 180 181 void Parse(int32& aRate, PVMFTimebase*& aTimebase) 182 { 183 aRate = (int32)iParam1; 184 aTimebase = (PVMFTimebase*)iParam2; 185 } 186 187 /* Constructor and parser for GetNodeMetadataKeys */ 188 void Construct(PVMFSessionId s, 189 int32 cmd, 190 PVMFMetadataList& aKeyList, 191 int32 aStartingIndex, 192 int32 aMaxEntries, 193 char* aQueryKey, 194 const OsclAny* aContext) 195 { 196 PVMFSMFSPBaseNodeCommandBase::Construct(s, cmd, aContext); 197 iParam1 = (OsclAny*) & aKeyList; 198 iParam2 = (OsclAny*)aStartingIndex; 199 iParam3 = (OsclAny*)aMaxEntries; 200 if (aQueryKey) 201 { 202 /*allocate a copy of the query key string */ 203 Oscl_TAlloc<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> str; 204 iParam4 = str.ALLOC_AND_CONSTRUCT(aQueryKey); 205 } 206 } 207 208 void Parse(PVMFMetadataList*& MetaDataListPtr, 209 uint32 &aStartingIndex, 210 int32 &aMaxEntries, 211 char*& aQueryKey) 212 { 213 MetaDataListPtr = (PVMFMetadataList*)iParam1; 214 aStartingIndex = (uint32)iParam2; 215 aMaxEntries = (int32)iParam3; 216 aQueryKey = NULL; 217 if (iParam4) 218 { 219 OSCL_HeapString<OsclMemAllocator>* keystring = 220 (OSCL_HeapString<OsclMemAllocator>*)iParam4; 221 aQueryKey = keystring->get_str(); 222 } 223 } 224 225 /* Constructor and parser for GetNodeMetadataValue */ 226 void Construct(PVMFSessionId s, 227 int32 cmd, 228 PVMFMetadataList& aKeyList, 229 Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList, 230 uint32 aStartIndex, 231 int32 aMaxEntries, 232 const OsclAny* aContext) 233 { 234 PVMFSMFSPBaseNodeCommandBase::Construct(s, cmd, aContext); 235 iParam1 = (OsclAny*) & aKeyList; 236 iParam2 = (OsclAny*) & aValueList; 237 iParam3 = (OsclAny*)aStartIndex; 238 iParam4 = (OsclAny*)aMaxEntries; 239 240 } 241 242 void Parse(PVMFMetadataList* &aKeyList, 243 Oscl_Vector<PvmiKvp, OsclMemAllocator>* &aValueList, 244 uint32 &aStartingIndex, 245 int32 &aMaxEntries) 246 { 247 aKeyList = (PVMFMetadataList*)iParam1; 248 aValueList = (Oscl_Vector<PvmiKvp, OsclMemAllocator>*)iParam2; 249 aStartingIndex = (uint32)iParam3; 250 aMaxEntries = (int32)iParam4; 251 } 252 253 /* Constructor and parser for GetLicenseW */ 254 void Construct(PVMFSessionId s, 255 int32 cmd, 256 OSCL_wString& aContentName, 257 OsclAny* aLicenseData, 258 uint32 aDataSize, 259 int32 aTimeoutMsec, 260 const OsclAny* aContext) 261 { 262 PVMFSMFSPBaseNodeCommandBase::Construct(s, cmd, aContext); 263 iParam1 = (OsclAny*) & aContentName; 264 iParam2 = (OsclAny*)aLicenseData; 265 iParam3 = (OsclAny*)aDataSize; 266 iParam4 = (OsclAny*)aTimeoutMsec; 267 iParam5 = NULL; 268 } 269 270 void Parse(OSCL_wString*& aContentName, 271 OsclAny*& aLicenseData, 272 uint32& aDataSize, 273 int32& aTimeoutMsec) 274 { 275 aContentName = (OSCL_wString*)iParam1; 276 aLicenseData = (PVMFTimestamp*)iParam2; 277 aDataSize = (uint32)iParam3; 278 aTimeoutMsec = (int32)iParam4; 279 } 280 281 /* Constructor and parser for GetLicense */ 282 void Construct(PVMFSessionId s, 283 int32 cmd, 284 OSCL_String& aContentName, 285 OsclAny* aLicenseData, 286 uint32 aDataSize, 287 int32 aTimeoutMsec, 288 const OsclAny*aContext) 289 { 290 PVMFSMFSPBaseNodeCommandBase::Construct(s, cmd, aContext); 291 iParam1 = (OsclAny*) & aContentName; 292 iParam2 = (OsclAny*)aLicenseData; 293 iParam3 = (OsclAny*)aDataSize; 294 iParam4 = (OsclAny*)aTimeoutMsec; 295 iParam5 = NULL; 296 }; 297 void Parse(OSCL_String*& aContentName, 298 OsclAny*& aLicenseData, 299 uint32& aDataSize, 300 int32& aTimeoutMsec) 301 { 302 aContentName = (OSCL_String*)iParam1; 303 aLicenseData = (PVMFTimestamp*)iParam2; 304 aDataSize = (uint32)iParam3; 305 aTimeoutMsec = (int32)iParam4; 306 } 307 308 /* Constructor and parser for setParametersAsync */ 309 void Construct(PVMFSessionId s, int32 cmd, PvmiMIOSession aSession, 310 PvmiKvp* aParameters, int num_elements, 311 PvmiKvp*& aRet_kvp, OsclAny* aContext) 312 { 313 PVMFSMFSPBaseNodeCommandBase::Construct(s, cmd, aContext); 314 iParam1 = (OsclAny*)aSession; 315 iParam2 = (OsclAny*)aParameters; 316 iParam3 = (OsclAny*)num_elements; 317 iParam4 = (OsclAny*) & aRet_kvp; 318 } 319 void Parse(PvmiMIOSession& aSession, PvmiKvp*& aParameters, 320 int &num_elements, PvmiKvp** &ppRet_kvp) 321 { 322 aSession = (PvmiMIOSession)iParam1; 323 aParameters = (PvmiKvp*)iParam2; 324 num_elements = (int)iParam3; 325 ppRet_kvp = (PvmiKvp**)iParam4; 326 } 327 328 virtual bool hipri() 329 { 330 return ((PVMF_GENERIC_NODE_CANCELALLCOMMANDS == iCmd) 331 || (PVMF_GENERIC_NODE_CANCELCOMMAND == iCmd)); 332 } 333 /* need to overlaod the base Copy routine to copy metadata key */ 334 void Copy(const PVMFGenericNodeCommand<OsclMemAllocator>& aCmd); 335 336 /* need to overlaod the base Destroy routine to cleanup metadata key */ 337 void Destroy(); 338 }; 339 340 class PVMFSMFSPChildNodeContainer 341 { 342 public: 343 PVMFSMFSPChildNodeContainer() 344 { 345 commandStartOffset = 0; 346 iNode = NULL; 347 iNodeTag = 0; 348 iSessionId = 0; 349 iNodeCmdState = PVMFSMFSP_NODE_CMD_IDLE; 350 iNumRequestPortsPending = 0; 351 iAutoPaused = false; 352 }; 353 354 PVMFSMFSPChildNodeContainer(const PVMFSMFSPChildNodeContainer& aNodeContainer) 355 { 356 commandStartOffset = aNodeContainer.commandStartOffset; 357 iNode = aNodeContainer.iNode; 358 iNodeTag = aNodeContainer.iNodeTag; 359 iSessionId = aNodeContainer.iSessionId; 360 iNodeCmdState = aNodeContainer.iNodeCmdState; 361 iNumRequestPortsPending = aNodeContainer.iNumRequestPortsPending; 362 iAutoPaused = aNodeContainer.iAutoPaused; 363 iInputPorts = aNodeContainer.iInputPorts; 364 iOutputPorts = aNodeContainer.iOutputPorts; 365 iFeedBackPorts = aNodeContainer.iFeedBackPorts; 366 iExtensions = aNodeContainer.iExtensions; 367 iExtensionUuids = aNodeContainer.iExtensionUuids; 368 } 369 370 PVMFSMFSPChildNodeContainer& operator=(const PVMFSMFSPChildNodeContainer& aNodeContainer) 371 { 372 if (&aNodeContainer != this) 373 { 374 commandStartOffset = aNodeContainer.commandStartOffset; 375 iNode = aNodeContainer.iNode; 376 iNodeTag = aNodeContainer.iNodeTag; 377 iSessionId = aNodeContainer.iSessionId; 378 iNodeCmdState = aNodeContainer.iNodeCmdState; 379 iNumRequestPortsPending = aNodeContainer.iNumRequestPortsPending; 380 iAutoPaused = aNodeContainer.iAutoPaused; 381 iInputPorts = aNodeContainer.iInputPorts; 382 iOutputPorts = aNodeContainer.iOutputPorts; 383 iFeedBackPorts = aNodeContainer.iFeedBackPorts; 384 iExtensions = aNodeContainer.iExtensions; 385 iExtensionUuids = aNodeContainer.iExtensionUuids; 386 } 387 return *this; 388 } 389 390 virtual ~PVMFSMFSPChildNodeContainer() {}; 391 392 void Reset() 393 { 394 commandStartOffset = 0; 395 iNode = NULL; 396 iNodeTag = 0; 397 iSessionId = 0; 398 iNodeCmdState = PVMFSMFSP_NODE_CMD_IDLE; 399 iNumRequestPortsPending = 0; 400 iAutoPaused = false; 401 iInputPorts.clear(); 402 iOutputPorts.clear(); 403 iFeedBackPorts.clear(); 404 for (uint32 i = 0; i < iExtensions.size(); i++) 405 { 406 iExtensions[i]->removeRef(); 407 } 408 iExtensions.clear(); 409 iExtensionUuids.clear(); 410 } 411 412 413 int32 commandStartOffset; 414 PVMFNodeInterface* iNode; 415 int32 iNodeTag; 416 PVMFSessionId iSessionId; 417 PVMFSMFSPChildNodeCmdState iNodeCmdState; 418 int32 iNumRequestPortsPending; 419 bool iAutoPaused; 420 Oscl_Vector<PVMFPortInterface*, OsclMemAllocator> iInputPorts; 421 Oscl_Vector<PVMFPortInterface*, OsclMemAllocator> iOutputPorts; 422 Oscl_Vector<PVMFPortInterface*, OsclMemAllocator> iFeedBackPorts; 423 Oscl_Vector<PVInterface*, OsclMemAllocator> iExtensions; 424 Oscl_Vector<PVUuid, OsclMemAllocator> iExtensionUuids; 425 426 }; 427 428 typedef Oscl_Vector<PVMFSMFSPChildNodeContainer, OsclMemAllocator> PVMFSMFSPChildNodeContainerVector; 429 430 typedef PVMFNodeCommandQueue<PVMFSMFSPBaseNodeCommand, OsclMemAllocator> PVMFFSPNodeCmdQ; 431 432 typedef struct tagPVMFSMFSPPortContext 433 { 434 tagPVMFSMFSPPortContext() 435 { 436 trackID = 0; 437 portTag = 0; 438 } 439 uint32 trackID; 440 uint32 portTag; 441 } PVMFSMFSPPortContext; 442 443 class PVMFSMFSPCommandContext 444 { 445 public: 446 PVMFSMFSPCommandContext() 447 { 448 oInternalCmd = false; 449 parentCmd = 0; 450 cmd = 0; 451 oFree = true; 452 }; 453 454 bool oInternalCmd; 455 int32 parentCmd; 456 int32 cmd; 457 bool oFree; 458 PVMFSMFSPPortContext portContext; 459 }; 460 461 class PVMFSMFSPSessionSourceInfo 462 { 463 public: 464 PVMFSMFSPSessionSourceInfo() 465 { 466 Reset(); 467 } 468 469 void Reset() 470 { 471 iDRMProtected = false; 472 _sessionType = PVMF_MIME_FORMAT_UNKNOWN; 473 _sourceData = NULL; 474 _sessionURL = NULL; 475 } 476 477 bool iDRMProtected; 478 PVMFFormatType _sessionType; 479 OsclAny* _sourceData; 480 OSCL_wHeapString<OsclMemAllocator> _sessionURL; 481 482 }; 483 484 /* 485 * class for saving kvps for CPM 486 */ 487 typedef Oscl_Vector<PvmiKvp, OsclMemAllocator> PVMFKvpVector; 488 class PVMFSMNodeKVPStore 489 { 490 public: 491 // add kvp string with W-string value 492 PVMFStatus addKVPString(const char* aKeyTypeString, OSCL_wString& aValString); 493 // add kvp string with normal string value 494 PVMFStatus addKVPString(const char* aKeyTypeString, const char* aValString); 495 // add kvp string with normal uint32 value 496 PVMFStatus addKVPuint32Value(const char* aKeyTypeString, uint32 aValue); 497 498 // get the vector for the all constructed KVPs 499 PVMFKvpVector* getKVPStore() 500 { 501 return &iKvpVector; 502 } 503 504 // check emptiness of the store 505 bool isEmpty() const 506 { 507 return iKvpVector.empty(); 508 } 509 510 // release memory for all the constructed KVPs and clear the vector 511 void destroy() 512 { 513 releaseMemory(); 514 clear(); 515 } 516 517 // constructor and destructor 518 PVMFSMNodeKVPStore() 519 { 520 clear(); 521 } 522 ~PVMFSMNodeKVPStore() 523 { 524 destroy(); 525 } 526 527 private: 528 enum KVPValueTypeForMemoryRelease 529 { 530 KVPValueTypeForMemoryRelease_NoInterest = 0, 531 KVPValueTypeForMemoryRelease_String, 532 KVPValueTypeForMemoryRelease_WString 533 }; 534 535 void clear() 536 { 537 iKvpVector.clear(); 538 iKVPValueTypeForMemoryRelease.clear(); 539 } 540 void releaseMemory(); 541 PVMFStatus pushKVPToVector(const PvmiKvp&, const KVPValueTypeForMemoryRelease&); 542 543 private: 544 PVMFKvpVector iKvpVector; 545 Oscl_Vector<uint32, OsclMemAllocator> iKVPValueTypeForMemoryRelease; 546 }; 547 548 template <class T> class PVMFSMSharedPtrAlloc: public OsclDestructDealloc 549 { 550 public: 551 T* allocate() 552 { 553 OsclMemAllocator alloc; 554 T* ptr = OSCL_PLACEMENT_NEW(alloc.allocate(sizeof(T)), T()); 555 return ptr; 556 } 557 558 virtual void destruct_and_dealloc(OsclAny* ptr) 559 { 560 T* tptr ; 561 tptr = reinterpret_cast<T*>(ptr); 562 tptr->~T(); 563 OsclMemAllocator alloc; 564 alloc.deallocate(ptr); 565 } 566 }; 567 #endif 568