From 93d4fe74c1d388a6cfaf1170b62a85e7bf9cb4ed Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 10 Mar 2023 09:15:09 -0500 Subject: [PATCH] MT#56861 use SSRC TS for "encoder" TS Support using the SSRC TS derived from received RTP packets as "encoder" TS (the "next" expected TS) for passthrough RTP in addition to the FIFO TS of an actual encoder. Change-Id: I7c49c27651eb89c5349bbf290b1c0ad160f77e3b --- daemon/codec.c | 12 +++++++++--- daemon/dtmf.c | 6 +++--- include/codec.h | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/daemon/codec.c b/daemon/codec.c index ff333fbbe..c67873d89 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -2452,9 +2452,15 @@ uint64_t codec_last_dtmf_event(struct codec_ssrc_handler *ch) { return ev->ts; } -uint64_t codec_encoder_pts(struct codec_ssrc_handler *ch) { - if (!ch || !ch->encoder) - return 0; +uint64_t codec_encoder_pts(struct codec_ssrc_handler *ch, struct ssrc_ctx *ssrc_in) { + if (!ch || !ch->encoder) { + if (!ssrc_in) + return 0; + uint64_t cur = atomic64_get(&ssrc_in->last_ts); + // return the TS of the next expected packet + cur += ch->ptime * ch->handler->source_pt.clock_rate / 1000; + return cur; + } return ch->encoder->fifo_pts; } diff --git a/daemon/dtmf.c b/daemon/dtmf.c index 323b7dd03..03706f61a 100644 --- a/daemon/dtmf.c +++ b/daemon/dtmf.c @@ -548,7 +548,7 @@ static const char *dtmf_inject_pcm(struct call_media *media, struct call_media * }; // keep track of how much PCM we've generated - uint64_t encoder_pts = codec_encoder_pts(csh); + uint64_t encoder_pts = codec_encoder_pts(csh, NULL); uint64_t skip_pts = codec_decoder_unskip_pts(csh); // reset to zero to take up our new samples ch->dtmf_injector->handler_func(ch->dtmf_injector, &packet); @@ -561,7 +561,7 @@ static const char *dtmf_inject_pcm(struct call_media *media, struct call_media * ch->dtmf_injector->handler_func(ch->dtmf_injector, &packet); // skip generated samples - uint64_t pts_offset = codec_encoder_pts(csh) - encoder_pts; + uint64_t pts_offset = codec_encoder_pts(csh, NULL) - encoder_pts; skip_pts += av_rescale(pts_offset, ch->dest_pt.clock_rate, ch->source_pt.clock_rate); codec_decoder_skip_pts(csh, skip_pts); @@ -641,7 +641,7 @@ const char *dtmf_inject(struct call_media *media, int code, int volume, int dura // synthesise start and stop events uint64_t num_samples = (uint64_t) duration * ch->dest_pt.clock_rate / 1000; - uint64_t start_pts = codec_encoder_pts(csh); + uint64_t start_pts = codec_encoder_pts(csh, ssrc_in); uint64_t last_end_pts = codec_last_dtmf_event(csh); if (last_end_pts) { // shift this new event past the end of the last event plus a pause diff --git a/include/codec.h b/include/codec.h index ab277234a..aa3084a84 100644 --- a/include/codec.h +++ b/include/codec.h @@ -150,7 +150,7 @@ bool codec_handlers_update(struct call_media *receiver, struct call_media *sink, const struct stream_params *); void codec_add_dtmf_event(struct codec_ssrc_handler *ch, int code, int level, uint64_t ts, bool injected); uint64_t codec_last_dtmf_event(struct codec_ssrc_handler *ch); -uint64_t codec_encoder_pts(struct codec_ssrc_handler *ch); +uint64_t codec_encoder_pts(struct codec_ssrc_handler *ch, struct ssrc_ctx *); void codec_decoder_skip_pts(struct codec_ssrc_handler *ch, uint64_t); uint64_t codec_decoder_unskip_pts(struct codec_ssrc_handler *ch); void codec_tracker_update(struct codec_store *);