Added support for padding RTP payload to a multiple of a chunk size.

git-svn-id: http://yate.null.ro/svn/yate/trunk@2032 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2008-06-19 13:52:18 +00:00
parent 3ba6ae7b9b
commit f7f8f63aa0
4 changed files with 61 additions and 3 deletions

View File

@ -23,6 +23,10 @@
; anyssrc: bool: Accept any incoming SSRC, even if it changes frequently
;anyssrc=disable
; padding: int: Pad the RTP payload to a multiple of this setting
; Supported values are between 2 and 128
;padding=0
; rtcp: bool: Allocate socket for the RTCP protocol by default
;rtcp=enabled

View File

@ -277,7 +277,7 @@ void RTPReceiver::timerTick(const Time& when)
RTPSender::RTPSender(RTPSession* session, bool randomTs)
: RTPBaseIO(session), m_evTime(0), m_tsLast(0)
: RTPBaseIO(session), m_evTime(0), m_tsLast(0), m_padding(0)
{
if (randomTs)
m_ts = ::random() & ~1;
@ -299,9 +299,21 @@ bool RTPSender::rtpSend(bool marker, int payload, unsigned int timestamp, const
ssrcInit();
m_seq++;
DataBlock buf(0,len+12);
unsigned char padding = 0;
unsigned char byte1 = 0x80;
if (m_padding > 1) {
padding = len % m_padding;
if (padding) {
padding = m_padding - padding;
byte1 |= 0x20;
}
}
DataBlock buf(0,len+padding+12);
unsigned char* pc = (unsigned char*)buf.data();
*pc++ = 0x80;
if (padding)
pc[buf.length() - 1] = padding;
*pc++ = byte1;
*pc++ = payload;
*pc++ = (unsigned char)(m_seq >> 8);
*pc++ = (unsigned char)(m_seq & 0xff);
@ -403,6 +415,14 @@ bool RTPSender::sendEventData(unsigned int timestamp)
return false;
}
bool RTPSender::padding(int chunk)
{
if ((chunk < 0) || (chunk > 128))
return false;
m_padding = chunk;
return true;
}
void RTPSender::timerTick(const Time& when)
{
}

View File

@ -626,6 +626,21 @@ public:
*/
bool rtpSendKey(char key, int duration, int volume = 0, unsigned int timestamp = 0);
/**
* Get the payload padding size
* @return Chunk size to pad the payload to a multiple of
*/
inline int padding() const
{ return m_padding; }
/**
* Set the padding to a multiple of a data chunk
* @param chunk Size to pad the payload to a multiple of
* @return True if the new chunk size is valid
*/
bool padding(int chunk);
protected:
/**
* Method called periodically to send events and buffered data
@ -636,6 +651,7 @@ protected:
private:
int m_evTime;
unsigned int m_tsLast;
unsigned char m_padding;
bool sendEventData(unsigned int timestamp);
};
@ -803,6 +819,21 @@ public:
inline bool rtpSendKey(char key, int duration, int volume = 0, unsigned int timestamp = 0)
{ return m_send && m_send->rtpSendKey(key,duration,volume,timestamp); }
/**
* Get the payload padding size
* @return Chunk size to pad the payload to a multiple of
*/
inline int padding() const
{ return m_send ? m_send->padding() : 0; }
/**
* Set the padding to a multiple of a data chunk
* @param chunk Size to pad the payload to a multiple of
* @return True if the new chunk size is valid
*/
inline bool padding(int chunk)
{ return m_send && m_send->padding(chunk); }
/**
* Allocate and set a new dejitter buffer for the receiver in the session
* @param mindelay Minimum length of the dejitter buffer in microseconds

View File

@ -83,6 +83,7 @@ static TokenDict dict_tos[] = {
static int s_minport = MIN_PORT;
static int s_maxport = MAX_PORT;
static int s_bufsize = BUF_SIZE;
static int s_padding = 0;
static String s_tos;
static String s_localip;
static String s_notifyMsg;
@ -472,6 +473,7 @@ bool YRTPWrapper::startRTP(const char* raddr, unsigned int rport, const Message&
m_rtp->dataPayload(payload);
m_rtp->eventPayload(evpayload);
m_rtp->setTOS(tos);
m_rtp->padding(msg.getIntValue("padding",s_padding));
if (msg.getBoolValue("drillhole",s_drill)) {
bool ok = m_rtp->drillHole();
Debug(&splugin,(ok ? DebugInfo : DebugWarn),
@ -948,6 +950,7 @@ void YRTPPlugin::initialize()
s_localip = cfg.getValue("general","localip");
s_autoaddr = cfg.getBoolValue("general","autoaddr",true);
s_anyssrc = cfg.getBoolValue("general","anyssrc",false);
s_padding = cfg.getIntValue("general","padding",0);
s_rtcp = cfg.getBoolValue("general","rtcp",true);
s_drill = cfg.getBoolValue("general","drillhole",Engine::clientMode());
s_sleep = cfg.getIntValue("general","defsleep",5);