v4l2: fix copying of encoded buffers
authorPhilipp Zabel <p.zabel@pengutronix.de>
Mon, 20 Aug 2012 07:52:34 +0000 (09:52 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 26 Apr 2013 13:36:49 +0000 (15:36 +0200)
The existence of a GstVideoFormatInfo does not guarantee, that
the buffer contains video frames, so the format must be checked.

Also, for encoded buffers the length is variable and must be set.

https://bugzilla.gnome.org/show_bug.cgi?id=698949

sys/v4l2/gstv4l2object.c

index fce83b2..05f66d4 100644 (file)
@@ -2528,7 +2528,10 @@ gboolean
 gst_v4l2_object_copy (GstV4l2Object * v4l2object, GstBuffer * dest,
     GstBuffer * src)
 {
-  if (v4l2object->info.finfo) {
+  const GstVideoFormatInfo *finfo = v4l2object->info.finfo;
+
+  if (finfo && (finfo->format != GST_VIDEO_FORMAT_UNKNOWN ||
+          finfo->format != GST_VIDEO_FORMAT_ENCODED)) {
     GstVideoFrame src_frame, dest_frame;
 
     GST_DEBUG_OBJECT (v4l2object->element, "copy video frame");
@@ -2554,6 +2557,7 @@ gst_v4l2_object_copy (GstV4l2Object * v4l2object, GstBuffer * dest,
     gst_buffer_map (src, &map, GST_MAP_READ);
     gst_buffer_fill (dest, 0, map.data, map.size);
     gst_buffer_unmap (src, &map);
+    gst_buffer_resize (dest, 0, map.size);
   }
   GST_CAT_LOG_OBJECT (GST_CAT_PERFORMANCE, v4l2object->element,
       "slow copy into buffer %p", dest);