From 351936aeac72e838297837ac4c6da66399fbc2d1 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Tue, 26 Mar 2024 23:53:30 +1100 Subject: [PATCH] rtpmp4adepay: Set duration on outgoing buffers If we can calculate timestamps for buffers, then set the duration on outgoing buffers based on the number of samples depayloaded. This can fix the muxing to mp4, where otherwise the last packet in a muxed file will have 0 duration in the mp4 file. Part-of: --- .../gst/rtp/gstrtpmp4adepay.c | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/subprojects/gst-plugins-good/gst/rtp/gstrtpmp4adepay.c b/subprojects/gst-plugins-good/gst/rtp/gstrtpmp4adepay.c index 6ef10d7275..fc5e603033 100644 --- a/subprojects/gst-plugins-good/gst/rtp/gstrtpmp4adepay.c +++ b/subprojects/gst-plugins-good/gst/rtp/gstrtpmp4adepay.c @@ -351,9 +351,11 @@ gst_rtp_mp4a_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp) guint8 *data; guint pos; GstClockTime timestamp; + guint64 samples_consumed; avail = gst_adapter_available (rtpmp4adepay->adapter); timestamp = gst_adapter_prev_pts (rtpmp4adepay->adapter, NULL); + samples_consumed = 0; GST_LOG_OBJECT (rtpmp4adepay, "have marker and %u available", avail); @@ -402,16 +404,25 @@ gst_rtp_mp4a_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp) avail -= skip; GST_BUFFER_PTS (tmp) = timestamp; + + if (timestamp != -1 && depayload->clock_rate != 0) { + GST_BUFFER_PTS (tmp) += + gst_util_uint64_scale_int (samples_consumed, GST_SECOND, + depayload->clock_rate); + + /* shift ts for next buffers */ + if (rtpmp4adepay->frame_len) { + samples_consumed += rtpmp4adepay->frame_len; + + GstClockTime next_timestamp = + timestamp + gst_util_uint64_scale_int (samples_consumed, + GST_SECOND, depayload->clock_rate); + GST_BUFFER_DURATION (tmp) = next_timestamp - GST_BUFFER_PTS (tmp); + } + } + gst_rtp_drop_non_audio_meta (depayload, tmp); gst_buffer_list_add (outbufs, tmp); - - /* shift ts for next buffers */ - if (rtpmp4adepay->frame_len && timestamp != -1 - && depayload->clock_rate != 0) { - timestamp += - gst_util_uint64_scale_int (rtpmp4adepay->frame_len, GST_SECOND, - depayload->clock_rate); - } } /* now push all sub-frames we found */