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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6447>
This commit is contained in:
Jan Schmidt 2024-03-26 23:53:30 +11:00 committed by GStreamer Marge Bot
parent 258e9d2bca
commit 351936aeac

View file

@ -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 */