Skip to content

Commit d935856

Browse files
ezequielgarciamchehab
authored andcommitted
media: uapi: h264: Clean slice invariants syntax elements
The H.264 specification requires in section 7.4.3 "Slice header semantics", that the following values shall be the same in all slice headers: pic_parameter_set_id frame_num field_pic_flag bottom_field_flag idr_pic_id pic_order_cnt_lsb delta_pic_order_cnt_bottom delta_pic_order_cnt[ 0 ] delta_pic_order_cnt[ 1 ] sp_for_switch_flag slice_group_change_cycle These bitstream fields are part of the slice header, and therefore passed redundantly on each slice. The purpose of the redundancy is to make the codec fault-tolerant in network scenarios. This is of course not needed to be reflected in the V4L2 controls, given the bitstream has already been parsed by applications. Therefore, move the redundant fields to the per-frame decode parameters control (DECODE_PARAMS). Field 'pic_parameter_set_id' is simply removed in this case, because the PPS control must currently contain the active PPS. Syntax elements dec_ref_pic_marking() and those related to pic order count, remain invariant as well, and therefore, the fields dec_ref_pic_marking_bit_size and pic_order_cnt_bit_size are also common to all slices. Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Tested-by: Jonas Karlman <jonas@kwiboo.se> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent 2287c5e commit d935856

9 files changed

Lines changed: 90 additions & 90 deletions

File tree

‎Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst‎

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,44 +1766,12 @@ enum v4l2_mpeg_video_h264_hierarchical_coding_type -
17661766
* - __u8
17671767
- ``slice_type``
17681768
-
1769-
* - __u8
1770-
- ``pic_parameter_set_id``
1771-
-
17721769
* - __u8
17731770
- ``colour_plane_id``
17741771
-
17751772
* - __u8
17761773
- ``redundant_pic_cnt``
17771774
-
1778-
* - __u16
1779-
- ``frame_num``
1780-
-
1781-
* - __u16
1782-
- ``idr_pic_id``
1783-
-
1784-
* - __u16
1785-
- ``pic_order_cnt_lsb``
1786-
-
1787-
* - __s32
1788-
- ``delta_pic_order_cnt_bottom``
1789-
-
1790-
* - __s32
1791-
- ``delta_pic_order_cnt0``
1792-
-
1793-
* - __s32
1794-
- ``delta_pic_order_cnt1``
1795-
-
1796-
* - struct :c:type:`v4l2_h264_pred_weight_table`
1797-
- ``pred_weight_table``
1798-
-
1799-
* - __u32
1800-
- ``dec_ref_pic_marking_bit_size``
1801-
- Size in bits of the dec_ref_pic_marking() syntax element.
1802-
* - __u32
1803-
- ``pic_order_cnt_bit_size``
1804-
- Combined size in bits of the picture order count related syntax
1805-
elements: pic_order_cnt_lsb, delta_pic_order_cnt_bottom,
1806-
delta_pic_order_cnt0, and delta_pic_order_cnt1.
18071775
* - __u8
18081776
- ``cabac_init_idc``
18091777
-
@@ -1830,9 +1798,9 @@ enum v4l2_mpeg_video_h264_hierarchical_coding_type -
18301798
- ``num_ref_idx_l1_active_minus1``
18311799
- If num_ref_idx_active_override_flag is not set, this field must be
18321800
set to the value of num_ref_idx_l1_default_active_minus1.
1833-
* - __u32
1834-
- ``slice_group_change_cycle``
1835-
-
1801+
* - __u8
1802+
- ``reserved``
1803+
- Applications and drivers must set this to zero.
18361804
* - struct :c:type:`v4l2_h264_reference`
18371805
- ``ref_pic_list0[32]``
18381806
- Reference picture list after applying the per-slice modifications
@@ -1854,17 +1822,11 @@ enum v4l2_mpeg_video_h264_hierarchical_coding_type -
18541822
:stub-columns: 0
18551823
:widths: 1 1 2
18561824

