• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_RTP_JITTER_BUFFER_IMPL_H_INCLUDED
19 #define PVMF_RTP_JITTER_BUFFER_IMPL_H_INCLUDED
20 
21 #ifndef PVMF_JITTER_BUFFER_H_INCLUDED
22 #include "pvmf_jitter_buffer.h"
23 #endif
24 
25 #ifndef PVMF_MEDIA_CLOCK_H_INCLUDED
26 #include "pvmf_media_clock.h"
27 #endif
28 
29 #ifndef PVMF_JITTER_BUFFER_COMMON_TYPES_H_INCLUDED
30 #include "pvmf_jitter_buffer_common_types.h"
31 #endif
32 
33 #define PVMF_JITTER_BUFFER_ROLL_OVER_THRESHOLD_16BIT 2000
34 
35 class PVMFRTPJitterBufferImpl: public PVMFJitterBufferImpl
36 {
37     public:
38         OSCL_IMPORT_REF static PVMFJitterBuffer* New(const PVMFJitterBufferConstructParams& aCreationData);
39         OSCL_IMPORT_REF virtual ~PVMFRTPJitterBufferImpl();
40         OSCL_IMPORT_REF virtual void StreamingSessionStarted();
41         OSCL_IMPORT_REF virtual void ResetJitterBuffer();
42 
43         OSCL_IMPORT_REF void AdjustRTPTimeStamp();
44         OSCL_IMPORT_REF virtual void setRTPInfoParams(PVMFRTPInfoParams rtpInfoParams, bool oPlayAfterASeek);
45         OSCL_IMPORT_REF uint32 getInterArrivalJitter();
46         OSCL_IMPORT_REF virtual void PurgeElementsWithSeqNumsLessThan(uint32 aSeqNum, uint32 aPlayerClockMS);
47         OSCL_IMPORT_REF virtual void PurgeElementsWithTimestampLessThan(PVMFTimestamp aTS);
48         OSCL_IMPORT_REF virtual PVMFSharedMediaDataPtr& GetFirstDataPacket(void);
49         OSCL_IMPORT_REF virtual bool GetRTPTimeStampOffset(uint32& aTimeStampOffset);
50         OSCL_IMPORT_REF virtual void  SetRTPTimeStampOffset(uint32 newTSBase);
51         OSCL_IMPORT_REF virtual bool NotifyFreeSpaceAvailable();
52         OSCL_IMPORT_REF virtual void SetEarlyDecodingTimeInMilliSeconds(uint32 duration);
53         OSCL_IMPORT_REF virtual void SetBurstThreshold(float burstThreshold);
54         OSCL_IMPORT_REF virtual bool IsDelayEstablished(uint32& aClockDiff);
55         OSCL_IMPORT_REF bool IsSeqTsValidForPkt(uint32 aSeqNum, uint32 aTs, PVMFJitterBufferStats& jbStats);
56 
57     protected:
58         void Construct();
59         virtual bool CanRetrievePacket();
60         virtual bool CanRetrievePacket(PVMFSharedMediaMsgPtr& aMediaOutMsg, bool& aCmdPacket);
61         virtual PVMFJBPacketParsingAndStatUpdationStatus ParsePacketHeaderAndUpdateJBStats(PVMFSharedMediaDataPtr& inDataPacket,
62                 PVMFSharedMediaDataPtr& outDataPacket,
63                 uint32 aFragIndex = 0);
64         PVMFRTPJitterBufferImpl(const PVMFJitterBufferConstructParams& aCreationData);
65 
66         //virtual uint32 GetNumOfPackets(PVMFSharedMediaMsgPtr& aMsg) const;
67         virtual void EOSCmdReceived();
68         void UpdateInterArrivalJitter(PVMFTimestamp currPacketTS);
69         void UpdateEstimatedServerClock(bool oFreshStart = false);
70 
71         //PVMFJitterBufferRegisterMediaMsgStatus addPacket(PVMFSharedMediaDataPtr& aDataPacket);
CheckForRTPTimeAndRTPSeqNumberBase()72         virtual void CheckForRTPTimeAndRTPSeqNumberBase()
73         {
74             if (iRTPInfoParamsVec.size() > 0)
75             {
76                 Oscl_Vector<PVMFRTPInfoParams, OsclMemAllocator>::iterator it;
77                 it = iRTPInfoParamsVec.begin();
78                 if (it->rtpTimeBaseSet == false)
79                 {
80                     /* Use the value from the first packet */
81                     if (seqNumLock)
82                     {
83                         iPrevTSOut = seqLockTimeStamp;
84                         iPrevTSIn = seqLockTimeStamp;
85                         iPrevAdjustedRTPTS = seqLockTimeStamp;
86                     }
87                 }
88                 if (it->seqNumBaseSet == false)
89                 {
90                     /* Use the value from the first packet */
91                     if (seqNumLock)
92                     {
93                         iPrevSeqNumBaseOut = iFirstSeqNum;
94                         iPrevSeqNumBaseIn = iFirstSeqNum;
95                     }
96                 }
97             }
98         }
99 
FindRTPInfoParams(uint32 aSeqNum)100         PVMFRTPInfoParams *FindRTPInfoParams(uint32 aSeqNum)
101         {
102             if (iRTPInfoParamsVec.size() == 1)
103             {
104                 return (iRTPInfoParamsVec.begin());
105             }
106 
107             PVMFRTPInfoParams* retVal = NULL;
108             Oscl_Vector<PVMFRTPInfoParams, OsclMemAllocator>::iterator it;
109 
110 
111             for (it = iRTPInfoParamsVec.begin();
112                     it < iRTPInfoParamsVec.end();
113                     it++)
114             {
115                 if (it->seqNum <= aSeqNum)
116                 {
117                     retVal = it;
118                 }
119             }
120             return retVal;
121         }
122         bool IsSequenceNumEarlier(uint16 aSeqNumToComp, uint16 aBaseSeqNum, uint16& aDiff);
123         void ReportJBInfoEvent(PVMFAsyncEvent& aEvent);
124         void UpdatePacketArrivalStats(PVMFSharedMediaDataPtr& aArrivedPacket);
125         void DeterminePrevTimeStampPeek(uint32 aSeqNum,
126                                         PVMFTimestamp& aPrevTS);
127         void DeterminePrevTimeStamp(uint32 aSeqNum);
128         void ComputeMaxAdjustedRTPTS();
129         PVMFStatus PerformFlowControl(bool aIncomingPacket);
130 
131         PVMFMediaClock* iPacketArrivalClock;
132         PVMFTimebase_Tickcount iPacketArrivalTimeBase;
133         PVMFTimestamp iPrevPacketTS;
134         double iInterArrivalJitterD;
135         uint32 iPrevPacketRecvTime;
136 
137         //Burst detection variables:
138         bool            iBurstDetect;
139         uint32          iBurstStartTimestamp;
140         uint32          iEstServerClockBurstStartTimestamp;
141         PVMFMediaClock  *iBurstClock;               //may be wallclock owned by the jitterbuffer Misc can be used instead
142         PVMFTimebase_Tickcount iBurstClockTimeBase;
143         bool            iRTPDataArrived;
144         uint32          iEarlyDecodingTime;
145         bool            iServerBurst;
146         float           iBurstThreshold;
147         uint32          iBurstDetectDurationInMilliSec;
148         bool            iInitialBuffering;
149 
150         uint32          iPlayListRTPTimeBase;
151         bool            iPlayListRTPTimeBaseSet;
152 
153         bool   isPrevRtpTimeSet;
154         uint32 iPrevRtpTimeBase;
155         bool   isPrevNptTimeSet;
156         uint32 iPrevNptTimeInRTPTimeScale;
157         MediaClockConverter iMediaClockConvertor;
158 
159 };
160 #endif
161 
162 
163