v4l2object: Fix support for planar format in 1 v4l2 mplane

So far we where only setting saving the first plane stride in the meta. This was
leading to wrong values in GstVideoMeta.
This commit is contained in:
Nicolas Dufresne 2014-03-25 10:49:39 -04:00
parent a6a8c2b5eb
commit 49065b1693

View file

@ -2239,12 +2239,43 @@ no_supported_capture_method:
}
}
static void
gst_v4l2_object_extrapolate_stride (GstV4l2Object * v4l2object,
struct v4l2_format *format, const GstVideoFormatInfo * finfo, guint stride)
{
gint i;
g_return_if_fail (v4l2object->n_v4l2_planes == 1);
/* figure out the frame layout */
for (i = 0; i < finfo->n_planes; i++) {
switch (finfo->format) {
case GST_VIDEO_FORMAT_NV12:
case GST_VIDEO_FORMAT_NV21:
case GST_VIDEO_FORMAT_NV16:
case GST_VIDEO_FORMAT_NV24:
v4l2object->bytesperline[i] = (i == 0 ? 1 : 2) *
GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, i, stride);
break;
default:
v4l2object->bytesperline[i] =
GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, i, stride);
break;
}
GST_DEBUG_OBJECT (v4l2object->element,
"Extrapolated stride for plane %d from %d to %d", i, stride,
v4l2object->bytesperline[i]);
}
}
static void
gst_v4l2_object_save_format (GstV4l2Object * v4l2object,
struct v4l2_fmtdesc *fmtdesc, struct v4l2_format *format,
GstVideoInfo * info, GstVideoAlignment * align)
{
const GstVideoFormatInfo *finfo = info->finfo;
guint stride;
gint i;
if (V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type)) {
@ -2256,34 +2287,18 @@ gst_v4l2_object_save_format (GstV4l2Object * v4l2object,
format->fmt.pix_mp.plane_fmt[i].bytesperline;
v4l2object->sizeimage += format->fmt.pix_mp.plane_fmt[i].sizeimage;
}
/* Extrapolate stride if planar format are being set in 1 v4l2 plane */
if (v4l2object->n_v4l2_planes < finfo->n_planes) {
stride = format->fmt.pix_mp.plane_fmt[0].bytesperline;
gst_v4l2_object_extrapolate_stride (v4l2object, format, finfo, stride);
}
} else {
/* only one plane in non-MPLANE mode */
v4l2object->n_v4l2_planes = 1;
/* figure out the frame layout */
for (i = 0; i < finfo->n_planes; i++) {
guint stride = format->fmt.pix.bytesperline;
switch (finfo->format) {
case GST_VIDEO_FORMAT_NV12:
case GST_VIDEO_FORMAT_NV21:
case GST_VIDEO_FORMAT_NV16:
case GST_VIDEO_FORMAT_NV24:
v4l2object->bytesperline[i] = (i == 0 ? 1 : 2) *
GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, i, stride);
break;
default:
v4l2object->bytesperline[i] =
GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, i, stride);
break;
}
GST_DEBUG_OBJECT (v4l2object->element,
"Extrapolated stride for plane %d from %d to %d", i, stride,
v4l2object->bytesperline[i]);
}
v4l2object->sizeimage = format->fmt.pix.sizeimage;
stride = format->fmt.pix.bytesperline;
gst_v4l2_object_extrapolate_stride (v4l2object, format, finfo, stride);
}
GST_DEBUG_OBJECT (v4l2object->element, "Got sizeimage %u",