1857-
* - ``V4L2_H264_SLICE_FLAG_FIELD_PIC``
1858-
- 0x00000001
1859-
-
1860-
* - ``V4L2_H264_SLICE_FLAG_BOTTOM_FIELD``
1861-
- 0x00000002
1862-
-
18631825
* - ``V4L2_H264_SLICE_FLAG_DIRECT_SPATIAL_MV_PRED``
1864-
- 0x00000004
1826+
- 0x00000001
18651827
-
18661828
* - ``V4L2_H264_SLICE_FLAG_SP_FOR_SWITCH``
1867-
- 0x00000008
1829+
- 0x00000002
18681830
-
18691831

18701832
``V4L2_CID_MPEG_VIDEO_H264_PRED_WEIGHTS (struct)``
@@ -1990,12 +1952,44 @@ enum v4l2_mpeg_video_h264_hierarchical_coding_type -
19901952
* - __u16
19911953
- ``nal_ref_idc``
19921954
- NAL reference ID value coming from the NAL Unit header
1955+
* - __u16
1956+
- ``frame_num``
1957+
-
19931958
* - __s32
19941959
- ``top_field_order_cnt``
19951960
- Picture Order Count for the coded top field
19961961
* - __s32
19971962
- ``bottom_field_order_cnt``
19981963
- Picture Order Count for the coded bottom field
1964+
* - __u16
1965+
- ``idr_pic_id``
1966+
-
1967+
* - __u16
1968+
- ``pic_order_cnt_lsb``
1969+
-
1970+
* - __s32
1971+
- ``delta_pic_order_cnt_bottom``
1972+
-
1973+
* - __s32
1974+
- ``delta_pic_order_cnt0``
1975+
-
1976+
* - __s32
1977+
- ``delta_pic_order_cnt1``
1978+
-
1979+
* - __u32
1980+
- ``dec_ref_pic_marking_bit_size``
1981+
- Size in bits of the dec_ref_pic_marking() syntax element.
1982+
* - __u32
1983+
- ``pic_order_cnt_bit_size``
1984+
- Combined size in bits of the picture order count related syntax
1985+
elements: pic_order_cnt_lsb, delta_pic_order_cnt_bottom,
1986+
delta_pic_order_cnt0, and delta_pic_order_cnt1.
1987+
* - __u32
1988+
- ``slice_group_change_cycle``
1989+
-
1990+
* - __u32
1991+
- ``reserved``
1992+
- Applications and drivers must set this to zero.
19991993
* - __u32
20001994
- ``flags``
20011995
- See :ref:`Decode Parameters Flags <h264_decode_params_flags>`
@@ -2014,6 +2008,12 @@ enum v4l2_mpeg_video_h264_hierarchical_coding_type -
20142008
* - ``V4L2_H264_DECODE_PARAM_FLAG_IDR_PIC``
20152009
- 0x00000001
20162010
- That picture is an IDR picture
2011+
* - ``V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC``
2012+
- 0x00000002
2013+
-
2014+
* - ``V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD``
2015+
- 0x00000004
2016+
-
20172017

20182018
.. c:type:: v4l2_h264_dpb_entry
20192019

‎drivers/media/v4l2-core/v4l2-ctrls.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
17371737
{
17381738
struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
17391739
struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
1740+
struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;
17401741
struct v4l2_ctrl_h264_decode_params *p_h264_dec_params;
17411742
struct v4l2_ctrl_hevc_sps *p_hevc_sps;
17421743
struct v4l2_ctrl_hevc_pps *p_hevc_pps;
@@ -1798,7 +1799,12 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
17981799
case V4L2_CTRL_TYPE_H264_PPS:
17991800
case V4L2_CTRL_TYPE_H264_SCALING_MATRIX:
18001801
case V4L2_CTRL_TYPE_H264_PRED_WEIGHTS:
1802+
break;
1803+
18011804
case V4L2_CTRL_TYPE_H264_SLICE_PARAMS:
1805+
p_h264_slice_params = p;
1806+
1807+
zero_reserved(*p_h264_slice_params);
18021808
break;
18031809

18041810
case V4L2_CTRL_TYPE_H264_DECODE_PARAMS:
@@ -1810,6 +1816,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
18101816

18111817
zero_reserved(*dpb_entry);
18121818
}
1819+
zero_reserved(*p_h264_dec_params);
18131820
break;
18141821

18151822
case V4L2_CTRL_TYPE_VP8_FRAME_HEADER:

