From 923be8a85b1cae4e509e2cc095e90780cf095578 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Sat, 26 May 2012 11:57:16 +0200 Subject: [PATCH] rtpmp2tdepay: Only output integral mpeg-ts packets From RFC 2250 2. Encapsulation of MPEG System and Transport Streams ... For MPEG2 Transport Streams the RTP payload will contain an integral number of MPEG transport packets. To avoid end system inefficiencies, data from multiple small MTS packets (normally fixed in size at 188 bytes) are aggregated into a single RTP packet. The number of transport packets contained is computed by dividing RTP payload length by the length of an MTS packet (188). .... Since it needs to contain "an integral number of MPEG transport packets", a simple fix is to check that's the case, and strip off any leftover data. Fixes #676799 Conflicts: gst/rtp/gstrtpmp2tdepay.c --- gst/rtp/gstrtpmp2tdepay.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/gst/rtp/gstrtpmp2tdepay.c b/gst/rtp/gstrtpmp2tdepay.c index acb4d52a8b..39699e58d1 100644 --- a/gst/rtp/gstrtpmp2tdepay.c +++ b/gst/rtp/gstrtpmp2tdepay.c @@ -150,7 +150,7 @@ gst_rtp_mp2t_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf) { GstRtpMP2TDepay *rtpmp2tdepay; GstBuffer *outbuf; - gint payload_len; + gint payload_len, leftover; GstRTPBuffer rtp = { NULL }; rtpmp2tdepay = GST_RTP_MP2T_DEPAY (depayload); @@ -161,11 +161,28 @@ gst_rtp_mp2t_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf) if (G_UNLIKELY (payload_len <= rtpmp2tdepay->skip_first_bytes)) goto empty_packet; - outbuf = gst_rtp_buffer_get_payload_subbuffer (&rtp, - rtpmp2tdepay->skip_first_bytes, -1); + payload_len -= rtpmp2tdepay->skip_first_bytes; + + /* RFC 2250 + * + * 2. Encapsulation of MPEG System and Transport Streams + * + * For MPEG2 Transport Streams the RTP payload will contain an integral + * number of MPEG transport packets. + */ + leftover = payload_len % 188; + if (G_UNLIKELY (leftover)) { + GST_WARNING ("We don't have an integral number of buffers (leftover: %d)", + leftover); + + payload_len -= leftover; + } + + outbuf = + gst_rtp_buffer_get_payload_subbuffer (&rtp, + rtpmp2tdepay->skip_first_bytes, payload_len); gst_rtp_buffer_unmap (&rtp); - if (outbuf) GST_DEBUG ("gst_rtp_mp2t_depay_chain: pushing buffer of size %" G_GSIZE_FORMAT, gst_buffer_get_size (outbuf));