aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/platform
diff options
context:
space:
mode:
authorPhilipp Zabel <p.zabel@pengutronix.de>2013-09-30 09:34:51 -0400
committerMauro Carvalho Chehab <m.chehab@samsung.com>2013-10-28 13:26:34 -0400
commit57625593589b51fbe713bcf3dbc97a8d92c2277f (patch)
tree95deeacae3961b18f20e36b379d5c154e6f6d8cf /drivers/media/platform
parent2e9e4f1182a001f263a2908c5f0115eacb3bd104 (diff)
[media] coda: v4l2-compliance fix: overwrite invalid pixel formats with the current setting
This patch fixes the v4l2-compliance "TRY_FMT(G_FMT) != G_FMT" issue. The driver now overwrites invalid formats with the current setting, using coda_get_max_dimensions to find device specific max width/height. Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Kamil Debski <k.debski@samsung.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media/platform')
-rw-r--r--drivers/media/platform/coda.c72
1 files changed, 56 insertions, 16 deletions
diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 6ddcf8ba5f76..4820bd57ed40 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -54,8 +54,6 @@
54 54
55#define CODA_MAX_FRAMEBUFFERS 8 55#define CODA_MAX_FRAMEBUFFERS 8
56 56
57#define MAX_W 8192
58#define MAX_H 8192
59#define CODA_MAX_FRAME_SIZE 0x100000 57#define CODA_MAX_FRAME_SIZE 0x100000
60#define FMO_SLICE_SAVE_BUF_SIZE (32) 58#define FMO_SLICE_SAVE_BUF_SIZE (32)
61#define CODA_DEFAULT_GAMMA 4096 59#define CODA_DEFAULT_GAMMA 4096
@@ -394,6 +392,31 @@ static struct coda_codec *coda_find_codec(struct coda_dev *dev, int src_fourcc,
394 return &codecs[k]; 392 return &codecs[k];
395} 393}
396 394
395static void coda_get_max_dimensions(struct coda_dev *dev,
396 struct coda_codec *codec,
397 int *max_w, int *max_h)
398{
399 struct coda_codec *codecs = dev->devtype->codecs;
400 int num_codecs = dev->devtype->num_codecs;
401 unsigned int w, h;
402 int k;
403
404 if (codec) {
405 w = codec->max_w;
406 h = codec->max_h;
407 } else {
408 for (k = 0, w = 0, h = 0; k < num_codecs; k++) {
409 w = max(w, codecs[k].max_w);
410 h = max(h, codecs[k].max_h);
411 }
412 }
413
414 if (max_w)
415 *max_w = w;
416 if (max_h)
417 *max_h = h;
418}
419
397static char *coda_product_name(int product) 420static char *coda_product_name(int product)
398{ 421{
399 static char buf[9]; 422 static char buf[9];
@@ -537,8 +560,11 @@ static int coda_g_fmt(struct file *file, void *priv,
537 return 0; 560 return 0;
538} 561}
539 562
540static int coda_try_fmt(struct coda_codec *codec, struct v4l2_format *f) 563static int coda_try_fmt(struct coda_ctx *ctx, struct coda_codec *codec,
564 struct v4l2_format *f)
541{ 565{
566 struct coda_dev *dev = ctx->dev;
567 struct coda_q_data *q_data;
542 unsigned int max_w, max_h; 568 unsigned int max_w, max_h;
543 enum v4l2_field field; 569 enum v4l2_field field;
544 570
@@ -552,25 +578,39 @@ static int coda_try_fmt(struct coda_codec *codec, struct v4l2_format *f)
552 * if any of the dimensions is unsupported */ 578 * if any of the dimensions is unsupported */
553 f->fmt.pix.field = field; 579 f->fmt.pix.field = field;
554 580
555 if (codec) { 581 coda_get_max_dimensions(dev, codec, &max_w, &max_h);
556 max_w = codec->max_w; 582 v4l_bound_align_image(&f->fmt.pix.width, MIN_W, max_w, W_ALIGN,
557 max_h = codec->max_h; 583 &f->fmt.pix.height, MIN_H, max_h, H_ALIGN,
558 } else { 584 S_ALIGN);
559 max_w = MAX_W; 585
560 max_h = MAX_H; 586 switch (f->fmt.pix.pixelformat) {
587 case V4L2_PIX_FMT_YUV420:
588 case V4L2_PIX_FMT_YVU420:
589 case V4L2_PIX_FMT_H264:
590 case V4L2_PIX_FMT_MPEG4:
591 case V4L2_PIX_FMT_JPEG:
592 break;
593 default:
594 q_data = get_q_data(ctx, f->type);
595 f->fmt.pix.pixelformat = q_data->fourcc;
561 } 596 }
562 v4l_bound_align_image(&f->fmt.pix.width, MIN_W, max_w,
563 W_ALIGN, &f->fmt.pix.height,
564 MIN_H, max_h, H_ALIGN, S_ALIGN);
565 597
566 if (coda_format_is_yuv(f->fmt.pix.pixelformat)) { 598 switch (f->fmt.pix.pixelformat) {
599 case V4L2_PIX_FMT_YUV420:
600 case V4L2_PIX_FMT_YVU420:
567 /* Frame stride must be multiple of 8 */ 601 /* Frame stride must be multiple of 8 */
568 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 8); 602 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 8);
569 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * 603 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
570 f->fmt.pix.height * 3 / 2; 604 f->fmt.pix.height * 3 / 2;
571 } else { /*encoded formats h.264/mpeg4 */ 605 break;
606 case V4L2_PIX_FMT_H264:
607 case V4L2_PIX_FMT_MPEG4:
608 case V4L2_PIX_FMT_JPEG:
572 f->fmt.pix.bytesperline = 0; 609 f->fmt.pix.bytesperline = 0;
573 f->fmt.pix.sizeimage = CODA_MAX_FRAME_SIZE; 610 f->fmt.pix.sizeimage = CODA_MAX_FRAME_SIZE;
611 break;
612 default:
613 BUG();
574 } 614 }
575 615
576 return 0; 616 return 0;
@@ -605,7 +645,7 @@ static int coda_try_fmt_vid_cap(struct file *file, void *priv,
605 645
606 f->fmt.pix.colorspace = ctx->colorspace; 646 f->fmt.pix.colorspace = ctx->colorspace;
607 647
608 ret = coda_try_fmt(codec, f); 648 ret = coda_try_fmt(ctx, codec, f);
609 if (ret < 0) 649 if (ret < 0)
610 return ret; 650 return ret;
611 651
@@ -634,7 +674,7 @@ static int coda_try_fmt_vid_out(struct file *file, void *priv,
634 if (!f->fmt.pix.colorspace) 674 if (!f->fmt.pix.colorspace)
635 f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709; 675 f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709;
636 676
637 return coda_try_fmt(codec, f); 677 return coda_try_fmt(ctx, codec, f);
638} 678}
639 679
640static int coda_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f) 680static int coda_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f)