Commit 3c39a16d authored by Jernej Skrabec's avatar Jernej Skrabec Committed by Mauro Carvalho Chehab

media: cedrus: Add support for VP8 decoding

VP8 in Cedrus shares same engine as H264.

Note that it seems necessary to call bitstream parsing functions,
to parse frame header, otherwise decoded image is garbage. This is
contrary to what is driver supposed to do. However, values are not
really used, so this might be acceptable. It's possible that bitstream
parsing functions set some internal VPU state, which is later necessary
for proper decoding. Biggest suspect is "VP8 probs update" trigger.
Signed-off-by: default avatarJernej Skrabec <jernej.skrabec@siol.net>
Signed-off-by: default avatarEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Reviewed-by: default avatarEzequiel Garcia <ezequiel@collabora.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent b4b3564c
......@@ -2,4 +2,5 @@
obj-$(CONFIG_VIDEO_SUNXI_CEDRUS) += sunxi-cedrus.o
sunxi-cedrus-y = cedrus.o cedrus_video.o cedrus_hw.o cedrus_dec.o \
cedrus_mpeg2.o cedrus_h264.o cedrus_h265.o
cedrus_mpeg2.o cedrus_h264.o cedrus_h265.o \
cedrus_vp8.o
......@@ -142,6 +142,13 @@ static const struct cedrus_control cedrus_controls[] = {
.codec = CEDRUS_CODEC_H265,
.required = false,
},
{
.cfg = {
.id = V4L2_CID_MPEG_VIDEO_VP8_FRAME_HEADER,
},
.codec = CEDRUS_CODEC_VP8,
.required = true,
},
};
#define CEDRUS_CONTROLS_COUNT ARRAY_SIZE(cedrus_controls)
......@@ -393,6 +400,7 @@ static int cedrus_probe(struct platform_device *pdev)
dev->dec_ops[CEDRUS_CODEC_MPEG2] = &cedrus_dec_ops_mpeg2;
dev->dec_ops[CEDRUS_CODEC_H264] = &cedrus_dec_ops_h264;
dev->dec_ops[CEDRUS_CODEC_H265] = &cedrus_dec_ops_h265;
dev->dec_ops[CEDRUS_CODEC_VP8] = &cedrus_dec_ops_vp8;
mutex_init(&dev->dev_mutex);
......
......@@ -22,6 +22,7 @@
#include <media/videobuf2-v4l2.h>
#include <media/videobuf2-dma-contig.h>
#include <linux/iopoll.h>
#include <linux/platform_device.h>
#define CEDRUS_NAME "cedrus"
......@@ -37,6 +38,7 @@ enum cedrus_codec {
CEDRUS_CODEC_MPEG2,
CEDRUS_CODEC_H264,
CEDRUS_CODEC_H265,
CEDRUS_CODEC_VP8,
CEDRUS_CODEC_LAST,
};
......@@ -78,6 +80,10 @@ struct cedrus_h265_run {
const struct v4l2_ctrl_hevc_slice_params *slice_params;
};
struct cedrus_vp8_run {
const struct v4l2_ctrl_vp8_frame_header *frame_params;
};
struct cedrus_run {
struct vb2_v4l2_buffer *src;
struct vb2_v4l2_buffer *dst;
......@@ -86,6 +92,7 @@ struct cedrus_run {
struct cedrus_h264_run h264;
struct cedrus_mpeg2_run mpeg2;
struct cedrus_h265_run h265;
struct cedrus_vp8_run vp8;
};
};
......@@ -137,6 +144,14 @@ struct cedrus_ctx {
void *neighbor_info_buf;
dma_addr_t neighbor_info_buf_addr;
} h265;
struct {
unsigned int last_frame_p_type;
unsigned int last_filter_type;
unsigned int last_sharpness_level;
u8 *entropy_probs_buf;
dma_addr_t entropy_probs_buf_dma;
} vp8;
} codec;
};
......@@ -183,6 +198,7 @@ struct cedrus_dev {
extern struct cedrus_dec_ops cedrus_dec_ops_mpeg2;
extern struct cedrus_dec_ops cedrus_dec_ops_h264;
extern struct cedrus_dec_ops cedrus_dec_ops_h265;
extern struct cedrus_dec_ops cedrus_dec_ops_vp8;
static inline void cedrus_write(struct cedrus_dev *dev, u32 reg, u32 val)
{
......@@ -194,6 +210,14 @@ static inline u32 cedrus_read(struct cedrus_dev *dev, u32 reg)
return readl(dev->base + reg);
}
static inline u32 cedrus_wait_for(struct cedrus_dev *dev, u32 reg, u32 flag)
{
u32 value;
return readl_poll_timeout_atomic(dev->base + reg, value,
(value & flag) == 0, 10, 1000);
}
static inline dma_addr_t cedrus_buf_addr(struct vb2_buffer *buf,
struct v4l2_pix_format *pix_fmt,
unsigned int plane)
......
......@@ -70,6 +70,11 @@ void cedrus_device_run(void *priv)
V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS);
break;
case V4L2_PIX_FMT_VP8_FRAME:
run.vp8.frame_params = cedrus_find_control_data(ctx,
V4L2_CID_MPEG_VIDEO_VP8_FRAME_HEADER);
break;
default:
break;
}
......
......@@ -47,7 +47,9 @@ int cedrus_engine_enable(struct cedrus_ctx *ctx, enum cedrus_codec codec)
reg |= VE_MODE_DEC_MPEG;
break;
/* H.264 and VP8 both use the same decoding mode bit. */
case CEDRUS_CODEC_H264:
case CEDRUS_CODEC_VP8:
reg |= VE_MODE_DEC_H264;
break;
......
......@@ -546,6 +546,7 @@
#define VE_H264_SHS_QP_SCALING_MATRIX_DEFAULT BIT(24)
#define VE_H264_CTRL 0x220
#define VE_H264_CTRL_VP8 BIT(29)
#define VE_H264_CTRL_VLD_DATA_REQ_INT BIT(2)
#define VE_H264_CTRL_DECODE_ERR_INT BIT(1)
#define VE_H264_CTRL_SLICE_DECODE_INT BIT(0)
......@@ -555,7 +556,12 @@
VE_H264_CTRL_SLICE_DECODE_INT)
#define VE_H264_TRIGGER_TYPE 0x224
#define VE_H264_TRIGGER_TYPE_PROBABILITY(x) SHIFT_AND_MASK_BITS(x, 31, 24)
#define VE_H264_TRIGGER_TYPE_BIN_LENS(x) SHIFT_AND_MASK_BITS((x) - 1, 18, 16)
#define VE_H264_TRIGGER_TYPE_N_BITS(x) (((x) & 0x3f) << 8)
#define VE_H264_TRIGGER_TYPE_VP8_GET_BITS (15 << 0)
#define VE_H264_TRIGGER_TYPE_VP8_UPDATE_COEF (14 << 0)
#define VE_H264_TRIGGER_TYPE_VP8_SLICE_DECODE (10 << 0)
#define VE_H264_TRIGGER_TYPE_AVC_SLICE_DECODE (8 << 0)
#define VE_H264_TRIGGER_TYPE_INIT_SWDEC (7 << 0)
#define VE_H264_TRIGGER_TYPE_FLUSH_BITS (3 << 0)
......@@ -565,6 +571,7 @@
#define VE_H264_STATUS_DECODE_ERR_INT VE_H264_CTRL_DECODE_ERR_INT
#define VE_H264_STATUS_SLICE_DECODE_INT VE_H264_CTRL_SLICE_DECODE_INT
#define VE_H264_STATUS_VLD_BUSY BIT(8)
#define VE_H264_STATUS_VP8_UPPROB_BUSY BIT(17)
#define VE_H264_STATUS_INT_MASK VE_H264_CTRL_INT_MASK
......@@ -583,10 +590,83 @@
#define VE_H264_OUTPUT_FRAME_IDX 0x24c
#define VE_H264_EXTRA_BUFFER1 0x250
#define VE_H264_EXTRA_BUFFER2 0x254
#define VE_H264_MB_ADDR 0x260
#define VE_H264_ERROR_CASE 0x2b8
#define VE_H264_BASIC_BITS 0x2dc
#define VE_AVC_SRAM_PORT_OFFSET 0x2e0
#define VE_AVC_SRAM_PORT_DATA 0x2e4
#define VE_VP8_PPS 0x214
#define VE_VP8_PPS_PIC_TYPE_P_FRAME BIT(31)
#define VE_VP8_PPS_LAST_SHARPNESS_LEVEL(v) SHIFT_AND_MASK_BITS(v, 30, 28)
#define VE_VP8_PPS_LAST_PIC_TYPE_P_FRAME BIT(27)
#define VE_VP8_PPS_ALTREF_SIGN_BIAS BIT(26)
#define VE_VP8_PPS_GOLDEN_SIGN_BIAS BIT(25)
#define VE_VP8_PPS_RELOAD_ENTROPY_PROBS BIT(24)
#define VE_VP8_PPS_REFRESH_ENTROPY_PROBS BIT(23)
#define VE_VP8_PPS_MB_NO_COEFF_SKIP BIT(22)
#define VE_VP8_PPS_TOKEN_PARTITION(v) SHIFT_AND_MASK_BITS(v, 21, 20)
#define VE_VP8_PPS_MODE_REF_LF_DELTA_UPDATE BIT(19)
#define VE_VP8_PPS_MODE_REF_LF_DELTA_ENABLE BIT(18)
#define VE_VP8_PPS_LOOP_FILTER_LEVEL(v) SHIFT_AND_MASK_BITS(v, 17, 12)
#define VE_VP8_PPS_LOOP_FILTER_SIMPLE BIT(11)
#define VE_VP8_PPS_SHARPNESS_LEVEL(v) SHIFT_AND_MASK_BITS(v, 10, 8)
#define VE_VP8_PPS_LAST_LOOP_FILTER_SIMPLE BIT(7)
#define VE_VP8_PPS_SEGMENTATION_ENABLE BIT(6)
#define VE_VP8_PPS_MB_SEGMENT_ABS_DELTA BIT(5)
#define VE_VP8_PPS_UPDATE_MB_SEGMENTATION_MAP BIT(4)
#define VE_VP8_PPS_FULL_PIXEL BIT(3)
#define VE_VP8_PPS_BILINEAR_MC_FILTER BIT(2)
#define VE_VP8_PPS_FILTER_TYPE_SIMPLE BIT(1)
#define VE_VP8_PPS_LPF_DISABLE BIT(0)
#define VE_VP8_QP_INDEX_DELTA 0x218
#define VE_VP8_QP_INDEX_DELTA_UVAC(v) SHIFT_AND_MASK_BITS(v, 31, 27)
#define VE_VP8_QP_INDEX_DELTA_UVDC(v) SHIFT_AND_MASK_BITS(v, 26, 22)
#define VE_VP8_QP_INDEX_DELTA_Y2AC(v) SHIFT_AND_MASK_BITS(v, 21, 17)
#define VE_VP8_QP_INDEX_DELTA_Y2DC(v) SHIFT_AND_MASK_BITS(v, 16, 12)
#define VE_VP8_QP_INDEX_DELTA_Y1DC(v) SHIFT_AND_MASK_BITS(v, 11, 7)
#define VE_VP8_QP_INDEX_DELTA_BASE_QINDEX(v) SHIFT_AND_MASK_BITS(v, 6, 0)
#define VE_VP8_PART_SIZE_OFFSET 0x21c
#define VE_VP8_ENTROPY_PROBS_ADDR 0x250
#define VE_VP8_FIRST_DATA_PART_LEN 0x254
#define VE_VP8_FSIZE 0x258
#define VE_VP8_FSIZE_WIDTH(w) \
SHIFT_AND_MASK_BITS(DIV_ROUND_UP(w, 16), 15, 8)
#define VE_VP8_FSIZE_HEIGHT(h) \
SHIFT_AND_MASK_BITS(DIV_ROUND_UP(h, 16), 7, 0)
#define VE_VP8_PICSIZE 0x25c
#define VE_VP8_PICSIZE_WIDTH(w) SHIFT_AND_MASK_BITS(w, 27, 16)
#define VE_VP8_PICSIZE_HEIGHT(h) SHIFT_AND_MASK_BITS(h, 11, 0)
#define VE_VP8_REC_LUMA 0x2ac
#define VE_VP8_FWD_LUMA 0x2b0
#define VE_VP8_BWD_LUMA 0x2b4
#define VE_VP8_REC_CHROMA 0x2d0
#define VE_VP8_FWD_CHROMA 0x2d4
#define VE_VP8_BWD_CHROMA 0x2d8
#define VE_VP8_ALT_LUMA 0x2e8
#define VE_VP8_ALT_CHROMA 0x2ec
#define VE_VP8_SEGMENT_FEAT_MB_LV0 0x2f0
#define VE_VP8_SEGMENT_FEAT_MB_LV1 0x2f4
#define VE_VP8_SEGMENT3(v) SHIFT_AND_MASK_BITS(v, 31, 24)
#define VE_VP8_SEGMENT2(v) SHIFT_AND_MASK_BITS(v, 23, 16)
#define VE_VP8_SEGMENT1(v) SHIFT_AND_MASK_BITS(v, 15, 8)
#define VE_VP8_SEGMENT0(v) SHIFT_AND_MASK_BITS(v, 7, 0)
#define VE_VP8_REF_LF_DELTA 0x2f8
#define VE_VP8_MODE_LF_DELTA 0x2fc
#define VE_VP8_LF_DELTA3(v) SHIFT_AND_MASK_BITS(v, 30, 24)
#define VE_VP8_LF_DELTA2(v) SHIFT_AND_MASK_BITS(v, 22, 16)
#define VE_VP8_LF_DELTA1(v) SHIFT_AND_MASK_BITS(v, 14, 8)
#define VE_VP8_LF_DELTA0(v) SHIFT_AND_MASK_BITS(v, 6, 0)
#define VE_ISP_INPUT_SIZE 0xa00
#define VE_ISP_INPUT_STRIDE 0xa04
#define VE_ISP_CTRL 0xa08
......
......@@ -50,6 +50,10 @@ static struct cedrus_format cedrus_formats[] = {
.directions = CEDRUS_DECODE_SRC,
.capabilities = CEDRUS_CAPABILITY_H265_DEC,
},
{
.pixelformat = V4L2_PIX_FMT_VP8_FRAME,
.directions = CEDRUS_DECODE_SRC,
},
{
.pixelformat = V4L2_PIX_FMT_SUNXI_TILED_NV12,
.directions = CEDRUS_DECODE_DST,
......@@ -112,6 +116,7 @@ void cedrus_prepare_format(struct v4l2_pix_format *pix_fmt)
case V4L2_PIX_FMT_MPEG2_SLICE:
case V4L2_PIX_FMT_H264_SLICE:
case V4L2_PIX_FMT_HEVC_SLICE:
case V4L2_PIX_FMT_VP8_FRAME:
/* Zero bytes per line for encoded source. */
bytesperline = 0;
/* Choose some minimum size since this can't be 0 */
......@@ -475,6 +480,10 @@ static int cedrus_start_streaming(struct vb2_queue *vq, unsigned int count)
ctx->current_codec = CEDRUS_CODEC_H265;
break;
case V4L2_PIX_FMT_VP8_FRAME:
ctx->current_codec = CEDRUS_CODEC_VP8;
break;
default:
return -EINVAL;
}
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment