v4l2bufferpool: Use default VideoInfo for frame operation
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Mon, 12 May 2014 22:03:18 +0000 (18:03 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Mon, 12 May 2014 22:08:19 +0000 (18:08 -0400)
When doing frame operation, we need to use the default VideoInfo
and let the frame API read the video meta in order to get the stride
and offset right. Currently we where using the specialized VideoInfo
which reflects what the HW is setup to.

sys/v4l2/gstv4l2bufferpool.c
sys/v4l2/gstv4l2bufferpool.h

index 375125a..e5f05cf 100644 (file)
@@ -95,7 +95,7 @@ static GstFlowReturn
 gst_v4l2_buffer_pool_copy_buffer (GstV4l2BufferPool * pool, GstBuffer * dest,
     GstBuffer * src)
 {
-  const GstVideoFormatInfo *finfo = pool->obj->info.finfo;
+  const GstVideoFormatInfo *finfo = pool->caps_info.finfo;
 
   GST_LOG_OBJECT (pool, "copying buffer");
 
@@ -106,10 +106,10 @@ gst_v4l2_buffer_pool_copy_buffer (GstV4l2BufferPool * pool, GstBuffer * dest,
     GST_DEBUG_OBJECT (pool, "copy video frame");
 
     /* we have raw video, use videoframe copy to get strides right */
-    if (!gst_video_frame_map (&src_frame, &pool->obj->info, src, GST_MAP_READ))
+    if (!gst_video_frame_map (&src_frame, &pool->caps_info, src, GST_MAP_READ))
       goto invalid_buffer;
 
-    if (!gst_video_frame_map (&dest_frame, &pool->obj->info, dest,
+    if (!gst_video_frame_map (&dest_frame, &pool->caps_info, dest,
             GST_MAP_WRITE)) {
       gst_video_frame_unmap (&src_frame);
       goto invalid_buffer;
@@ -185,7 +185,7 @@ gst_v4l2_buffer_pool_import_userptr (GstV4l2BufferPool * pool,
   GstFlowReturn ret = GST_FLOW_OK;
   GstV4l2MemoryGroup *group = NULL;
   GstMapFlags flags;
-  const GstVideoFormatInfo *finfo = pool->obj->info.finfo;
+  const GstVideoFormatInfo *finfo = pool->caps_info.finfo;
   struct UserPtrData *data = NULL;
 
   GST_LOG_OBJECT (pool, "importing userptr");
@@ -205,7 +205,7 @@ gst_v4l2_buffer_pool_import_userptr (GstV4l2BufferPool * pool,
           finfo->format != GST_VIDEO_FORMAT_ENCODED)) {
     data->is_frame = TRUE;
 
-    if (!gst_video_frame_map (&data->frame, &pool->obj->info, src, flags))
+    if (!gst_video_frame_map (&data->frame, &pool->caps_info, src, flags))
       goto invalid_buffer;
 
     if (!gst_v4l2_allocator_import_userptr (pool->vallocator, group,
@@ -502,6 +502,9 @@ gst_v4l2_buffer_pool_set_config (GstBufferPool * bpool, GstStructure * config)
     gst_buffer_pool_config_set_params (config, caps, size, min_buffers,
         max_buffers);
 
+  /* keep a GstVideoInfo with defaults for the when we need to copy */
+  gst_video_info_from_caps (&pool->caps_info, caps);
+
 done:
   ret = GST_BUFFER_POOL_CLASS (parent_class)->set_config (bpool, config);
 
index d212655..3a0aeda 100644 (file)
@@ -56,6 +56,7 @@ struct _GstV4l2BufferPool
   GstAllocationParams params;
   GstBufferPool *other_pool;
   guint size;
+  GstVideoInfo caps_info;   /* Default video information */
 
   gboolean add_videometa;    /* set if video meta should be added */