aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2009-02-18 15:11:17 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-03-30 11:42:56 -0400
commit0ba514d5d39d017e320ffba6d2a98563b829d37c (patch)
tree20ea0f4a59e71f1864620f676057019acd2d16fe
parent7f37cc9bae7aa29d567460c3ac8178d587f710bc (diff)
V4L/DVB (10711): zoran: fix TRY_FMT support
Actually try to turn the format into something usable rather than just rejecting it if it isn't perfect. Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/video/zoran/zoran_card.c63
-rw-r--r--drivers/media/video/zoran/zoran_card.h3
-rw-r--r--drivers/media/video/zoran/zoran_driver.c21
3 files changed, 63 insertions, 24 deletions
diff --git a/drivers/media/video/zoran/zoran_card.c b/drivers/media/video/zoran/zoran_card.c
index 18834b18435b..774717bf43cc 100644
--- a/drivers/media/video/zoran/zoran_card.c
+++ b/drivers/media/video/zoran/zoran_card.c
@@ -835,7 +835,8 @@ zoran_unregister_i2c (struct zoran *zr)
835 835
836int 836int
837zoran_check_jpg_settings (struct zoran *zr, 837zoran_check_jpg_settings (struct zoran *zr,
838 struct zoran_jpg_settings *settings) 838 struct zoran_jpg_settings *settings,
839 int try)
839{ 840{
840 int err = 0, err0 = 0; 841 int err = 0, err0 = 0;
841 842
@@ -900,35 +901,61 @@ zoran_check_jpg_settings (struct zoran *zr,
900 /* We have to check the data the user has set */ 901 /* We have to check the data the user has set */
901 902
902 if (settings->HorDcm != 1 && settings->HorDcm != 2 && 903 if (settings->HorDcm != 1 && settings->HorDcm != 2 &&
903 (zr->card.type == DC10_new || settings->HorDcm != 4)) 904 (zr->card.type == DC10_new || settings->HorDcm != 4)) {
905 settings->HorDcm = clamp(settings->HorDcm, 1, 2);
904 err0++; 906 err0++;
905 if (settings->VerDcm != 1 && settings->VerDcm != 2) 907 }
908 if (settings->VerDcm != 1 && settings->VerDcm != 2) {
909 settings->VerDcm = clamp(settings->VerDcm, 1, 2);
906 err0++; 910 err0++;
907 if (settings->TmpDcm != 1 && settings->TmpDcm != 2) 911 }
912 if (settings->TmpDcm != 1 && settings->TmpDcm != 2) {
913 settings->TmpDcm = clamp(settings->TmpDcm, 1, 2);
908 err0++; 914 err0++;
915 }
909 if (settings->field_per_buff != 1 && 916 if (settings->field_per_buff != 1 &&
910 settings->field_per_buff != 2) 917 settings->field_per_buff != 2) {
918 settings->field_per_buff = clamp(settings->field_per_buff, 1, 2);
911 err0++; 919 err0++;
912 if (settings->img_x < 0) 920 }
921 if (settings->img_x < 0) {
922 settings->img_x = 0;
913 err0++; 923 err0++;
914 if (settings->img_y < 0) 924 }
925 if (settings->img_y < 0) {
926 settings->img_y = 0;
915 err0++; 927 err0++;
916 if (settings->img_width < 0) 928 }
929 if (settings->img_width < 0 || settings->img_width > BUZ_MAX_WIDTH) {
930 settings->img_width = clamp(settings->img_width, 0, (int)BUZ_MAX_WIDTH);
917 err0++; 931 err0++;
918 if (settings->img_height < 0) 932 }
933 if (settings->img_height < 0 || settings->img_height > BUZ_MAX_HEIGHT / 2) {
934 settings->img_height = clamp(settings->img_height, 0, BUZ_MAX_HEIGHT / 2);
919 err0++; 935 err0++;
920 if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH) 936 }
937 if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH) {
938 settings->img_x = BUZ_MAX_WIDTH - settings->img_width;
939 err0++;
940 }
941 if (settings->img_y + settings->img_height > BUZ_MAX_HEIGHT / 2) {
942 settings->img_y = BUZ_MAX_HEIGHT / 2 - settings->img_height;
921 err0++; 943 err0++;
922 if (settings->img_y + settings->img_height > BUZ_MAX_HEIGHT / 2) 944 }
945 if (settings->img_width % (16 * settings->HorDcm) != 0) {
946 settings->img_width -= settings->img_width % (16 * settings->HorDcm);
947 if (settings->img_width == 0)
948 settings->img_width = 16 * settings->HorDcm;
949 err0++;
950 }
951 if (settings->img_height % (8 * settings->VerDcm) != 0) {
952 settings->img_height -= settings->img_height % (8 * settings->VerDcm);
953 if (settings->img_height == 0)
954 settings->img_height = 8 * settings->VerDcm;
923 err0++; 955 err0++;
924 if (settings->HorDcm && settings->VerDcm) {
925 if (settings->img_width % (16 * settings->HorDcm) != 0)
926 err0++;
927 if (settings->img_height % (8 * settings->VerDcm) != 0)
928 err0++;
929 } 956 }
930 957
931 if (err0) { 958 if (!try && err0) {
932 dprintk(1, 959 dprintk(1,
933 KERN_ERR 960 KERN_ERR
934 "%s: check_jpg_settings() - error in params for decimation = 0\n", 961 "%s: check_jpg_settings() - error in params for decimation = 0\n",
@@ -1018,7 +1045,7 @@ zoran_open_init_params (struct zoran *zr)
1018 sizeof(zr->jpg_settings.jpg_comp.COM_data)); 1045 sizeof(zr->jpg_settings.jpg_comp.COM_data));
1019 zr->jpg_settings.jpg_comp.jpeg_markers = 1046 zr->jpg_settings.jpg_comp.jpeg_markers =
1020 JPEG_MARKER_DHT | JPEG_MARKER_DQT; 1047 JPEG_MARKER_DHT | JPEG_MARKER_DQT;
1021 i = zoran_check_jpg_settings(zr, &zr->jpg_settings); 1048 i = zoran_check_jpg_settings(zr, &zr->jpg_settings, 0);
1022 if (i) 1049 if (i)
1023 dprintk(1, 1050 dprintk(1,
1024 KERN_ERR 1051 KERN_ERR
diff --git a/drivers/media/video/zoran/zoran_card.h b/drivers/media/video/zoran/zoran_card.h
index 4507bdc5e338..4936fead73e8 100644
--- a/drivers/media/video/zoran/zoran_card.h
+++ b/drivers/media/video/zoran/zoran_card.h
@@ -44,7 +44,8 @@ extern int zr36067_debug;
44extern struct video_device zoran_template; 44extern struct video_device zoran_template;
45 45
46extern int zoran_check_jpg_settings(struct zoran *zr, 46extern int zoran_check_jpg_settings(struct zoran *zr,
47 struct zoran_jpg_settings *settings); 47 struct zoran_jpg_settings *settings,
48 int try);
48extern void zoran_open_init_params(struct zoran *zr); 49extern void zoran_open_init_params(struct zoran *zr);
49extern void zoran_vdev_release(struct video_device *vdev); 50extern void zoran_vdev_release(struct video_device *vdev);
50 51
diff --git a/drivers/media/video/zoran/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c
index 0cce652011ff..cdfd3cc05151 100644
--- a/drivers/media/video/zoran/zoran_driver.c
+++ b/drivers/media/video/zoran/zoran_driver.c
@@ -1797,7 +1797,7 @@ static long zoran_default(struct file *file, void *__fh, int cmd, void *arg)
1797 1797
1798 /* Check the params first before overwriting our 1798 /* Check the params first before overwriting our
1799 * nternal values */ 1799 * nternal values */
1800 if (zoran_check_jpg_settings(zr, &settings)) { 1800 if (zoran_check_jpg_settings(zr, &settings, 0)) {
1801 res = -EINVAL; 1801 res = -EINVAL;
1802 goto sparams_unlock_and_return; 1802 goto sparams_unlock_and_return;
1803 } 1803 }
@@ -2205,7 +2205,7 @@ static int zoran_try_fmt_vid_out(struct file *file, void *__fh,
2205 settings.field_per_buff = 1; 2205 settings.field_per_buff = 1;
2206 2206
2207 /* check */ 2207 /* check */
2208 res = zoran_check_jpg_settings(zr, &settings); 2208 res = zoran_check_jpg_settings(zr, &settings, 1);
2209 if (res) 2209 if (res)
2210 goto tryfmt_unlock_and_return; 2210 goto tryfmt_unlock_and_return;
2211 2211
@@ -2231,6 +2231,7 @@ static int zoran_try_fmt_vid_cap(struct file *file, void *__fh,
2231{ 2231{
2232 struct zoran_fh *fh = __fh; 2232 struct zoran_fh *fh = __fh;
2233 struct zoran *zr = fh->zr; 2233 struct zoran *zr = fh->zr;
2234 int bpp;
2234 int i; 2235 int i;
2235 2236
2236 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) 2237 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG)
@@ -2247,6 +2248,8 @@ static int zoran_try_fmt_vid_cap(struct file *file, void *__fh,
2247 return -EINVAL; 2248 return -EINVAL;
2248 } 2249 }
2249 2250
2251 bpp = (zoran_formats[i].depth + 7) / 8;
2252 fmt->fmt.pix.width &= ~((bpp == 2) ? 1 : 3);
2250 if (fmt->fmt.pix.width > BUZ_MAX_WIDTH) 2253 if (fmt->fmt.pix.width > BUZ_MAX_WIDTH)
2251 fmt->fmt.pix.width = BUZ_MAX_WIDTH; 2254 fmt->fmt.pix.width = BUZ_MAX_WIDTH;
2252 if (fmt->fmt.pix.width < BUZ_MIN_WIDTH) 2255 if (fmt->fmt.pix.width < BUZ_MIN_WIDTH)
@@ -2334,8 +2337,16 @@ static int zoran_s_fmt_vid_out(struct file *file, void *__fh,
2334 else 2337 else
2335 settings.field_per_buff = 1; 2338 settings.field_per_buff = 1;
2336 2339
2340 if (settings.HorDcm > 1) {
2341 settings.img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0;
2342 settings.img_width = (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH;
2343 } else {
2344 settings.img_x = 0;
2345 settings.img_width = BUZ_MAX_WIDTH;
2346 }
2347
2337 /* check */ 2348 /* check */
2338 res = zoran_check_jpg_settings(zr, &settings); 2349 res = zoran_check_jpg_settings(zr, &settings, 0);
2339 if (res) 2350 if (res)
2340 goto sfmtjpg_unlock_and_return; 2351 goto sfmtjpg_unlock_and_return;
2341 2352
@@ -3216,7 +3227,7 @@ static int zoran_s_crop(struct file *file, void *__fh, struct v4l2_crop *crop)
3216 settings.img_height = crop->c.height; 3227 settings.img_height = crop->c.height;
3217 3228
3218 /* check validity */ 3229 /* check validity */
3219 res = zoran_check_jpg_settings(zr, &settings); 3230 res = zoran_check_jpg_settings(zr, &settings, 0);
3220 if (res) 3231 if (res)
3221 goto scrop_unlock_and_return; 3232 goto scrop_unlock_and_return;
3222 3233
@@ -3278,7 +3289,7 @@ static int zoran_s_jpegcomp(struct file *file, void *__fh,
3278 goto sjpegc_unlock_and_return; 3289 goto sjpegc_unlock_and_return;
3279 } 3290 }
3280 3291
3281 res = zoran_check_jpg_settings(zr, &settings); 3292 res = zoran_check_jpg_settings(zr, &settings, 0);
3282 if (res) 3293 if (res)
3283 goto sjpegc_unlock_and_return; 3294 goto sjpegc_unlock_and_return;
3284 if (!fh->jpg_buffers.allocated) 3295 if (!fh->jpg_buffers.allocated)