Skip to content

Commit

Permalink
media: uapi: h264: Increase size of DPB entry pic_num
Browse files Browse the repository at this point in the history
DPB entry PicNum maximum value is 2*MaxFrameNum for interlaced
content (field_pic_flag=1).

As specified, MaxFrameNum is 2^(log2_max_frame_num_minus4 + 4)
and log2_max_frame_num_minus4 is in the range of 0 to 12,
which means pic_num should be a 32-bit field.

The v4l2_h264_dpb_entry struct needs to be padded to avoid a hole,
which might be also useful to allow future uAPI extensions.

Signed-off-by: Ezequiel Garcia <[email protected]>
  • Loading branch information
ezequielgarcia authored and sigmaris committed Aug 3, 2020
1 parent b321383 commit 157e4f6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2049,7 +2049,10 @@ enum v4l2_mpeg_video_h264_hierarchical_coding_type -
* - __u16
- ``frame_num``
-
* - __u16
* - __u8
- ``reserved[2]``
- Applications and drivers must set this to zero.
* - __u32
- ``pic_num``
-
* - __s32
Expand Down
13 changes: 13 additions & 0 deletions drivers/media/v4l2-core/v4l2-ctrls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,8 @@ static void std_log(const struct v4l2_ctrl *ctrl)

#define zero_padding(s) \
memset(&(s).padding, 0, sizeof((s).padding))
#define zero_reserved(s) \
memset(&(s).reserved, 0, sizeof((s).reserved))

/*
* Compound controls validation requires setting unused fields/flags to zero
Expand All @@ -1734,6 +1736,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
{
struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
struct v4l2_ctrl_h264_decode_params *p_h264_dec_params;
struct v4l2_ctrl_hevc_sps *p_hevc_sps;
struct v4l2_ctrl_hevc_pps *p_hevc_pps;
struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
Expand Down Expand Up @@ -1794,7 +1797,17 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
case V4L2_CTRL_TYPE_H264_PPS:
case V4L2_CTRL_TYPE_H264_SCALING_MATRIX:
case V4L2_CTRL_TYPE_H264_SLICE_PARAMS:
break;

case V4L2_CTRL_TYPE_H264_DECODE_PARAMS:
p_h264_dec_params = p;

for (i = 0; i < V4L2_H264_NUM_DPB_ENTRIES; i++) {
struct v4l2_h264_dpb_entry *dpb_entry =
&p_h264_dec_params->dpb[i];

zero_reserved(*dpb_entry);
}
break;

case V4L2_CTRL_TYPE_VP8_FRAME_HEADER:
Expand Down
3 changes: 2 additions & 1 deletion include/media/h264-ctrls.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ enum v4l2_h264_dpb_reference {
struct v4l2_h264_dpb_entry {
__u64 reference_ts;
__u16 frame_num;
__u16 pic_num;
__u8 reserved[2];
__u32 pic_num;
/* Note that field is indicated by v4l2_buffer.field */
__s32 top_field_order_cnt;
__s32 bottom_field_order_cnt;
Expand Down
2 changes: 1 addition & 1 deletion include/media/v4l2-h264.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct v4l2_h264_reflist_builder {
struct {
s32 pic_order_count;
int frame_num;
u16 pic_num;
u32 pic_num;
u16 longterm : 1;
} refs[V4L2_H264_NUM_DPB_ENTRIES];
s32 cur_pic_order_count;
Expand Down

0 comments on commit 157e4f6

Please sign in to comment.