rtph265pay: Extract sending fragments into _payload_nal_fragment

Align with rtph264pay
This commit is contained in:
Olivier Crête 2019-06-13 17:23:26 -04:00 committed by Nicolas Dufresne
parent 378c422e0c
commit f5765ccf05

View file

@ -132,6 +132,10 @@ static GstStateChangeReturn gst_rtp_h265_pay_change_state (GstElement *
static GstFlowReturn gst_rtp_h265_pay_payload_nal_single (GstRTPBasePayload *
basepayload, GstBuffer * paybuf, GstClockTime dts, GstClockTime pts,
gboolean marker);
static GstFlowReturn gst_rtp_h265_pay_payload_nal_fragment (GstRTPBasePayload *
basepayload, GstBuffer * paybuf, GstClockTime dts, GstClockTime pts,
gboolean marker, guint mtu, guint8 nal_type, const guint8 * nal_header,
int size);
#define gst_rtp_h265_pay_parent_class parent_class
G_DEFINE_TYPE (GstRtpH265Pay, gst_rtp_h265_pay, GST_TYPE_RTP_BASE_PAYLOAD);
@ -893,13 +897,9 @@ gst_rtp_h265_pay_payload_nal (GstRTPBasePayload * basepayload,
for (i = 0; i < paybufs->len; i++) {
guint8 nal_header[2];
guint8 nal_type;
guint packet_len, payload_len;
guint packet_len;
GstBuffer *paybuf;
GstBuffer *outbuf;
guint8 *payload;
GstBufferList *outlist = NULL;
gboolean send_ps;
GstRTPBuffer rtp = { NULL };
guint size;
gboolean marker;
@ -1004,18 +1004,78 @@ gst_rtp_h265_pay_payload_nal (GstRTPBasePayload * basepayload,
marker);
} else {
/* fragmentation Units */
guint fragment_size;
int ii = 0, start = 1, end = 0, pos = 0;
GST_DEBUG_OBJECT (basepayload,
"NAL Unit DOES NOT fit in one packet datasize=%d mtu=%d", size, mtu);
GST_DEBUG_OBJECT (basepayload, "Using FU fragmentation for data size=%d",
size - 2);
ret = gst_rtp_h265_pay_payload_nal_fragment (basepayload, paybuf, dts,
pts, marker, mtu, nal_type, nal_header, size);
}
}
g_ptr_array_free (paybufs, TRUE);
return ret;
}
static GstFlowReturn
gst_rtp_h265_pay_payload_nal_single (GstRTPBasePayload * basepayload,
GstBuffer * paybuf, GstClockTime dts, GstClockTime pts, gboolean marker)
{
GstBufferList *outlist;
GstBuffer *outbuf;
GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
/* use buffer lists
* create buffer without payload containing only the RTP header
* (memory block at index 0) */
outbuf = gst_rtp_buffer_new_allocate (0, 0, 0);
gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
/* Mark the end of a frame */
gst_rtp_buffer_set_marker (&rtp, marker);
/* timestamp the outbuffer */
GST_BUFFER_PTS (outbuf) = pts;
GST_BUFFER_DTS (outbuf) = dts;
/* insert payload memory block */
gst_rtp_copy_video_meta (basepayload, outbuf, paybuf);
outbuf = gst_buffer_append (outbuf, paybuf);
outlist = gst_buffer_list_new ();
/* add the buffer to the buffer list */
gst_buffer_list_add (outlist, outbuf);
gst_rtp_buffer_unmap (&rtp);
/* push the list to the next element in the pipe */
return gst_rtp_base_payload_push_list (basepayload, outlist);
}
static GstFlowReturn
gst_rtp_h265_pay_payload_nal_fragment (GstRTPBasePayload * basepayload,
GstBuffer * paybuf, GstClockTime dts, GstClockTime pts, gboolean marker,
guint mtu, guint8 nal_type, const guint8 * nal_header, int size)
{
GstRtpH265Pay *rtph265pay = (GstRtpH265Pay *) basepayload;
GstFlowReturn ret;
guint payload_len;
GstBuffer *outbuf;
GstBufferList *outlist = NULL;
guint fragment_size;
int ii = 0, start = 1, end = 0, pos = 0;
GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
guint8 *payload;
pos += 2;
size -= 2;
GST_DEBUG_OBJECT (basepayload, "Using FU fragmentation for data size=%d",
size);
/* We keep 3 bytes for PayloadHdr and FU Header */
payload_len = gst_rtp_buffer_calc_payload_len (mtu - 3, 0, 0);
@ -1071,52 +1131,10 @@ gst_rtp_h265_pay_payload_nal (GstRTPBasePayload * basepayload,
ret = gst_rtp_base_payload_push_list (basepayload, outlist);
gst_buffer_unref (paybuf);
}
}
g_ptr_array_free (paybufs, TRUE);
return ret;
}
static GstFlowReturn
gst_rtp_h265_pay_payload_nal_single (GstRTPBasePayload * basepayload,
GstBuffer * paybuf, GstClockTime dts, GstClockTime pts, gboolean marker)
{
GstBufferList *outlist;
GstBuffer *outbuf;
GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
/* use buffer lists
* create buffer without payload containing only the RTP header
* (memory block at index 0) */
outbuf = gst_rtp_buffer_new_allocate (0, 0, 0);
gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
/* Mark the end of a frame */
gst_rtp_buffer_set_marker (&rtp, marker);
/* timestamp the outbuffer */
GST_BUFFER_PTS (outbuf) = pts;
GST_BUFFER_DTS (outbuf) = dts;
/* insert payload memory block */
gst_rtp_copy_video_meta (basepayload, outbuf, paybuf);
outbuf = gst_buffer_append (outbuf, paybuf);
outlist = gst_buffer_list_new ();
/* add the buffer to the buffer list */
gst_buffer_list_add (outlist, outbuf);
gst_rtp_buffer_unmap (&rtp);
/* push the list to the next element in the pipe */
return gst_rtp_base_payload_push_list (basepayload, outlist);
}
static GstFlowReturn
gst_rtp_h265_pay_handle_buffer (GstRTPBasePayload * basepayload,