jitter.h
Go to the documentation of this file.
/*
* jitter.h
*
* Jitter buffer support
*
* Open H323 Library
*
* Copyright (c) 1999-2001 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Open H323 Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Portions of this code were written with the assisance of funding from
* Vovida Networks, Inc. http://www.vovida.com.
*
* Contributor(s): ______________________________________.
*
* $Revision: 28053 $
* $Author: rjongbloed $
* $Date: 2012-07-18 02:50:22 -0500 (Wed, 18 Jul 2012) $
*/
#ifndef OPAL_RTP_JITTER_H
#define OPAL_RTP_JITTER_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <opal/buildopts.h>
#include <rtp/rtp.h>
class RTP_JitterBuffer;
class RTP_JitterBufferAnalyser;
class OpalJitterBuffer : public PSafeObject
{
PCLASSINFO(OpalJitterBuffer, PSafeObject);
public:
OpalJitterBuffer(
unsigned minJitterDelay,
unsigned maxJitterDelay,
unsigned timeUnits = 8,
PINDEX packetSize = 2048
);
virtual ~OpalJitterBuffer();
void PrintOn(
ostream & strm
) const;
void SetDelay(
unsigned minJitterDelay,
unsigned maxJitterDelay,
PINDEX packetSize = 2048
);
void Reset();
virtual PBoolean WriteData(
const RTP_DataFrame & frame,
const PTimeInterval & tick = 0
);
virtual PBoolean ReadData(
RTP_DataFrame & frame,
const PTimeInterval & tick = 0
);
DWORD GetCurrentJitterDelay() const { return m_currentJitterDelay; }
DWORD GetMinJitterDelay() const { return m_minJitterDelay; }
DWORD GetMaxJitterDelay() const { return m_maxJitterDelay; }
unsigned GetTimeUnits() const { return m_timeUnits; }
DWORD GetPacketsTooLate() const { return m_packetsTooLate; }
DWORD GetBufferOverruns() const { return m_bufferOverruns; }
DWORD GetMaxConsecutiveMarkerBits() const { return m_maxConsecutiveMarkerBits; }
void SetMaxConsecutiveMarkerBits(DWORD max) { m_maxConsecutiveMarkerBits = max; }
protected:
DWORD CalculateRequiredTimestamp(DWORD playOutTimestamp) const;
bool AdjustCurrentJitterDelay(int delta);
unsigned m_timeUnits;
PINDEX m_packetSize;
DWORD m_minJitterDelay;
DWORD m_maxJitterDelay;
int m_jitterGrowTime;
DWORD m_jitterShrinkPeriod;
int m_jitterShrinkTime;
DWORD m_silenceShrinkPeriod;
int m_silenceShrinkTime;
DWORD m_jitterDriftPeriod;
int m_currentJitterDelay;
DWORD m_packetsTooLate;
DWORD m_bufferOverruns;
DWORD m_consecutiveMarkerBits;
DWORD m_maxConsecutiveMarkerBits;
DWORD m_consecutiveLatePackets;
DWORD m_averageFrameTime;
DWORD m_lastTimestamp;
DWORD m_lastSyncSource;
DWORD m_bufferFilledTime;
DWORD m_bufferLowTime;
DWORD m_bufferEmptiedTime;
int m_timestampDelta;
enum {
e_SynchronisationStart,
e_SynchronisationFill,
e_SynchronisationShrink,
e_SynchronisationDone
} m_synchronisationState;
typedef std::map<DWORD, RTP_DataFrame> FrameMap;
FrameMap m_frames;
PMutex m_bufferMutex;
RTP_JitterBufferAnalyser * m_analyser;
};
class OpalJitterBufferThread : public OpalJitterBuffer
{
PCLASSINFO(OpalJitterBufferThread, OpalJitterBuffer);
public:
OpalJitterBufferThread(
unsigned minJitterDelay,
unsigned maxJitterDelay,
unsigned timeUnits = 8,
PINDEX packetSize = 2048
);
~OpalJitterBufferThread();
virtual PBoolean ReadData(
RTP_DataFrame & frame
);
virtual PBoolean OnReadPacket(
RTP_DataFrame & frame
) = 0;
void StartThread();
protected:
PDECLARE_NOTIFIER(PThread, OpalJitterBufferThread, JitterThreadMain);
void WaitForThreadTermination();
PThread * m_jitterThread;
bool m_running;
};
class RTP_JitterBuffer : public OpalJitterBufferThread
{
PCLASSINFO(RTP_JitterBuffer, OpalJitterBufferThread);
public:
RTP_JitterBuffer(
RTP_Session & session,
unsigned minJitterDelay,
unsigned maxJitterDelay,
unsigned timeUnits = 8,
PINDEX packetSize = 2048
);
~RTP_JitterBuffer();
virtual PBoolean OnReadPacket(
RTP_DataFrame & frame
);
protected:
RTP_Session & m_session;
};
#endif // OPAL_RTP_JITTER_H
OpalJitterBuffer::m_consecutiveLatePackets
DWORD m_consecutiveLatePackets
Definition: jitter.h:169
OpalJitterBuffer::m_timeUnits
unsigned m_timeUnits
Definition: jitter.h:152
OpalJitterBuffer::m_minJitterDelay
DWORD m_minJitterDelay
Minimum jitter delay in timestamp units.
Definition: jitter.h:154
OpalJitterBuffer::m_lastTimestamp
DWORD m_lastTimestamp
Definition: jitter.h:172
RTP_Session
Definition: rtp.h:502
RTP_JitterBuffer::~RTP_JitterBuffer
~RTP_JitterBuffer()
OpalJitterBuffer::m_maxConsecutiveMarkerBits
DWORD m_maxConsecutiveMarkerBits
Definition: jitter.h:168
OpalJitterBuffer::WriteData
virtual PBoolean WriteData(const RTP_DataFrame &frame, const PTimeInterval &tick=0)
OpalJitterBuffer::m_jitterShrinkTime
int m_jitterShrinkTime
Amount to shrink jitter delay by if consistently filled.
Definition: jitter.h:159
buildopts.h
OpalJitterBufferThread::m_running
bool m_running
Definition: jitter.h:236
OpalJitterBuffer::m_lastSyncSource
DWORD m_lastSyncSource
Definition: jitter.h:173
OpalJitterBuffer::GetMaxConsecutiveMarkerBits
DWORD GetMaxConsecutiveMarkerBits() const
Definition: jitter.h:141
OpalJitterBuffer::FrameMap
std::map< DWORD, RTP_DataFrame > FrameMap
Definition: jitter.h:186
OpalJitterBuffer::GetMinJitterDelay
DWORD GetMinJitterDelay() const
Definition: jitter.h:121
OpalJitterBufferThread::ReadData
virtual PBoolean ReadData(RTP_DataFrame &frame)
RTP_JitterBuffer::RTP_JitterBuffer
RTP_JitterBuffer(RTP_Session &session, unsigned minJitterDelay, unsigned maxJitterDelay, unsigned timeUnits=8, PINDEX packetSize=2048)
OpalJitterBuffer::AdjustCurrentJitterDelay
bool AdjustCurrentJitterDelay(int delta)
OpalJitterBufferThread::OnReadPacket
virtual PBoolean OnReadPacket(RTP_DataFrame &frame)=0
OpalJitterBuffer::SetDelay
void SetDelay(unsigned minJitterDelay, unsigned maxJitterDelay, PINDEX packetSize=2048)
RTP_JitterBuffer::OnReadPacket
virtual PBoolean OnReadPacket(RTP_DataFrame &frame)
OpalJitterBuffer::m_packetsTooLate
DWORD m_packetsTooLate
Definition: jitter.h:165
OpalJitterBuffer::ReadData
virtual PBoolean ReadData(RTP_DataFrame &frame, const PTimeInterval &tick=0)
OpalJitterBuffer::SetMaxConsecutiveMarkerBits
void SetMaxConsecutiveMarkerBits(DWORD max)
Definition: jitter.h:145
OpalJitterBuffer::m_analyser
RTP_JitterBufferAnalyser * m_analyser
Definition: jitter.h:190
OpalJitterBufferThread::WaitForThreadTermination
void WaitForThreadTermination()
Internal function to be called from derived class destructor.
OpalJitterBuffer::GetMaxJitterDelay
DWORD GetMaxJitterDelay() const
Definition: jitter.h:125
OpalJitterBuffer::PrintOn
void PrintOn(ostream &strm) const
OpalJitterBufferThread::m_jitterThread
PThread * m_jitterThread
Definition: jitter.h:235
OpalJitterBuffer::m_bufferMutex
PMutex m_bufferMutex
Definition: jitter.h:188
OpalJitterBuffer::m_bufferEmptiedTime
DWORD m_bufferEmptiedTime
Definition: jitter.h:176
RTP_DataFrame
Definition: rtp.h:71
OpalJitterBuffer::m_silenceShrinkPeriod
DWORD m_silenceShrinkPeriod
Reduce jitter delay is silent for this long.
Definition: jitter.h:160
OpalJitterBuffer
Definition: jitter.h:55
OpalJitterBuffer::~OpalJitterBuffer
virtual ~OpalJitterBuffer()
OpalJitterBuffer::OpalJitterBuffer
OpalJitterBuffer(unsigned minJitterDelay, unsigned maxJitterDelay, unsigned timeUnits=8, PINDEX packetSize=2048)
OpalJitterBuffer::GetCurrentJitterDelay
DWORD GetCurrentJitterDelay() const
Definition: jitter.h:117
OpalJitterBuffer::m_bufferFilledTime
DWORD m_bufferFilledTime
Definition: jitter.h:174
RTP_JitterBuffer::m_session
RTP_Session & m_session
Definition: jitter.h:267
OpalJitterBuffer::GetPacketsTooLate
DWORD GetPacketsTooLate() const
Definition: jitter.h:133
OpalJitterBuffer::e_SynchronisationDone
Definition: jitter.h:183
OpalJitterBufferThread::OpalJitterBufferThread
OpalJitterBufferThread(unsigned minJitterDelay, unsigned maxJitterDelay, unsigned timeUnits=8, PINDEX packetSize=2048)
OpalJitterBufferThread::StartThread
void StartThread()
OpalJitterBufferThread
Definition: jitter.h:197
OpalJitterBuffer::e_SynchronisationStart
Definition: jitter.h:180
OpalJitterBuffer::CalculateRequiredTimestamp
DWORD CalculateRequiredTimestamp(DWORD playOutTimestamp) const
OpalJitterBuffer::GetBufferOverruns
DWORD GetBufferOverruns() const
Definition: jitter.h:137
OpalJitterBuffer::m_maxJitterDelay
DWORD m_maxJitterDelay
Maximum jitter delay in timestamp units.
Definition: jitter.h:155
OpalJitterBuffer::m_silenceShrinkTime
int m_silenceShrinkTime
Amount to shrink jitter delay by if consistently silent.
Definition: jitter.h:161
OpalJitterBuffer::m_frames
FrameMap m_frames
Definition: jitter.h:187
OpalJitterBuffer::GetTimeUnits
unsigned GetTimeUnits() const
Definition: jitter.h:129
OpalJitterBufferThread::PDECLARE_NOTIFIER
PDECLARE_NOTIFIER(PThread, OpalJitterBufferThread, JitterThreadMain)
OpalJitterBuffer::m_bufferLowTime
DWORD m_bufferLowTime
Definition: jitter.h:175
RTP_JitterBuffer
Definition: jitter.h:244
OpalJitterBufferThread::~OpalJitterBufferThread
~OpalJitterBufferThread()
OpalJitterBuffer::m_currentJitterDelay
int m_currentJitterDelay
Definition: jitter.h:164
OpalJitterBuffer::m_jitterDriftPeriod
DWORD m_jitterDriftPeriod
Definition: jitter.h:162
OpalJitterBuffer::m_averageFrameTime
DWORD m_averageFrameTime
Definition: jitter.h:171
OpalJitterBuffer::m_consecutiveMarkerBits
DWORD m_consecutiveMarkerBits
Definition: jitter.h:167
OpalJitterBuffer::e_SynchronisationFill
Definition: jitter.h:181
OpalJitterBuffer::m_timestampDelta
int m_timestampDelta
Definition: jitter.h:177
OpalJitterBuffer::m_jitterShrinkPeriod
DWORD m_jitterShrinkPeriod
Definition: jitter.h:157
rtp.h
OpalJitterBuffer::Reset
void Reset()
OpalJitterBuffer::m_packetSize
PINDEX m_packetSize
Definition: jitter.h:153
OpalJitterBuffer::e_SynchronisationShrink
Definition: jitter.h:182
OpalJitterBuffer::m_bufferOverruns
DWORD m_bufferOverruns
Definition: jitter.h:166
OpalJitterBuffer::m_synchronisationState
enum OpalJitterBuffer::@35 m_synchronisationState
OpalJitterBuffer::m_jitterGrowTime
int m_jitterGrowTime
Amaint to increase jitter delay by when get "late" packet.
Definition: jitter.h:156