Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: cedrus: identify buffers by timestamp

Use the new v4l2_m2m_buf_copy_data helper function and use
timestamps to refer to reference frames instead of using
buffer indices.

Also remove the padding fields in the structs, that's a bad
idea. Just use the right types to keep everything aligned.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Tested-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
d998e03e 245ede42

+24 -33
-9
drivers/media/v4l2-core/v4l2-ctrls.c
··· 1661 1661 return -EINVAL; 1662 1662 } 1663 1663 1664 - if (p_mpeg2_slice_params->backward_ref_index >= VIDEO_MAX_FRAME || 1665 - p_mpeg2_slice_params->forward_ref_index >= VIDEO_MAX_FRAME) 1666 - return -EINVAL; 1667 - 1668 - if (p_mpeg2_slice_params->pad || 1669 - p_mpeg2_slice_params->picture.pad || 1670 - p_mpeg2_slice_params->sequence.pad) 1671 - return -EINVAL; 1672 - 1673 1664 return 0; 1674 1665 1675 1666 case V4L2_CTRL_TYPE_MPEG2_QUANTIZATION:
+6 -3
drivers/staging/media/sunxi/cedrus/cedrus.h
··· 140 140 } 141 141 142 142 static inline dma_addr_t cedrus_dst_buf_addr(struct cedrus_ctx *ctx, 143 - unsigned int index, 144 - unsigned int plane) 143 + int index, unsigned int plane) 145 144 { 146 - struct vb2_buffer *buf = ctx->dst_bufs[index]; 145 + struct vb2_buffer *buf; 147 146 147 + if (index < 0) 148 + return 0; 149 + 150 + buf = ctx->dst_bufs[index]; 148 151 return buf ? cedrus_buf_addr(buf, &ctx->dst_fmt, plane) : 0; 149 152 } 150 153
+2
drivers/staging/media/sunxi/cedrus/cedrus_dec.c
··· 50 50 break; 51 51 } 52 52 53 + v4l2_m2m_buf_copy_data(run.src, run.dst, true); 54 + 53 55 dev->dec_ops[ctx->current_codec]->setup(ctx, &run); 54 56 55 57 /* Complete request(s) controls if needed. */
+11 -12
drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c
··· 82 82 dma_addr_t fwd_luma_addr, fwd_chroma_addr; 83 83 dma_addr_t bwd_luma_addr, bwd_chroma_addr; 84 84 struct cedrus_dev *dev = ctx->dev; 85 + struct vb2_queue *cap_q = &ctx->fh.m2m_ctx->cap_q_ctx.q; 85 86 const u8 *matrix; 87 + int forward_idx; 88 + int backward_idx; 86 89 unsigned int i; 87 90 u32 reg; 88 91 ··· 159 156 cedrus_write(dev, VE_DEC_MPEG_PICBOUNDSIZE, reg); 160 157 161 158 /* Forward and backward prediction reference buffers. */ 159 + forward_idx = vb2_find_timestamp(cap_q, 160 + slice_params->forward_ref_ts, 0); 162 161 163 - fwd_luma_addr = cedrus_dst_buf_addr(ctx, 164 - slice_params->forward_ref_index, 165 - 0); 166 - fwd_chroma_addr = cedrus_dst_buf_addr(ctx, 167 - slice_params->forward_ref_index, 168 - 1); 162 + fwd_luma_addr = cedrus_dst_buf_addr(ctx, forward_idx, 0); 163 + fwd_chroma_addr = cedrus_dst_buf_addr(ctx, forward_idx, 1); 169 164 170 165 cedrus_write(dev, VE_DEC_MPEG_FWD_REF_LUMA_ADDR, fwd_luma_addr); 171 166 cedrus_write(dev, VE_DEC_MPEG_FWD_REF_CHROMA_ADDR, fwd_chroma_addr); 172 167 173 - bwd_luma_addr = cedrus_dst_buf_addr(ctx, 174 - slice_params->backward_ref_index, 175 - 0); 176 - bwd_chroma_addr = cedrus_dst_buf_addr(ctx, 177 - slice_params->backward_ref_index, 178 - 1); 168 + backward_idx = vb2_find_timestamp(cap_q, 169 + slice_params->backward_ref_ts, 0); 170 + bwd_luma_addr = cedrus_dst_buf_addr(ctx, backward_idx, 0); 171 + bwd_chroma_addr = cedrus_dst_buf_addr(ctx, backward_idx, 1); 179 172 180 173 cedrus_write(dev, VE_DEC_MPEG_BWD_REF_LUMA_ADDR, bwd_luma_addr); 181 174 cedrus_write(dev, VE_DEC_MPEG_BWD_REF_CHROMA_ADDR, bwd_chroma_addr);
+5 -9
include/media/mpeg2-ctrls.h
··· 30 30 __u32 vbv_buffer_size; 31 31 32 32 /* ISO/IEC 13818-2, ITU-T Rec. H.262: Sequence extension */ 33 - __u8 profile_and_level_indication; 33 + __u16 profile_and_level_indication; 34 34 __u8 progressive_sequence; 35 35 __u8 chroma_format; 36 - __u8 pad; 37 36 }; 38 37 39 38 struct v4l2_mpeg2_picture { ··· 50 51 __u8 intra_vlc_format; 51 52 __u8 alternate_scan; 52 53 __u8 repeat_first_field; 53 - __u8 progressive_frame; 54 - __u8 pad; 54 + __u16 progressive_frame; 55 55 }; 56 56 57 57 struct v4l2_ctrl_mpeg2_slice_params { 58 58 __u32 bit_size; 59 59 __u32 data_bit_offset; 60 + __u64 backward_ref_ts; 61 + __u64 forward_ref_ts; 60 62 61 63 struct v4l2_mpeg2_sequence sequence; 62 64 struct v4l2_mpeg2_picture picture; 63 65 64 66 /* ISO/IEC 13818-2, ITU-T Rec. H.262: Slice */ 65 - __u8 quantiser_scale_code; 66 - 67 - __u8 backward_ref_index; 68 - __u8 forward_ref_index; 69 - __u8 pad; 67 + __u32 quantiser_scale_code; 70 68 }; 71 69 72 70 struct v4l2_ctrl_mpeg2_quantization {