rtpjpegpay: Ceil jpeg dimensions, instead of floor
authorSebastian Rasmussen <sebrn@axis.com>
Thu, 24 Nov 2011 12:58:01 +0000 (13:58 +0100)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Mon, 5 Dec 2011 09:48:54 +0000 (10:48 +0100)
A JPEG image inside an RTP stream has a preceeding RFC2435 header that
conveys width/height. The dimensions in this header are limited to be
multiples of 8. Since JPEG uses an MCU of 8x8 pixels any image must
already indirectly have image data dimensions that are rounded up in
order to contain enough data to render the image. Therefore this fix
safely rounds the image dimensions in the RFC2435 header up to the
closest multiple of 8.

gst/rtp/gstrtpjpegpay.c

index ff1fe7e..eae2840 100644 (file)
@@ -314,13 +314,13 @@ gst_rtp_jpeg_pay_setcaps (GstBaseRTPPayload * basepayload, GstCaps * caps)
     if (height <= 0 || height > 2040)
       goto invalid_dimension;
   }
-  pay->height = height / 8;
+  pay->height = GST_ROUND_UP_8 (height) / 8;
 
   if (gst_structure_get_int (caps_structure, "width", &width)) {
     if (width <= 0 || width > 2040)
       goto invalid_dimension;
   }
-  pay->width = width / 8;
+  pay->width = GST_ROUND_UP_8 (width) / 8;
 
   gst_basertppayload_set_options (basepayload, "video", TRUE, "JPEG", 90000);
   res = gst_basertppayload_set_outcaps (basepayload, NULL);
@@ -459,8 +459,8 @@ gst_rtp_jpeg_pay_read_sof (GstRtpJPEGPay * pay, const guint8 * data,
   if (width == 0 || width > 2040)
     goto invalid_dimension;
 
-  pay->height = height / 8;
-  pay->width = width / 8;
+  pay->height = GST_ROUND_UP_8 (height) / 8;
+  pay->width = GST_ROUND_UP_8 (width) / 8;
 
   /* we only support 3 components */
   if (data[off++] != 3)