Home | History | Annotate | Download | only in include
      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_JITTER_BUFFER_INTERNAL_H_INCLUDED
     19 #define PVMF_JITTER_BUFFER_INTERNAL_H_INCLUDED
     20 
     21 #ifndef PVMF_NODE_UTILS_H_INCLUDED
     22 #include "pvmf_node_utils.h"
     23 #endif
     24 #ifndef OSCL_MEM_MEMPOOL_H_INCLUDED
     25 #include "oscl_mem_mempool.h"
     26 #endif
     27 #ifndef PVMF_MEDIA_DATA_H_INCLUDED
     28 #include "pvmf_media_data.h"
     29 #endif
     30 #ifndef PVMF_JITTER_BUFFER_EXT_INTERFACE_H_INCLUDED
     31 #include "pvmf_jitter_buffer_ext_interface.h"
     32 #endif
     33 
     34 /**
     35  * Macros for calling PVLogger
     36  */
     37 #define PVMF_JBNODE_LOGERROR(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,ipLogger,PVLOGMSG_ERR,m);
     38 #define PVMF_JBNODE_LOGWARNING(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,ipLogger,PVLOGMSG_WARNING,m);
     39 #define PVMF_JBNODE_LOGINFOHI(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG,ipLogger,PVLOGMSG_INFO,m);
     40 #define PVMF_JBNODE_LOGINFOMED(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG,ipLogger,PVLOGMSG_INFO,m);
     41 #define PVMF_JBNODE_LOGINFOLOW(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG,ipLogger,PVLOGMSG_INFO,m);
     42 #define PVMF_JBNODE_LOGINFO(m) PVMF_JBNODE_LOGINFOMED(m)
     43 #define PVMF_JBNODE_LOGDATATRAFFIC(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,ipDataPathLogger,PVLOGMSG_INFO,m);
     44 #define PVMF_JBNODE_LOGDATATRAFFIC_IN(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,ipDataPathLoggerIn,PVLOGMSG_INFO,m);
     45 #define PVMF_JBNODE_LOGDATATRAFFIC_IN_E(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,ipDataPathLoggerIn,PVLOGMSG_ERR,m);
     46 #define PVMF_JBNODE_LOGDATATRAFFIC_OUT(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,ipDataPathLoggerOut,PVLOGMSG_INFO,m);
     47 #define PVMF_JBNODE_LOGDATATRAFFIC_OUT_E(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,ipDataPathLoggerOut,PVLOGMSG_ERR,m);
     48 #define PVMF_JBNODE_LOGCLOCK(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,ipClockLogger,PVLOGMSG_INFO,m);
     49 #define PVMF_JBNODE_LOGCLOCK_SESSION_DURATION(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,ipClockLoggerSessionDuration,PVLOGMSG_INFO,m);
     50 #define PVMF_JBNODE_LOGCLOCK_REBUFF(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,ipClockLoggerRebuff,PVLOGMSG_INFO,m);
     51 #define PVMF_JBNODE_LOGDIAGNOSTICS(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_PROF,ipDiagnosticsLogger,PVLOGMSG_INFO,m);
     52 #define PVMF_JBNODE_LOGDATATRAFFIC_FLOWCTRL(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,ipDataPathLoggerFlowCtrl,PVLOGMSG_INFO,m);
     53 #define PVMF_JBNODE_LOGDATATRAFFIC_FLOWCTRL_E(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,ipDataPathLoggerFlowCtrl,PVLOGMSG_ERR,m);
     54 #define PVMF_JBNODE_LOG_RTCP_DATAPATH(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,ipDataPathLoggerRTCP,PVLOGMSG_ERR,m);
     55 #define PVMF_JBNODE_LOG_EVENTS_CLOCK(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG,ipJBEventsClockLogger ,PVLOGMSG_INFO,m);
     56 #define PVMF_JBNODE_LOG_RTCP_AVSYNC(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,ipRTCPAVSyncLogger,PVLOGMSG_INFO,m);
     57 
     58 #define PVMF_JITTER_BUFFER_NEW(auditCB,T,params,ptr)    \
     59     {                                                   \
     60         ptr = OSCL_NEW(T,params);                       \
     61     }
     62 
     63 #define PVMF_JITTER_BUFFER_DELETE(auditCB,T,ptr)    \
     64     {                                               \
     65         OSCL_DELETE(ptr);                           \
     66     }
     67 
     68 #define PVMF_JITTER_BUFFER_TEMPLATED_DELETE(auditCB, T, Tsimple, ptr)   \
     69     {                                                                   \
     70         OSCL_DELETE(ptr);                                               \
     71     }
     72 
     73 //Default vector reserve size
     74 #define PVMF_JITTER_BUFFER_VECTOR_RESERVE 10
     75 
     76 //Starting value for command IDs
     77 #define PVMF_JITTER_BUFFER_NODE_COMMAND_ID_START 10000
     78 
     79 #define PVMF_JITTER_BUFFER_INTERNAL_CMDQ_SIZE 20
     80 
     81 //Node command type.
     82 typedef PVMFGenericNodeCommand<OsclMemAllocator> PVMFJitterBufferNodeCommandBase;
     83 
     84 class PVMFJitterBufferNodeCommand : public PVMFJitterBufferNodeCommandBase
     85 {
     86     public:
     87         void Construct(PVMFSessionId s,
     88                        int32 cmd,
     89                        int32 arg1,
     90                        int32 arg2,
     91                        int32& arg3,
     92                        const OsclAny*aContext)
     93         {
     94             PVMFJitterBufferNodeCommandBase::Construct(s, cmd, aContext);
     95             iParam1 = (OsclAny*)arg1;
     96             iParam2 = (OsclAny*)arg2;
     97             iParam3 = (OsclAny*) & arg3;
     98         };
     99 
    100         void Parse(int32&arg1, int32&arg2, int32*&arg3)
    101         {
    102             arg1 = (int32)iParam1;
    103             arg2 = (int32)iParam2;
    104             arg3 = (int32*)iParam3;
    105         };
    106 };
    107 
    108 //Command queue type
    109 typedef PVMFNodeCommandQueue<PVMFJitterBufferNodeCommand, OsclMemAllocator> PVMFJitterBufferNodeCmdQ;
    110 
    111 typedef struct tagPVMFJBCommandContext
    112 {
    113     int32 cmd;
    114     bool  oFree;
    115 } PVMFJBCommandContext;
    116 
    117 ///////////////////////////////////////////////////////
    118 // For Extension Interface implementation
    119 ///////////////////////////////////////////////////////
    120 
    121 //implementation class for extension interface
    122 class PVMFJitterBufferNode;
    123 
    124 class PVMFJitterBufferExtensionInterfaceImpl :
    125         public PVInterfaceImpl<OsclMemAllocator>,
    126         public PVMFJitterBufferExtensionInterface
    127 {
    128     public:
    129         PVMFJitterBufferExtensionInterfaceImpl(PVMFJitterBufferNode*);
    130         ~PVMFJitterBufferExtensionInterfaceImpl();
    131 
    132         OSCL_IMPORT_REF void setRTCPIntervalInMicroSecs(uint32 aRTCPInterval);
    133 
    134         OSCL_IMPORT_REF bool setPortParams(PVMFPortInterface* aPort,
    135                                            uint32 aTimeScale,
    136                                            uint32 aBitRate,
    137                                            OsclRefCounterMemFrag& aConfig,
    138                                            bool aRateAdaptation = false,
    139                                            uint32 aRateAdaptationFeedBackFrequency = 0);
    140 
    141         OSCL_IMPORT_REF bool setPlayRange(int32 aStartTimeInMS,
    142                                           int32 aStopTimeInMS,
    143                                           bool oPlayAfterASeek,
    144                                           bool aStopTimeAvailable = true);
    145 
    146         OSCL_IMPORT_REF void setPlayBackThresholdInMilliSeconds(uint32 threshold);
    147 
    148         OSCL_IMPORT_REF void setJitterBufferRebufferingThresholdInMilliSeconds(uint32 aThreshold);
    149         OSCL_IMPORT_REF void getJitterBufferRebufferingThresholdInMilliSeconds(uint32& aThreshold);
    150         OSCL_IMPORT_REF void setJitterBufferDurationInMilliSeconds(uint32 duration);
    151         OSCL_IMPORT_REF void getJitterBufferDurationInMilliSeconds(uint32& duration);
    152 
    153         OSCL_IMPORT_REF void setEarlyDecodingTimeInMilliSeconds(uint32 duration);
    154         OSCL_IMPORT_REF void setBurstThreshold(float burstThreshold);
    155 
    156         OSCL_IMPORT_REF void setClientPlayBackClock(PVMFMediaClock* clientClock);
    157         OSCL_IMPORT_REF void setMaxInactivityDurationForMediaInMs(uint32 duration);
    158         OSCL_IMPORT_REF void getMaxInactivityDurationForMediaInMs(uint32& duration);
    159 
    160         OSCL_IMPORT_REF bool PrepareForRepositioning(bool oUseExpectedClientClockVal = false,
    161                 uint32 aExpectedClientClockVal = 0);
    162 
    163         OSCL_IMPORT_REF bool setPortSSRC(PVMFPortInterface* aPort, uint32 aSSRC);
    164 
    165         OSCL_IMPORT_REF bool setPortRTPParams(PVMFPortInterface* aPort,
    166                                               bool   aSeqNumBasePresent,
    167                                               uint32 aSeqNumBase,
    168                                               bool   aRTPTimeBasePresent,
    169                                               uint32 aRTPTimeBase,
    170                                               bool   aNPTTimeBasePresent,
    171                                               uint32 aNPTInMS,
    172                                               bool oPlayAfterASeek = false);
    173 
    174         OSCL_IMPORT_REF bool setPortRTCPParams(PVMFPortInterface* aPort,
    175                                                int aNumSenders,
    176                                                uint32 aRR,
    177                                                uint32 aRS);
    178 
    179         OSCL_IMPORT_REF PVMFTimestamp getActualMediaDataTSAfterSeek();
    180         OSCL_IMPORT_REF PVMFTimestamp getMaxMediaDataTS();
    181 
    182         void addRef()
    183         {
    184             PVInterfaceImpl<OsclMemAllocator>::addRef();
    185         }
    186         void removeRef()
    187         {
    188             PVInterfaceImpl<OsclMemAllocator>::removeRef();
    189         }
    190         bool queryInterface(const PVUuid& uuid, PVInterface*& iface)
    191         {
    192             if (uuid == Uuid())
    193             {
    194                 addRef();
    195                 iface = this;
    196                 return true;
    197             }
    198             else
    199             {
    200                 iface = NULL;
    201                 return false;
    202             }
    203         }
    204 
    205         OSCL_IMPORT_REF PVMFStatus setServerInfo(PVMFJitterBufferFireWallPacketInfo& aServerInfo);
    206 
    207         OSCL_IMPORT_REF PVMFStatus NotifyOutOfBandEOS();
    208         OSCL_IMPORT_REF PVMFStatus SendBOSMessage(uint32 aStramID);
    209 
    210         OSCL_IMPORT_REF void SetSharedBufferResizeParams(uint32 maxNumResizes, uint32 resizeSize);
    211         OSCL_IMPORT_REF void GetSharedBufferResizeParams(uint32& maxNumResizes, uint32& resizeSize);
    212 
    213         OSCL_IMPORT_REF bool ClearJitterBuffer(PVMFPortInterface* aPort, uint32 aSeqNum);
    214         OSCL_IMPORT_REF void FlushJitterBuffer();
    215 
    216         OSCL_IMPORT_REF bool NotifyAutoPauseComplete();
    217 
    218         OSCL_IMPORT_REF bool NotifyAutoResumeComplete();
    219 
    220         OSCL_IMPORT_REF PVMFStatus SetInputMediaHeaderPreParsed(PVMFPortInterface* aPort,
    221                 bool aHeaderPreParsed);
    222 
    223         OSCL_IMPORT_REF PVMFStatus HasSessionDurationExpired(bool& aExpired);
    224         OSCL_IMPORT_REF bool PurgeElementsWithNPTLessThan(NptTimeFormat &aNPTTime);
    225 
    226         OSCL_IMPORT_REF void SetBroadCastSession();
    227         OSCL_IMPORT_REF void DisableFireWallPackets();
    228 
    229 
    230         OSCL_IMPORT_REF void StartOutputPorts();
    231         OSCL_IMPORT_REF void StopOutputPorts();
    232         OSCL_IMPORT_REF void UpdateJitterBufferState();
    233         OSCL_IMPORT_REF virtual void SetJitterBufferMemPoolInfo(const PvmfPortBaseImpl* aPort, uint32 aSize, uint32 aResizeSize, uint32 aMaxNumResizes, uint32 aExpectedNumberOfBlocksPerBuffer);
    234         OSCL_IMPORT_REF virtual void GetJitterBufferMemPoolInfo(const PvmfPortBaseImpl* aPort, uint32& aSize, uint32& aResizeSize, uint32& aMaxNumResizes, uint32& aExpectedNumberOfBlocksPerBuffer) const;
    235         OSCL_IMPORT_REF void SetJitterBufferChunkAllocator(OsclMemPoolResizableAllocator* aDataBufferAllocator, const PVMFPortInterface* aPort);
    236         OSCL_IMPORT_REF virtual bool PrepareForPlaylistSwitch();
    237 
    238     private:
    239         PVMFJitterBufferNode *iContainer;
    240         friend class PVMFJitterBufferNode;
    241 };
    242 
    243 #endif
    244