aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/media/platform/coda/coda-common.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 490b933ad616..15f4c2b91e42 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -468,6 +468,18 @@ static int coda_try_pixelformat(struct coda_ctx *ctx, struct v4l2_format *f)
468 return 0; 468 return 0;
469} 469}
470 470
471static unsigned int coda_estimate_sizeimage(struct coda_ctx *ctx, u32 sizeimage,
472 u32 width, u32 height)
473{
474 /*
475 * This is a rough estimate for sensible compressed buffer
476 * sizes (between 1 and 16 bits per pixel). This could be
477 * improved by better format specific worst case estimates.
478 */
479 return round_up(clamp(sizeimage, width * height / 8,
480 width * height * 2), PAGE_SIZE);
481}
482
471static int coda_try_fmt(struct coda_ctx *ctx, const struct coda_codec *codec, 483static int coda_try_fmt(struct coda_ctx *ctx, const struct coda_codec *codec,
472 struct v4l2_format *f) 484 struct v4l2_format *f)
473{ 485{
@@ -513,15 +525,10 @@ static int coda_try_fmt(struct coda_ctx *ctx, const struct coda_codec *codec,
513 case V4L2_PIX_FMT_H264: 525 case V4L2_PIX_FMT_H264:
514 case V4L2_PIX_FMT_MPEG4: 526 case V4L2_PIX_FMT_MPEG4:
515 f->fmt.pix.bytesperline = 0; 527 f->fmt.pix.bytesperline = 0;
516 /* 528 f->fmt.pix.sizeimage = coda_estimate_sizeimage(ctx,
517 * This is a rough estimate for sensible compressed buffer 529 f->fmt.pix.sizeimage,
518 * sizes (between 1 and 16 bits per pixel). This could be 530 f->fmt.pix.width,
519 * improved by better format specific worst case estimates. 531 f->fmt.pix.height);
520 */
521 f->fmt.pix.sizeimage = round_up(clamp(f->fmt.pix.sizeimage,
522 f->fmt.pix.width * f->fmt.pix.height / 8,
523 f->fmt.pix.width * f->fmt.pix.height * 2),
524 PAGE_SIZE);
525 break; 532 break;
526 default: 533 default:
527 BUG(); 534 BUG();
@@ -1056,13 +1063,14 @@ static void coda_set_tiled_map_type(struct coda_ctx *ctx, int tiled_map_type)
1056 1063
1057static void set_default_params(struct coda_ctx *ctx) 1064static void set_default_params(struct coda_ctx *ctx)
1058{ 1065{
1059 unsigned int max_w, max_h, size; 1066 unsigned int max_w, max_h, usize, csize;
1060 1067
1061 ctx->codec = coda_find_codec(ctx->dev, ctx->cvd->src_formats[0], 1068 ctx->codec = coda_find_codec(ctx->dev, ctx->cvd->src_formats[0],
1062 ctx->cvd->dst_formats[0]); 1069 ctx->cvd->dst_formats[0]);
1063 max_w = min(ctx->codec->max_w, 1920U); 1070 max_w = min(ctx->codec->max_w, 1920U);
1064 max_h = min(ctx->codec->max_h, 1088U); 1071 max_h = min(ctx->codec->max_h, 1088U);
1065 size = max_w * max_h * 3 / 2; 1072 usize = max_w * max_h * 3 / 2;
1073 csize = coda_estimate_sizeimage(ctx, usize, max_w, max_h);
1066 1074
1067 ctx->params.codec_mode = ctx->codec->mode; 1075 ctx->params.codec_mode = ctx->codec->mode;
1068 ctx->colorspace = V4L2_COLORSPACE_REC709; 1076 ctx->colorspace = V4L2_COLORSPACE_REC709;
@@ -1077,14 +1085,14 @@ static void set_default_params(struct coda_ctx *ctx)
1077 ctx->q_data[V4L2_M2M_DST].height = max_h; 1085 ctx->q_data[V4L2_M2M_DST].height = max_h;
1078 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_YUV420) { 1086 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_YUV420) {
1079 ctx->q_data[V4L2_M2M_SRC].bytesperline = max_w; 1087 ctx->q_data[V4L2_M2M_SRC].bytesperline = max_w;
1080 ctx->q_data[V4L2_M2M_SRC].sizeimage = size; 1088 ctx->q_data[V4L2_M2M_SRC].sizeimage = usize;
1081 ctx->q_data[V4L2_M2M_DST].bytesperline = 0; 1089 ctx->q_data[V4L2_M2M_DST].bytesperline = 0;
1082 ctx->q_data[V4L2_M2M_DST].sizeimage = round_up(size, PAGE_SIZE); 1090 ctx->q_data[V4L2_M2M_DST].sizeimage = csize;
1083 } else { 1091 } else {
1084 ctx->q_data[V4L2_M2M_SRC].bytesperline = 0; 1092 ctx->q_data[V4L2_M2M_SRC].bytesperline = 0;
1085 ctx->q_data[V4L2_M2M_SRC].sizeimage = round_up(size, PAGE_SIZE); 1093 ctx->q_data[V4L2_M2M_SRC].sizeimage = csize;
1086 ctx->q_data[V4L2_M2M_DST].bytesperline = max_w; 1094 ctx->q_data[V4L2_M2M_DST].bytesperline = max_w;
1087 ctx->q_data[V4L2_M2M_DST].sizeimage = size; 1095 ctx->q_data[V4L2_M2M_DST].sizeimage = usize;
1088 } 1096 }
1089 ctx->q_data[V4L2_M2M_SRC].rect.width = max_w; 1097 ctx->q_data[V4L2_M2M_SRC].rect.width = max_w;
1090 ctx->q_data[V4L2_M2M_SRC].rect.height = max_h; 1098 ctx->q_data[V4L2_M2M_SRC].rect.height = max_h;