rtpmp2tdepay: Only output integral mpeg-ts packets
authorEdward Hervey <edward.hervey@collabora.co.uk>
Sat, 26 May 2012 09:57:16 +0000 (11:57 +0200)
committerEdward Hervey <edward.hervey@collabora.co.uk>
Sat, 26 May 2012 10:04:54 +0000 (12:04 +0200)
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

index acb4d52..39699e5 100644 (file)
@@ -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;
+  }
 
-  gst_rtp_buffer_unmap (&rtp);
+  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));