‎drivers/media/v4l2-core/v4l2-h264.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,26 @@
1818
*
1919
* @b: the builder context to initialize
2020
* @dec_params: decode parameters control
21-
* @slice_params: first slice parameters control
2221
* @sps: SPS control
2322
* @dpb: DPB to use when creating the reference list
2423
*/
2524
void
2625
v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
2726
const struct v4l2_ctrl_h264_decode_params *dec_params,
28-
const struct v4l2_ctrl_h264_slice_params *slice_params,
2927
const struct v4l2_ctrl_h264_sps *sps,
3028
const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES])
3129
{
3230
int cur_frame_num, max_frame_num;
3331
unsigned int i;
3432

3533
max_frame_num = 1 << (sps->log2_max_frame_num_minus4 + 4);
36-
cur_frame_num = slice_params->frame_num;
34+
cur_frame_num = dec_params->frame_num;
3735

3836
memset(b, 0, sizeof(*b));
39-
if (!(slice_params->flags & V4L2_H264_SLICE_FLAG_FIELD_PIC))
37+
if (!(dec_params->flags & V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC))
4038
b->cur_pic_order_count = min(dec_params->bottom_field_order_cnt,
4139
dec_params->top_field_order_cnt);
42-
else if (slice_params->flags & V4L2_H264_SLICE_FLAG_BOTTOM_FIELD)
40+
else if (dec_params->flags & V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD)
4341
b->cur_pic_order_count = dec_params->bottom_field_order_cnt;
4442
else
4543
b->cur_pic_order_count = dec_params->top_field_order_cnt;

‎drivers/staging/media/hantro/hantro_g1_h264_dec.c‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ static void set_params(struct hantro_ctx *ctx)
2323
{
2424
const struct hantro_h264_dec_ctrls *ctrls = &ctx->h264_dec.ctrls;
2525
const struct v4l2_ctrl_h264_decode_params *dec_param = ctrls->decode;
26-
const struct v4l2_ctrl_h264_slice_params *slices = ctrls->slices;
2726
const struct v4l2_ctrl_h264_sps *sps = ctrls->sps;
2827
const struct v4l2_ctrl_h264_pps *pps = ctrls->pps;
2928
struct vb2_v4l2_buffer *src_buf = hantro_get_src_buf(ctx);
@@ -42,11 +41,11 @@ static void set_params(struct hantro_ctx *ctx)
4241

4342
if (!(sps->flags & V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY) &&
4443
(sps->flags & V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD ||
45-
slices[0].flags & V4L2_H264_SLICE_FLAG_FIELD_PIC))
44+
dec_param->flags & V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC))
4645
reg |= G1_REG_DEC_CTRL0_PIC_INTERLACE_E;
47-
if (slices[0].flags & V4L2_H264_SLICE_FLAG_FIELD_PIC)
46+
if (dec_param->flags & V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC)
4847
reg |= G1_REG_DEC_CTRL0_PIC_FIELDMODE_E;
49-
if (!(slices[0].flags & V4L2_H264_SLICE_FLAG_BOTTOM_FIELD))
48+
if (!(dec_param->flags & V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD))
5049
reg |= G1_REG_DEC_CTRL0_PIC_TOPFIELD_E;
5150
vdpu_write_relaxed(vpu, reg, G1_REG_DEC_CTRL0);
5251

@@ -75,7 +74,7 @@ static void set_params(struct hantro_ctx *ctx)
7574

7675
/* Decoder control register 4. */
7776
reg = G1_REG_DEC_CTRL4_FRAMENUM_LEN(sps->log2_max_frame_num_minus4 + 4) |
78-
G1_REG_DEC_CTRL4_FRAMENUM(slices[0].frame_num) |
77+
G1_REG_DEC_CTRL4_FRAMENUM(dec_param->frame_num) |
7978
G1_REG_DEC_CTRL4_WEIGHT_BIPR_IDC(pps->weighted_bipred_idc);
8079
if (pps->flags & V4L2_H264_PPS_FLAG_ENTROPY_CODING_MODE)
8180
reg |= G1_REG_DEC_CTRL4_CABAC_E;
@@ -88,8 +87,8 @@ static void set_params(struct hantro_ctx *ctx)
8887
vdpu_write_relaxed(vpu, reg, G1_REG_DEC_CTRL4);
8988

9089
/* Decoder control register 5. */
91-
reg = G1_REG_DEC_CTRL5_REFPIC_MK_LEN(slices[0].dec_ref_pic_marking_bit_size) |
92-
G1_REG_DEC_CTRL5_IDR_PIC_ID(slices[0].idr_pic_id);
90+
reg = G1_REG_DEC_CTRL5_REFPIC_MK_LEN(dec_param->dec_ref_pic_marking_bit_size) |
91+
G1_REG_DEC_CTRL5_IDR_PIC_ID(dec_param->idr_pic_id);
9392
if (pps->flags & V4L2_H264_PPS_FLAG_CONSTRAINED_INTRA_PRED)
9493
reg |= G1_REG_DEC_CTRL5_CONST_INTRA_E;
9594
if (pps->flags & V4L2_H264_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT)
@@ -103,10 +102,10 @@ static void set_params(struct hantro_ctx *ctx)
103102
vdpu_write_relaxed(vpu, reg, G1_REG_DEC_CTRL5);
104103

105104
/* Decoder control register 6. */
106-
reg = G1_REG_DEC_CTRL6_PPS_ID(slices[0].pic_parameter_set_id) |
105+
reg = G1_REG_DEC_CTRL6_PPS_ID(pps->pic_parameter_set_id) |
107106
G1_REG_DEC_CTRL6_REFIDX0_ACTIVE(pps->num_ref_idx_l0_default_active_minus1 + 1) |
108107
G1_REG_DEC_CTRL6_REFIDX1_ACTIVE(pps->num_ref_idx_l1_default_active_minus1 + 1) |
109-
G1_REG_DEC_CTRL6_POC_LENGTH(slices[0].pic_order_cnt_bit_size);
108+
G1_REG_DEC_CTRL6_POC_LENGTH(dec_param->pic_order_cnt_bit_size);
110109
vdpu_write_relaxed(vpu, reg, G1_REG_DEC_CTRL6);
111110

112111
/* Error concealment register. */
@@ -246,7 +245,7 @@ static void set_buffers(struct hantro_ctx *ctx)
246245
/* Destination (decoded frame) buffer. */
247246
dst_dma = hantro_get_dec_buf_addr(ctx, &dst_buf->vb2_buf);
248247
/* Adjust dma addr to start at second line for bottom field */
249-
if (ctrls->slices[0].flags & V4L2_H264_SLICE_FLAG_BOTTOM_FIELD)
248+
if (ctrls->decode->flags & V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD)
250249
offset = ALIGN(ctx->src_fmt.width, MB_DIM);
251250
vdpu_write_relaxed(vpu, dst_dma + offset, G1_REG_ADDR_DST);
252251

@@ -265,7 +264,7 @@ static void set_buffers(struct hantro_ctx *ctx)
265264
* DMV buffer is split in two for field encoded frames,
266265
* adjust offset for bottom field
267266
*/
268-
if (ctrls->slices[0].flags & V4L2_H264_SLICE_FLAG_BOTTOM_FIELD)
267+
if (ctrls->decode->flags & V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD)
269268
offset += 32 * MB_WIDTH(ctx->src_fmt.width) *
270269
MB_HEIGHT(ctx->src_fmt.height);
271270
vdpu_write_relaxed(vpu, dst_dma + offset, G1_REG_ADDR_DIR_MV);

‎drivers/staging/media/hantro/hantro_h264.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ int hantro_h264_dec_prepare_run(struct hantro_ctx *ctx)
372372

373373
/* Build the P/B{0,1} ref lists. */
374374
v4l2_h264_init_reflist_builder(&reflist_builder, ctrls->decode,
375-
&ctrls->slices[0], ctrls->sps,
376-
ctx->h264_dec.dpb);
375+
ctrls->sps, ctx->h264_dec.dpb);
377376
v4l2_h264_build_p_ref_list(&reflist_builder, h264_ctx->reflists.p);
378377
v4l2_h264_build_b_ref_lists(&reflist_builder, h264_ctx->reflists.b0,
379378
h264_ctx->reflists.b1);

