Port plugins to gst_video_format_info_extrapolate_stride()
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Tue, 25 Jan 2022 19:08:47 +0000 (14:08 -0500)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Sun, 20 Feb 2022 22:32:55 +0000 (22:32 +0000)
This reduces code duplication and simplify addition of new
pixel formats into related plugins.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1567>

subprojects/gst-plugins-bad/ext/wayland/wlshmallocator.c
subprojects/gst-plugins-bad/sys/kms/gstkmsallocator.c
subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2format.c
subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c
subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c
subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.h

index 0a82a35..611e2fb 100644 (file)
@@ -144,31 +144,6 @@ gst_is_wl_shm_memory (GstMemory * mem)
   return gst_memory_is_type (mem, GST_ALLOCATOR_WL_SHM);
 }
 
-/* Copied from gst_v4l2_object_extrapolate_stride() */
-static gint
-gst_wl_shm_extrapolate_stride (const GstVideoFormatInfo * finfo, gint plane,
-    gint stride)
-{
-  gint estride;
-
-  switch (finfo->format) {
-    case GST_VIDEO_FORMAT_NV12:
-    case GST_VIDEO_FORMAT_NV12_64Z32:
-    case GST_VIDEO_FORMAT_NV21:
-    case GST_VIDEO_FORMAT_NV16:
-    case GST_VIDEO_FORMAT_NV61:
-    case GST_VIDEO_FORMAT_NV24:
-      estride = (plane == 0 ? 1 : 2) *
-          GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, plane, stride);
-      break;
-    default:
-      estride = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, plane, stride);
-      break;
-  }
-
-  return estride;
-}
-
 static gboolean
 gst_wl_shm_validate_video_info (const GstVideoInfo * vinfo)
 {
@@ -183,7 +158,8 @@ gst_wl_shm_validate_video_info (const GstVideoInfo * vinfo)
 
     /* Overwrite the video info's stride and offset using the pitch calculcated
      * by the kms driver. */
-    estride = gst_wl_shm_extrapolate_stride (vinfo->finfo, i, base_stride);
+    estride = gst_video_format_info_extrapolate_stride (vinfo->finfo, i,
+        base_stride);
 
     if (estride != GST_VIDEO_INFO_PLANE_STRIDE (vinfo, i))
       return FALSE;
index 2ae22fc..6687f3b 100644 (file)
@@ -138,34 +138,6 @@ gst_kms_allocator_memory_reset (GstKMSAllocator * allocator, GstKMSMemory * mem)
   mem->bo = NULL;
 }
 
-/* Copied from gst_v4l2_object_extrapolate_stride() */
-static gint
-extrapolate_stride (const GstVideoFormatInfo * finfo, gint plane, gint stride)
-{
-  gint estride;
-
-  switch (finfo->format) {
-    case GST_VIDEO_FORMAT_NV12:
-    case GST_VIDEO_FORMAT_NV12_64Z32:
-    case GST_VIDEO_FORMAT_NV21:
-    case GST_VIDEO_FORMAT_NV16:
-    case GST_VIDEO_FORMAT_NV61:
-    case GST_VIDEO_FORMAT_NV24:
-    case GST_VIDEO_FORMAT_P010_10LE:
-    case GST_VIDEO_FORMAT_P010_10BE:
-    case GST_VIDEO_FORMAT_P016_LE:
-    case GST_VIDEO_FORMAT_P016_BE:
-      estride = (plane == 0 ? 1 : 2) *
-          GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, plane, stride);
-      break;
-    default:
-      estride = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, plane, stride);
-      break;
-  }
-
-  return estride;
-}
-
 static gboolean
 gst_kms_allocator_memory_create (GstKMSAllocator * allocator,
     GstKMSMemory * kmsmem, GstVideoInfo * vinfo)
@@ -207,7 +179,8 @@ gst_kms_allocator_memory_create (GstKMSAllocator * allocator,
 
     /* Overwrite the video info's stride and offset using the pitch calculcated
      * by the kms driver. */
-    pitch = extrapolate_stride (vinfo->finfo, i, arg.pitch);
+    pitch = gst_video_format_info_extrapolate_stride (vinfo->finfo, i,
+        arg.pitch);
     GST_VIDEO_INFO_PLANE_STRIDE (vinfo, i) = pitch;
     GST_VIDEO_INFO_PLANE_OFFSET (vinfo, i) = offs;
 
index 15e57fb..3a6a06f 100644 (file)
@@ -71,31 +71,6 @@ lookup_gst_fmt (GstVideoFormat gst_fmt)
   return ret;
 }
 
