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_MEDIALAYER_PORT_H_INCLUDED 19 #define PVMF_MEDIALAYER_PORT_H_INCLUDED 20 21 #ifndef OSCL_BASE_H_INCLUDED 22 #include "oscl_base.h" 23 #endif 24 #ifndef OSCL_MEM_MEMPOOL_H_INCLUDED 25 #include "oscl_mem_mempool.h" 26 #endif 27 #ifndef PVLOGGER_H_INCLUDED 28 #include "pvlogger.h" 29 #endif 30 #ifndef PVLOGGER_FILE_APPENDER_H_INCLUDED 31 #include "pvlogger_file_appender.h" 32 #endif 33 #ifndef PVMF_PORT_BASE_IMPL_H_INCLUDED 34 #include "pvmf_port_base_impl.h" 35 #endif 36 #ifndef PVMI_CONFIG_AND_CAPABILITY_H_INCLUDED 37 #include "pvmi_config_and_capability.h" 38 #endif 39 #ifndef PAYLOAD_PARSER_H_INCLUDED 40 #include "payload_parser.h" 41 #endif 42 #ifndef PVMF_MEDIA_FRAG_GROU_H_INCLUDED 43 #include "pvmf_media_frag_group.h" 44 #endif 45 46 /** 47 * Macros for calling PVLogger 48 */ 49 #define PVMF_MLNODE_LOGERROR(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iLogger,PVLOGMSG_ERR,m); 50 #define PVMF_MLNODE_LOGWARNING(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iLogger,PVLOGMSG_WARNING,m); 51 #define PVMF_MLNODE_LOGINFOHI(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG,iLogger,PVLOGMSG_INFO,m); 52 #define PVMF_MLNODE_LOGINFOMED(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG,iLogger,PVLOGMSG_INFO,m); 53 #define PVMF_MLNODE_LOGINFOLOW(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG,iLogger,PVLOGMSG_INFO,m); 54 #define PVMF_MLNODE_LOGINFO(m) PVMF_MLNODE_LOGINFOMED(m) 55 #define PVMF_MLNODE_LOGBIN(iPortLogger, m) PVLOGGER_LOGBIN(PVLOGMSG_INST_LLDBG, iPortLogger, PVLOGMSG_ERR, m); 56 #define PVMF_MLNODE_LOGDATATRAFFIC(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iDataPathLogger,PVLOGMSG_INFO,m); 57 #define PVMF_MLNODE_LOGDATATRAFFIC_IN(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iDataPathLoggerIn,PVLOGMSG_INFO,m); 58 #define PVMF_MLNODE_LOGDATATRAFFIC_OUT(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iDataPathLoggerOut,PVLOGMSG_INFO,m); 59 #define PVMF_MLNODE_LOGDATATRAFFIC_E(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iDataPathLogger,PVLOGMSG_ERR,m); 60 #define PVMF_MLNODE_LOGDATATRAFFIC_FLOWCTRL(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iDataPathLoggerFlowCtrl,PVLOGMSG_INFO,m); 61 #define PVMF_MLNODE_LOGDIAGNOSTICS(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_PROF,iDiagnosticsLogger,PVLOGMSG_INFO,m); 62 #define PVMF_MLNODE_LOG_REPOS(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iReposLogger,PVLOGMSG_INFO,m); 63 #define PVMF_MLNODE_LOG_RUNL(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iRunlLogger,PVLOGMSG_INFO,m); 64 65 66 /** memory allocator type for this node */ 67 typedef OsclMemAllocator PVMFMediaLayerNodeAllocator; 68 69 /** Enumerated list of port tags supported by this port */ 70 typedef enum 71 { 72 PVMF_MEDIALAYER_PORT_TYPE_UNKNOWN = -1, 73 PVMF_MEDIALAYER_PORT_TYPE_INPUT = 0, 74 PVMF_MEDIALAYER_PORT_TYPE_OUTPUT = 1 75 } PVMFMediaLayerNodePortTag; 76 77 // Capability mime strings 78 #define PVMF_MEDIA_LAYER_PORT_SPECIFIC_ALLOCATOR "x-pvmf/pvmfstreaming/socketmemallocator" 79 #define PVMF_MEDIA_LAYER_PORT_SPECIFIC_ALLOCATOR_VALTYPE "x-pvmf/pvmfstreaming/socketmemallocator;valtype=ksv" 80 81 /* Supported Port Input Formats */ 82 #define RTP_PAYLOAD_RFC_3016_VISUAL 1 83 #define RTP_PAYLOAD_RFC_3016_AUDIO 2 84 #define RTP_PAYLOAD_RFC_3267_AMR 3 85 #define RTP_PAYLOAD_RFC_2429_H263 4 86 #define RTP_PAYLOAD_ASF 5 87 88 #define PVMF_MEDIA_LAYER_NODE_ASF_REPOS_TIME_OFFSET_IN_MS 2 89 90 /** values for FirstDataArrival */ 91 #define PVMF_ASF_TRACK_NO_DATA 1 92 #define PVMI_ASF_TRACK_DATA_ARRIVAL 2 93 #define PVMI_ASF_TRACK_DROP 3 94 95 class PVMFMediaLayerPortContainer 96 { 97 public: PVMFMediaLayerPortContainer()98 PVMFMediaLayerPortContainer() 99 { 100 id = -1; 101 tag = PVMF_MEDIALAYER_PORT_TYPE_UNKNOWN; 102 iPort = NULL; 103 iPayLoadParser = NULL; 104 oEOSReached = false; 105 oFirstDataArrival = PVMF_ASF_TRACK_NO_DATA; 106 oFormatSpecificInfoLogged = false; 107 oUpStreamEOSRecvd = false; 108 oProcessIncomingMessages = true; 109 oProcessOutgoingMessages = true; 110 iPrevMsgSeqNum = 0; 111 iPrevMsgTimeStamp = 0; 112 iPreRollInMS = 0; 113 iLiveStream = false; 114 iContinuousTimeStamp = 0; 115 iFirstFrameAfterRepositioning = false; 116 iFirstFrameAfterReposTimeStamp = 0; 117 118 ipFragGroupMemPool = NULL; 119 ipFragGroupAllocator = NULL; 120 121 iReConfig = false; 122 oDetectBrokenTrack = false; 123 oDisableTrack = false; 124 oReconfigId = 0; 125 126 iIsOneToN = false; 127 }; 128 129 PVMFMediaLayerPortContainer(const PVMFMediaLayerPortContainer & a)130 PVMFMediaLayerPortContainer(const PVMFMediaLayerPortContainer& a) 131 { 132 id = a.id; 133 tag = a.tag; 134 iPort = a.iPort; 135 iPayLoadParser = a.iPayLoadParser; 136 oEOSReached = a.oEOSReached; 137 oFirstDataArrival = a.oFirstDataArrival; 138 oFormatSpecificInfoLogged = a.oFormatSpecificInfoLogged; 139 oUpStreamEOSRecvd = a.oUpStreamEOSRecvd; 140 oProcessIncomingMessages = a.oProcessIncomingMessages; 141 oProcessOutgoingMessages = a.oProcessOutgoingMessages; 142 oDetectBrokenTrack = a.oDetectBrokenTrack; 143 oDisableTrack = a.oDisableTrack; 144 oReconfigId = a.oReconfigId; 145 pvOutPortLookupTable = a.pvOutPortLookupTable; 146 iPrevMsgSeqNum = a.iPrevMsgSeqNum; 147 iPrevMsgTimeStamp = a.iPrevMsgTimeStamp; 148 iPreRollInMS = a.iPreRollInMS; 149 iLiveStream = a.iLiveStream; 150 iIsOneToN = a.iIsOneToN; 151 iMimeType = a.iMimeType; 152 iTransportType = a.iTransportType; 153 iTrackConfig = a.iTrackConfig; 154 iPortLogger = a.iPortLogger; 155 iLogFile = a.iLogFile; 156 iBinAppenderPtr = a.iBinAppenderPtr; 157 vCounterPorts = a.vCounterPorts; 158 iContinuousTimeStamp = a.iContinuousTimeStamp; 159 iFirstFrameAfterRepositioning = a.iFirstFrameAfterRepositioning; 160 iFirstFrameAfterReposTimeStamp = a.iFirstFrameAfterReposTimeStamp; 161 vAccessUnits = Oscl_Vector<IPayloadParser::Payload, OsclMemAllocator>(a.vAccessUnits); 162 ipFragGroupMemPool = a.ipFragGroupMemPool;; 163 ipFragGroupAllocator = a.ipFragGroupAllocator; 164 iReConfig = a.iReConfig; 165 }; 166 167 PVMFMediaLayerPortContainer& operator=(const PVMFMediaLayerPortContainer& a) 168 { 169 if (&a != this) 170 { 171 id = a.id; 172 tag = a.tag; 173 iPort = a.iPort; 174 iPayLoadParser = a.iPayLoadParser; 175 oEOSReached = a.oEOSReached; 176 oFirstDataArrival = a.oFirstDataArrival; 177 oFormatSpecificInfoLogged = a.oFormatSpecificInfoLogged; 178 oUpStreamEOSRecvd = a.oUpStreamEOSRecvd; 179 oProcessIncomingMessages = a.oProcessIncomingMessages; 180 oProcessOutgoingMessages = a.oProcessOutgoingMessages; 181 oDetectBrokenTrack = a.oDetectBrokenTrack; 182 oDisableTrack = a.oDisableTrack; 183 oReconfigId = a.oReconfigId; 184 pvOutPortLookupTable.clear(); 185 pvOutPortLookupTable = a.pvOutPortLookupTable; 186 iPrevMsgSeqNum = a.iPrevMsgSeqNum; 187 iPrevMsgTimeStamp = a.iPrevMsgTimeStamp; 188 iPreRollInMS = a.iPreRollInMS; 189 iLiveStream = a.iLiveStream; 190 iIsOneToN = a.iIsOneToN; 191 iMimeType = a.iMimeType; 192 iTransportType = a.iTransportType; 193 iTrackConfig = a.iTrackConfig; 194 iPortLogger = a.iPortLogger; 195 iLogFile = a.iLogFile; 196 iBinAppenderPtr = a.iBinAppenderPtr; 197 vCounterPorts = a.vCounterPorts; 198 iContinuousTimeStamp = a.iContinuousTimeStamp; 199 iFirstFrameAfterRepositioning = a.iFirstFrameAfterRepositioning; 200 iFirstFrameAfterReposTimeStamp = a.iFirstFrameAfterReposTimeStamp; 201 vAccessUnits = Oscl_Vector<IPayloadParser::Payload, OsclMemAllocator>(a.vAccessUnits); 202 ipFragGroupMemPool = a.ipFragGroupMemPool; 203 ipFragGroupAllocator = a.ipFragGroupAllocator; 204 iReConfig = a.iReConfig; 205 } 206 return *this; 207 }; 208 ~PVMFMediaLayerPortContainer()209 virtual ~PVMFMediaLayerPortContainer() 210 { 211 pvOutPortLookupTable.clear(); 212 vAccessUnits.clear(); 213 }; 214 CleanUp()215 void CleanUp() 216 { 217 pvOutPortLookupTable.clear(); 218 vAccessUnits.clear(); 219 }; 220 ResetParams()221 void ResetParams() 222 { 223 oEOSReached = false; 224 oFirstDataArrival = PVMF_ASF_TRACK_NO_DATA; 225 oFormatSpecificInfoLogged = false; 226 oUpStreamEOSRecvd = false; 227 oProcessIncomingMessages = true; 228 oProcessOutgoingMessages = true; 229 oDetectBrokenTrack = false; 230 oDisableTrack = false; 231 oReconfigId = 0; 232 iPrevMsgSeqNum = 0; 233 iPrevMsgTimeStamp = 0; 234 iFirstFrameAfterRepositioning = false; 235 iFirstFrameAfterReposTimeStamp = 0; 236 iReConfig = false; 237 iContinuousTimeStamp = 0; 238 } 239 240 int32 id; 241 PVMFMediaLayerNodePortTag tag; 242 PVMFPortInterface* iPort; 243 244 // for input ports: 245 // - contains a vector of the associated output port indices 246 // for output ports: 247 // - contains a single element, the associated input port index 248 Oscl_Vector<int, OsclMemAllocator> vCounterPorts; 249 // for 1-n flows using stream id based lookups 250 Oscl_Vector<int, OsclMemAllocator> pvOutPortLookupTable; 251 252 253 // 254 // data for parsed payloads waiting to be sent 255 // 256 Oscl_Vector<IPayloadParser::Payload, OsclMemAllocator> vAccessUnits; 257 PVUid32 iCurrFormatId; 258 OsclRefCounterMemFrag iCurrFormatSpecInfo; 259 260 261 IPayloadParser* iPayLoadParser; 262 bool iIsOneToN; 263 OSCL_HeapString<PVMFMediaLayerNodeAllocator> iMimeType; 264 OSCL_HeapString<PVMFMediaLayerNodeAllocator> iTransportType; 265 OsclRefCounterMemFrag iTrackConfig; 266 PVLogger* iPortLogger; 267 OSCL_HeapString<PVMFMediaLayerNodeAllocator> iLogFile; 268 bool oUpStreamEOSRecvd; 269 bool oEOSReached; 270 uint32 oFirstDataArrival; 271 bool oFormatSpecificInfoLogged; 272 OsclSharedPtr<PVLoggerAppender> iBinAppenderPtr; 273 bool oProcessIncomingMessages; 274 bool oProcessOutgoingMessages; 275 bool oDetectBrokenTrack; 276 bool oDisableTrack; 277 278 uint32 iPrevMsgSeqNum; 279 uint32 iPrevMsgTimeStamp; 280 uint32 iPreRollInMS; 281 bool iLiveStream; 282 uint64 iContinuousTimeStamp; 283 bool iFirstFrameAfterRepositioning; 284 uint32 iFirstFrameAfterReposTimeStamp; 285 286 /*Send Reconfig*/ 287 uint32 oReconfigId; 288 PVMFSharedMediaMsgPtr oMsgReconfig; 289 290 // allocator for outgoing media frag groups 291 OsclMemPoolFixedChunkAllocator* ipFragGroupMemPool; 292 PVMFMediaFragGroupCombinedAlloc<OsclMemAllocator>* ipFragGroupAllocator; 293 294 /* stream switching related */ 295 bool iReConfig; 296 }; 297 298 /** 299 * 300 * 301 */ 302 class PVMFMediaLayerNode; 303 class PVMFMediaLayerPort : public PvmfPortBaseImpl, 304 public PvmiCapabilityAndConfig, 305 public OsclMemPoolFixedChunkAllocatorObserver 306 { 307 public: 308 /** 309 * Default constructor. Default settings will be used for the data queues. 310 * @param aId ID assigned to this port 311 * @param aTag Port tag 312 * @param aNode Container node 313 */ 314 PVMFMediaLayerPort(int32 aTag, 315 PVMFNodeInterface* aNode, 316 const char*); 317 318 /** 319 * Constructor that allows the node to configure the data queues of this port. 320 * @param aTag Port tag 321 * @param aNode Container node 322 * @param aSize Data queue capacity. The data queue size will not grow beyond this capacity. 323 * @param aReserve Size of data queue for which memory is reserved. This must be 324 * less than or equal to the capacity. If this is less than capacity, memory will be 325 * allocated when the queue grows beyond the reserve size, but will stop growing at 326 * capacity. 327 * @param aThreshold Ready-to-receive threshold, in terms of percentage of the data queue capacity. 328 * This value should be between 0 - 100. 329 */ 330 PVMFMediaLayerPort(int32 aTag, 331 PVMFNodeInterface* aNode, 332 uint32 aInCapacity, 333 uint32 aInReserve, 334 uint32 aInThreshold, 335 uint32 aOutCapacity, 336 uint32 aOutReserve, 337 uint32 aOutThreshold, 338 const char*); 339 340 /** Destructor */ 341 ~PVMFMediaLayerPort(); 342 343 /* Over ride QueryInterface - this port supports config interface */ QueryInterface(const PVUuid & aUuid,OsclAny * & aPtr)344 void QueryInterface(const PVUuid &aUuid, OsclAny*&aPtr) 345 { 346 if (aUuid == PVMI_CAPABILITY_AND_CONFIG_PVUUID) 347 aPtr = (PvmiCapabilityAndConfig*)this; 348 else 349 aPtr = NULL; 350 } 351 352 /* Over ride Connect() */ 353 PVMFStatus Connect(PVMFPortInterface* aPort); 354 355 /* Implement pure virtuals from PvmiCapabilityAndConfig interface */ 356 PVMFStatus getParametersSync(PvmiMIOSession aSession, PvmiKeyType aIdentifier, 357 PvmiKvp*& aParameters, int& num_parameter_elements, PvmiCapabilityContext aContext); 358 PVMFStatus releaseParameters(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements); 359 void setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, 360 int num_elements, PvmiKvp * & aRet_kvp); 361 PVMFStatus verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements); 362 363 /* Unsupported PvmiCapabilityAndConfig methods */ setObserver(PvmiConfigAndCapabilityCmdObserver * aObserver)364 void setObserver(PvmiConfigAndCapabilityCmdObserver* aObserver) 365 { 366 OSCL_UNUSED_ARG(aObserver); 367 }; createContext(PvmiMIOSession aSession,PvmiCapabilityContext & aContext)368 void createContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext) 369 { 370 OSCL_UNUSED_ARG(aSession); 371 OSCL_UNUSED_ARG(aContext); 372 } setContextParameters(PvmiMIOSession aSession,PvmiCapabilityContext & aContext,PvmiKvp * aParameters,int num_parameter_elements)373 void setContextParameters(PvmiMIOSession aSession, PvmiCapabilityContext& aContext, 374 PvmiKvp* aParameters, int num_parameter_elements) 375 { 376 OSCL_UNUSED_ARG(aSession); 377 OSCL_UNUSED_ARG(aContext); 378 OSCL_UNUSED_ARG(aParameters); 379 OSCL_UNUSED_ARG(num_parameter_elements); 380 } DeleteContext(PvmiMIOSession aSession,PvmiCapabilityContext & aContext)381 void DeleteContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext) 382 { 383 OSCL_UNUSED_ARG(aSession); 384 OSCL_UNUSED_ARG(aContext); 385 } 386 PVMFCommandId setParametersAsync(PvmiMIOSession aSession, PvmiKvp* aParameters, 387 int num_elements, PvmiKvp*& aRet_kvp, OsclAny* context = NULL) 388 { 389 OSCL_UNUSED_ARG(aSession); 390 OSCL_UNUSED_ARG(aParameters); 391 OSCL_UNUSED_ARG(num_elements); 392 OSCL_UNUSED_ARG(aRet_kvp); 393 OSCL_UNUSED_ARG(context); 394 return -1; 395 } getCapabilityMetric(PvmiMIOSession aSession)396 uint32 getCapabilityMetric(PvmiMIOSession aSession) 397 { 398 OSCL_UNUSED_ARG(aSession); 399 return 0; 400 } 401 402 403 //from OsclMemPoolFixedChunkAllocatorObserver 404 void freechunkavailable(OsclAny*) ; 405 406 bool peekHead(PVMFSharedMediaDataPtr& dataPtr, bool& bEos); 407 408 409 PVMFStatus pvmiVerifyPortFormatSpecificInfoSync(const char* aFormatValType, 410 OsclAny* aConfig); 411 412 //overrides from PVMFPortInterface 413 PVMFStatus QueueOutgoingMsg(PVMFSharedMediaMsgPtr aMsg); 414 bool IsOutgoingQueueBusy(); 415 416 private: 417 bool pvmiSetPortFormatSpecificInfoSync(PvmiCapabilityAndConfig *aPort, 418 const char* aFormatValType); 419 420 bool pvmiGetPortFormatSpecificInfoSync(const char* aFormatValType, 421 PvmiKvp*& aKvp); 422 423 void Construct(); 424 425 PVLogger *iLogger; 426 427 friend class Oscl_TAlloc<PVMFMediaLayerPort, PVMFMediaLayerNodeAllocator>; 428 friend class PVMFMediaLayerNodeExtensionInterfaceImpl; 429 430 PVMFMediaLayerNode *iMLNode; 431 PVMFMediaLayerNodePortTag iPortType; 432 433 434 435 }; 436 437 #endif // PVMF_MEDIALAYER_PORT_H_INCLUDED 438 439 440 441