rtptheoradepay: handle packets > 0xffff
authorWim Taymans <wtaymans@redhat.com>
Thu, 21 Nov 2013 10:30:28 +0000 (11:30 +0100)
committerWim Taymans <wtaymans@redhat.com>
Thu, 21 Nov 2013 10:30:28 +0000 (11:30 +0100)
Reorganize some things in the depayloader so that it can handle packets larger
than 16 bits.
Remove the size restriction on the payloader.

gst/rtp/gstrtptheoradepay.c
gst/rtp/gstrtptheorapay.c

index 8fa348a..39c8d2a 100644 (file)
@@ -398,6 +398,7 @@ gst_rtp_theora_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
   guint32 header, ident;
   guint8 F, TDT, packets;
   GstRTPBuffer rtp = { NULL };
+  guint length;
 
   rtptheoradepay = GST_RTP_THEORA_DEPAY (depayload);
 
@@ -488,10 +489,14 @@ gst_rtp_theora_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
     /* construct assembled buffer */
     payload_len = gst_adapter_available (rtptheoradepay->adapter);
     payload = gst_adapter_take (rtptheoradepay->adapter, payload_len);
-    /* fix the length */
-    payload[0] = ((payload_len - 2) >> 8) & 0xff;
-    payload[1] = (payload_len - 2) & 0xff;
+
+    /* use this length */
+    length = payload_len - 2;
+
     to_free = payload;
+  } else {
+    /* read length from data */
+    length = 0;
   }
 
   GST_DEBUG_OBJECT (depayload, "assemble done, payload_len %d", payload_len);
@@ -516,9 +521,9 @@ gst_rtp_theora_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
    * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*
    */
   while (payload_len >= 2) {
-    guint16 length;
+    if (length == 0)
+      length = GST_READ_UINT16_BE (payload);
 
-    length = GST_READ_UINT16_BE (payload);
     payload += 2;
     payload_len -= 2;
 
@@ -557,6 +562,8 @@ gst_rtp_theora_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
 
     payload += length;
     payload_len -= length;
+    /* make sure to read next length */
+    length = 0;
 
     ret = gst_rtp_base_depayload_push (depayload, outbuf);
     if (ret != GST_FLOW_OK)
index baca249..7e00216 100644 (file)
@@ -734,9 +734,6 @@ gst_rtp_theora_pay_handle_buffer (GstRTPBasePayload * basepayload,
   GST_DEBUG_OBJECT (rtptheorapay, "size %" G_GSIZE_FORMAT
       ", duration %" GST_TIME_FORMAT, size, GST_TIME_ARGS (duration));
 
-  if (G_UNLIKELY (size > 0xffff))
-    goto wrong_size;
-
   /* find packet type */
   if (size == 0) {
     TDT = 0;
@@ -833,14 +830,6 @@ done:
   return ret;
 
   /* ERRORS */
-wrong_size:
-  {
-    GST_ELEMENT_WARNING (rtptheorapay, STREAM, DECODE,
-        ("Invalid packet size (%" G_GSIZE_FORMAT " <= 0xffff)", size), (NULL));
-    gst_buffer_unmap (buffer, &map);
-    gst_buffer_unref (buffer);
-    return GST_FLOW_OK;
-  }
 parse_id_failed:
   {
     gst_buffer_unmap (buffer, &map);