1*624922a2SBoris Brezillon /* SPDX-License-Identifier: GPL-2.0-or-later */ 2*624922a2SBoris Brezillon /* 3*624922a2SBoris Brezillon * Helper functions for H264 codecs. 4*624922a2SBoris Brezillon * 5*624922a2SBoris Brezillon * Copyright (c) 2019 Collabora, Ltd. 6*624922a2SBoris Brezillon * 7*624922a2SBoris Brezillon * Author: Boris Brezillon <boris.brezillon@collabora.com> 8*624922a2SBoris Brezillon */ 9*624922a2SBoris Brezillon 10*624922a2SBoris Brezillon #ifndef _MEDIA_V4L2_H264_H 11*624922a2SBoris Brezillon #define _MEDIA_V4L2_H264_H 12*624922a2SBoris Brezillon 13*624922a2SBoris Brezillon #include <media/h264-ctrls.h> 14*624922a2SBoris Brezillon 15*624922a2SBoris Brezillon /** 16*624922a2SBoris Brezillon * struct v4l2_h264_reflist_builder - Reference list builder object 17*624922a2SBoris Brezillon * 18*624922a2SBoris Brezillon * @refs.pic_order_count: reference picture order count 19*624922a2SBoris Brezillon * @refs.frame_num: reference frame number 20*624922a2SBoris Brezillon * @refs.pic_num: reference picture number 21*624922a2SBoris Brezillon * @refs.longterm: set to true for a long term reference 22*624922a2SBoris Brezillon * @refs: array of references 23*624922a2SBoris Brezillon * @cur_pic_order_count: picture order count of the frame being decoded 24*624922a2SBoris Brezillon * @unordered_reflist: unordered list of references. Will be used to generate 25*624922a2SBoris Brezillon * ordered P/B0/B1 lists 26*624922a2SBoris Brezillon * @num_valid: number of valid references in the refs array 27*624922a2SBoris Brezillon * 28*624922a2SBoris Brezillon * This object stores the context of the P/B0/B1 reference list builder. 29*624922a2SBoris Brezillon * This procedure is described in section '8.2.4 Decoding process for reference 30*624922a2SBoris Brezillon * picture lists construction' of the H264 spec. 31*624922a2SBoris Brezillon */ 32*624922a2SBoris Brezillon struct v4l2_h264_reflist_builder { 33*624922a2SBoris Brezillon struct { 34*624922a2SBoris Brezillon s32 pic_order_count; 35*624922a2SBoris Brezillon int frame_num; 36*624922a2SBoris Brezillon u16 pic_num; 37*624922a2SBoris Brezillon u16 longterm : 1; 38*624922a2SBoris Brezillon } refs[V4L2_H264_NUM_DPB_ENTRIES]; 39*624922a2SBoris Brezillon s32 cur_pic_order_count; 40*624922a2SBoris Brezillon u8 unordered_reflist[V4L2_H264_NUM_DPB_ENTRIES]; 41*624922a2SBoris Brezillon u8 num_valid; 42*624922a2SBoris Brezillon }; 43*624922a2SBoris Brezillon 44*624922a2SBoris Brezillon void 45*624922a2SBoris Brezillon v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b, 46*624922a2SBoris Brezillon const struct v4l2_ctrl_h264_decode_params *dec_params, 47*624922a2SBoris Brezillon const struct v4l2_ctrl_h264_slice_params *slice_params, 48*624922a2SBoris Brezillon const struct v4l2_ctrl_h264_sps *sps, 49*624922a2SBoris Brezillon const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES]); 50*624922a2SBoris Brezillon 51*624922a2SBoris Brezillon /** 52*624922a2SBoris Brezillon * v4l2_h264_build_b_ref_lists() - Build the B0/B1 reference lists 53*624922a2SBoris Brezillon * 54*624922a2SBoris Brezillon * @builder: reference list builder context 55*624922a2SBoris Brezillon * @b0_reflist: 16-bytes array used to store the B0 reference list. Each entry 56*624922a2SBoris Brezillon * is an index in the DPB 57*624922a2SBoris Brezillon * @b1_reflist: 16-bytes array used to store the B1 reference list. Each entry 58*624922a2SBoris Brezillon * is an index in the DPB 59*624922a2SBoris Brezillon * 60*624922a2SBoris Brezillon * This functions builds the B0/B1 reference lists. This procedure is described 61*624922a2SBoris Brezillon * in section '8.2.4 Decoding process for reference picture lists construction' 62*624922a2SBoris Brezillon * of the H264 spec. This function can be used by H264 decoder drivers that 63*624922a2SBoris Brezillon * need to pass B0/B1 reference lists to the hardware. 64*624922a2SBoris Brezillon */ 65*624922a2SBoris Brezillon void 66*624922a2SBoris Brezillon v4l2_h264_build_b_ref_lists(const struct v4l2_h264_reflist_builder *builder, 67*624922a2SBoris Brezillon u8 *b0_reflist, u8 *b1_reflist); 68*624922a2SBoris Brezillon 69*624922a2SBoris Brezillon /** 70*624922a2SBoris Brezillon * v4l2_h264_build_b_ref_lists() - Build the P reference list 71*624922a2SBoris Brezillon * 72*624922a2SBoris Brezillon * @builder: reference list builder context 73*624922a2SBoris Brezillon * @p_reflist: 16-bytes array used to store the P reference list. Each entry 74*624922a2SBoris Brezillon * is an index in the DPB 75*624922a2SBoris Brezillon * 76*624922a2SBoris Brezillon * This functions builds the P reference lists. This procedure is describe in 77*624922a2SBoris Brezillon * section '8.2.4 Decoding process for reference picture lists construction' 78*624922a2SBoris Brezillon * of the H264 spec. This function can be used by H264 decoder drivers that 79*624922a2SBoris Brezillon * need to pass a P reference list to the hardware. 80*624922a2SBoris Brezillon */ 81*624922a2SBoris Brezillon void 82*624922a2SBoris Brezillon v4l2_h264_build_p_ref_list(const struct v4l2_h264_reflist_builder *builder, 83*624922a2SBoris Brezillon u8 *reflist); 84*624922a2SBoris Brezillon 85*624922a2SBoris Brezillon #endif /* _MEDIA_V4L2_H264_H */ 86