Commit cabc6508 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] saa7134: fix empress format compliance bugs

Fix uninitialized fields and a missing TRY_FMT implementation in saa6752hs.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 3a0a5a78
...@@ -568,10 +568,36 @@ static int saa6752hs_g_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefm ...@@ -568,10 +568,36 @@ static int saa6752hs_g_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefm
return 0; return 0;
} }
static int saa6752hs_try_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
{
int dist_352, dist_480, dist_720;
f->code = V4L2_MBUS_FMT_FIXED;
dist_352 = abs(f->width - 352);
dist_480 = abs(f->width - 480);
dist_720 = abs(f->width - 720);
if (dist_720 < dist_480) {
f->width = 720;
f->height = 576;
} else if (dist_480 < dist_352) {
f->width = 480;
f->height = 576;
} else {
f->width = 352;
if (abs(f->height - 576) < abs(f->height - 288))
f->height = 576;
else
f->height = 288;
}
f->field = V4L2_FIELD_INTERLACED;
f->colorspace = V4L2_COLORSPACE_SMPTE170M;
return 0;
}
static int saa6752hs_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f) static int saa6752hs_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
{ {
struct saa6752hs_state *h = to_state(sd); struct saa6752hs_state *h = to_state(sd);
int dist_352, dist_480, dist_720;
if (f->code != V4L2_MBUS_FMT_FIXED) if (f->code != V4L2_MBUS_FMT_FIXED)
return -EINVAL; return -EINVAL;
...@@ -588,30 +614,15 @@ static int saa6752hs_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefm ...@@ -588,30 +614,15 @@ static int saa6752hs_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefm
D1 | 720x576 | 720x480 D1 | 720x576 | 720x480
*/ */
dist_352 = abs(f->width - 352); saa6752hs_try_mbus_fmt(sd, f);
dist_480 = abs(f->width - 480); if (f->width == 720)
dist_720 = abs(f->width - 720);
if (dist_720 < dist_480) {
f->width = 720;
f->height = 576;
h->video_format = SAA6752HS_VF_D1; h->video_format = SAA6752HS_VF_D1;
} else if (dist_480 < dist_352) { else if (f->width == 480)
f->width = 480;
f->height = 576;
h->video_format = SAA6752HS_VF_2_3_D1; h->video_format = SAA6752HS_VF_2_3_D1;
} else { else if (f->height == 576)
f->width = 352; h->video_format = SAA6752HS_VF_1_2_D1;
if (abs(f->height - 576) < else
abs(f->height - 288)) { h->video_format = SAA6752HS_VF_SIF;
f->height = 576;
h->video_format = SAA6752HS_VF_1_2_D1;
} else {
f->height = 288;
h->video_format = SAA6752HS_VF_SIF;
}
}
f->field = V4L2_FIELD_INTERLACED;
f->colorspace = V4L2_COLORSPACE_SMPTE170M;
return 0; return 0;
} }
...@@ -644,6 +655,7 @@ static const struct v4l2_subdev_core_ops saa6752hs_core_ops = { ...@@ -644,6 +655,7 @@ static const struct v4l2_subdev_core_ops saa6752hs_core_ops = {
static const struct v4l2_subdev_video_ops saa6752hs_video_ops = { static const struct v4l2_subdev_video_ops saa6752hs_video_ops = {
.s_mbus_fmt = saa6752hs_s_mbus_fmt, .s_mbus_fmt = saa6752hs_s_mbus_fmt,
.try_mbus_fmt = saa6752hs_try_mbus_fmt,
.g_mbus_fmt = saa6752hs_g_mbus_fmt, .g_mbus_fmt = saa6752hs_g_mbus_fmt,
}; };
......
...@@ -212,7 +212,7 @@ static int empress_enum_fmt_vid_cap(struct file *file, void *priv, ...@@ -212,7 +212,7 @@ static int empress_enum_fmt_vid_cap(struct file *file, void *priv,
strlcpy(f->description, "MPEG TS", sizeof(f->description)); strlcpy(f->description, "MPEG TS", sizeof(f->description));
f->pixelformat = V4L2_PIX_FMT_MPEG; f->pixelformat = V4L2_PIX_FMT_MPEG;
f->flags = V4L2_FMT_FLAG_COMPRESSED;
return 0; return 0;
} }
...@@ -227,6 +227,8 @@ static int empress_g_fmt_vid_cap(struct file *file, void *priv, ...@@ -227,6 +227,8 @@ static int empress_g_fmt_vid_cap(struct file *file, void *priv,
v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt);
f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
f->fmt.pix.bytesperline = 0;
f->fmt.pix.priv = 0;
return 0; return 0;
} }
...@@ -243,6 +245,8 @@ static int empress_s_fmt_vid_cap(struct file *file, void *priv, ...@@ -243,6 +245,8 @@ static int empress_s_fmt_vid_cap(struct file *file, void *priv,
f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
f->fmt.pix.bytesperline = 0;
f->fmt.pix.priv = 0;
return 0; return 0;
} }
...@@ -251,9 +255,16 @@ static int empress_try_fmt_vid_cap(struct file *file, void *priv, ...@@ -251,9 +255,16 @@ static int empress_try_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *f) struct v4l2_format *f)
{ {
struct saa7134_dev *dev = file->private_data; struct saa7134_dev *dev = file->private_data;
struct v4l2_mbus_framefmt mbus_fmt;
v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED);
saa_call_all(dev, video, try_mbus_fmt, &mbus_fmt);
v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt);
f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
f->fmt.pix.bytesperline = 0;
f->fmt.pix.priv = 0;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment