Port plugins to gst_video_format_info_extrapolate_stride()

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>
This commit is contained in:
Nicolas Dufresne 2022-01-25 14:08:47 -05:00 committed by GStreamer Marge Bot
parent fa1f042d1d
commit bab9041c4b
6 changed files with 9 additions and 111 deletions

View 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;

View 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;

View 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;

View 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);

View 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)
{

View 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);