summaryrefslogtreecommitdiffstats
path: root/gst/rtp/gstrtpjpegdepay.c
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2009-05-05 16:28:44 +0200
committerWim Taymans <wim.taymans@collabora.co.uk>2009-05-05 16:28:44 +0200
commit7c59f39bfe6eb6a1888ee94001d85d603d504770 (patch)
tree24a345810fdd38eb1499cad80ac715a4e41c2d4b /gst/rtp/gstrtpjpegdepay.c
parent46061880390812e229a8a86d5fbbc0cb545d0d36 (diff)
rtpjpegdepay: use width/height from payload
Use the width and the height from the payload headers and set them on the output caps for added awesomeness. Fix quant parsing, we need to check the type in the lower 6 bits. Add first bits of caching quantization tables.
Diffstat (limited to 'gst/rtp/gstrtpjpegdepay.c')
-rw-r--r--gst/rtp/gstrtpjpegdepay.c56
1 files changed, 45 insertions, 11 deletions
diff --git a/gst/rtp/gstrtpjpegdepay.c b/gst/rtp/gstrtpjpegdepay.c
index 3eac3cc0..01216adc 100644
--- a/gst/rtp/gstrtpjpegdepay.c
+++ b/gst/rtp/gstrtpjpegdepay.c
@@ -338,7 +338,7 @@ MakeHeaders (guint8 * p, int type, int width, int height, guint8 * qt,
*p++ = width; /* width lsb */
*p++ = 3; /* number of components */
*p++ = 0; /* comp 0 */
- if (type == 0)
+ if ((type & 0x3f) == 0)
*p++ = 0x21; /* hsamp = 2, vsamp = 1 */
else
*p++ = 0x22; /* hsamp = 2, vsamp = 2 */
@@ -380,10 +380,11 @@ MakeHeaders (guint8 * p, int type, int width, int height, guint8 * qt,
static gboolean
gst_rtp_jpeg_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
{
+ GstRtpJPEGDepay *rtpjpegdepay;
GstStructure *structure;
- GstCaps *outcaps;
gint clock_rate;
- gboolean res;
+
+ rtpjpegdepay = GST_RTP_JPEG_DEPAY (depayload);
structure = gst_caps_get_structure (caps, 0);
@@ -391,13 +392,10 @@ gst_rtp_jpeg_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
clock_rate = 90000;
depayload->clock_rate = clock_rate;
- outcaps =
- gst_caps_new_simple ("image/jpeg", "framerate", GST_TYPE_FRACTION, 0, 1,
- NULL);
- res = gst_pad_set_caps (depayload->srcpad, outcaps);
- gst_caps_unref (outcaps);
+ rtpjpegdepay->width = 0;
+ rtpjpegdepay->height = 0;
- return res;
+ return TRUE;
}
static GstBuffer *
@@ -441,6 +439,9 @@ gst_rtp_jpeg_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
width = payload[6] * 8;
height = payload[7] * 8;
+ if (width == 0 || height == 0)
+ goto invalid_dimension;
+
GST_DEBUG_OBJECT (rtpjpegdepay, "frag %u, type %u, Q %d, width %u, height %u",
frag_offset, type, Q, width, height);
@@ -497,7 +498,10 @@ gst_rtp_jpeg_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
if (length > payload_len)
goto empty_packet;
- qtable = payload;
+ if (length > 0)
+ qtable = payload;
+ else
+ qtable = rtpjpegdepay->qtables[Q];
payload += length;
header_len += length;
@@ -511,6 +515,22 @@ gst_rtp_jpeg_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
if (frag_offset == 0) {
guint size;
+ if (rtpjpegdepay->width != width || rtpjpegdepay->height != height) {
+ GstCaps *outcaps;
+
+ outcaps =
+ gst_caps_new_simple ("image/jpeg", "framerate", GST_TYPE_FRACTION, 0,
+ 1, "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, NULL);
+ gst_pad_set_caps (depayload->srcpad, outcaps);
+ gst_caps_unref (outcaps);
+
+ rtpjpegdepay->width = width;
+ rtpjpegdepay->height = height;
+ }
+
+ GST_LOG_OBJECT (rtpjpegdepay, "first packet, length %" G_GUINT16_FORMAT,
+ length);
+
/* first packet */
if (length == 0) {
if (Q < 128) {
@@ -527,6 +547,9 @@ gst_rtp_jpeg_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
}
/* all 8 bit quantizers */
precision = 0;
+ } else {
+ if (!qtable)
+ goto no_qtable;
}
}
/* max header length, should be big enough */
@@ -534,7 +557,7 @@ gst_rtp_jpeg_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
size = MakeHeaders (GST_BUFFER_DATA (outbuf), type,
width, height, qtable, precision, dri);
- GST_DEBUG_OBJECT (rtpjpegdepay, "pushing %u bytes header", size);
+ GST_DEBUG_OBJECT (rtpjpegdepay, "pushing %u bytes of header", size);
GST_BUFFER_SIZE (outbuf) = size;
@@ -586,6 +609,17 @@ empty_packet:
("Empty Payload."), (NULL));
return NULL;
}
+invalid_dimension:
+ {
+ GST_ELEMENT_WARNING (rtpjpegdepay, STREAM, FORMAT,
+ ("Invalid Dimension %dx%d.", width, height), (NULL));
+ return NULL;
+ }
+no_qtable:
+ {
+ GST_WARNING_OBJECT (rtpjpegdepay, "no qtable");
+ return NULL;
+ }
}
gboolean