[asterisk-commits] oej: branch group/pinefool-poor-mans-plc-1.4 r383510 - /team/group/pinefool-p...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Mar 21 10:35:17 CDT 2013
Author: oej
Date: Thu Mar 21 10:35:12 2013
New Revision: 383510
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383510
Log:
Plan B mostly by Martin Festr Vit (voipmonitor.org).
If we have packet loss shown in incoming stream - actually skip some
sequence numbers in the outbound stream so that the other end can
handle packet loss properly.
Modified:
team/group/pinefool-poor-mans-plc-1.4/main/rtp.c
Modified: team/group/pinefool-poor-mans-plc-1.4/main/rtp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pinefool-poor-mans-plc-1.4/main/rtp.c?view=diff&rev=383510&r1=383509&r2=383510
==============================================================================
--- team/group/pinefool-poor-mans-plc-1.4/main/rtp.c (original)
+++ team/group/pinefool-poor-mans-plc-1.4/main/rtp.c Thu Mar 21 10:35:12 2013
@@ -162,6 +162,7 @@
struct ast_smoother *smoother;
int *ioid;
unsigned short seqno; /*!< Sequence number, RFC 3550, page 13. */
+ unsigned short prev_frame_seqno; /*!< Sequence number, RFC 3550, page 13. */
unsigned short rxseqno;
struct sched_context *sched;
struct io_context *io;
@@ -508,6 +509,16 @@
/*! \brief List of current sessions */
static AST_LIST_HEAD_STATIC(protos, ast_rtp_protocol);
+static void increment_seqno(struct ast_rtp *rtp, struct ast_frame *f)
+{
+ if (f != NULL) {
+ rtp->prev_frame_seqno = f->seqno;
+ } else {
+ rtp->prev_frame_seqno = 0; /* Reset if we're sending DTMF or so */
+ }
+ rtp->seqno++;
+}
+
static void timeval2ntp(struct timeval tv, unsigned int *msw, unsigned int *lsw)
{
unsigned int sec, usec, frac;
@@ -1360,6 +1371,11 @@
}
if (ast_test_flag(rtp, FLAG_POORMANSPLC) && rtp->plcbuf != NULL) {
int i;
+ rtp->lastrxseqno++;
+ /* Fix the seqno in the frame */
+ rtp->plcbuf->seqno = rtp->lastrxseqno;
+ /* OEJ:: Fix timestamp */
+ ;rtp->lastrxts = timestamp;
for (i = 0; i < lostpackets; i++) {
AST_LIST_INSERT_TAIL(&frames, ast_frdup(rtp->plcbuf), frame_list);
ast_log(LOG_DEBUG, "**** Inserting buffer frame %d. \n", i + 1);
@@ -2431,7 +2447,7 @@
ast_inet_ntoa(rtp->them.sin_addr),
ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastdigitts, res - hdrlen);
/* Increment sequence number */
- rtp->seqno++;
+ increment_seqno(rtp, NULL);
/* Increment duration */
rtp->send_duration += 160;
/* Clear marker bit and set seqno */
@@ -2476,7 +2492,7 @@
ntohs(rtp->them.sin_port), rtp->send_payload, rtp->seqno, rtp->lastdigitts, res - hdrlen);
/* Increment sequence number */
- rtp->seqno++;
+ increment_seqno(rtp, NULL);
/* Increment duration */
rtp->send_duration += 160;
@@ -2535,7 +2551,7 @@
for (i = 0; i < 3; i++) {
rtpheader[0] = htonl((2 << 30) | (rtp->send_payload << 16) | (rtp->seqno));
res = sendto(rtp->s, (void *) rtpheader, hdrlen + 4, 0, (struct sockaddr *) &rtp->them, sizeof(rtp->them));
- rtp->seqno++;
+ increment_seqno(rtp, NULL);
if (res < 0)
ast_log(LOG_ERROR, "RTP Transmission error to %s:%d: %s\n",
ast_inet_ntoa(rtp->them.sin_addr),
@@ -2805,7 +2821,7 @@
/* Get a pointer to the header */
rtpheader = (unsigned int *)data;
- rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno++));
+ rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno));
rtpheader[1] = htonl(rtp->lastts);
rtpheader[2] = htonl(rtp->ssrc);
data[12] = level;
@@ -2818,6 +2834,7 @@
, ast_inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastts,res - hdrlen);
}
+ increment_seqno(rtp, NULL);
return 0;
}
@@ -2838,6 +2855,16 @@
if (rtp->sending_digit) {
return 0;
+ }
+
+ if (rtp->prev_frame_seqno > 0 && f->seqno && f->seqno != (rtp->prev_frame_seqno + 1)) {
+ /* We have incoming packet loss and need to signal that outbound. */
+ unsigned int loss = f->seqno - rtp->prev_frame_seqno - 1;
+ if (option_debug > 2) {
+ ast_log(LOG_DEBUG, "**** Incoming packet loss, letting it through: %u packets\n", loss);
+ }
+ /* Jump ahead, let the packet loss go straight through */
+ rtp->seqno += loss;
}
ms = calc_txstamp(rtp, &f->delivery);
@@ -2924,7 +2951,7 @@
ast_inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port), codec, rtp->seqno, rtp->lastts,res - hdrlen);
}
- rtp->seqno++;
+ increment_seqno(rtp, f);
return 0;
}
More information about the asterisk-commits
mailing list