[Pkg-voip-commits] [janus] 203/282: Added option to override threshold for detecting timestamp resets
Jonas Smedegaard
dr at jones.dk
Wed Dec 20 21:53:41 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/0.2.6-1
in repository janus.
commit 33dcf724826a917a35c1b53345e793868960f72a
Author: Lorenzo Miniero <lminiero at gmail.com>
Date: Mon Nov 27 16:50:29 2017 +0100
Added option to override threshold for detecting timestamp resets
---
plugins/janus_streaming.c | 40 +++++++++++++++-------------------------
postprocessing/janus-pp-rec.c | 34 +++++++++++++++++++++++++++-------
2 files changed, 42 insertions(+), 32 deletions(-)
diff --git a/plugins/janus_streaming.c b/plugins/janus_streaming.c
index a46b240..e21bcc0 100644
--- a/plugins/janus_streaming.c
+++ b/plugins/janus_streaming.c
@@ -388,6 +388,7 @@ typedef struct janus_streaming_rtp_source {
janus_recorder *vrc; /* The Janus recorder instance for this streams's video, if enabled */
janus_recorder *drc; /* The Janus recorder instance for this streams's data, if enabled */
janus_mutex rec_mutex; /* Mutex to protect the recorders from race conditions */
+ janus_rtp_switching_context context[3];
int audio_fd;
int video_fd[3];
int data_fd;
@@ -3250,6 +3251,9 @@ janus_streaming_mountpoint *janus_streaming_create_rtp_source(
live_rtp_source->arc = NULL;
live_rtp_source->vrc = NULL;
live_rtp_source->drc = NULL;
+ janus_rtp_switching_context_reset(&live_rtp_source->context[0]);
+ janus_rtp_switching_context_reset(&live_rtp_source->context[1]);
+ janus_rtp_switching_context_reset(&live_rtp_source->context[2]);
janus_mutex_init(&live_rtp_source->rec_mutex);
live_rtp_source->audio_fd = audio_fd;
live_rtp_source->video_fd[0] = video_fd[0];
@@ -4075,10 +4079,7 @@ static void *janus_streaming_relay_thread(void *data) {
int data_fd = source->data_fd;
char *name = g_strdup(mountpoint->name ? mountpoint->name : "??");
/* Needed to fix seq and ts */
- uint32_t a_last_ssrc = 0, a_last_ts = 0, a_base_ts = 0, a_base_ts_prev = 0,
- v_last_ssrc[3] = {0, 0, 0}, v_last_ts[3] = {0, 0, 0}, v_base_ts[3] = {0, 0, 0}, v_base_ts_prev[3] = {0, 0, 0};
- uint16_t a_last_seq = 0, a_base_seq = 0, a_base_seq_prev = 0,
- v_last_seq[3] = {0, 0, 0}, v_base_seq[3] = {0, 0, 0}, v_base_seq_prev[3] = {0, 0, 0};
+ uint32_t ssrc = 0, a_last_ssrc = 0, v_last_ssrc[3] = {0, 0, 0};
/* File descriptors */
socklen_t addrlen;
struct sockaddr_in remote;
@@ -4290,20 +4291,14 @@ static void *janus_streaming_relay_thread(void *data) {
if(ntohl(packet.data->ssrc) != a_last_ssrc) {
a_last_ssrc = ntohl(packet.data->ssrc);
JANUS_LOG(LOG_INFO, "[%s] New audio stream! (ssrc=%u)\n", name, a_last_ssrc);
- a_base_ts_prev = a_last_ts;
- a_base_ts = ntohl(packet.data->timestamp);
- a_base_seq_prev = a_last_seq;
- a_base_seq = ntohs(packet.data->seq_number);
}
- a_last_ts = (ntohl(packet.data->timestamp)-a_base_ts)+a_base_ts_prev+960; /* FIXME We're assuming Opus here... */
- packet.data->timestamp = htonl(a_last_ts);
- a_last_seq = (ntohs(packet.data->seq_number)-a_base_seq)+a_base_seq_prev+1;
- packet.data->seq_number = htons(a_last_seq);
- //~ JANUS_LOG(LOG_VERB, " ... updated RTP packet (ssrc=%u, pt=%u, seq=%u, ts=%u)...\n",
- //~ ntohl(rtp->ssrc), rtp->type, ntohs(rtp->seq_number), ntohl(rtp->timestamp));
packet.data->type = mountpoint->codecs.audio_pt;
/* Is there a recorder? */
+ janus_rtp_header_update(packet.data, &source->context[0], FALSE, 960);
+ ssrc = ntohl(packet.data->ssrc);
+ packet.data->ssrc = ntohl((uint32_t)mountpoint->id);
janus_recorder_save_frame(source->arc, buffer, bytes);
+ packet.data->ssrc = ntohl(ssrc);
/* Backup the actual timestamp and sequence number set by the restreamer, in case switching is involved */
packet.timestamp = ntohl(packet.data->timestamp);
packet.seq_number = ntohs(packet.data->seq_number);
@@ -4438,21 +4433,16 @@ static void *janus_streaming_relay_thread(void *data) {
if(ntohl(packet.data->ssrc) != v_last_ssrc[index]) {
v_last_ssrc[index] = ntohl(packet.data->ssrc);
JANUS_LOG(LOG_INFO, "[%s] New video stream! (ssrc=%u, index %d)\n", name, v_last_ssrc[index], index);
- v_base_ts_prev[index] = v_last_ts[index];
- v_base_ts[index] = ntohl(packet.data->timestamp);
- v_base_seq_prev[index] = v_last_seq[index];
- v_base_seq[index] = ntohs(packet.data->seq_number);
}
- v_last_ts[index] = (ntohl(packet.data->timestamp)-v_base_ts[index])+v_base_ts_prev[index]+4500; /* FIXME We're assuming 15fps here... */
- packet.data->timestamp = htonl(v_last_ts[index]);
- v_last_seq[index] = (ntohs(packet.data->seq_number)-v_base_seq[index])+v_base_seq_prev[index]+1;
- packet.data->seq_number = htons(v_last_seq[index]);
- //~ JANUS_LOG(LOG_VERB, " ... updated RTP packet (ssrc=%u, pt=%u, seq=%u, ts=%u)...\n",
- //~ ntohl(rtp->ssrc), rtp->type, ntohs(rtp->seq_number), ntohl(rtp->timestamp));
packet.data->type = mountpoint->codecs.video_pt;
/* Is there a recorder? (FIXME notice we only record the first substream, if simulcasting) */
- if(index == 0)
+ janus_rtp_header_update(packet.data, &source->context[index], TRUE, 4500);
+ if(index == 0) {
+ ssrc = ntohl(packet.data->ssrc);
+ packet.data->ssrc = ntohl((uint32_t)mountpoint->id);
janus_recorder_save_frame(source->vrc, buffer, bytes);
+ packet.data->ssrc = ntohl(ssrc);
+ }
/* Backup the actual timestamp and sequence number set by the restreamer, in case switching is involved */
packet.timestamp = ntohl(packet.data->timestamp);
packet.seq_number = ntohs(packet.data->seq_number);
diff --git a/postprocessing/janus-pp-rec.c b/postprocessing/janus-pp-rec.c
index a045b96..91ab40a 100644
--- a/postprocessing/janus-pp-rec.c
+++ b/postprocessing/janus-pp-rec.c
@@ -81,12 +81,13 @@ gboolean janus_log_timestamps = FALSE;
gboolean janus_log_colors = TRUE;
static janus_pp_frame_packet *list = NULL, *last = NULL;
-int working = 0;
+static int working = 0;
+
+static int post_reset_trigger = 200;
/* Signal handler */
-void janus_pp_handle_signal(int signum);
-void janus_pp_handle_signal(int signum) {
+static void janus_pp_handle_signal(int signum) {
working = 0;
}
@@ -104,6 +105,12 @@ int main(int argc, char *argv[])
janus_log_level = val;
JANUS_LOG(LOG_INFO, "Logging level: %d\n", janus_log_level);
}
+ if(g_getenv("JANUS_PPREC_POSTRESETTRIGGER") != NULL) {
+ int val = atoi(g_getenv("JANUS_PPREC_POSTRESETTRIGGER"));
+ if(val >= 0)
+ post_reset_trigger = val;
+ JANUS_LOG(LOG_INFO, "Post reset trigger: %d\n", post_reset_trigger);
+ }
/* Evaluate arguments */
if(argc != 3) {
@@ -162,6 +169,7 @@ int main(int argc, char *argv[])
long offset = 0;
uint16_t len = 0;
uint32_t count = 0;
+ uint32_t ssrc = 0;
char prebuffer[1500];
memset(prebuffer, 0, 1500);
/* Let's look for timestamp resets first */
@@ -362,7 +370,7 @@ int main(int argc, char *argv[])
/* Now let's parse the frames and order them */
uint32_t last_ts = 0, reset = 0;
int times_resetted = 0;
- uint32_t post_reset_pkts = 0;
+ int post_reset_pkts = 0;
offset = 0;
/* Timestamp reset related stuff */
last_ts = 0;
@@ -445,6 +453,18 @@ int main(int argc, char *argv[])
ntohs(ext->type), ntohs(ext->length));
skip += 4 + ntohs(ext->length)*4;
}
+ if(ssrc == 0) {
+ ssrc = ntohl(rtp->ssrc);
+ JANUS_LOG(LOG_INFO, "SSRC detected: %"SCNu32"\n", ssrc);
+ }
+ if(ssrc != ntohl(rtp->ssrc)) {
+ JANUS_LOG(LOG_WARN, "Dropping packet with unexpected SSRC: %"SCNu32" != %"SCNu32"\n",
+ ntohl(rtp->ssrc), ssrc);
+ /* Skip data */
+ offset += len;
+ count++;
+ continue;
+ }
/* Generate frame packet and insert in the ordered list */
janus_pp_frame_packet *p = g_malloc0(sizeof(janus_pp_frame_packet));
if(p == NULL) {
@@ -461,7 +481,7 @@ int main(int argc, char *argv[])
/* Is the new timestamp smaller than the next one, and if so, is it a timestamp reset or simply out of order? */
gboolean late_pkt = FALSE;
if(ntohl(rtp->timestamp) < last_ts && (last_ts-ntohl(rtp->timestamp) > 2*1000*1000*1000)) {
- if(post_reset_pkts > 1000) {
+ if(post_reset_pkts > post_reset_trigger) {
reset = ntohl(rtp->timestamp);
JANUS_LOG(LOG_WARN, "Timestamp reset: %"SCNu32"\n", reset);
times_resetted++;
@@ -469,13 +489,13 @@ int main(int argc, char *argv[])
}
} else if(ntohl(rtp->timestamp) > reset && ntohl(rtp->timestamp) > last_ts &&
(ntohl(rtp->timestamp)-last_ts > 2*1000*1000*1000)) {
- if(post_reset_pkts < 1000) {
+ if(post_reset_pkts < post_reset_trigger) {
JANUS_LOG(LOG_WARN, "Late pre-reset packet after a timestamp reset: %"SCNu32"\n", ntohl(rtp->timestamp));
late_pkt = TRUE;
times_resetted--;
}
} else if(ntohl(rtp->timestamp) < reset) {
- if(post_reset_pkts < 1000) {
+ if(post_reset_pkts < post_reset_trigger) {
JANUS_LOG(LOG_WARN, "Updating latest timestamp reset: %"SCNu32" (was %"SCNu32")\n", ntohl(rtp->timestamp), reset);
reset = ntohl(rtp->timestamp);
} else {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/janus.git
More information about the Pkg-voip-commits
mailing list