From 9de4c137ea4c797b5af4d9d3634bca9032dcd069 Mon Sep 17 00:00:00 2001 From: Alessandro Toppi Date: Fri, 27 Oct 2023 12:21:56 +0200 Subject: [PATCH] Fix postprocessing restamping (broken since commit f51524e for DTX support) --- src/postprocessing/janus-pp-rec.c | 8 ++++++-- src/postprocessing/pp-opus.c | 5 +++-- src/postprocessing/pp-opus.h | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/postprocessing/janus-pp-rec.c b/src/postprocessing/janus-pp-rec.c index 087d0140fb..1dbca56c43 100644 --- a/src/postprocessing/janus-pp-rec.c +++ b/src/postprocessing/janus-pp-rec.c @@ -1277,7 +1277,11 @@ int main(int argc, char *argv[]) { } /* Run restamping */ - if(!video && !data && options.restamp_multiplier > 0) { + gboolean restamping = FALSE; + if(options.restamp_multiplier > 0) { + restamping = TRUE; + } + if(!video && !data && restamping) { tmp = list; uint64_t restamping_offset = 0; double restamp_threshold = (double) options.restamp_min_th/1000; @@ -1439,7 +1443,7 @@ int main(int argc, char *argv[]) { /* Loop */ if(!video && !data) { if(opus) { - if(janus_pp_opus_process(file, list, &working) < 0) { + if(janus_pp_opus_process(file, list, restamping, &working) < 0) { JANUS_LOG(LOG_ERR, "Error processing Opus RTP frames...\n"); } } else if(g711) { diff --git a/src/postprocessing/pp-opus.c b/src/postprocessing/pp-opus.c index df0fb85fed..1521e4a7d4 100644 --- a/src/postprocessing/pp-opus.c +++ b/src/postprocessing/pp-opus.c @@ -101,7 +101,7 @@ int janus_pp_opus_create(char *destination, char *metadata, gboolean multiopus, // It assumes ALL the packets are of the 20ms kind #define OPUS_PACKET_DURATION 48 * 20; -int janus_pp_opus_process(FILE *file, janus_pp_frame_packet *list, int *working) { +int janus_pp_opus_process(FILE *file, janus_pp_frame_packet *list, gboolean restamping, int *working) { if(!file || !list || !working) return -1; janus_pp_frame_packet *tmp = list; @@ -251,7 +251,8 @@ int janus_pp_opus_process(FILE *file, janus_pp_frame_packet *list, int *working) AVRational timebase = {1, 48000}; while(*working && tmp != NULL) { - if(tmp->prev != NULL && ((tmp->ts - tmp->prev->ts)/48/20 > 1) && (tmp->seq != tmp->prev->seq+1)) { + /* if restamping is being used, do not evaluate the sequence number jump */ + if(tmp->prev != NULL && ((tmp->ts - tmp->prev->ts)/48/20 > 1) && (restamping || (tmp->seq != tmp->prev->seq+1))) { JANUS_LOG(LOG_WARN, "Lost a packet here? (got seq %"SCNu16" after %"SCNu16", time ~%"SCNu64"s)\n", tmp->seq, tmp->prev->seq, (tmp->ts-list->ts)/48000); /* use ts differ to insert silence packet */ diff --git a/src/postprocessing/pp-opus.h b/src/postprocessing/pp-opus.h index 3d45317f59..bdf37cc4e0 100644 --- a/src/postprocessing/pp-opus.h +++ b/src/postprocessing/pp-opus.h @@ -19,7 +19,7 @@ /* Opus stuff */ const char **janus_pp_opus_get_extensions(void); int janus_pp_opus_create(char *destination, char *metadata, gboolean multiopus, const char *extension, int opusred_pt); -int janus_pp_opus_process(FILE *file, janus_pp_frame_packet *list, int *working); +int janus_pp_opus_process(FILE *file, janus_pp_frame_packet *list, gboolean restamping, int *working); void janus_pp_opus_close(void); #endif