-static gint
-extrapolate_stride (const GstVideoFormatInfo * finfo, gint plane, gint stride)
-{
-  gint estride;
-
-  switch (finfo->format) {
-    case GST_VIDEO_FORMAT_NV12:
-    case GST_VIDEO_FORMAT_NV12_4L4:
-    case GST_VIDEO_FORMAT_NV12_32L32:
-    case GST_VIDEO_FORMAT_NV12_64Z32:
-    case GST_VIDEO_FORMAT_NV16:
-    case GST_VIDEO_FORMAT_NV21:
-    case GST_VIDEO_FORMAT_NV24:
-    case GST_VIDEO_FORMAT_NV61:
-      estride = (plane == 0 ? 1 : 2) *
-          GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, plane, stride);
-      break;
-    default:
-      estride = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, plane, stride);
-      break;
-  }
-
-  return estride;
-}
-
 static void
 set_stride (GstVideoInfo * info, gint plane, gint stride)
 {
@@ -152,10 +127,11 @@ gst_v4l2_format_to_video_info (struct v4l2_format *fmt, GstVideoInfo * out_info)
     gint stride;
 
     if (V4L2_TYPE_IS_MULTIPLANAR (fmt->type))
-      stride = extrapolate_stride (out_info->finfo, plane,
+      stride = gst_video_format_info_extrapolate_stride (out_info->finfo, plane,
           pix_mp->plane_fmt[0].bytesperline);
     else
-      stride = extrapolate_stride (out_info->finfo, plane, pix->bytesperline);
+      stride = gst_video_format_info_extrapolate_stride (out_info->finfo, plane,
+          pix->bytesperline);
 
     set_stride (out_info, plane, stride);
     out_info->offset[plane] = offset;
index 58667de..d687326 100644 (file)
@@ -270,7 +270,7 @@ gst_v4l2_buffer_pool_import_userptr (GstV4l2BufferPool * pool,
       for (i = 0; i < (GST_VIDEO_FORMAT_INFO_N_PLANES (finfo) - 1); i++) {
         const struct v4l2_pix_format *pix_fmt = &pool->obj->format.fmt.pix;
         gpointer tmp;
-        gint estride = gst_v4l2_object_extrapolate_stride (finfo, i,
+        gint estride = gst_video_format_info_extrapolate_stride (finfo, i,
             pix_fmt->bytesperline);
         guint eheight = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (finfo, i,
             pix_fmt->height);
index 9eb3b8e..be5276d 100644 (file)
@@ -3204,7 +3204,7 @@ gst_v4l2_object_extrapolate_info (GstV4l2Object * v4l2object,
       align->padding_bottom;
 
   for (i = 0; i < finfo->n_planes; i++) {
-    estride = gst_v4l2_object_extrapolate_stride (finfo, i, stride);
+    estride = gst_video_format_info_extrapolate_stride (finfo, i, stride);
 
     gst_v4l2_object_set_stride (info, align, i, estride);
 
@@ -3369,30 +3369,6 @@ store_info:
   }
 }
 
-gint
-gst_v4l2_object_extrapolate_stride (const GstVideoFormatInfo * finfo,
-    gint plane, gint stride)
-{
-  gint estride;
-
-  switch (finfo->format) {
-    case GST_VIDEO_FORMAT_NV12:
-    case GST_VIDEO_FORMAT_NV12_64Z32:
-    case GST_VIDEO_FORMAT_NV21:
-    case GST_VIDEO_FORMAT_NV16:
-    case GST_VIDEO_FORMAT_NV61:
-    case GST_VIDEO_FORMAT_NV24:
-      estride = (plane == 0 ? 1 : 2) *
-          GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, plane, stride);
-      break;
-    default:
-      estride = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, plane, stride);
-      break;
-  }
-
-  return estride;
-}
-
 static enum v4l2_field
 get_v4l2_field_for_info (GstVideoInfo * info)
 {
index e5ed0ac..ed32d8e 100644 (file)
@@ -286,9 +286,6 @@ GstCaps*     gst_v4l2_object_get_raw_caps (void);
 
 GstCaps*     gst_v4l2_object_get_codec_caps (void);
 
-gint         gst_v4l2_object_extrapolate_stride (const GstVideoFormatInfo * finfo,
-                                                  gint plane, gint stride);
-
 gboolean     gst_v4l2_object_set_format  (GstV4l2Object * v4l2object, GstCaps * caps, GstV4l2Error * error);
 gboolean     gst_v4l2_object_try_format  (GstV4l2Object * v4l2object, GstCaps * caps, GstV4l2Error * error);
 gboolean     gst_v4l2_object_try_import  (GstV4l2Object * v4l2object, GstBuffer * buffer);