From fd0123800c8c1cf1468c0fa5d592ad0d0d8b4140 Mon Sep 17 00:00:00 2001
From: Philipp Zabel
Date: Mon, 20 Aug 2012 09:52:34 +0200
Subject: [PATCH] v4l2: fix copying of encoded buffers
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 | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c
index fce83b26cc..05f66d49a5 100644
--- a/sys/v4l2/gstv4l2object.c
+++ b/sys/v4l2/gstv4l2object.c
@@ -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);