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_DOWNLOADMANAGER_NODE_H_INCLUDED 19 #define PVMF_DOWNLOADMANAGER_NODE_H_INCLUDED 20 21 22 #ifndef OSCL_BASE_H_INCLUDED 23 #include "oscl_base.h" 24 #endif 25 #ifndef OSCL_SCHEDULER_AO_H_INCLUDED 26 #include "oscl_scheduler_ao.h" 27 #endif 28 #ifndef OSCL_STRING_H_INCLUDED 29 #include "oscl_string.h" 30 #endif 31 #ifndef PVMF_FORMAT_TYPE_H_INCLUDED 32 #include "pvmf_format_type.h" 33 #endif 34 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED 35 #include "pvmf_node_interface.h" 36 #endif 37 #ifndef PVMF_NODE_UTILS_H_INCLUDED 38 #include "pvmf_node_utils.h" 39 #endif 40 #ifndef PVMF_DOWNLOADMANAGER_DEFS_H_INCLUDED 41 #include "pvmf_downloadmanager_defs.h" 42 #endif 43 #ifndef PVMF_DATA_SOURCE_PLAYBACK_CONTROL_H_INCLUDED 44 #include "pvmf_data_source_playback_control.h" 45 #endif 46 #ifndef PVMF_META_DATA_EXTENSION_H_INCLUDED 47 #include "pvmf_meta_data_extension.h" 48 #endif 49 #ifndef PVMF_DATA_SOURCE_INIT_EXTENSION_H_INCLUDED 50 #include "pvmf_data_source_init_extension.h" 51 #endif 52 #ifndef PVMF_TRACK_SELECTION_EXTENSION_H_INCLUDED 53 #include "pvmf_track_selection_extension.h" 54 #endif 55 #ifndef PVMF_MEDIA_PRESENTATION_INFO_H_INCLUDED 56 #include "pvmf_media_presentation_info.h" 57 #endif 58 #ifndef PVMF_DOWNLOAD_PROGRESS_INTERFACE_H_INCLUDED 59 #include "pvmf_download_progress_interface.h" 60 #endif 61 #ifndef PVMF_FF_PROGDOWNLOAD_SUPPORT_EXTENSION_H_INCLUDED 62 #include "pvmf_format_progdownload_support_extension.h" 63 #endif 64 #ifndef PVMFPROTOCOLENGINENODE_EXTENSION_H_INCLUDED 65 #include "pvmf_protocol_engine_node_extension.h" 66 #endif 67 #ifndef PVMF_FILEBUFFERDATASTREAM_FACTORY_H_INCLUDED 68 #include "pvmf_filebufferdatastream_factory.h" 69 #endif 70 #ifndef PVMF_SOURCE_CONTEXT_DATA_H_INCLUDED 71 #include "pvmf_source_context_data.h" 72 #endif 73 #ifndef PVMF_RECOGNIZER_REGISTRY_H_INCLUDED 74 #include "pvmf_recognizer_registry.h" 75 #endif 76 #ifndef PV_PLAYER_NODE_REGISTRY_INTERFACE_H_INCLUDED 77 #include "pv_player_node_registry_interface.h" 78 #endif 79 #ifndef PVMI_CONFIG_AND_CAPABILITY_H_INCLUDED 80 #include "pvmi_config_and_capability.h" 81 #endif 82 83 // only include pvmf_downloadmanager_config.h if CML2 is NOT being used 84 #ifndef USE_CML2_CONFIG 85 #ifndef PVMF_DOWNLOADMANAGER_CONFIG_H_INCLUDED 86 #include "pvmf_downloadmanager_config.h" 87 #endif 88 #endif 89 90 #if(PVMF_DOWNLOADMANAGER_SUPPORT_PPB) 91 #ifndef PVMF_MEMORYBUFFERDATASTREAM_FACTORY_H_INCLUDED 92 #include "pvmf_memorybufferdatastream_factory.h" 93 #endif 94 #endif //PVMF_DOWNLOADMANAGER_SUPPORT_PPB 95 96 #ifndef PVMF_CPMPLUGIN_LICENSE_INTERFACE_H_INCLUDED 97 #include "pvmf_cpmplugin_license_interface.h" 98 #endif 99 100 /** 101 * Node command handling 102 */ 103 104 typedef PVMFGenericNodeCommand<OsclMemAllocator> PVMFDownloadManagerNodeCommandBase; 105 106 enum PVMFDownloadManagerNodeCommandType 107 { 108 PVDLM_NODE_CMD_SETDATASOURCEPOSITION = PVMF_GENERIC_NODE_COMMAND_LAST 109 , PVDLM_NODE_CMD_QUERYDATASOURCEPOSITION 110 , PVDLM_NODE_CMD_SETDATASOURCERATE 111 , PVDLM_NODE_CMD_GETNODEMETADATAKEY 112 , PVDLM_NODE_CMD_GETNODEMETADATAVALUE 113 , PVDLM_NODE_CMD_GET_LICENSE 114 , PVDLM_NODE_CMD_GET_LICENSE_W 115 , PVDLM_NODE_CMD_CANCEL_GET_LICENSE 116 }; 117 118 class PVMFDownloadManagerNodeCommand : public PVMFDownloadManagerNodeCommandBase 119 { 120 public: 121 //override the default implementation of "hipri" and add the "cancel get license" 122 //command to the list of hi-priority commands. hipri()123 bool hipri() 124 { 125 return PVMFDownloadManagerNodeCommandBase::hipri() 126 || iCmd == PVDLM_NODE_CMD_CANCEL_GET_LICENSE; 127 } 128 129 // Constructor and parser for GetNodeMetadataKey Construct(PVMFSessionId s,int32 cmd,PVMFMetadataList & aKeyList,uint32 aStartingIndex,int32 aMaxEntries,char * aQueryKey,const OsclAny * aContext)130 void Construct(PVMFSessionId s, int32 cmd 131 , PVMFMetadataList& aKeyList 132 , uint32 aStartingIndex 133 , int32 aMaxEntries 134 , char* aQueryKey 135 , const OsclAny* aContext) 136 { 137 PVMFDownloadManagerNodeCommandBase::Construct(s, cmd, aContext); 138 iParam1 = (OsclAny*) & aKeyList; 139 iParam2 = (OsclAny*)aStartingIndex; 140 iParam3 = (OsclAny*)aMaxEntries; 141 if (aQueryKey) 142 { 143 //allocate a copy of the query key string. 144 Oscl_TAlloc<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> str; 145 iParam4 = str.ALLOC_AND_CONSTRUCT(aQueryKey); 146 } 147 } Parse(PVMFMetadataList * & MetaDataListPtr,uint32 & aStartingIndex,int32 & aMaxEntries,char * & aQueryKey)148 void Parse(PVMFMetadataList*& MetaDataListPtr, uint32 &aStartingIndex, int32 &aMaxEntries, char*& aQueryKey) 149 { 150 MetaDataListPtr = (PVMFMetadataList*)iParam1; 151 aStartingIndex = (uint32)iParam2; 152 aMaxEntries = (int32)iParam3; 153 aQueryKey = NULL; 154 if (iParam4) 155 { 156 OSCL_HeapString<OsclMemAllocator>* keystring = (OSCL_HeapString<OsclMemAllocator>*)iParam4; 157 aQueryKey = keystring->get_str(); 158 } 159 } 160 161 // Constructor and parser for GetNodeMetadataValue Construct(PVMFSessionId s,int32 cmd,PVMFMetadataList & aKeyList,Oscl_Vector<PvmiKvp,OsclMemAllocator> & aValueList,uint32 aStartIndex,int32 aMaxEntries,const OsclAny * aContext)162 void Construct(PVMFSessionId s, int32 cmd, PVMFMetadataList& aKeyList, Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList, uint32 aStartIndex, int32 aMaxEntries, const OsclAny* aContext) 163 { 164 PVMFDownloadManagerNodeCommandBase::Construct(s, cmd, aContext); 165 iParam1 = (OsclAny*) & aKeyList; 166 iParam2 = (OsclAny*) & aValueList; 167 iParam3 = (OsclAny*)aStartIndex; 168 iParam4 = (OsclAny*)aMaxEntries; 169 170 } Parse(PVMFMetadataList * & aKeyList,Oscl_Vector<PvmiKvp,OsclMemAllocator> * & aValueList,uint32 & aStartingIndex,int32 & aMaxEntries)171 void Parse(PVMFMetadataList* &aKeyList, Oscl_Vector<PvmiKvp, OsclMemAllocator>* &aValueList, uint32 &aStartingIndex, int32 &aMaxEntries) 172 { 173 aKeyList = (PVMFMetadataList*)iParam1; 174 aValueList = (Oscl_Vector<PvmiKvp, OsclMemAllocator>*)iParam2; 175 aStartingIndex = (uint32)iParam3; 176 aMaxEntries = (int32)iParam4; 177 } 178 179 // Constructor and parser for SetDataSourcePosition Construct(PVMFSessionId s,int32 cmd,PVMFTimestamp aTargetNPT,PVMFTimestamp & aActualNPT,PVMFTimestamp & aActualMediaDataTS,bool aSeekToSyncPoint,uint32 aStreamID,const OsclAny * aContext)180 void Construct(PVMFSessionId s, int32 cmd, PVMFTimestamp aTargetNPT, PVMFTimestamp& aActualNPT, PVMFTimestamp& aActualMediaDataTS, 181 bool aSeekToSyncPoint, uint32 aStreamID, const OsclAny*aContext) 182 { 183 PVMFDownloadManagerNodeCommandBase::Construct(s, cmd, aContext); 184 iParam1 = (OsclAny*)aTargetNPT; 185 iParam2 = (OsclAny*) & aActualNPT; 186 iParam3 = (OsclAny*) & aActualMediaDataTS; 187 iParam4 = (OsclAny*)aSeekToSyncPoint; 188 iParam5 = (OsclAny*)aStreamID; 189 } Parse(PVMFTimestamp & aTargetNPT,PVMFTimestamp * & aActualNPT,PVMFTimestamp * & aActualMediaDataTS,bool & aSeekToSyncPoint,uint32 & aStreamID)190 void Parse(PVMFTimestamp& aTargetNPT, PVMFTimestamp*& aActualNPT, PVMFTimestamp*& aActualMediaDataTS, bool& aSeekToSyncPoint, uint32& aStreamID) 191 { 192 aTargetNPT = (PVMFTimestamp)iParam1; 193 aActualNPT = (PVMFTimestamp*)iParam2; 194 aActualMediaDataTS = (PVMFTimestamp*)iParam3; 195 aSeekToSyncPoint = (iParam4) ? true : false; 196 aStreamID = (uint32)iParam5; 197 } 198 199 // Constructor and parser for QueryDataSourcePosition Construct(PVMFSessionId s,int32 cmd,PVMFTimestamp aTargetNPT,PVMFTimestamp & aActualNPT,bool aSeekToSyncPoint,const OsclAny * aContext)200 void Construct(PVMFSessionId s, int32 cmd, PVMFTimestamp aTargetNPT, PVMFTimestamp& aActualNPT, 201 bool aSeekToSyncPoint, const OsclAny*aContext) 202 { 203 PVMFDownloadManagerNodeCommandBase::Construct(s, cmd, aContext); 204 iParam1 = (OsclAny*)aTargetNPT; 205 iParam2 = (OsclAny*) & aActualNPT; 206 iParam3 = (OsclAny*)aSeekToSyncPoint; 207 iParam4 = NULL; 208 iParam5 = NULL; 209 } Parse(PVMFTimestamp & aTargetNPT,PVMFTimestamp * & aActualNPT,bool & aSeekToSyncPoint)210 void Parse(PVMFTimestamp& aTargetNPT, PVMFTimestamp*& aActualNPT, bool& aSeekToSyncPoint) 211 { 212 aTargetNPT = (PVMFTimestamp)iParam1; 213 aActualNPT = (PVMFTimestamp*)iParam2; 214 aSeekToSyncPoint = (iParam3) ? true : false; 215 } 216 217 // Constructor and parser for SetDataSourceRate Construct(PVMFSessionId s,int32 cmd,int32 aRate,PVMFTimebase * aTimebase,const OsclAny * aContext)218 void Construct(PVMFSessionId s, int32 cmd, int32 aRate, PVMFTimebase* aTimebase, const OsclAny*aContext) 219 { 220 PVMFDownloadManagerNodeCommandBase::Construct(s, cmd, aContext); 221 iParam1 = (OsclAny*)aRate; 222 iParam2 = (OsclAny*)aTimebase; 223 iParam3 = NULL; 224 iParam4 = NULL; 225 iParam5 = NULL; 226 } Parse(int32 & aRate,PVMFTimebase * & aTimebase)227 void Parse(int32& aRate, PVMFTimebase*& aTimebase) 228 { 229 aRate = (int32)iParam1; 230 aTimebase = (PVMFTimebase*)iParam2; 231 } 232 233 //need to overload the base Destroy routine to cleanup metadata key. Destroy()234 void Destroy() 235 { 236 PVMFGenericNodeCommand<OsclMemAllocator>::Destroy(); 237 switch (iCmd) 238 { 239 case PVDLM_NODE_CMD_GETNODEMETADATAKEY: 240 if (iParam4) 241 { 242 //cleanup the allocated string 243 Oscl_TAlloc<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> str; 244 str.destruct_and_dealloc(iParam4); 245 } 246 break; 247 default: 248 break; 249 } 250 } 251 252 //need to overlaod the base Copy routine to copy metadata key. Copy(const PVMFGenericNodeCommand<OsclMemAllocator> & aCmd)253 void Copy(const PVMFGenericNodeCommand<OsclMemAllocator>& aCmd) 254 { 255 PVMFGenericNodeCommand<OsclMemAllocator>::Copy(aCmd); 256 switch (aCmd.iCmd) 257 { 258 case PVDLM_NODE_CMD_GETNODEMETADATAKEY: 259 if (aCmd.iParam4) 260 { 261 //copy the allocated string 262 OSCL_HeapString<OsclMemAllocator>* aStr = (OSCL_HeapString<OsclMemAllocator>*)aCmd.iParam4; 263 Oscl_TAlloc<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> str; 264 iParam4 = str.ALLOC_AND_CONSTRUCT(*aStr); 265 } 266 break; 267 default: 268 break; 269 } 270 } 271 /* Constructor and parser for GetLicenseW */ Construct(PVMFSessionId s,int32 cmd,OSCL_wString & aContentName,OsclAny * aLicenseData,uint32 aDataSize,int32 aTimeoutMsec,OsclAny * aContext)272 void Construct(PVMFSessionId s, 273 int32 cmd, 274 OSCL_wString& aContentName, 275 OsclAny* aLicenseData, 276 uint32 aDataSize, 277 int32 aTimeoutMsec, 278 OsclAny* aContext) 279 { 280 PVMFDownloadManagerNodeCommandBase::Construct(s, cmd, aContext); 281 iParam1 = (OsclAny*) & aContentName; 282 iParam2 = (OsclAny*)aLicenseData; 283 iParam3 = (OsclAny*)aDataSize; 284 iParam4 = (OsclAny*)aTimeoutMsec; 285 iParam5 = NULL; 286 } Parse(OSCL_wString * & aContentName,OsclAny * & aLicenseData,uint32 & aDataSize,int32 & aTimeoutMsec)287 void Parse(OSCL_wString*& aContentName, 288 OsclAny*& aLicenseData, 289 uint32& aDataSize, 290 int32& aTimeoutMsec) 291 { 292 aContentName = (OSCL_wString*)iParam1; 293 aLicenseData = (PVMFTimestamp*)iParam2; 294 aDataSize = (uint32)iParam3; 295 aTimeoutMsec = (int32)iParam4; 296 } 297 298 /* Constructor and parser for GetLicense */ Construct(PVMFSessionId s,int32 cmd,OSCL_String & aContentName,OsclAny * aLicenseData,uint32 aDataSize,int32 aTimeoutMsec,OsclAny * aContext)299 void Construct(PVMFSessionId s, 300 int32 cmd, 301 OSCL_String& aContentName, 302 OsclAny* aLicenseData, 303 uint32 aDataSize, 304 int32 aTimeoutMsec, 305 OsclAny* aContext) 306 { 307 PVMFDownloadManagerNodeCommandBase::Construct(s, cmd, aContext); 308 iParam1 = (OsclAny*) & aContentName; 309 iParam2 = (OsclAny*)aLicenseData; 310 iParam3 = (OsclAny*)aDataSize; 311 iParam4 = (OsclAny*)aTimeoutMsec; 312 iParam5 = NULL; 313 } Parse(OSCL_String * & aContentName,OsclAny * & aLicenseData,uint32 & aDataSize,int32 & aTimeoutMsec)314 void Parse(OSCL_String*& aContentName, 315 OsclAny*& aLicenseData, 316 uint32& aDataSize, 317 int32& aTimeoutMsec) 318 { 319 aContentName = (OSCL_String*)iParam1; 320 aLicenseData = (PVMFTimestamp*)iParam2; 321 aDataSize = (uint32)iParam3; 322 aTimeoutMsec = (int32)iParam4; 323 } 324 325 }; 326 327 328 typedef PVMFNodeCommandQueue<PVMFDownloadManagerNodeCommand, OsclMemAllocator> PVMFDownloadManagerNodeCmdQueue; 329 330 class PVMFDownloadManagerNode; 331 class PVLogger; 332 333 334 /** 335 * Base for Containers for the protocol engine, socket, and parser nodes and CPM object 336 */ 337 class PVMFDownloadManagerSubNodeContainerBase 338 { 339 public: 340 PVMFDownloadManagerSubNodeContainerBase(); 341 342 /* 343 * EFormatParser indicates the format parser node 344 * EProtocolEngine indicates the protocol engine node 345 * ESocket indicates the socket node 346 * ECPM is the CPM container 347 */ 348 enum NodeType {EFormatParser, EProtocolEngine, ESocket, ECPM, ERecognizer}; 349 350 void Construct(NodeType t, PVMFDownloadManagerNode* container); 351 352 // Each subnode has a pointer to its container, which is the DLMGR node 353 PVMFDownloadManagerNode* iContainer; 354 355 NodeType iType; 356 PVMFSessionId iSessionId; 357 358 //Node Command processing 359 PVMFCommandId iCmdId; 360 361 //License Command Processing 362 PVMFCommandId iCPMGetLicenseCmdId; 363 PVMFCommandId iCPMCancelGetLicenseCmdId; 364 365 enum CmdState 366 { 367 EIdle, // no command 368 EBusy // command issued to the sub-node, completion pending. 369 }; 370 371 CmdState iCmdState; 372 373 enum CmdType 374 { 375 // common commands 376 ECleanup = 0 377 // node commands 378 , EQueryDataSourceInit = 1 379 , EQueryTrackSelection = 2 380 , EQueryMetadata = 3 381 , EQueryDataSourcePlayback = 4 382 , EQueryFFProgDownload = 5 383 , EQueryDownloadProgress = 6 384 , EQueryProtocolEngine = 7 385 , EQueryDatastreamUser = 8 386 , EInit = 9 387 , ERequestPort = 10 388 , EReleasePort = 11 389 , EPrepare = 12 390 , EStop = 13 391 , EStart = 14 392 , EPause = 15 393 , EFlush = 16 394 , EReset = 17 395 , EGetMetadataKey = 18 396 , EGetMetadataValue = 19 397 , ESetFFProgDownloadSupport = 20 398 , ESetDataSourcePosition = 21 399 , EQueryDataSourcePosition = 22 400 , EParserCreate = 23 401 //Recognizer module commands 402 , ERecognizerStart = 24 403 , ERecognizerClose = 25 404 //License commands. 405 , ECPMQueryLicenseInterface = 26 406 , ECPMGetLicense = 27 407 , ECPMGetLicenseW = 28 408 , ECPMCancelGetLicense = 29 409 }; 410 411 int32 iCmd; 412 413 // The pure virtual method IssueCommand is called on a subnode container to request that the passed 414 // command be issued to the contained node (or object). 415 virtual PVMFStatus IssueCommand(int32) = 0; 416 417 // CommandDone is a base class method, which is called by the subnode container when a command that was issued completes. 418 // In this method we handle removing the completed subnode command from the subnode command vector, and then we call Run 419 // on our container (the DLMGR) so that the next subnode command will be run. If we see that there are no more subnode 420 // commands in the subnode command vector, we instead call CommandComplete on the DLMGR. 421 void CommandDone(PVMFStatus, PVInterface*, OsclAny*); 422 423 //for canceling commands. 424 virtual bool CancelPendingCommand() = 0; 425 PVMFCommandId iCancelCmdId; 426 CmdState iCancelCmdState; 427 void CancelCommandDone(PVMFStatus, PVInterface*, OsclAny*); 428 CmdPending()429 bool CmdPending() 430 { 431 return iCmdState != EIdle || iCancelCmdState != EIdle; 432 } 433 }; 434 435 /* 436 * Containers for the protocol, socket, and parser nodes (but not the cpm object and not the recognizer) 437 */ 438 class PVMFDownloadManagerSubNodeContainer 439 : public PVMFDownloadManagerSubNodeContainerBase 440 , public PVMFNodeErrorEventObserver 441 , public PVMFNodeInfoEventObserver 442 , public PVMFNodeCmdStatusObserver 443 { 444 public: PVMFDownloadManagerSubNodeContainer()445 PVMFDownloadManagerSubNodeContainer() 446 { 447 iDataSourceInit = NULL; 448 iProtocolEngineExtensionInt = NULL; 449 iDataSourcePlayback = NULL; 450 iTrackSelection = NULL; 451 iDatastreamUser = NULL; 452 iMetadata = NULL; 453 iFormatProgDownloadSupport = NULL; 454 iDownloadProgress = NULL; 455 iNode = NULL; 456 iLicenseInterface = NULL; 457 } 458 ~PVMFDownloadManagerSubNodeContainer()459 ~PVMFDownloadManagerSubNodeContainer() 460 { 461 Cleanup(); 462 } 463 464 void Cleanup(); 465 466 // pure virtuals from PVMFDownloadManagerSubNodeContainerBase 467 PVMFStatus IssueCommand(int32); 468 bool CancelPendingCommand(); 469 470 // node 471 PVMFNodeInterface *iNode; 472 void Connect(); 473 474 // Node data-- pointers to retrieved interfaces. 475 PVInterface* iDataSourceInit; 476 PVInterface* iProtocolEngineExtensionInt; 477 PVInterface* iTrackSelection; 478 PVInterface* iMetadata; 479 PVInterface* iFormatProgDownloadSupport; // The support interface provided by the format parser node 480 PVInterface* iDownloadProgress; 481 PVInterface* iDataSourcePlayback; 482 PVInterface* iDatastreamUser; 483 PVInterface* iLicenseInterface; 484 DataSourceInit()485 PVMFDataSourceInitializationExtensionInterface *DataSourceInit() 486 { 487 return (PVMFDataSourceInitializationExtensionInterface*)iDataSourceInit; 488 } ProtocolEngineExtension()489 PVMFProtocolEngineNodeExtensionInterface* ProtocolEngineExtension() 490 { 491 return (PVMFProtocolEngineNodeExtensionInterface*)iProtocolEngineExtensionInt; 492 } TrackSelection()493 PVMFTrackSelectionExtensionInterface* TrackSelection() 494 { 495 return (PVMFTrackSelectionExtensionInterface*)iTrackSelection; 496 } DatastreamUser()497 PVMIDatastreamuserInterface* DatastreamUser() 498 { 499 return (PVMIDatastreamuserInterface*)iDatastreamUser; 500 } Metadata()501 PVMFMetadataExtensionInterface *Metadata() 502 { 503 return (PVMFMetadataExtensionInterface*)iMetadata; 504 } FormatProgDownloadSupport()505 PVMFFormatProgDownloadSupportInterface *FormatProgDownloadSupport() 506 { 507 return (PVMFFormatProgDownloadSupportInterface*)iFormatProgDownloadSupport; 508 } DownloadProgress()509 PVMFDownloadProgressInterface *DownloadProgress() 510 { 511 return (PVMFDownloadProgressInterface*)iDownloadProgress; 512 } DataSourcePlayback()513 PvmfDataSourcePlaybackControlInterface *DataSourcePlayback() 514 { 515 return (PvmfDataSourcePlaybackControlInterface*)iDataSourcePlayback; 516 } LicenseInterface()517 PVMFCPMPluginLicenseInterface* LicenseInterface() 518 { 519 return (PVMFCPMPluginLicenseInterface*)iLicenseInterface; 520 } 521 522 //Node event observers 523 void HandleNodeErrorEvent(const PVMFAsyncEvent& aEvent); 524 void HandleNodeInformationalEvent(const PVMFAsyncEvent& aEvent); 525 void NodeCommandCompleted(const PVMFCmdResp& aResponse); 526 }; 527 528 529 /* Container for the recognizer 530 */ 531 class PVMFDownloadManagerRecognizerContainer 532 : public PVMFDownloadManagerSubNodeContainerBase, 533 public PVMFRecognizerCommmandHandler 534 { 535 public: 536 // Recognizer to use for determining mime type of downloaded data 537 // PVMFRecognizer iRecognizer; PVMFDownloadManagerRecognizerContainer()538 PVMFDownloadManagerRecognizerContainer() 539 { 540 iRecognizerSessionId = 0; 541 }; 542 ~PVMFDownloadManagerRecognizerContainer()543 ~PVMFDownloadManagerRecognizerContainer() 544 { 545 Cleanup(); 546 } 547 void Cleanup(); 548 549 //pure virtuals from PVMFDownloadManagerSubNodeContainerBase 550 PVMFStatus IssueCommand(int32); 551 bool CancelPendingCommand(); 552 553 void RecognizerCommandCompleted(const PVMFCmdResp& aResponse); 554 555 PVMFSessionId iRecognizerSessionId; 556 Oscl_Vector<PVMFRecognizerResult, OsclMemAllocator> iRecognizerResultVec; 557 }; 558 559 /** 560 * Download Manager Node. 561 * This node contains the protocol engine node, the socket node, and a format parser node. 562 * The format parser node is instantiated after using the recognizer to determine the 563 * format type of the data stream. 564 * 565 * The usage sequence is as follows: 566 * 567 * Create 568 * Connect 569 * ThreadLogon 570 * 571 * (All extension intefaces are available for query now.) 572 * 573 * QueryInterface 574 * SetSourceInitializationData 575 * Init (CPM authorization is done during this command) 576 * 577 * (Track selection is available now) 578 * 579 * GetMediaPresentationInfo 580 * SelectTracks 581 * Prepare 582 * 583 * (The Metadata is available now) 584 * (Ports are available now) 585 * 586 * RequestPort 587 * Configure & Connect ports 588 * 589 * (App should wait on PVMFInfoDataReady before calling Start, but 590 * it is not a strict requirement. If Start is called too soon, 591 * playback will likely underflow immediately.) 592 * 593 * Start 594 * 595 * (playback begins) 596 * 597 * This node does not create any ports. Port requests are passed directly 598 * to the format parser node. 599 * 600 */ 601 class PVMFDownloadManagerNode 602 : public PVMFNodeInterface 603 , public OsclActiveObject 604 , public PvmiCapabilityAndConfig 605 //required extension interfaces for player source nodes. 606 , public PVMFDataSourceInitializationExtensionInterface 607 , public PVMFTrackSelectionExtensionInterface 608 , public PvmfDataSourcePlaybackControlInterface 609 , public PVMFMetadataExtensionInterface 610 , public PVMFDataSourceNodeRegistryInitInterface 611 , public PVMFCPMPluginLicenseInterface 612 // For observing the playback clock states 613 , public PVMFMediaClockStateObserver 614 { 615 public: 616 PVMFDownloadManagerNode(int32 aPriority = OsclActiveObject::EPriorityNominal); 617 ~PVMFDownloadManagerNode(); 618 619 // From PVMFNodeInterface 620 PVMFStatus ThreadLogon(); 621 PVMFStatus ThreadLogoff(); 622 PVMFStatus GetCapability(PVMFNodeCapability& aNodeCapability); 623 PVMFPortIter* GetPorts(const PVMFPortFilter* aFilter = NULL); 624 625 PVMFCommandId QueryUUID(PVMFSessionId aSessionId, 626 const PvmfMimeString& aMimeType, 627 Oscl_Vector<PVUuid, OsclMemAllocator>& aUuids, 628 bool aExactUuidsOnly = false, 629 const OsclAny* aContext = NULL); 630 PVMFCommandId QueryInterface(PVMFSessionId aSessionId, 631 const PVUuid& aUuid, 632 PVInterface*& aInterfacePtr, 633 const OsclAny* aContext = NULL); 634 635 PVMFCommandId RequestPort(PVMFSessionId aSessionId, int32 aPortTag, 636 const PvmfMimeString* aPortConfig = NULL, 637 const OsclAny* aContext = NULL); 638 PVMFStatus ReleasePort(PVMFSessionId aSessionId, PVMFPortInterface& aPort, 639 const OsclAny* aContext = NULL); 640 641 PVMFCommandId Init(PVMFSessionId aSessionId, const OsclAny* aContext = NULL); 642 PVMFCommandId Prepare(PVMFSessionId aSessionId, const OsclAny* aContext = NULL); 643 PVMFCommandId Start(PVMFSessionId aSessionId, const OsclAny* aContext = NULL); 644 PVMFCommandId Stop(PVMFSessionId aSessionId, const OsclAny* aContext = NULL); 645 PVMFCommandId Flush(PVMFSessionId aSessionId, const OsclAny* aContext = NULL); 646 PVMFCommandId Pause(PVMFSessionId aSessionId, const OsclAny* aContext = NULL); 647 PVMFCommandId Reset(PVMFSessionId aSessionId, const OsclAny* aContext = NULL); 648 649 PVMFCommandId CancelAllCommands(PVMFSessionId aSessionId, const OsclAny* aContextData = NULL); 650 PVMFCommandId CancelCommand(PVMFSessionId aSessionId, PVMFCommandId aCmdId, const OsclAny* aContextData = NULL); 651 652 //From PVInterface 653 void addRef(); 654 void removeRef(); 655 bool queryInterface(const PVUuid& uuid, PVInterface*& iface); 656 657 //From PVMFDataSourceInitializationExtensionInterface 658 PVMFStatus SetSourceInitializationData(OSCL_wString& aSourceURL, PVMFFormatType& aSourceFormat, OsclAny* aSourceData); 659 PVMFStatus SetClientPlayBackClock(PVMFMediaClock* aClientClock); 660 PVMFStatus SetEstimatedServerClock(PVMFMediaClock* aClientClock); 661 662 //From PVMFTrackSelectionExtensionInterface 663 PVMFStatus GetMediaPresentationInfo(PVMFMediaPresentationInfo& aInfo); 664 PVMFStatus SelectTracks(PVMFMediaPresentationInfo& aInfo); 665 666 // From PVMFMetadataExtensionInterface 667 uint32 GetNumMetadataKeys(char* aQueryKeyString = NULL); 668 uint32 GetNumMetadataValues(PVMFMetadataList& aKeyList); 669 PVMFCommandId GetNodeMetadataKeys(PVMFSessionId aSessionId, PVMFMetadataList& aKeyList, uint32 aStartingKeyIndex, int32 aMaxKeyEntries, 670 char* aQueryKeyString = NULL, const OsclAny* aContextData = NULL); 671 PVMFCommandId GetNodeMetadataValues(PVMFSessionId aSessionId, PVMFMetadataList& aKeyList, 672 Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList, uint32 aStartingValueIndex, int32 aMaxValueEntries, const OsclAny* aContextData = NULL); 673 PVMFStatus ReleaseNodeMetadataKeys(PVMFMetadataList& aKeyList, uint32 aStartingKeyIndex, uint32 aEndKeyIndex); 674 PVMFStatus ReleaseNodeMetadataValues(Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList, uint32 aStartingValueIndex, uint32 aEndValueIndex); 675 676 677 // From PvmfDataSourcePositioningControlInterface 678 PVMFCommandId SetDataSourcePosition(PVMFSessionId aSessionId, PVMFTimestamp aTargetNPT, PVMFTimestamp& aActualNPT, 679 PVMFTimestamp& aActualMediaDataTS, bool aSeekToSyncPoint = true, uint32 aStreamId = 0, OsclAny* aContext = NULL); 680 PVMFCommandId QueryDataSourcePosition(PVMFSessionId aSessionId, PVMFTimestamp aTargetNPT, PVMFTimestamp& aActualNPT, 681 bool aSeekToSyncPoint = true, OsclAny* aContext = NULL); 682 PVMFCommandId QueryDataSourcePosition(PVMFSessionId aSessionId, PVMFTimestamp aTargetNPT, 683 PVMFTimestamp& aSeekPointBeforeTargetNPT, PVMFTimestamp& aSeekPointAfterTargetNPT, 684 OsclAny* aContext = NULL, bool aSeekToSyncPoint = true); 685 686 PVMFCommandId SetDataSourceRate(PVMFSessionId aSessionId, int32 aRate, PVMFTimebase* aTimebase = NULL, OsclAny* aContext = NULL); 687 688 // From PVMFPortActivityHandler HandlePortActivity(const PVMFPortActivity & aActivity)689 void HandlePortActivity(const PVMFPortActivity& aActivity) 690 { 691 OSCL_UNUSED_ARG(aActivity); 692 } 693 694 //From PVMFDataSourceNodeRegistryInitInterface 695 PVMFStatus SetPlayerNodeRegistry(PVPlayerNodeRegistryInterface* aRegistry); 696 SetDebugMode()697 void SetDebugMode() 698 { 699 iDebugMode = true; 700 } 701 702 //From capability and config interface setObserver(PvmiConfigAndCapabilityCmdObserver * aObserver)703 virtual void setObserver(PvmiConfigAndCapabilityCmdObserver* aObserver) 704 { 705 ciObserver = aObserver; 706 } 707 708 virtual PVMFStatus getParametersSync(PvmiMIOSession aSession, 709 PvmiKeyType aIdentifier, 710 PvmiKvp*& aParameters, 711 int& aNumParamElements, 712 PvmiCapabilityContext aContext); 713 virtual PVMFStatus releaseParameters(PvmiMIOSession aSession, 714 PvmiKvp* aParameters, 715 int num_elements); 716 virtual void createContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext); 717 virtual void setContextParameters(PvmiMIOSession aSession, PvmiCapabilityContext& aContext, 718 PvmiKvp* aParameters, int num_parameter_elements); 719 virtual void DeleteContext(PvmiMIOSession aSession, 720 PvmiCapabilityContext& aContext); 721 virtual void setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, 722 int num_elements, PvmiKvp * & aRet_kvp); 723 virtual PVMFCommandId setParametersAsync(PvmiMIOSession aSession, 724 PvmiKvp* aParameters, 725 int num_elements, 726 PvmiKvp*& aRet_kvp, 727 OsclAny* context = NULL); 728 virtual uint32 getCapabilityMetric(PvmiMIOSession aSession); 729 virtual PVMFStatus verifyParametersSync(PvmiMIOSession aSession, 730 PvmiKvp* aParameters, 731 int num_elements); 732 733 //from PVMFMediaClockStateObserver 734 void ClockStateUpdated(); 735 void NotificationsInterfaceDestroyed(); 736 737 /* From PVMFCPMPluginLicenseInterface */ GetLicenseURL(PVMFSessionId aSessionId,OSCL_wString & aContentName,OSCL_wString & aLicenseURL)738 PVMFStatus GetLicenseURL(PVMFSessionId aSessionId, 739 OSCL_wString& aContentName, 740 OSCL_wString& aLicenseURL) 741 { 742 OSCL_UNUSED_ARG(aSessionId); 743 OSCL_UNUSED_ARG(aContentName); 744 OSCL_UNUSED_ARG(aLicenseURL); 745 //must use Async method. 746 return PVMFErrNotSupported; 747 } GetLicenseURL(PVMFSessionId aSessionId,OSCL_String & aContentName,OSCL_String & aLicenseURL)748 PVMFStatus GetLicenseURL(PVMFSessionId aSessionId, 749 OSCL_String& aContentName, 750 OSCL_String& aLicenseURL) 751 { 752 OSCL_UNUSED_ARG(aSessionId); 753 OSCL_UNUSED_ARG(aContentName); 754 OSCL_UNUSED_ARG(aLicenseURL); 755 //must use Async method. 756 return PVMFErrNotSupported; 757 } 758 759 PVMFCommandId GetLicense(PVMFSessionId aSessionId, 760 OSCL_wString& aContentName, 761 OsclAny* aData, 762 uint32 aDataSize, 763 int32 aTimeoutMsec, 764 OsclAny* aContextData) ; 765 766 PVMFCommandId GetLicense(PVMFSessionId aSessionId, 767 OSCL_String& aContentName, 768 OsclAny* aData, 769 uint32 aDataSize, 770 int32 aTimeoutMsec, 771 OsclAny* aContextData); 772 773 PVMFCommandId CancelGetLicense(PVMFSessionId aSessionId 774 , PVMFCommandId aCmdId 775 , OsclAny* aContextData); 776 777 private: 778 bool iDebugMode; 779 780 void ConstructL(); 781 782 // from OsclTimerObject 783 void Run(); 784 785 //Command processing 786 //There are 3 command queues. 787 //iInputCommands is the input queue for the node. It is N deep and allows for high priority commands to go to the front of the list. 788 //iCurrentCommand is a 1-deep holding place for a command that has started executing but has asynchronous completion. 789 //iCancelCommand is a 1-deep holding place for a cancel command that has started executing but has asynchronous completion. 790 PVMFDownloadManagerNodeCmdQueue iInputCommands; 791 PVMFDownloadManagerNodeCmdQueue iCurrentCommand; 792 PVMFDownloadManagerNodeCmdQueue iCancelCommand; 793 PVMFCommandId QueueCommandL(PVMFDownloadManagerNodeCommand& aCmd); 794 void ProcessCommand(); 795 void CommandComplete(PVMFDownloadManagerNodeCmdQueue& aCmdQueue, PVMFDownloadManagerNodeCommand& aCmd, PVMFStatus , PVInterface*, OsclAny*); 796 797 // Event reporting 798 void ReportErrorEvent(PVMFEventType aEventType, PVInterface*aExt = NULL, OsclAny* aEventData = NULL); 799 void ReportInfoEvent(PVMFAsyncEvent&); 800 void ChangeNodeState(TPVMFNodeInterfaceState aNewState); 801 802 // Node command handlers 803 PVMFStatus DoQueryUuid(PVMFDownloadManagerNodeCommand& aCmd); 804 PVMFStatus DoQueryInterface(PVMFDownloadManagerNodeCommand& aCmd); 805 PVMFStatus DoRequestPort(PVMFDownloadManagerNodeCommand& aCmd); 806 PVMFStatus DoReleasePort(PVMFDownloadManagerNodeCommand& aCmd); 807 PVMFStatus DoInitNode(PVMFDownloadManagerNodeCommand& aCmd); 808 PVMFStatus DoPrepareNode(PVMFDownloadManagerNodeCommand& aCmd); 809 PVMFStatus DoStartNode(PVMFDownloadManagerNodeCommand& aCmd); 810 PVMFStatus DoStopNode(PVMFDownloadManagerNodeCommand& aCmd); 811 PVMFStatus DoFlushNode(PVMFDownloadManagerNodeCommand& aCmd); 812 PVMFStatus DoPauseNode(PVMFDownloadManagerNodeCommand& aCmd); 813 PVMFStatus DoResetNode(PVMFDownloadManagerNodeCommand& aCmd); 814 PVMFStatus DoCancelAllCommands(PVMFDownloadManagerNodeCommand& aCmd); 815 PVMFStatus DoCancelCommand(PVMFDownloadManagerNodeCommand& aCmd); 816 // For metadata extention interface 817 PVMFStatus DoGetNodeMetadataKey(PVMFDownloadManagerNodeCommand& aCmd); 818 PVMFStatus DoGetNodeMetadataValue(PVMFDownloadManagerNodeCommand& aCmd); 819 // For data source position extension interface 820 PVMFStatus DoSetDataSourcePosition(PVMFDownloadManagerNodeCommand& aCmd); 821 PVMFStatus DoQueryDataSourcePosition(PVMFDownloadManagerNodeCommand& aCmd); 822 823 bool IsByteBasedDownloadProgress(OSCL_String &aDownloadProgressInfo); 824 bool GetHttpExtensionHeaderParams(PvmiKvp &aParameter, 825 OSCL_String &extensionHeaderKey, 826 OSCL_String &extensionHeaderValue, 827 HttpMethod &httpMethod, 828 bool &aPurgeOnRedirect); 829 bool IsHttpExtensionHeaderValid(PvmiKvp &aParameter); 830 // remove the ending ';', ',' or ' ' and calulate value length 831 uint32 getItemLen(char *ptrItemStart, char *ptrItemEnd); 832 833 bool IsDownloadExtensionHeaderValid(PvmiKvp &); 834 835 // MIME type of the downloaded data 836 OSCL_HeapString<OsclMemAllocator> iMimeType; 837 838 // playback mode 839 enum TDlMgrPlaybackMode 840 { 841 EPlayAsap 842 , EDownloadThenPlay 843 , EDownloadOnly 844 #if(PVMF_DOWNLOADMANAGER_SUPPORT_PPB) 845 , EPlaybackOnly 846 #endif//PVMF_DOWNLOADMANAGER_SUPPORT_PPB 847 }; 848 TDlMgrPlaybackMode iPlaybackMode; 849 850 // Name of local file to store downloaded data 851 OSCL_wHeapString<OsclMemAllocator> iDownloadFileName; 852 853 // Format type of media 854 PVMFFormatType iFmt; 855 856 // The local data source info gleaned from the source data set via SetSourceInit interface 857 PVMFSourceContextDataCommon iLocalDataSource; 858 859 //Source data. 860 PVMFFormatType iSourceFormat; 861 OSCL_wHeapString<OsclMemAllocator> iSourceURL; 862 OsclAny*iSourceData; 863 864 PVMFNodeCapability iCapability; 865 PVLogger* iLogger; 866 friend class PVMFDownloadManagerSubNodeContainerBase; 867 friend class PVMFDownloadManagerSubNodeContainer; 868 friend class PVMFDownloadManagerRecognizerContainer; 869 870 // Reference counter for extension 871 uint32 iExtensionRefCount; 872 873 //Sub-nodes. 874 PVMFDownloadManagerSubNodeContainer iFormatParserNode; 875 PVMFDownloadManagerSubNodeContainer iProtocolEngineNode; 876 PVMFDownloadManagerSubNodeContainer iSocketNode; 877 878 PVMFDownloadManagerSubNodeContainer& TrackSelectNode(); 879 880 // Recognizer 881 PVMFDownloadManagerRecognizerContainer iRecognizerNode; 882 883 // Filebufferdatastream object 884 PVMFFileBufferDataStream* iFileBufferDatastreamFactory; 885 #if(PVMF_DOWNLOADMANAGER_SUPPORT_PPB) 886 // MemoryBufferDataStream object 887 PVMFMemoryBufferDataStream* iMemoryBufferDatastreamFactory; 888 #endif //PVMF_DOWNLOADMANAGER_SUPPORT_PPB 889 PVMFDataStreamFactory* iReadFactory; 890 PVMFDataStreamFactory* iWriteFactory; 891 NotifyDownloadComplete()892 void NotifyDownloadComplete() 893 { 894 #if(PVMF_DOWNLOADMANAGER_SUPPORT_PPB) 895 if (EPlaybackOnly == iPlaybackMode) 896 { 897 if (iMemoryBufferDatastreamFactory != NULL) 898 { 899 iMemoryBufferDatastreamFactory->NotifyDownloadComplete(); 900 } 901 } 902 else 903 #endif//PVMF_DOWNLOADMANAGER_SUPPORT_PPB 904 { 905 if (iFileBufferDatastreamFactory != NULL) 906 { 907 iFileBufferDatastreamFactory->NotifyDownloadComplete(); 908 } 909 } 910 } 911 912 //flags 913 bool iParserInit;//set when file parse sequence is initiated. 914 bool iDataReady;//set when initial data ready is received or generated. 915 bool iDownloadComplete;//set when DL is complete. 916 bool iMovieAtomComplete;//set when movie atom DL complete for fast-track. 917 bool iNoPETrackSelect;//set after deciding that PE cannot to track selection. 918 bool iParserInitAfterMovieAtom; 919 bool iParserPrepareAfterMovieAtom; 920 921 bool iRecognizerError;//set when recognizer fails. 922 PVMFStatus iRecognizerStartStatus; 923 924 bool iInitFailedLicenseRequired; //set when PVMFErrLicenseRequired failed 925 926 void ContinueInitAfterTrackSelectDecision(); 927 void ContinueFromDownloadTrackSelectionPoint(); 928 void ContinueAfterMovieAtom(); 929 930 PVMFNodeInterface* CreateParser(); 931 932 //event handling 933 void GenerateDataReadyEvent(); 934 bool FilterPlaybackEventsFromSubNodes(const PVMFAsyncEvent& aEvent); 935 936 // Socket Config Info, for configuring socket node. 937 OSCL_HeapString<OsclMemAllocator> iServerAddr; 938 939 // Ports for the protocol node and the socket node 940 PVMFPortInterface* iProtocolEngineNodePort; 941 PVMFPortInterface* iSocketNodePort; 942 943 //The sub-node command vec contains all the sub-node commands needed for a single node command. 944 class CmdElem 945 { 946 public: 947 PVMFDownloadManagerSubNodeContainerBase* iNC; 948 PVMFDownloadManagerSubNodeContainerBase::CmdType iCmd; 949 }; 950 Oscl_Vector<CmdElem, OsclMemAllocator> iSubNodeCmdVec; 951 PVMFStatus ScheduleSubNodeCommands(PVMFDownloadManagerNodeCommand& aCmd); 952 void Push(PVMFDownloadManagerSubNodeContainerBase&, PVMFDownloadManagerSubNodeContainerBase::CmdType); 953 954 //Recognizer related 955 PVPlayerNodeRegistryInterface* iPlayerNodeRegistry; 956 957 //Vector to store the Uuids for the download manager nodes created throughout the playback 958 Oscl_Vector<PVUuid, OsclMemAllocator> iDNodeUuids; 959 960 //Count for Uuids 961 uint32 iDNodeUuidCount; 962 // playback clock which will be received form the engine. 963 PVMFMediaClock *iPlayBackClock; 964 PVMFMediaClockNotificationsInterface *iClockNotificationsInf; 965 966 // HTTP Content-Type header MIME string hint from the server 967 OSCL_HeapString<OsclMemAllocator> iContentTypeMIMEString; 968 969 PVMFStatus DoGetLicense(PVMFDownloadManagerNodeCommand& aCmd, 970 bool aWideCharVersion = false); 971 void CompleteGetLicense(); 972 973 PVMFStatus DoCancelGetLicense(PVMFDownloadManagerNodeCommand& aCmd); 974 }; 975 976 /////////////////////////////////////////////////////////////////////////////// 977 // 978 // Capability and config interface related constants and definitions 979 // - based on pv_player_engine.h 980 // 981 /////////////////////////////////////////////////////////////////////////////// 982 struct DownloadManagerKeyStringData 983 { 984 char iString[64]; 985 PvmiKvpType iType; 986 PvmiKvpValueType iValueType; 987 }; 988 989 // The number of characters to allocate for the key string 990 #define DLMCONFIG_KEYSTRING_SIZE 128 991 992 993 /////////////////////////////////////////////////////////////////////////////// 994 // 995 // Constants for setting up socket mem pool for progressive playback and shoutcast 996 // These constants are not tunables. 997 // 998 /////////////////////////////////////////////////////////////////////////////// 999 #define PVMF_DOWNLOADMANAGER_TCP_BUFFER_SIZE_FOR_SC 1500 1000 #define PVMF_DOWNLOADMANAGER_TCP_BUFFER_SIZE_FOR_PPB 64000 1001 #define PVMF_DOWNLOADMANAGER_TCP_BUFFER_NOT_AVAILABLE 2 1002 #define PVMF_DOWNLOADMANAGER_TCP_BUFFER_OVERHEAD 64 1003 #define PVMF_DOWNLOADMANAGER_TCP_AVG_SMALL_PACKET_SIZE 250 1004 1005 1006 1007 #endif // PVMF_DOWNLOADMANAGER_NODE_H_INCLUDED 1008 1009