‎drivers/staging/media/rkvdec/rkvdec-h264.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,6 @@ static void assemble_hw_rps(struct rkvdec_ctx *ctx,
730730
struct rkvdec_h264_run *run)
731731
{
732732
const struct v4l2_ctrl_h264_decode_params *dec_params = run->decode_params;
733-
const struct v4l2_ctrl_h264_slice_params *sl_params = &run->slices_params[0];
734733
const struct v4l2_h264_dpb_entry *dpb = dec_params->dpb;
735734
struct rkvdec_h264_ctx *h264_ctx = ctx->priv;
736735
const struct v4l2_ctrl_h264_sps *sps = run->sps;
@@ -754,7 +753,7 @@ static void assemble_hw_rps(struct rkvdec_ctx *ctx,
754753
continue;
755754

756755
if (dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM ||
757-
dpb[i].frame_num < sl_params->frame_num) {
756+
dpb[i].frame_num < dec_params->frame_num) {
758757
p[i] = dpb[i].frame_num;
759758
continue;
760759
}
@@ -1094,8 +1093,7 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx)
10941093

10951094
/* Build the P/B{0,1} ref lists. */
10961095
v4l2_h264_init_reflist_builder(&reflist_builder, run.decode_params,
1097-
&run.slices_params[0], run.sps,
1098-
run.decode_params->dpb);
1096+
run.sps, run.decode_params->dpb);
10991097
h264_ctx->reflists.num_valid = reflist_builder.num_valid;
11001098
v4l2_h264_build_p_ref_list(&reflist_builder, h264_ctx->reflists.p);
11011099
v4l2_h264_build_b_ref_lists(&reflist_builder, h264_ctx->reflists.b0,

‎drivers/staging/media/sunxi/cedrus/cedrus_h264.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ static void cedrus_write_frame_list(struct cedrus_ctx *ctx,
9595
{
9696
struct cedrus_h264_sram_ref_pic pic_list[CEDRUS_H264_FRAME_NUM];
9797
const struct v4l2_ctrl_h264_decode_params *decode = run->h264.decode_params;
98-
const struct v4l2_ctrl_h264_slice_params *slice = run->h264.slice_params;
9998
const struct v4l2_ctrl_h264_sps *sps = run->h264.sps;
10099
struct vb2_queue *cap_q;
101100
struct cedrus_buffer *output_buf;
@@ -144,7 +143,7 @@ static void cedrus_write_frame_list(struct cedrus_ctx *ctx,
144143
output_buf = vb2_to_cedrus_buffer(&run->dst->vb2_buf);
145144
output_buf->codec.h264.position = position;
146145

147-
if (slice->flags & V4L2_H264_SLICE_FLAG_FIELD_PIC)
146+
if (decode->flags & V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC)
148147
output_buf->codec.h264.pic_type = CEDRUS_H264_PIC_TYPE_FIELD;
149148
else if (sps->flags & V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD)
150149
output_buf->codec.h264.pic_type = CEDRUS_H264_PIC_TYPE_MBAFF;
@@ -407,7 +406,7 @@ static void cedrus_set_params(struct cedrus_ctx *ctx,
407406
reg |= VE_H264_SPS_DIRECT_8X8_INFERENCE;
408407
cedrus_write(dev, VE_H264_SPS, reg);
409408

410-
mbaff_pic = !(slice->flags & V4L2_H264_SLICE_FLAG_FIELD_PIC) &&
409+
mbaff_pic = !(decode->flags & V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC) &&
411410
(sps->flags & V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD);
412411
pic_width_in_mbs = sps->pic_width_in_mbs_minus1 + 1;
413412

@@ -421,9 +420,9 @@ static void cedrus_set_params(struct cedrus_ctx *ctx,
421420
reg |= slice->cabac_init_idc & 0x3;
422421
if (ctx->fh.m2m_ctx->new_frame)
423422
reg |= VE_H264_SHS_FIRST_SLICE_IN_PIC;
424-
if (slice->flags & V4L2_H264_SLICE_FLAG_FIELD_PIC)
423+
if (decode->flags & V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC)
425424
reg |= VE_H264_SHS_FIELD_PIC;
426-
if (slice->flags & V4L2_H264_SLICE_FLAG_BOTTOM_FIELD)
425+
if (decode->flags & V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD)
427426
reg |= VE_H264_SHS_BOTTOM_FIELD;
428427
if (slice->flags & V4L2_H264_SLICE_FLAG_DIRECT_SPATIAL_MV_PRED)
429428
reg |= VE_H264_SHS_DIRECT_SPATIAL_MV_PRED;

0 commit comments

Comments
 (0)