Skip to content

Commit

Permalink
[media] media: v4l: remove single to multiplane conversion
Browse files Browse the repository at this point in the history
This patch removes an implicit conversion between multi and single plane
formats from V4L2 framework. The conversion is to be performed by libv4l2.

Signed-off-by: Tomasz Stanislawski <t.stanislaws@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Tomasz Stanislawski authored and Mauro Carvalho Chehab committed Sep 6, 2011
1 parent 93d5a30 commit 1d0c86c
Showing 1 changed file with 12 additions and 238 deletions.
250 changes: 12 additions & 238 deletions drivers/media/video/v4l2-ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,71 +490,13 @@ static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
return -EINVAL;
}

/**
* fmt_sp_to_mp() - Convert a single-plane format to its multi-planar 1-plane
* equivalent
*/
static int fmt_sp_to_mp(const struct v4l2_format *f_sp,
struct v4l2_format *f_mp)
{
struct v4l2_pix_format_mplane *pix_mp = &f_mp->fmt.pix_mp;
const struct v4l2_pix_format *pix = &f_sp->fmt.pix;

if (f_sp->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
f_mp->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
else if (f_sp->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
f_mp->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
else
return -EINVAL;

pix_mp->width = pix->width;
pix_mp->height = pix->height;
pix_mp->pixelformat = pix->pixelformat;
pix_mp->field = pix->field;
pix_mp->colorspace = pix->colorspace;
pix_mp->num_planes = 1;
pix_mp->plane_fmt[0].sizeimage = pix->sizeimage;
pix_mp->plane_fmt[0].bytesperline = pix->bytesperline;

return 0;
}

/**
* fmt_mp_to_sp() - Convert a multi-planar 1-plane format to its single-planar
* equivalent
*/
static int fmt_mp_to_sp(const struct v4l2_format *f_mp,
struct v4l2_format *f_sp)
{
const struct v4l2_pix_format_mplane *pix_mp = &f_mp->fmt.pix_mp;
struct v4l2_pix_format *pix = &f_sp->fmt.pix;

if (f_mp->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
f_sp->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
else if (f_mp->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
f_sp->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
else
return -EINVAL;

pix->width = pix_mp->width;
pix->height = pix_mp->height;
pix->pixelformat = pix_mp->pixelformat;
pix->field = pix_mp->field;
pix->colorspace = pix_mp->colorspace;
pix->sizeimage = pix_mp->plane_fmt[0].sizeimage;
pix->bytesperline = pix_mp->plane_fmt[0].bytesperline;

return 0;
}

static long __video_do_ioctl(struct file *file,
unsigned int cmd, void *arg)
{
struct video_device *vfd = video_devdata(file);
const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
void *fh = file->private_data;
struct v4l2_fh *vfh = NULL;
struct v4l2_format f_copy;
int use_fh_prio = 0;
long ret_prio = 0;
long ret = -ENOTTY;
Expand Down Expand Up @@ -697,42 +639,15 @@ static long __video_do_ioctl(struct file *file,

switch (f->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (ops->vidioc_g_fmt_vid_cap) {
if (ops->vidioc_g_fmt_vid_cap)
ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
} else if (ops->vidioc_g_fmt_vid_cap_mplane) {
if (fmt_sp_to_mp(f, &f_copy))
break;
ret = ops->vidioc_g_fmt_vid_cap_mplane(file, fh,
&f_copy);
if (ret)
break;

/* Driver is currently in multi-planar format,
* we can't return it in single-planar API*/
if (f_copy.fmt.pix_mp.num_planes > 1) {
ret = -EBUSY;
break;
}

ret = fmt_mp_to_sp(&f_copy, f);
}
if (!ret)
v4l_print_pix_fmt(vfd, &f->fmt.pix);
break;
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
if (ops->vidioc_g_fmt_vid_cap_mplane) {
if (ops->vidioc_g_fmt_vid_cap_mplane)
ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
fh, f);
} else if (ops->vidioc_g_fmt_vid_cap) {
if (fmt_mp_to_sp(f, &f_copy))
break;
ret = ops->vidioc_g_fmt_vid_cap(file,
fh, &f_copy);
if (ret)
break;

ret = fmt_sp_to_mp(&f_copy, f);
}
if (!ret)
v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
break;
Expand All @@ -742,42 +657,15 @@ static long __video_do_ioctl(struct file *file,
fh, f);
break;
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
if (ops->vidioc_g_fmt_vid_out) {
if (ops->vidioc_g_fmt_vid_out)
ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
} else if (ops->vidioc_g_fmt_vid_out_mplane) {
if (fmt_sp_to_mp(f, &f_copy))
break;
ret = ops->vidioc_g_fmt_vid_out_mplane(file, fh,
&f_copy);
if (ret)
break;

/* Driver is currently in multi-planar format,
* we can't return it in single-planar API*/
if (f_copy.fmt.pix_mp.num_planes > 1) {
ret = -EBUSY;
break;
}

ret = fmt_mp_to_sp(&f_copy, f);
}
if (!ret)
v4l_print_pix_fmt(vfd, &f->fmt.pix);
break;
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
if (ops->vidioc_g_fmt_vid_out_mplane) {
if (ops->vidioc_g_fmt_vid_out_mplane)
ret = ops->vidioc_g_fmt_vid_out_mplane(file,
fh, f);
} else if (ops->vidioc_g_fmt_vid_out) {
if (fmt_mp_to_sp(f, &f_copy))
break;
ret = ops->vidioc_g_fmt_vid_out(file,
fh, &f_copy);
if (ret)
break;

ret = fmt_sp_to_mp(&f_copy, f);
}
if (!ret)
v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
break;
Expand Down Expand Up @@ -834,44 +722,15 @@ static long __video_do_ioctl(struct file *file,
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
CLEAR_AFTER_FIELD(f, fmt.pix);
v4l_print_pix_fmt(vfd, &f->fmt.pix);
if (ops->vidioc_s_fmt_vid_cap) {
if (ops->vidioc_s_fmt_vid_cap)
ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
} else if (ops->vidioc_s_fmt_vid_cap_mplane) {
if (fmt_sp_to_mp(f, &f_copy))
break;
ret = ops->vidioc_s_fmt_vid_cap_mplane(file, fh,
&f_copy);
if (ret)
break;

if (f_copy.fmt.pix_mp.num_planes > 1) {
/* Drivers shouldn't adjust from 1-plane
* to more than 1-plane formats */
ret = -EBUSY;
WARN_ON(1);
break;
}

ret = fmt_mp_to_sp(&f_copy, f);
}
break;
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
CLEAR_AFTER_FIELD(f, fmt.pix_mp);
v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
if (ops->vidioc_s_fmt_vid_cap_mplane) {
if (ops->vidioc_s_fmt_vid_cap_mplane)
ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
fh, f);
} else if (ops->vidioc_s_fmt_vid_cap &&
f->fmt.pix_mp.num_planes == 1) {
if (fmt_mp_to_sp(f, &f_copy))
break;
ret = ops->vidioc_s_fmt_vid_cap(file,
fh, &f_copy);
if (ret)
break;

ret = fmt_sp_to_mp(&f_copy, f);
}
break;
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
CLEAR_AFTER_FIELD(f, fmt.win);
Expand All @@ -882,44 +741,15 @@ static long __video_do_ioctl(struct file *file,
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
CLEAR_AFTER_FIELD(f, fmt.pix);
v4l_print_pix_fmt(vfd, &f->fmt.pix);
if (ops->vidioc_s_fmt_vid_out) {
if (ops->vidioc_s_fmt_vid_out)
ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
} else if (ops->vidioc_s_fmt_vid_out_mplane) {
if (fmt_sp_to_mp(f, &f_copy))
break;
ret = ops->vidioc_s_fmt_vid_out_mplane(file, fh,
&f_copy);
if (ret)
break;

if (f_copy.fmt.pix_mp.num_planes > 1) {
/* Drivers shouldn't adjust from 1-plane
* to more than 1-plane formats */
ret = -EBUSY;
WARN_ON(1);
break;
}

ret = fmt_mp_to_sp(&f_copy, f);
}
break;
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
CLEAR_AFTER_FIELD(f, fmt.pix_mp);
v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
if (ops->vidioc_s_fmt_vid_out_mplane) {
if (ops->vidioc_s_fmt_vid_out_mplane)
ret = ops->vidioc_s_fmt_vid_out_mplane(file,
fh, f);
} else if (ops->vidioc_s_fmt_vid_out &&
f->fmt.pix_mp.num_planes == 1) {
if (fmt_mp_to_sp(f, &f_copy))
break;
ret = ops->vidioc_s_fmt_vid_out(file,
fh, &f_copy);
if (ret)
break;

ret = fmt_mp_to_sp(&f_copy, f);
}
break;
case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
CLEAR_AFTER_FIELD(f, fmt.win);
Expand Down Expand Up @@ -969,44 +799,16 @@ static long __video_do_ioctl(struct file *file,
switch (f->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
CLEAR_AFTER_FIELD(f, fmt.pix);
if (ops->vidioc_try_fmt_vid_cap) {
if (ops->vidioc_try_fmt_vid_cap)
ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
} else if (ops->vidioc_try_fmt_vid_cap_mplane) {
if (fmt_sp_to_mp(f, &f_copy))
break;
ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
fh, &f_copy);
if (ret)
break;

if (f_copy.fmt.pix_mp.num_planes > 1) {
/* Drivers shouldn't adjust from 1-plane
* to more than 1-plane formats */
ret = -EBUSY;
WARN_ON(1);
break;
}
ret = fmt_mp_to_sp(&f_copy, f);
}
if (!ret)
v4l_print_pix_fmt(vfd, &f->fmt.pix);
break;
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
CLEAR_AFTER_FIELD(f, fmt.pix_mp);
if (ops->vidioc_try_fmt_vid_cap_mplane) {
if (ops->vidioc_try_fmt_vid_cap_mplane)
ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
fh, f);
} else if (ops->vidioc_try_fmt_vid_cap &&
f->fmt.pix_mp.num_planes == 1) {
if (fmt_mp_to_sp(f, &f_copy))
break;
ret = ops->vidioc_try_fmt_vid_cap(file,
fh, &f_copy);
if (ret)
break;

ret = fmt_sp_to_mp(&f_copy, f);
}
if (!ret)
v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
break;
Expand All @@ -1018,44 +820,16 @@ static long __video_do_ioctl(struct file *file,
break;
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
CLEAR_AFTER_FIELD(f, fmt.pix);
if (ops->vidioc_try_fmt_vid_out) {
if (ops->vidioc_try_fmt_vid_out)
ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
} else if (ops->vidioc_try_fmt_vid_out_mplane) {
if (fmt_sp_to_mp(f, &f_copy))
break;
ret = ops->vidioc_try_fmt_vid_out_mplane(file,
fh, &f_copy);
if (ret)
break;

if (f_copy.fmt.pix_mp.num_planes > 1) {
/* Drivers shouldn't adjust from 1-plane
* to more than 1-plane formats */
ret = -EBUSY;
WARN_ON(1);
break;
}
ret = fmt_mp_to_sp(&f_copy, f);
}
if (!ret)
v4l_print_pix_fmt(vfd, &f->fmt.pix);
break;
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
CLEAR_AFTER_FIELD(f, fmt.pix_mp);
if (ops->vidioc_try_fmt_vid_out_mplane) {
if (ops->vidioc_try_fmt_vid_out_mplane)
ret = ops->vidioc_try_fmt_vid_out_mplane(file,
fh, f);
} else if (ops->vidioc_try_fmt_vid_out &&
f->fmt.pix_mp.num_planes == 1) {
if (fmt_mp_to_sp(f, &f_copy))
break;
ret = ops->vidioc_try_fmt_vid_out(file,
fh, &f_copy);
if (ret)
break;

ret = fmt_sp_to_mp(&f_copy, f);
}
if (!ret)
v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
break;
Expand Down

0 comments on commit 1d0c86c

Please sign in to comment.