Skip to content

Commit

Permalink
media: rkvdec: h264: Support High 10 and 4:2:2 profiles
Browse files Browse the repository at this point in the history
Add support and enable decoding of H264 High 10 and 4:2:2 profiles.

Decoded CAPTURE buffer width is aligned to 64 pixels to accommodate HW
requirement on 10-bit format buffers.

The new valid_fmt operation is implemented and return a valid pixelformat
for the provided SPS control.

Signed-off-by: Jonas Karlman <[email protected]>
  • Loading branch information
Kwiboo authored and sigmaris committed Aug 8, 2020
1 parent 52bde27 commit 62d7573
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
20 changes: 20 additions & 0 deletions drivers/staging/media/rkvdec/rkvdec-h264.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,25 @@ static int rkvdec_h264_adjust_fmt(struct rkvdec_ctx *ctx,
return 0;
}

static u32 rkvdec_h264_valid_fmt(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl)
{
const struct v4l2_ctrl_h264_sps *sps = ctrl->p_new.p_h264_sps;

if (sps->bit_depth_luma_minus8 == 0) {
if (sps->chroma_format_idc == 2)
return V4L2_PIX_FMT_NV16;
else
return V4L2_PIX_FMT_NV12;
} else if (sps->bit_depth_luma_minus8 == 2) {
if (sps->chroma_format_idc == 2)
return V4L2_PIX_FMT_NV20;
else
return V4L2_PIX_FMT_NV15;
}

return 0;
}

static int rkvdec_h264_start(struct rkvdec_ctx *ctx)
{
struct rkvdec_dev *rkvdec = ctx->dev;
Expand Down Expand Up @@ -1120,6 +1139,7 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx)

const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops = {
.adjust_fmt = rkvdec_h264_adjust_fmt,
.valid_fmt = rkvdec_h264_valid_fmt,
.start = rkvdec_h264_start,
.stop = rkvdec_h264_stop,
.run = rkvdec_h264_run,
Expand Down
19 changes: 9 additions & 10 deletions drivers/staging/media/rkvdec/rkvdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void rkvdec_fill_decoded_pixfmt(struct rkvdec_ctx *ctx,
struct v4l2_pix_format_mplane *pix_mp)
{
v4l2_fill_pixfmt_mp(pix_mp, pix_mp->pixelformat,
pix_mp->width, pix_mp->height);
ALIGN(pix_mp->width, 64), pix_mp->height);
pix_mp->plane_fmt[0].sizeimage += 128 *
DIV_ROUND_UP(pix_mp->width, 16) *
DIV_ROUND_UP(pix_mp->height, 16);
Expand All @@ -55,19 +55,15 @@ static int rkvdec_try_ctrl(struct v4l2_ctrl *ctrl)
if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_SPS) {
const struct v4l2_ctrl_h264_sps *sps = ctrl->p_new.p_h264_sps;
unsigned int width, height;
/*
* TODO: The hardware supports 10-bit and 4:2:2 profiles,
* but it's currently broken in the driver.
* Reject them for now, until it's fixed.
*/
if (sps->chroma_format_idc > 1)
/* Only 4:0:0 and 4:2:0 are supported */

if (sps->chroma_format_idc > 2)
/* Only 4:0:0, 4:2:0 and 4:2:2 are supported */
return -EINVAL;
if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8)
/* Luma and chroma bit depth mismatch */
return -EINVAL;
if (sps->bit_depth_luma_minus8 != 0)
/* Only 8-bit is supported */
if (sps->bit_depth_luma_minus8 != 0 && sps->bit_depth_luma_minus8 != 2)
/* Only 8-bit and 10-bit is supported */
return -EINVAL;

if (ctx->valid_fmt && ctx->valid_fmt != rkvdec_valid_fmt(ctx, ctrl))
Expand Down Expand Up @@ -152,6 +148,9 @@ static const struct rkvdec_ctrls rkvdec_h264_ctrls = {

static const u32 rkvdec_h264_decoded_fmts[] = {
V4L2_PIX_FMT_NV12,
V4L2_PIX_FMT_NV15,
V4L2_PIX_FMT_NV16,
V4L2_PIX_FMT_NV20,
};

static const struct rkvdec_coded_fmt_desc rkvdec_coded_fmts[] = {
Expand Down

0 comments on commit 62d7573

Please sign in to comment.