rtp: In payloaders map the RTP marker flag to the corresponding buffer flag

This allows downstream of a payloader to know the RTP header's marker
flag without first having to map the buffer and parse the RTP header.

Especially inside RTP header extension implementations this can be
useful to decide which packet corresponds to e.g. the last packet of a
video frame.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1776>
This commit is contained in:
Sebastian Dröge 2022-02-22 11:18:53 +02:00 committed by GStreamer Marge Bot
parent 630dbea94c
commit b0afaffc5d
25 changed files with 49 additions and 5 deletions

View file

@ -322,8 +322,10 @@ gst_rtp_ac3_pay_flush (GstRtpAC3Pay * rtpac3pay)
payload[1] = NF; payload[1] = NF;
payload_len -= 2; payload_len -= 2;
if (avail == payload_len) if (avail == payload_len) {
gst_rtp_buffer_set_marker (&rtp, TRUE); gst_rtp_buffer_set_marker (&rtp, TRUE);
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
}
gst_rtp_buffer_unmap (&rtp); gst_rtp_buffer_unmap (&rtp);
payload_buffer = payload_buffer =

View file

@ -333,6 +333,7 @@ gst_rtp_amr_pay_handle_buffer (GstRTPBasePayload * basepayload,
if (GST_BUFFER_IS_DISCONT (buffer)) { if (GST_BUFFER_IS_DISCONT (buffer)) {
GST_DEBUG_OBJECT (basepayload, "discont, setting marker bit"); GST_DEBUG_OBJECT (basepayload, "discont, setting marker bit");
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
gst_rtp_buffer_set_marker (&rtp, TRUE); gst_rtp_buffer_set_marker (&rtp, TRUE);
gst_rtp_amr_pay_recalc_rtp_time (rtpamrpay, timestamp); gst_rtp_amr_pay_recalc_rtp_time (rtpamrpay, timestamp);
} }

View file

@ -372,6 +372,7 @@ gst_rtp_dv_pay_handle_buffer (GstRTPBasePayload * basepayload,
/* set marker */ /* set marker */
gst_rtp_buffer_set_marker (&rtp, TRUE); gst_rtp_buffer_set_marker (&rtp, TRUE);
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
/* shrink buffer to last packet */ /* shrink buffer to last packet */
hlen = gst_rtp_buffer_get_header_len (&rtp); hlen = gst_rtp_buffer_get_header_len (&rtp);

View file

@ -164,6 +164,7 @@ gst_rtp_g723_pay_flush (GstRTPG723Pay * pay)
/* set discont and marker */ /* set discont and marker */
if (pay->discont) { if (pay->discont) {
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
gst_rtp_buffer_set_marker (&rtp, TRUE); gst_rtp_buffer_set_marker (&rtp, TRUE);
pay->discont = FALSE; pay->discont = FALSE;
} }

View file

@ -189,6 +189,7 @@ gst_rtp_g729_pay_push (GstRTPG729Pay * rtpg729pay, GstBuffer * buf)
if (G_UNLIKELY (rtpg729pay->discont)) { if (G_UNLIKELY (rtpg729pay->discont)) {
GST_DEBUG_OBJECT (basepayload, "discont, setting marker bit"); GST_DEBUG_OBJECT (basepayload, "discont, setting marker bit");
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
gst_rtp_buffer_set_marker (&rtp, TRUE); gst_rtp_buffer_set_marker (&rtp, TRUE);
rtpg729pay->discont = FALSE; rtpg729pay->discont = FALSE;
} }

View file

@ -335,8 +335,10 @@ gst_rtp_gst_pay_create_from_adapter (GstRtpGSTPay * rtpgstpay,
frag_offset += payload_len; frag_offset += payload_len;
avail -= payload_len; avail -= payload_len;
if (avail == 0) if (avail == 0) {
gst_rtp_buffer_set_marker (&rtp, TRUE); gst_rtp_buffer_set_marker (&rtp, TRUE);
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
}
gst_rtp_buffer_unmap (&rtp); gst_rtp_buffer_unmap (&rtp);

View file

@ -844,6 +844,8 @@ gst_rtp_h261_pay_fragment_push (GstRtpH261Pay * pay, GstBuffer * buffer,
bits + GST_ROUND_DOWN_8 (start) / 8, nbytes); bits + GST_ROUND_DOWN_8 (start) / 8, nbytes);
GST_BUFFER_TIMESTAMP (outbuf) = pay->timestamp; GST_BUFFER_TIMESTAMP (outbuf) = pay->timestamp;
if (marker)
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
gst_rtp_buffer_set_marker (&rtp, marker); gst_rtp_buffer_set_marker (&rtp, marker);
pay->offset = end & 7; pay->offset = end & 7;

View file

@ -1311,8 +1311,10 @@ gst_rtp_h263_pay_push (GstRtpH263Pay * rtph263pay,
GST_BUFFER_PTS (package->outbuf) = rtph263pay->first_ts; GST_BUFFER_PTS (package->outbuf) = rtph263pay->first_ts;
gst_rtp_buffer_set_marker (&rtp, package->marker); gst_rtp_buffer_set_marker (&rtp, package->marker);
if (package->marker) if (package->marker) {
GST_BUFFER_FLAG_SET (package->outbuf, GST_BUFFER_FLAG_MARKER);
GST_DEBUG_OBJECT (rtph263pay, "Marker set!"); GST_DEBUG_OBJECT (rtph263pay, "Marker set!");
}
gst_rtp_buffer_unmap (&rtp); gst_rtp_buffer_unmap (&rtp);

View file

@ -742,6 +742,8 @@ gst_rtp_h263p_pay_flush (GstRtpH263PPay * rtph263ppay)
gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp); gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
/* last fragment gets the marker bit set */ /* last fragment gets the marker bit set */
gst_rtp_buffer_set_marker (&rtp, avail > towrite ? 0 : 1); gst_rtp_buffer_set_marker (&rtp, avail > towrite ? 0 : 1);
if (avail <= towrite)
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
payload = gst_rtp_buffer_get_payload (&rtp); payload = gst_rtp_buffer_get_payload (&rtp);

View file

@ -1085,6 +1085,8 @@ gst_rtp_h264_pay_payload_nal_fragment (GstRTPBasePayload * basepayload,
/* If it's the last fragment and the end of this au, mark the end of /* If it's the last fragment and the end of this au, mark the end of
* slice */ * slice */
gst_rtp_buffer_set_marker (&rtp, last_fragment && end_of_au); gst_rtp_buffer_set_marker (&rtp, last_fragment && end_of_au);
if (last_fragment && end_of_au)
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
/* FU indicator */ /* FU indicator */
payload[0] = (nal_header & 0x60) | FU_A_TYPE_ID; payload[0] = (nal_header & 0x60) | FU_A_TYPE_ID;
@ -1142,6 +1144,8 @@ gst_rtp_h264_pay_payload_nal_single (GstRTPBasePayload * basepayload,
/* Mark the end of a frame */ /* Mark the end of a frame */
gst_rtp_buffer_set_marker (&rtp, end_of_au); gst_rtp_buffer_set_marker (&rtp, end_of_au);
if (end_of_au)
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
/* timestamp the outbuffer */ /* timestamp the outbuffer */
GST_BUFFER_PTS (outbuf) = pts; GST_BUFFER_PTS (outbuf) = pts;

View file

@ -1140,6 +1140,7 @@ gst_rtp_h265_pay_payload_nal_single (GstRTPBasePayload * basepayload,
/* Mark the end of a frame */ /* Mark the end of a frame */
gst_rtp_buffer_set_marker (&rtp, marker); gst_rtp_buffer_set_marker (&rtp, marker);
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
/* timestamp the outbuffer */ /* timestamp the outbuffer */
GST_BUFFER_PTS (outbuf) = pts; GST_BUFFER_PTS (outbuf) = pts;
@ -1224,6 +1225,8 @@ gst_rtp_h265_pay_payload_nal_fragment (GstRTPBasePayload * basepayload,
/* If it's the last fragment and the end of this au, mark the end of /* If it's the last fragment and the end of this au, mark the end of
* slice */ * slice */
gst_rtp_buffer_set_marker (&rtp, last_fragment && marker); gst_rtp_buffer_set_marker (&rtp, last_fragment && marker);
if (last_fragment && marker)
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
/* FU Header */ /* FU Header */
payload[2] = (first_fragment << 7) | (last_fragment << 6) | payload[2] = (first_fragment << 7) | (last_fragment << 6) |

View file

@ -459,6 +459,7 @@ gst_rtp_j2k_pay_handle_buffer (GstRTPBasePayload * basepayload,
/* reached the end of a packetization unit */ /* reached the end of a packetization unit */
if (pu_size == 0 && end >= map.size) { if (pu_size == 0 && end >= map.size) {
gst_rtp_buffer_set_marker (&rtp, TRUE); gst_rtp_buffer_set_marker (&rtp, TRUE);
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
} }
/* If we were processing a header, see if all fits in one RTP packet /* If we were processing a header, see if all fits in one RTP packet
or if we have to fragment it */ or if we have to fragment it */

View file

@ -899,6 +899,7 @@ gst_rtp_jpeg_pay_handle_buffer (GstRTPBasePayload * basepayload,
GST_LOG_OBJECT (pay, "last packet of frame"); GST_LOG_OBJECT (pay, "last packet of frame");
frame_done = TRUE; frame_done = TRUE;
gst_rtp_buffer_set_marker (&rtp, 1); gst_rtp_buffer_set_marker (&rtp, 1);
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
} }
payload = gst_rtp_buffer_get_payload (&rtp); payload = gst_rtp_buffer_get_payload (&rtp);

View file

@ -157,6 +157,7 @@ gst_rtp_klv_pay_handle_buffer (GstRTPBasePayload * basepayload, GstBuffer * buf)
gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp); gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
gst_rtp_buffer_set_marker (&rtp, 1); gst_rtp_buffer_set_marker (&rtp, 1);
gst_rtp_buffer_unmap (&rtp); gst_rtp_buffer_unmap (&rtp);
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
} }
GST_LOG_OBJECT (pay, "packet with payload size %u", payload_size); GST_LOG_OBJECT (pay, "packet with payload size %u", payload_size);

View file

@ -432,6 +432,8 @@ gst_rtp_mp4a_pay_handle_buffer (GstRTPBasePayload * basepayload,
/* marker only if the packet is complete */ /* marker only if the packet is complete */
gst_rtp_buffer_set_marker (&rtp, size == payload_len); gst_rtp_buffer_set_marker (&rtp, size == payload_len);
if (size == payload_len)
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
gst_rtp_buffer_unmap (&rtp); gst_rtp_buffer_unmap (&rtp);

View file

@ -534,6 +534,8 @@ gst_rtp_mp4g_pay_flush (GstRtpMP4GPay * rtpmp4gpay)
/* marker only if the packet is complete */ /* marker only if the packet is complete */
gst_rtp_buffer_set_marker (&rtp, avail <= payload_len); gst_rtp_buffer_set_marker (&rtp, avail <= payload_len);
if (avail <= payload_len)
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
gst_rtp_buffer_unmap (&rtp); gst_rtp_buffer_unmap (&rtp);

View file

@ -297,6 +297,8 @@ gst_rtp_mp4v_pay_flush (GstRtpMP4VPay * rtpmp4vpay)
gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp); gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
gst_rtp_buffer_set_marker (&rtp, avail == 0); gst_rtp_buffer_set_marker (&rtp, avail == 0);
if (avail == 0)
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
gst_rtp_buffer_unmap (&rtp); gst_rtp_buffer_unmap (&rtp);
gst_rtp_copy_video_meta (rtpmp4vpay, outbuf, outbuf_data); gst_rtp_copy_video_meta (rtpmp4vpay, outbuf, outbuf_data);
outbuf = gst_buffer_append (outbuf, outbuf_data); outbuf = gst_buffer_append (outbuf, outbuf_data);

View file

@ -242,8 +242,10 @@ gst_rtp_mpa_pay_flush (GstRtpMPAPay * rtpmpapay)
avail -= payload_len; avail -= payload_len;
frag_offset += payload_len; frag_offset += payload_len;
if (avail == 0) if (avail == 0) {
gst_rtp_buffer_set_marker (&rtp, TRUE); gst_rtp_buffer_set_marker (&rtp, TRUE);
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
}
gst_rtp_buffer_unmap (&rtp); gst_rtp_buffer_unmap (&rtp);

View file

@ -234,6 +234,8 @@ gst_rtp_mpv_pay_flush (GstRTPMPVPay * rtpmpvpay)
avail -= payload_len; avail -= payload_len;
gst_rtp_buffer_set_marker (&rtp, avail == 0); gst_rtp_buffer_set_marker (&rtp, avail == 0);
if (avail == 0)
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
gst_rtp_buffer_unmap (&rtp); gst_rtp_buffer_unmap (&rtp);
paybuf = gst_adapter_take_buffer_fast (rtpmpvpay->adapter, payload_len); paybuf = gst_adapter_take_buffer_fast (rtpmpvpay->adapter, payload_len);

View file

@ -313,6 +313,8 @@ gst_rtp_red_create_packet (GstRtpRedDec * self, GstRTPBuffer * red_rtp,
/* Timestamps, meta, flags from the RED packet should go to main block packet */ /* Timestamps, meta, flags from the RED packet should go to main block packet */
gst_buffer_copy_into (ret, red_rtp->buffer, GST_BUFFER_COPY_METADATA, 0, -1); gst_buffer_copy_into (ret, red_rtp->buffer, GST_BUFFER_COPY_METADATA, 0, -1);
if (marker)
GST_BUFFER_FLAG_SET (ret, GST_BUFFER_FLAG_MARKER);
return ret; return ret;
} }

View file

@ -548,6 +548,8 @@ gst_rtp_vp8_create_header_buffer (GstRtpVP8Pay * self, guint8 partid,
} }
gst_rtp_buffer_set_marker (&rtpbuffer, mark); gst_rtp_buffer_set_marker (&rtpbuffer, mark);
if (mark)
GST_BUFFER_FLAG_SET (out, GST_BUFFER_FLAG_MARKER);
gst_rtp_buffer_unmap (&rtpbuffer); gst_rtp_buffer_unmap (&rtpbuffer);

View file

@ -432,6 +432,8 @@ gst_rtp_vp9_create_header_buffer (GstRtpVP9Pay * self,
g_assert_cmpint (off, ==, hdrlen); g_assert_cmpint (off, ==, hdrlen);
gst_rtp_buffer_set_marker (&rtpbuffer, mark); gst_rtp_buffer_set_marker (&rtpbuffer, mark);
if (mark)
GST_BUFFER_FLAG_SET (out, GST_BUFFER_FLAG_MARKER);
gst_rtp_buffer_unmap (&rtpbuffer); gst_rtp_buffer_unmap (&rtpbuffer);

View file

@ -566,6 +566,7 @@ gst_rtp_vraw_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buffer)
if (line >= height) { if (line >= height) {
GST_LOG_OBJECT (rtpvrawpay, "field/frame complete, set marker"); GST_LOG_OBJECT (rtpvrawpay, "field/frame complete, set marker");
gst_rtp_buffer_set_marker (&rtp, TRUE); gst_rtp_buffer_set_marker (&rtp, TRUE);
GST_BUFFER_FLAG_SET (out, GST_BUFFER_FLAG_MARKER);
complete = TRUE; complete = TRUE;
} }
gst_rtp_buffer_unmap (&rtp); gst_rtp_buffer_unmap (&rtp);

View file

@ -310,6 +310,8 @@ rtp_ulpfec_bitstring_to_fec_rtp_buffer (GArray * arr,
g_assert_not_reached (); g_assert_not_reached ();
gst_rtp_buffer_set_marker (&rtp, marker); gst_rtp_buffer_set_marker (&rtp, marker);
if (marker)
GST_BUFFER_FLAG_SET (ret, GST_BUFFER_FLAG_MARKER);
gst_rtp_buffer_set_payload_type (&rtp, pt); gst_rtp_buffer_set_payload_type (&rtp, pt);
gst_rtp_buffer_set_seq (&rtp, seq); gst_rtp_buffer_set_seq (&rtp, seq);
gst_rtp_buffer_set_timestamp (&rtp, timestamp); gst_rtp_buffer_set_timestamp (&rtp, timestamp);

View file

@ -167,7 +167,8 @@ GST_START_TEST (rtpreddec_main_block)
bufout = gst_harness_push_and_pull (h, bufinp); bufout = gst_harness_push_and_pull (h, bufinp);
fail_unless (gst_rtp_buffer_map (bufout, GST_MAP_READ, &rtp)); fail_unless (gst_rtp_buffer_map (bufout, GST_MAP_READ, &rtp));
fail_unless_equals_int (GST_BUFFER_TIMESTAMP (bufout), gst_ts); fail_unless_equals_int (GST_BUFFER_TIMESTAMP (bufout), gst_ts);
fail_unless_equals_int (GST_BUFFER_FLAGS (bufout), bufinp_flags); fail_unless_equals_int (GST_BUFFER_FLAGS (bufout),
bufinp_flags | GST_BUFFER_FLAG_MARKER);
fail_unless_equals_int (gst_buffer_get_size (bufout), fail_unless_equals_int (gst_buffer_get_size (bufout),
gst_rtp_buffer_calc_packet_len (sizeof (out_data), 0, csrc_count)); gst_rtp_buffer_calc_packet_len (sizeof (out_data), 0, csrc_count));
fail_unless_equals_int (gst_rtp_buffer_get_timestamp (&rtp), fail_unless_equals_int (gst_rtp_buffer_get_timestamp (&rtp),