+ gst_rtp_h265_pay_reset_bundle (rtph265pay);
+ return gst_rtp_h265_pay_payload_nal_single (basepayload, outbuf, dts, pts,
+ marker);
+}
+
+static gboolean
+gst_rtp_h265_pay_payload_nal_bundle (GstRTPBasePayload * basepayload,
+ GstBuffer * paybuf, GstClockTime dts, GstClockTime pts,
+ gboolean marker, guint8 nal_type, const guint8 * nal_header, int size)
+{
+ GstRtpH265Pay *rtph265pay;
+ GstFlowReturn ret;
+ guint pay_size, bundle_size;
+ GstBufferList *bundle;
+ gboolean start_of_au;
+ guint mtu;
+
+ rtph265pay = GST_RTP_H265_PAY (basepayload);
+ mtu = GST_RTP_BASE_PAYLOAD_MTU (rtph265pay);
+ pay_size = 2 + gst_buffer_get_size (paybuf);
+ bundle = rtph265pay->bundle;
+ start_of_au = FALSE;
+
+ if (bundle) {
+ GstBuffer *first = gst_buffer_list_get (bundle, 0);
+
+ if (nal_type == GST_H265_NAL_AUD) {
+ GST_DEBUG_OBJECT (rtph265pay, "found access delimiter");
+ start_of_au = TRUE;
+ } else if (GST_BUFFER_IS_DISCONT (paybuf)) {
+ GST_DEBUG_OBJECT (rtph265pay, "found discont");
+ start_of_au = TRUE;
+ } else if (GST_BUFFER_PTS (first) != pts || GST_BUFFER_DTS (first) != dts) {
+ GST_DEBUG_OBJECT (rtph265pay, "found timestamp mismatch");
+ start_of_au = TRUE;
+ }
+ }
+
+ if (start_of_au) {
+ GST_DEBUG_OBJECT (rtph265pay, "sending bundle before start of AU");
+
+ ret = gst_rtp_h265_pay_send_bundle (rtph265pay, TRUE);
+ if (ret != GST_FLOW_OK)
+ goto out;
+
+ bundle = NULL;
+ }
+
+ bundle_size = 2 + pay_size;
+
+ if (gst_rtp_buffer_calc_packet_len (bundle_size, 0, 0) > mtu) {
+ GST_DEBUG_OBJECT (rtph265pay, "NAL Unit cannot fit in a bundle");
+
+ ret = gst_rtp_h265_pay_send_bundle (rtph265pay, FALSE);
+ if (ret != GST_FLOW_OK)
+ goto out;
+
+ return gst_rtp_h265_pay_payload_nal_fragment (basepayload, paybuf, dts, pts,
+ marker, mtu, nal_type, nal_header, size);
+ }
+
+ bundle_size = rtph265pay->bundle_size + pay_size;
+
+ if (gst_rtp_buffer_calc_packet_len (bundle_size, 0, 0) > mtu) {
+ GST_DEBUG_OBJECT (rtph265pay,
+ "bundle overflows, sending: bundlesize=%u datasize=2+%u mtu=%u",
+ rtph265pay->bundle_size, pay_size - 2, mtu);
+
+ ret = gst_rtp_h265_pay_send_bundle (rtph265pay, FALSE);
+ if (ret != GST_FLOW_OK)
+ goto out;
+
+ bundle = NULL;
+ }
+
+ if (!bundle) {
+ GST_DEBUG_OBJECT (rtph265pay, "creating new AP aggregate");
+ bundle = rtph265pay->bundle = gst_buffer_list_new ();
+ bundle_size = rtph265pay->bundle_size = 2;
+ rtph265pay->bundle_contains_vcl_or_suffix = FALSE;
+ }
+
+ GST_DEBUG_OBJECT (rtph265pay,
+ "bundling NAL Unit: bundlesize=%u datasize=2+%u mtu=%u",
+ rtph265pay->bundle_size, pay_size - 2, mtu);
+
+ paybuf = gst_buffer_make_writable (paybuf);
+ GST_BUFFER_PTS (paybuf) = pts;
+ GST_BUFFER_DTS (paybuf) = dts;
+
+ gst_buffer_list_add (bundle, gst_buffer_ref (paybuf));
+ rtph265pay->bundle_size += pay_size;
+ ret = GST_FLOW_OK;