[asterisk-commits] res rtp multicast: Use consistent timestamps when possible (asterisk[master])
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 6 14:49:10 CDT 2017
Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/5764 )
Change subject: res_rtp_multicast: Use consistent timestamps when possible
......................................................................
res_rtp_multicast: Use consistent timestamps when possible
When a frame destined for a MulticastRTP channel does not have timing
information (such as when an 'originate' is done), we generate the RTP
timestamps ourselves without regard to the number of samples we are
about to send.
Instead, use the same method as res_rtp_asterisk and 'predict' a
timestamp given the number of samples. If the difference between the
timestamp that we generate and the one we predict is within a specific
threshold, use the predicted timestamp so that we end up with timestamps
that are consistent with the number of samples we are actually sending.
Change-Id: I2bf0db3541b1573043330421cbb114ff0f22ec1f
---
M res/res_rtp_multicast.c
1 file changed, 27 insertions(+), 10 deletions(-)
Approvals:
Mark Michelson: Looks good to me, approved
Jenkins2: Approved for Submit
Joshua Colp: Looks good to me, but someone else must approve
diff --git a/res/res_rtp_multicast.c b/res/res_rtp_multicast.c
index 14176da..72c5321 100644
--- a/res/res_rtp_multicast.c
+++ b/res/res_rtp_multicast.c
@@ -99,6 +99,8 @@
struct ast_smoother *smoother;
};
+#define MAX_TIMESTAMP_SKEW 640
+
enum {
OPT_CODEC = (1 << 0),
OPT_LOOP = (1 << 1),
@@ -415,21 +417,36 @@
unsigned char *rtpheader;
struct ast_sockaddr remote_address = { {0,} };
int rate = rtp_get_rate(frame->subclass.format) / 1000;
- int hdrlen = 12;
+ int hdrlen = 12, mark = 0;
- /* Calculate last TS */
- multicast->lastts = multicast->lastts + ms * rate;
+ if (ast_format_cmp(frame->subclass.format, ast_format_g722) == AST_FORMAT_CMP_EQUAL) {
+ frame->samples /= 2;
+ }
+
+ if (ast_test_flag(frame, AST_FRFLAG_HAS_TIMING_INFO)) {
+ multicast->lastts = frame->ts * rate;
+ } else {
+ /* Try to predict what our timestamp should be */
+ int pred = multicast->lastts + frame->samples;
+
+ /* Calculate last TS */
+ multicast->lastts = multicast->lastts + ms * rate;
+ if (ast_tvzero(frame->delivery)) {
+ int delta = abs((int) multicast->lastts - pred);
+ if (delta < MAX_TIMESTAMP_SKEW) {
+ multicast->lastts = pred;
+ } else {
+ ast_debug(3, "Difference is %d, ms is %u\n", delta, ms);
+ mark = 1;
+ }
+ }
+ }
/* Construct an RTP header for our packet */
rtpheader = (unsigned char *)(frame->data.ptr - hdrlen);
- put_unaligned_uint32(rtpheader, htonl((2 << 30) | (codec << 16) | (multicast->seqno)));
- if (ast_test_flag(frame, AST_FRFLAG_HAS_TIMING_INFO)) {
- put_unaligned_uint32(rtpheader + 4, htonl(frame->ts * 8));
- } else {
- put_unaligned_uint32(rtpheader + 4, htonl(multicast->lastts));
- }
-
+ put_unaligned_uint32(rtpheader, htonl((2 << 30) | (codec << 16) | (multicast->seqno) | (mark << 23)));
+ put_unaligned_uint32(rtpheader + 4, htonl(multicast->lastts));
put_unaligned_uint32(rtpheader + 8, htonl(multicast->ssrc));
/* Increment sequence number and wrap to 0 if it overflows 16 bits. */
--
To view, visit https://gerrit.asterisk.org/5764
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2bf0db3541b1573043330421cbb114ff0f22ec1f
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>
More information about the asterisk-commits
mailing list