2018-09-02 18:37:04 +08:00
|
|
|
// SPDX-License-Identifier: LGPL-2.1
|
2018-08-22 15:50:56 +08:00
|
|
|
/*
|
|
|
|
* A V4L2 frontend for the FWHT codec
|
|
|
|
*
|
|
|
|
* Copyright 2018 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
#include "codec-v4l2-fwht.h"
|
|
|
|
|
|
|
|
static const struct v4l2_fwht_pixfmt_info v4l2_fwht_pixfmts[] = {
|
2020-11-26 20:58:20 +08:00
|
|
|
{ V4L2_PIX_FMT_YUV420, 1, 3, 2, 1, 1, 2, 2, 3, 3, V4L2_FWHT_FL_PIXENC_YUV},
|
|
|
|
{ V4L2_PIX_FMT_YVU420, 1, 3, 2, 1, 1, 2, 2, 3, 3, V4L2_FWHT_FL_PIXENC_YUV},
|
|
|
|
{ V4L2_PIX_FMT_YUV422P, 1, 2, 1, 1, 1, 2, 1, 3, 3, V4L2_FWHT_FL_PIXENC_YUV},
|
|
|
|
{ V4L2_PIX_FMT_NV12, 1, 3, 2, 1, 2, 2, 2, 3, 2, V4L2_FWHT_FL_PIXENC_YUV},
|
|
|
|
{ V4L2_PIX_FMT_NV21, 1, 3, 2, 1, 2, 2, 2, 3, 2, V4L2_FWHT_FL_PIXENC_YUV},
|
|
|
|
{ V4L2_PIX_FMT_NV16, 1, 2, 1, 1, 2, 2, 1, 3, 2, V4L2_FWHT_FL_PIXENC_YUV},
|
|
|
|
{ V4L2_PIX_FMT_NV61, 1, 2, 1, 1, 2, 2, 1, 3, 2, V4L2_FWHT_FL_PIXENC_YUV},
|
|
|
|
{ V4L2_PIX_FMT_NV24, 1, 3, 1, 1, 2, 1, 1, 3, 2, V4L2_FWHT_FL_PIXENC_YUV},
|
|
|
|
{ V4L2_PIX_FMT_NV42, 1, 3, 1, 1, 2, 1, 1, 3, 2, V4L2_FWHT_FL_PIXENC_YUV},
|
|
|
|
{ V4L2_PIX_FMT_YUYV, 2, 2, 1, 2, 4, 2, 1, 3, 1, V4L2_FWHT_FL_PIXENC_YUV},
|
|
|
|
{ V4L2_PIX_FMT_YVYU, 2, 2, 1, 2, 4, 2, 1, 3, 1, V4L2_FWHT_FL_PIXENC_YUV},
|
|
|
|
{ V4L2_PIX_FMT_UYVY, 2, 2, 1, 2, 4, 2, 1, 3, 1, V4L2_FWHT_FL_PIXENC_YUV},
|
|
|
|
{ V4L2_PIX_FMT_VYUY, 2, 2, 1, 2, 4, 2, 1, 3, 1, V4L2_FWHT_FL_PIXENC_YUV},
|
|
|
|
{ V4L2_PIX_FMT_BGR24, 3, 3, 1, 3, 3, 1, 1, 3, 1, V4L2_FWHT_FL_PIXENC_RGB},
|
|
|
|
{ V4L2_PIX_FMT_RGB24, 3, 3, 1, 3, 3, 1, 1, 3, 1, V4L2_FWHT_FL_PIXENC_RGB},
|
|
|
|
{ V4L2_PIX_FMT_HSV24, 3, 3, 1, 3, 3, 1, 1, 3, 1, V4L2_FWHT_FL_PIXENC_HSV},
|
|
|
|
{ V4L2_PIX_FMT_BGR32, 4, 4, 1, 4, 4, 1, 1, 4, 1, V4L2_FWHT_FL_PIXENC_RGB},
|
|
|
|
{ V4L2_PIX_FMT_XBGR32, 4, 4, 1, 4, 4, 1, 1, 4, 1, V4L2_FWHT_FL_PIXENC_RGB},
|
|
|
|
{ V4L2_PIX_FMT_ABGR32, 4, 4, 1, 4, 4, 1, 1, 4, 1, V4L2_FWHT_FL_PIXENC_RGB},
|
|
|
|
{ V4L2_PIX_FMT_RGB32, 4, 4, 1, 4, 4, 1, 1, 4, 1, V4L2_FWHT_FL_PIXENC_RGB},
|
|
|
|
{ V4L2_PIX_FMT_XRGB32, 4, 4, 1, 4, 4, 1, 1, 4, 1, V4L2_FWHT_FL_PIXENC_RGB},
|
|
|
|
{ V4L2_PIX_FMT_ARGB32, 4, 4, 1, 4, 4, 1, 1, 4, 1, V4L2_FWHT_FL_PIXENC_RGB},
|
|
|
|
{ V4L2_PIX_FMT_BGRX32, 4, 4, 1, 4, 4, 1, 1, 4, 1, V4L2_FWHT_FL_PIXENC_RGB},
|
|
|
|
{ V4L2_PIX_FMT_BGRA32, 4, 4, 1, 4, 4, 1, 1, 4, 1, V4L2_FWHT_FL_PIXENC_RGB},
|
|
|
|
{ V4L2_PIX_FMT_RGBX32, 4, 4, 1, 4, 4, 1, 1, 4, 1, V4L2_FWHT_FL_PIXENC_RGB},
|
|
|
|
{ V4L2_PIX_FMT_RGBA32, 4, 4, 1, 4, 4, 1, 1, 4, 1, V4L2_FWHT_FL_PIXENC_RGB},
|
|
|
|
{ V4L2_PIX_FMT_HSV32, 4, 4, 1, 4, 4, 1, 1, 4, 1, V4L2_FWHT_FL_PIXENC_HSV},
|
|
|
|
{ V4L2_PIX_FMT_GREY, 1, 1, 1, 1, 0, 1, 1, 1, 1, V4L2_FWHT_FL_PIXENC_RGB},
|
2018-08-22 15:50:56 +08:00
|
|
|
};
|
|
|
|
|
2019-03-07 05:13:34 +08:00
|
|
|
bool v4l2_fwht_validate_fmt(const struct v4l2_fwht_pixfmt_info *info,
|
|
|
|
u32 width_div, u32 height_div, u32 components_num,
|
|
|
|
u32 pixenc)
|
|
|
|
{
|
|
|
|
if (info->width_div == width_div &&
|
|
|
|
info->height_div == height_div &&
|
|
|
|
(!pixenc || info->pixenc == pixenc) &&
|
|
|
|
info->components_num == components_num)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct v4l2_fwht_pixfmt_info *v4l2_fwht_find_nth_fmt(u32 width_div,
|
2019-01-21 19:46:16 +08:00
|
|
|
u32 height_div,
|
|
|
|
u32 components_num,
|
|
|
|
u32 pixenc,
|
|
|
|
unsigned int start_idx)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v4l2_fwht_pixfmts); i++) {
|
2019-03-07 05:13:34 +08:00
|
|
|
bool is_valid = v4l2_fwht_validate_fmt(&v4l2_fwht_pixfmts[i],
|
|
|
|
width_div, height_div,
|
|
|
|
components_num, pixenc);
|
|
|
|
if (is_valid) {
|
2019-01-21 19:46:16 +08:00
|
|
|
if (start_idx == 0)
|
|
|
|
return v4l2_fwht_pixfmts + i;
|
|
|
|
start_idx--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-08-22 15:50:56 +08:00
|
|
|
const struct v4l2_fwht_pixfmt_info *v4l2_fwht_find_pixfmt(u32 pixelformat)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v4l2_fwht_pixfmts); i++)
|
|
|
|
if (v4l2_fwht_pixfmts[i].id == pixelformat)
|
|
|
|
return v4l2_fwht_pixfmts + i;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct v4l2_fwht_pixfmt_info *v4l2_fwht_get_pixfmt(u32 idx)
|
|
|
|
{
|
|
|
|
if (idx >= ARRAY_SIZE(v4l2_fwht_pixfmts))
|
|
|
|
return NULL;
|
|
|
|
return v4l2_fwht_pixfmts + idx;
|
|
|
|
}
|
|
|
|
|
2019-03-07 05:13:30 +08:00
|
|
|
static int prepare_raw_frame(struct fwht_raw_frame *rf,
|
|
|
|
const struct v4l2_fwht_pixfmt_info *info, u8 *buf,
|
|
|
|
unsigned int size)
|
2018-08-22 15:50:56 +08:00
|
|
|
{
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->luma = buf;
|
|
|
|
rf->width_div = info->width_div;
|
|
|
|
rf->height_div = info->height_div;
|
|
|
|
rf->luma_alpha_step = info->luma_alpha_step;
|
|
|
|
rf->chroma_step = info->chroma_step;
|
|
|
|
rf->alpha = NULL;
|
|
|
|
rf->components_num = info->components_num;
|
2018-08-22 15:50:56 +08:00
|
|
|
|
2019-03-07 05:13:35 +08:00
|
|
|
/*
|
|
|
|
* The buffer is NULL if it is the reference
|
|
|
|
* frame of an I-frame in the stateless decoder
|
|
|
|
*/
|
|
|
|
if (!buf) {
|
|
|
|
rf->luma = NULL;
|
|
|
|
rf->cb = NULL;
|
|
|
|
rf->cr = NULL;
|
|
|
|
rf->alpha = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-08-22 15:50:56 +08:00
|
|
|
switch (info->id) {
|
2018-11-15 19:23:31 +08:00
|
|
|
case V4L2_PIX_FMT_GREY:
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->cb = NULL;
|
|
|
|
rf->cr = NULL;
|
2018-11-15 19:23:31 +08:00
|
|
|
break;
|
2018-08-22 15:50:56 +08:00
|
|
|
case V4L2_PIX_FMT_YUV420:
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->cb = rf->luma + size;
|
|
|
|
rf->cr = rf->cb + size / 4;
|
2018-08-22 15:50:56 +08:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_YVU420:
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->cr = rf->luma + size;
|
|
|
|
rf->cb = rf->cr + size / 4;
|
2018-08-22 15:50:56 +08:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_YUV422P:
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->cb = rf->luma + size;
|
|
|
|
rf->cr = rf->cb + size / 2;
|
2018-08-22 15:50:56 +08:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_NV12:
|
|
|
|
case V4L2_PIX_FMT_NV16:
|
|
|
|
case V4L2_PIX_FMT_NV24:
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->cb = rf->luma + size;
|
|
|
|
rf->cr = rf->cb + 1;
|
2018-08-22 15:50:56 +08:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_NV21:
|
|
|
|
case V4L2_PIX_FMT_NV61:
|
|
|
|
case V4L2_PIX_FMT_NV42:
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->cr = rf->luma + size;
|
|
|
|
rf->cb = rf->cr + 1;
|
2018-08-22 15:50:56 +08:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_YUYV:
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->cb = rf->luma + 1;
|
|
|
|
rf->cr = rf->cb + 2;
|
2018-08-22 15:50:56 +08:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_YVYU:
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->cr = rf->luma + 1;
|
|
|
|
rf->cb = rf->cr + 2;
|
2018-08-22 15:50:56 +08:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_UYVY:
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->cb = rf->luma;
|
|
|
|
rf->cr = rf->cb + 2;
|
|
|
|
rf->luma++;
|
2018-08-22 15:50:56 +08:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_VYUY:
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->cr = rf->luma;
|
|
|
|
rf->cb = rf->cr + 2;
|
|
|
|
rf->luma++;
|
2018-08-22 15:50:56 +08:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB24:
|
|
|
|
case V4L2_PIX_FMT_HSV24:
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->cr = rf->luma;
|
|
|
|
rf->cb = rf->cr + 2;
|
|
|
|
rf->luma++;
|
2018-08-22 15:50:56 +08:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_BGR24:
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->cb = rf->luma;
|
|
|
|
rf->cr = rf->cb + 2;
|
|
|
|
rf->luma++;
|
2018-08-22 15:50:56 +08:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB32:
|
|
|
|
case V4L2_PIX_FMT_XRGB32:
|
|
|
|
case V4L2_PIX_FMT_HSV32:
|
2018-11-15 19:23:32 +08:00
|
|
|
case V4L2_PIX_FMT_ARGB32:
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->alpha = rf->luma;
|
|
|
|
rf->cr = rf->luma + 1;
|
|
|
|
rf->cb = rf->cr + 2;
|
|
|
|
rf->luma += 2;
|
2018-11-15 19:23:32 +08:00
|
|
|
break;
|
2020-02-04 20:45:04 +08:00
|
|
|
case V4L2_PIX_FMT_BGR32:
|
|
|
|
case V4L2_PIX_FMT_XBGR32:
|
2018-11-15 19:23:32 +08:00
|
|
|
case V4L2_PIX_FMT_ABGR32:
|
2019-03-07 05:13:30 +08:00
|
|
|
rf->cb = rf->luma;
|
|
|
|
rf->cr = rf->cb + 2;
|
|
|
|
rf->luma++;
|
|
|
|
rf->alpha = rf->cr + 1;
|
2018-11-15 19:23:32 +08:00
|
|
|
break;
|
2019-07-30 21:00:20 +08:00
|
|
|
case V4L2_PIX_FMT_BGRX32:
|
|
|
|
case V4L2_PIX_FMT_BGRA32:
|
|
|
|
rf->alpha = rf->luma;
|
|
|
|
rf->cb = rf->luma + 1;
|
|
|
|
rf->cr = rf->cb + 2;
|
|
|
|
rf->luma += 2;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGBX32:
|
|
|
|
case V4L2_PIX_FMT_RGBA32:
|
|
|
|
rf->alpha = rf->luma + 3;
|
|
|
|
rf->cr = rf->luma;
|
|
|
|
rf->cb = rf->cr + 2;
|
|
|
|
rf->luma++;
|
|
|
|
break;
|
2018-09-10 23:00:39 +08:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2018-08-22 15:50:56 +08:00
|
|
|
}
|
2019-03-07 05:13:30 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int v4l2_fwht_encode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out)
|
|
|
|
{
|
|
|
|
unsigned int size = state->stride * state->coded_height;
|
|
|
|
unsigned int chroma_stride = state->stride;
|
|
|
|
const struct v4l2_fwht_pixfmt_info *info = state->info;
|
|
|
|
struct fwht_cframe_hdr *p_hdr;
|
|
|
|
struct fwht_cframe cf;
|
|
|
|
struct fwht_raw_frame rf;
|
|
|
|
u32 encoding;
|
|
|
|
u32 flags = 0;
|
|
|
|
|
|
|
|
if (!info)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (prepare_raw_frame(&rf, info, p_in, size))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (info->planes_num == 3)
|
|
|
|
chroma_stride /= 2;
|
|
|
|
|
|
|
|
if (info->id == V4L2_PIX_FMT_NV24 ||
|
|
|
|
info->id == V4L2_PIX_FMT_NV42)
|
|
|
|
chroma_stride *= 2;
|
2018-08-22 15:50:56 +08:00
|
|
|
|
|
|
|
cf.i_frame_qp = state->i_frame_qp;
|
|
|
|
cf.p_frame_qp = state->p_frame_qp;
|
|
|
|
cf.rlc_data = (__be16 *)(p_out + sizeof(*p_hdr));
|
|
|
|
|
|
|
|
encoding = fwht_encode_frame(&rf, &state->ref_frame, &cf,
|
|
|
|
!state->gop_cnt,
|
2019-01-21 19:46:14 +08:00
|
|
|
state->gop_cnt == state->gop_size - 1,
|
|
|
|
state->visible_width,
|
|
|
|
state->visible_height,
|
|
|
|
state->stride, chroma_stride);
|
2018-08-22 15:50:56 +08:00
|
|
|
if (!(encoding & FWHT_FRAME_PCODED))
|
|
|
|
state->gop_cnt = 0;
|
|
|
|
if (++state->gop_cnt >= state->gop_size)
|
|
|
|
state->gop_cnt = 0;
|
|
|
|
|
|
|
|
p_hdr = (struct fwht_cframe_hdr *)p_out;
|
|
|
|
p_hdr->magic1 = FWHT_MAGIC1;
|
|
|
|
p_hdr->magic2 = FWHT_MAGIC2;
|
2020-11-26 20:58:20 +08:00
|
|
|
p_hdr->version = htonl(V4L2_FWHT_VERSION);
|
2019-01-21 19:46:14 +08:00
|
|
|
p_hdr->width = htonl(state->visible_width);
|
|
|
|
p_hdr->height = htonl(state->visible_height);
|
2020-11-26 20:58:20 +08:00
|
|
|
flags |= (info->components_num - 1) << V4L2_FWHT_FL_COMPONENTS_NUM_OFFSET;
|
2019-01-21 19:46:16 +08:00
|
|
|
flags |= info->pixenc;
|
2018-08-22 15:50:56 +08:00
|
|
|
if (encoding & FWHT_LUMA_UNENCODED)
|
2020-11-26 20:58:20 +08:00
|
|
|
flags |= V4L2_FWHT_FL_LUMA_IS_UNCOMPRESSED;
|
2018-08-22 15:50:56 +08:00
|
|
|
if (encoding & FWHT_CB_UNENCODED)
|
2020-11-26 20:58:20 +08:00
|
|
|
flags |= V4L2_FWHT_FL_CB_IS_UNCOMPRESSED;
|
2018-08-22 15:50:56 +08:00
|
|
|
if (encoding & FWHT_CR_UNENCODED)
|
2020-11-26 20:58:20 +08:00
|
|
|
flags |= V4L2_FWHT_FL_CR_IS_UNCOMPRESSED;
|
2018-11-15 19:23:32 +08:00
|
|
|
if (encoding & FWHT_ALPHA_UNENCODED)
|
2020-11-26 20:58:20 +08:00
|
|
|
flags |= V4L2_FWHT_FL_ALPHA_IS_UNCOMPRESSED;
|
2019-02-16 04:58:53 +08:00
|
|
|
if (!(encoding & FWHT_FRAME_PCODED))
|
2020-11-26 20:58:20 +08:00
|
|
|
flags |= V4L2_FWHT_FL_I_FRAME;
|
2018-08-22 15:50:56 +08:00
|
|
|
if (rf.height_div == 1)
|
2020-11-26 20:58:20 +08:00
|
|
|
flags |= V4L2_FWHT_FL_CHROMA_FULL_HEIGHT;
|
2018-08-22 15:50:56 +08:00
|
|
|
if (rf.width_div == 1)
|
2020-11-26 20:58:20 +08:00
|
|
|
flags |= V4L2_FWHT_FL_CHROMA_FULL_WIDTH;
|
2018-08-22 15:50:56 +08:00
|
|
|
p_hdr->flags = htonl(flags);
|
|
|
|
p_hdr->colorspace = htonl(state->colorspace);
|
|
|
|
p_hdr->xfer_func = htonl(state->xfer_func);
|
|
|
|
p_hdr->ycbcr_enc = htonl(state->ycbcr_enc);
|
|
|
|
p_hdr->quantization = htonl(state->quantization);
|
|
|
|
p_hdr->size = htonl(cf.size);
|
|
|
|
return cf.size + sizeof(*p_hdr);
|
|
|
|
}
|
|
|
|
|
2018-09-10 23:00:39 +08:00
|
|
|
int v4l2_fwht_decode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out)
|
2018-08-22 15:50:56 +08:00
|
|
|
{
|
|
|
|
u32 flags;
|
|
|
|
struct fwht_cframe cf;
|
2018-11-15 19:23:31 +08:00
|
|
|
unsigned int components_num = 3;
|
|
|
|
unsigned int version;
|
2019-01-21 19:46:14 +08:00
|
|
|
const struct v4l2_fwht_pixfmt_info *info;
|
|
|
|
unsigned int hdr_width_div, hdr_height_div;
|
2019-03-07 05:13:32 +08:00
|
|
|
struct fwht_raw_frame dst_rf;
|
|
|
|
unsigned int dst_chroma_stride = state->stride;
|
|
|
|
unsigned int ref_chroma_stride = state->ref_stride;
|
|
|
|
unsigned int dst_size = state->stride * state->coded_height;
|
|
|
|
unsigned int ref_size;
|
2018-08-22 15:50:56 +08:00
|
|
|
|
2018-09-10 23:00:39 +08:00
|
|
|
if (!state->info)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2019-01-21 19:46:14 +08:00
|
|
|
info = state->info;
|
2018-11-15 19:23:31 +08:00
|
|
|
|
2019-01-21 19:46:17 +08:00
|
|
|
version = ntohl(state->header.version);
|
2020-11-26 20:58:20 +08:00
|
|
|
if (!version || version > V4L2_FWHT_VERSION) {
|
2018-11-15 19:23:31 +08:00
|
|
|
pr_err("version %d is not supported, current version is %d\n",
|
2020-11-26 20:58:20 +08:00
|
|
|
version, V4L2_FWHT_VERSION);
|
2018-11-15 19:23:31 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2018-08-22 15:50:56 +08:00
|
|
|
|
2019-01-21 19:46:17 +08:00
|
|
|
if (state->header.magic1 != FWHT_MAGIC1 ||
|
|
|
|
state->header.magic2 != FWHT_MAGIC2)
|
2018-08-22 15:50:56 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* TODO: support resolution changes */
|
2019-01-21 19:46:17 +08:00
|
|
|
if (ntohl(state->header.width) != state->visible_width ||
|
|
|
|
ntohl(state->header.height) != state->visible_height)
|
2018-08-22 15:50:56 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2019-01-21 19:46:17 +08:00
|
|
|
flags = ntohl(state->header.flags);
|
2018-11-15 19:23:31 +08:00
|
|
|
|
2019-02-16 04:58:53 +08:00
|
|
|
if (version >= 2) {
|
2020-11-26 20:58:20 +08:00
|
|
|
if ((flags & V4L2_FWHT_FL_PIXENC_MSK) != info->pixenc)
|
2019-01-21 19:46:16 +08:00
|
|
|
return -EINVAL;
|
2020-11-26 20:58:20 +08:00
|
|
|
components_num = 1 + ((flags & V4L2_FWHT_FL_COMPONENTS_NUM_MSK) >>
|
|
|
|
V4L2_FWHT_FL_COMPONENTS_NUM_OFFSET);
|
2018-11-15 19:23:31 +08:00
|
|
|
}
|
|
|
|
|
2019-01-21 19:46:16 +08:00
|
|
|
if (components_num != info->components_num)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2019-01-21 19:46:17 +08:00
|
|
|
state->colorspace = ntohl(state->header.colorspace);
|
|
|
|
state->xfer_func = ntohl(state->header.xfer_func);
|
|
|
|
state->ycbcr_enc = ntohl(state->header.ycbcr_enc);
|
|
|
|
state->quantization = ntohl(state->header.quantization);
|
|
|
|
cf.rlc_data = (__be16 *)p_in;
|
2019-01-24 17:51:08 +08:00
|
|
|
cf.size = ntohl(state->header.size);
|
2018-11-15 19:23:31 +08:00
|
|
|
|
2020-11-26 20:58:20 +08:00
|
|
|
hdr_width_div = (flags & V4L2_FWHT_FL_CHROMA_FULL_WIDTH) ? 1 : 2;
|
|
|
|
hdr_height_div = (flags & V4L2_FWHT_FL_CHROMA_FULL_HEIGHT) ? 1 : 2;
|
2019-01-21 19:46:14 +08:00
|
|
|
if (hdr_width_div != info->width_div ||
|
|
|
|
hdr_height_div != info->height_div)
|
|
|
|
return -EINVAL;
|
2018-08-22 15:50:56 +08:00
|
|
|
|
2019-03-07 05:13:32 +08:00
|
|
|
if (prepare_raw_frame(&dst_rf, info, p_out, dst_size))
|
2019-01-24 17:51:08 +08:00
|
|
|
return -EINVAL;
|
2019-03-07 05:13:32 +08:00
|
|
|
if (info->planes_num == 3) {
|
|
|
|
dst_chroma_stride /= 2;
|
|
|
|
ref_chroma_stride /= 2;
|
|
|
|
}
|
|
|
|
if (info->id == V4L2_PIX_FMT_NV24 ||
|
|
|
|
info->id == V4L2_PIX_FMT_NV42) {
|
|
|
|
dst_chroma_stride *= 2;
|
|
|
|
ref_chroma_stride *= 2;
|
|
|
|
}
|
2018-08-22 15:50:56 +08:00
|
|
|
|
2019-01-21 19:46:14 +08:00
|
|
|
|
2019-03-07 05:13:32 +08:00
|
|
|
ref_size = state->ref_stride * state->coded_height;
|
2019-01-21 19:46:14 +08:00
|
|
|
|
2019-03-07 05:13:32 +08:00
|
|
|
if (prepare_raw_frame(&state->ref_frame, info, state->ref_frame.buf,
|
|
|
|
ref_size))
|
|
|
|
return -EINVAL;
|
2019-01-21 19:46:14 +08:00
|
|
|
|
2019-03-07 05:13:32 +08:00
|
|
|
if (!fwht_decode_frame(&cf, flags, components_num,
|
|
|
|
state->visible_width, state->visible_height,
|
|
|
|
&state->ref_frame, state->ref_stride, ref_chroma_stride,
|
|
|
|
&dst_rf, state->stride, dst_chroma_stride))
|
2018-09-10 23:00:39 +08:00
|
|
|
return -EINVAL;
|
2018-08-22 15:50:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|