diff --git a/packages/multimedia/ffmpeg/patches/v4l2-request/ffmpeg-001-v4l2-request.patch b/packages/multimedia/ffmpeg/patches/v4l2-request/ffmpeg-001-v4l2-request.patch index 6bd75c0343..a09da010de 100644 --- a/packages/multimedia/ffmpeg/patches/v4l2-request/ffmpeg-001-v4l2-request.patch +++ b/packages/multimedia/ffmpeg/patches/v4l2-request/ffmpeg-001-v4l2-request.patch @@ -1,7 +1,7 @@ -From 2c839cfe011862b06bf986a7999caf21c4d54d6e Mon Sep 17 00:00:00 2001 +From fd7c38d6a87d92faaf3b7f18df5cb19918aca3a7 Mon Sep 17 00:00:00 2001 From: Jonas Karlman Date: Mon, 3 Dec 2018 23:48:04 +0100 -Subject: [PATCH 01/19] avutil: add av_buffer_pool_flush() +Subject: [PATCH 01/18] avutil: add av_buffer_pool_flush() Used by V4L2 request API hwaccel @@ -52,10 +52,10 @@ index c0f3f6cc9abe..998beec9ac5b 100644 * Mark the pool as being available for freeing. It will actually be freed only * once all the allocated buffers associated with the pool are released. Thus it -From adcd1a0731d769828bb88e4637452a8ad84a30d3 Mon Sep 17 00:00:00 2001 +From 73677b0d323aca461e88c9ee287afb4d6744a0bc Mon Sep 17 00:00:00 2001 From: Jonas Karlman Date: Sat, 15 Dec 2018 22:32:16 +0100 -Subject: [PATCH 02/19] Add common V4L2 request API code +Subject: [PATCH 02/18] Add common V4L2 request API code Signed-off-by: Jonas Karlman --- @@ -1239,10 +1239,10 @@ index 000000000000..58d2aa70af80 + +#endif /* AVCODEC_V4L2_REQUEST_H */ -From bfb39057e0ba9a8b1e81c799d09730a70af1fa28 Mon Sep 17 00:00:00 2001 +From 4b5bc3f75955694bfe7af15a323f0c902e53acf1 Mon Sep 17 00:00:00 2001 From: Ezequiel Garcia Date: Wed, 20 Feb 2019 11:18:00 -0300 -Subject: [PATCH 03/19] h264dec: add idr_pic_id to slice context +Subject: [PATCH 03/18] h264dec: add idr_pic_id to slice context Used by V4L2 request API h264 hwaccel @@ -1279,10 +1279,10 @@ index a419615124b2..316dc6a2c890 100644 /** -From 34c532ae4ff98c49ae4517699acecd491661a4f0 Mon Sep 17 00:00:00 2001 +From 89a05a843c5ecef72b37e5381d2169027e3450b0 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Wed, 22 May 2019 14:44:22 +0200 -Subject: [PATCH 04/19] h264dec: add ref_pic_marking and pic_order_cnt bit_size +Subject: [PATCH 04/18] h264dec: add ref_pic_marking and pic_order_cnt bit_size to slice context Used by V4L2 request API h264 hwaccel @@ -1356,10 +1356,10 @@ index 316dc6a2c890..f2cabac468d0 100644 /** -From 67d7c840cdd1b687272e5c482af6688916843a52 Mon Sep 17 00:00:00 2001 +From bd9786a78eb4c44325caef40305f86b2856ecad4 Mon Sep 17 00:00:00 2001 From: Jernej Skrabec Date: Sat, 15 Dec 2018 22:32:16 +0100 -Subject: [PATCH 05/19] Add V4L2 request API h264 hwaccel +Subject: [PATCH 05/18] Add V4L2 request API h264 hwaccel Signed-off-by: Jernej Skrabec Signed-off-by: Jonas Karlman @@ -1917,10 +1917,10 @@ index 000000000000..88da8f0a2db0 + .caps_internal = HWACCEL_CAP_ASYNC_SAFE, +}; -From d23614d6e368e796019db46b5330c76323bcc49e Mon Sep 17 00:00:00 2001 +From e36de603c7c9daa8e1a833539c7311438eb1dc0c Mon Sep 17 00:00:00 2001 From: Jonas Karlman Date: Sat, 15 Dec 2018 22:32:16 +0100 -Subject: [PATCH 06/19] Add V4L2 request API mpeg2 hwaccel +Subject: [PATCH 06/18] Add V4L2 request API mpeg2 hwaccel Signed-off-by: Jonas Karlman --- @@ -1928,8 +1928,8 @@ Signed-off-by: Jonas Karlman libavcodec/Makefile | 1 + libavcodec/hwaccels.h | 1 + libavcodec/mpeg12dec.c | 6 ++ - libavcodec/v4l2_request_mpeg2.c | 154 ++++++++++++++++++++++++++++++++ - 5 files changed, 165 insertions(+) + libavcodec/v4l2_request_mpeg2.c | 159 ++++++++++++++++++++++++++++++++ + 5 files changed, 170 insertions(+) create mode 100644 libavcodec/v4l2_request_mpeg2.c diff --git a/configure b/configure @@ -2003,10 +2003,10 @@ index 99e56532a59e..15aaf97a34c7 100644 }, diff --git a/libavcodec/v4l2_request_mpeg2.c b/libavcodec/v4l2_request_mpeg2.c new file mode 100644 -index 000000000000..88d86cc4c23f +index 000000000000..84d53209c79d --- /dev/null +++ b/libavcodec/v4l2_request_mpeg2.c -@@ -0,0 +1,154 @@ +@@ -0,0 +1,159 @@ +/* + * This file is part of FFmpeg. + * @@ -2030,8 +2030,9 @@ index 000000000000..88d86cc4c23f +#include "v4l2_request.h" + +typedef struct V4L2RequestControlsMPEG2 { -+ struct v4l2_ctrl_mpeg2_slice_params slice_params; -+ struct v4l2_ctrl_mpeg2_quantization quantization; ++ struct v4l2_ctrl_mpeg2_sequence sequence; ++ struct v4l2_ctrl_mpeg2_picture picture; ++ struct v4l2_ctrl_mpeg2_quantisation quantisation; +} V4L2RequestControlsMPEG2; + +static int v4l2_request_mpeg2_start_frame(AVCodecContext *avctx, @@ -2042,69 +2043,71 @@ index 000000000000..88d86cc4c23f + V4L2RequestControlsMPEG2 *controls = s->current_picture_ptr->hwaccel_picture_private; + V4L2RequestDescriptor *req = (V4L2RequestDescriptor*)s->current_picture_ptr->f->data[0]; + -+ controls->slice_params = (struct v4l2_ctrl_mpeg2_slice_params) { -+ .bit_size = 0, -+ .data_bit_offset = 0, ++ controls->sequence = (struct v4l2_ctrl_mpeg2_sequence) { ++ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Sequence header */ ++ .horizontal_size = s->width, ++ .vertical_size = s->height, ++ .vbv_buffer_size = req->output.size, + -+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Slice */ -+ .quantiser_scale_code = s->qscale >> 1, -+ -+ .sequence = { -+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Sequence header */ -+ .horizontal_size = s->width, -+ .vertical_size = s->height, -+ .vbv_buffer_size = req->output.size, -+ -+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Sequence extension */ -+ .profile_and_level_indication = 0, -+ .progressive_sequence = s->progressive_sequence, -+ .chroma_format = s->chroma_format, -+ }, -+ -+ .picture = { -+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Picture header */ -+ .picture_coding_type = s->pict_type, -+ -+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Picture coding extension */ -+ .f_code[0][0] = s->mpeg_f_code[0][0], -+ .f_code[0][1] = s->mpeg_f_code[0][1], -+ .f_code[1][0] = s->mpeg_f_code[1][0], -+ .f_code[1][1] = s->mpeg_f_code[1][1], -+ .intra_dc_precision = s->intra_dc_precision, -+ .picture_structure = s->picture_structure, -+ .top_field_first = s->top_field_first, -+ .frame_pred_frame_dct = s->frame_pred_frame_dct, -+ .concealment_motion_vectors = s->concealment_motion_vectors, -+ .q_scale_type = s->q_scale_type, -+ .intra_vlc_format = s->intra_vlc_format, -+ .alternate_scan = s->alternate_scan, -+ .repeat_first_field = s->repeat_first_field, -+ .progressive_frame = s->progressive_frame, -+ }, ++ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Sequence extension */ ++ .profile_and_level_indication = 0, ++ .chroma_format = s->chroma_format, + }; + ++ if (s->progressive_sequence) ++ controls->sequence.flags |= V4L2_MPEG2_SEQ_FLAG_PROGRESSIVE; ++ ++ controls->picture = (struct v4l2_ctrl_mpeg2_picture) { ++ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Picture header */ ++ .picture_coding_type = s->pict_type, ++ ++ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Picture coding extension */ ++ .f_code[0][0] = s->mpeg_f_code[0][0], ++ .f_code[0][1] = s->mpeg_f_code[0][1], ++ .f_code[1][0] = s->mpeg_f_code[1][0], ++ .f_code[1][1] = s->mpeg_f_code[1][1], ++ .picture_structure = s->picture_structure, ++ .intra_dc_precision = s->intra_dc_precision, ++ }; ++ ++ if (s->top_field_first) ++ controls->picture.flags |= V4L2_MPEG2_PIC_FLAG_TOP_FIELD_FIRST; ++ ++ if (s->frame_pred_frame_dct) ++ controls->picture.flags |= V4L2_MPEG2_PIC_FLAG_FRAME_PRED_DCT; ++ ++ if (s->concealment_motion_vectors) ++ controls->picture.flags |= V4L2_MPEG2_PIC_FLAG_CONCEALMENT_MV; ++ ++ if (s->intra_vlc_format) ++ controls->picture.flags |= V4L2_MPEG2_PIC_FLAG_INTRA_VLC; ++ ++ if (s->q_scale_type) ++ controls->picture.flags |= V4L2_MPEG2_PIC_FLAG_Q_SCALE_TYPE; ++ ++ if (s->alternate_scan) ++ controls->picture.flags |= V4L2_MPEG2_PIC_FLAG_ALT_SCAN; ++ ++ if (s->repeat_first_field) ++ controls->picture.flags |= V4L2_MPEG2_PIC_FLAG_REPEAT_FIRST; ++ ++ if (s->progressive_frame) ++ controls->picture.flags |= V4L2_MPEG2_PIC_FLAG_PROGRESSIVE; ++ + switch (s->pict_type) { + case AV_PICTURE_TYPE_B: -+ controls->slice_params.backward_ref_ts = ff_v4l2_request_get_capture_timestamp(s->next_picture.f); ++ controls->picture.backward_ref_ts = ff_v4l2_request_get_capture_timestamp(s->next_picture.f); + // fall-through + case AV_PICTURE_TYPE_P: -+ controls->slice_params.forward_ref_ts = ff_v4l2_request_get_capture_timestamp(s->last_picture.f); ++ controls->picture.forward_ref_ts = ff_v4l2_request_get_capture_timestamp(s->last_picture.f); + } + -+ controls->quantization = (struct v4l2_ctrl_mpeg2_quantization) { -+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Quant matrix extension */ -+ .load_intra_quantiser_matrix = 1, -+ .load_non_intra_quantiser_matrix = 1, -+ .load_chroma_intra_quantiser_matrix = 1, -+ .load_chroma_non_intra_quantiser_matrix = 1, -+ }; -+ + for (int i = 0; i < 64; i++) { + int n = s->idsp.idct_permutation[ff_zigzag_direct[i]]; -+ controls->quantization.intra_quantiser_matrix[i] = s->intra_matrix[n]; -+ controls->quantization.non_intra_quantiser_matrix[i] = s->inter_matrix[n]; -+ controls->quantization.chroma_intra_quantiser_matrix[i] = s->chroma_intra_matrix[n]; -+ controls->quantization.chroma_non_intra_quantiser_matrix[i] = s->chroma_inter_matrix[n]; ++ controls->quantisation.intra_quantiser_matrix[i] = s->intra_matrix[n]; ++ controls->quantisation.non_intra_quantiser_matrix[i] = s->inter_matrix[n]; ++ controls->quantisation.chroma_intra_quantiser_matrix[i] = s->chroma_intra_matrix[n]; ++ controls->quantisation.chroma_non_intra_quantiser_matrix[i] = s->chroma_inter_matrix[n]; + } + + return ff_v4l2_request_reset_frame(avctx, s->current_picture_ptr->f); @@ -2121,23 +2124,25 @@ index 000000000000..88d86cc4c23f +{ + const MpegEncContext *s = avctx->priv_data; + V4L2RequestControlsMPEG2 *controls = s->current_picture_ptr->hwaccel_picture_private; -+ V4L2RequestDescriptor *req = (V4L2RequestDescriptor*)s->current_picture_ptr->f->data[0]; + + struct v4l2_ext_control control[] = { + { -+ .id = V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS, -+ .ptr = &controls->slice_params, -+ .size = sizeof(controls->slice_params), ++ .id = V4L2_CID_STATELESS_MPEG2_SEQUENCE, ++ .ptr = &controls->sequence, ++ .size = sizeof(controls->sequence), + }, + { -+ .id = V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION, -+ .ptr = &controls->quantization, -+ .size = sizeof(controls->quantization), ++ .id = V4L2_CID_STATELESS_MPEG2_PICTURE, ++ .ptr = &controls->picture, ++ .size = sizeof(controls->picture), ++ }, ++ { ++ .id = V4L2_CID_STATELESS_MPEG2_QUANTISATION, ++ .ptr = &controls->quantisation, ++ .size = sizeof(controls->quantisation), + }, + }; + -+ controls->slice_params.bit_size = req->output.used * 8; -+ + return ff_v4l2_request_decode_frame(avctx, s->current_picture_ptr->f, control, FF_ARRAY_ELEMS(control)); +} + @@ -2162,10 +2167,10 @@ index 000000000000..88d86cc4c23f + .caps_internal = HWACCEL_CAP_ASYNC_SAFE, +}; -From d09f7dc15ca0d889dcd112a66d2ebc88046fc271 Mon Sep 17 00:00:00 2001 +From 8fedb1c1d5c232936ec7ddff71e72dd27dbace6d Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Wed, 22 May 2019 14:46:58 +0200 -Subject: [PATCH 07/19] Add V4L2 request API vp8 hwaccel +Subject: [PATCH 07/18] Add V4L2 request API vp8 hwaccel Signed-off-by: Boris Brezillon Signed-off-by: Ezequiel Garcia @@ -2444,10 +2449,10 @@ index e84fcdeaa1e7..0608d9e4e165 100644 NULL }, -From 81d6e95b5f2753737791a8a9561850d4a028ad86 Mon Sep 17 00:00:00 2001 +From aba2a109c8191b8e914522c7504f78385e1da3ed Mon Sep 17 00:00:00 2001 From: Jernej Skrabec Date: Sat, 15 Dec 2018 22:32:16 +0100 -Subject: [PATCH 08/19] Add V4L2 request API hevc hwaccel +Subject: [PATCH 08/18] Add V4L2 request API hevc hwaccel Signed-off-by: Jernej Skrabec Signed-off-by: Jonas Karlman @@ -2456,8 +2461,8 @@ Signed-off-by: Jonas Karlman libavcodec/Makefile | 1 + libavcodec/hevcdec.c | 10 + libavcodec/hwaccels.h | 1 + - libavcodec/v4l2_request_hevc.c | 533 +++++++++++++++++++++++++++++++++ - 5 files changed, 548 insertions(+) + libavcodec/v4l2_request_hevc.c | 574 +++++++++++++++++++++++++++++++++ + 5 files changed, 589 insertions(+) create mode 100644 libavcodec/v4l2_request_hevc.c diff --git a/configure b/configure @@ -2549,10 +2554,10 @@ index 14838083ec36..bd75e94f4cae 100644 extern const AVHWAccel ff_hevc_videotoolbox_hwaccel; diff --git a/libavcodec/v4l2_request_hevc.c b/libavcodec/v4l2_request_hevc.c new file mode 100644 -index 000000000000..f72490954653 +index 000000000000..d385c2f03615 --- /dev/null +++ b/libavcodec/v4l2_request_hevc.c -@@ -0,0 +1,533 @@ +@@ -0,0 +1,574 @@ +/* + * This file is part of FFmpeg. + * @@ -2580,6 +2585,7 @@ index 000000000000..f72490954653 +typedef struct V4L2RequestControlsHEVC { + struct v4l2_ctrl_hevc_sps sps; + struct v4l2_ctrl_hevc_pps pps; ++ struct v4l2_ctrl_hevc_decode_params dec_params; + struct v4l2_ctrl_hevc_slice_params slice_params[MAX_SLICES]; + int first_slice; + int num_slices; //TODO: this should be in control @@ -2660,8 +2666,56 @@ index 000000000000..f72490954653 + return 0; +} + ++static void fill_dec_params(struct v4l2_ctrl_hevc_decode_params *dec_params, const HEVCContext *h) ++{ ++ const HEVCFrame *pic = h->ref; ++ const SliceHeader *sh = &h->sh; ++ int i, entries = 0; ++ ++ *dec_params = (struct v4l2_ctrl_hevc_decode_params) { ++ .pic_order_cnt_val = pic->poc, /* FIXME: is this same as slice_params->slice_pic_order_cnt ? */ ++ .num_poc_st_curr_before = h->rps[ST_CURR_BEF].nb_refs, ++ .num_poc_st_curr_after = h->rps[ST_CURR_AFT].nb_refs, ++ .num_poc_lt_curr = h->rps[LT_CURR].nb_refs, ++ }; ++ ++ for (i = 0; i < FF_ARRAY_ELEMS(h->DPB); i++) { ++ const HEVCFrame *frame = &h->DPB[i]; ++ if (frame != pic && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF))) { ++ struct v4l2_hevc_dpb_entry *entry = &dec_params->dpb[entries++]; ++ ++ entry->timestamp = ff_v4l2_request_get_capture_timestamp(frame->frame); ++ entry->rps = find_frame_rps_type(h, entry->timestamp); ++ entry->field_pic = frame->frame->interlaced_frame; ++ ++ /* TODO: Interleaved: Get the POC for each field. */ ++ entry->pic_order_cnt[0] = frame->poc; ++ entry->pic_order_cnt[1] = frame->poc; ++ } ++ } ++ ++ dec_params->num_active_dpb_entries = entries; ++ ++ if (IS_IRAP(h)) ++ dec_params->flags |= V4L2_HEVC_DECODE_PARAM_FLAG_IRAP_PIC; ++ ++ if (IS_IDR(h)) ++ dec_params->flags |= V4L2_HEVC_DECODE_PARAM_FLAG_IDR_PIC; ++ ++ /* FIXME: is this really frame property? */ ++ if (sh->no_output_of_prior_pics_flag) ++ dec_params->flags |= V4L2_HEVC_DECODE_PARAM_FLAG_NO_OUTPUT_OF_PRIOR; ++ ++ /* ++ * TODO: fill ++ * dec_params->poc_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; ++ * dec_params->poc_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; ++ * dec_params->poc_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; ++ */ ++} ++ +static uint8_t get_ref_pic_index(const HEVCContext *h, const HEVCFrame *frame, -+ struct v4l2_ctrl_hevc_slice_params *slice_params) ++ struct v4l2_ctrl_hevc_decode_params *dec_params) +{ + uint64_t timestamp; + @@ -2670,8 +2724,8 @@ index 000000000000..f72490954653 + + timestamp = ff_v4l2_request_get_capture_timestamp(frame->frame); + -+ for (uint8_t i = 0; i < slice_params->num_active_dpb_entries; i++) { -+ struct v4l2_hevc_dpb_entry *entry = &slice_params->dpb[i]; ++ for (uint8_t i = 0; i < dec_params->num_active_dpb_entries; i++) { ++ struct v4l2_hevc_dpb_entry *entry = &dec_params->dpb[i]; + if (entry->timestamp == timestamp) + return i; + } @@ -2680,12 +2734,13 @@ index 000000000000..f72490954653 +} + +static void v4l2_request_hevc_fill_slice_params(const HEVCContext *h, ++ struct v4l2_ctrl_hevc_decode_params *dec_params, + struct v4l2_ctrl_hevc_slice_params *slice_params) +{ + const HEVCFrame *pic = h->ref; + const SliceHeader *sh = &h->sh; -+ int i, entries = 0; + RefPicList *rpl; ++ int i; + + *slice_params = (struct v4l2_ctrl_hevc_slice_params) { + .bit_size = 0, @@ -2714,11 +2769,6 @@ index 000000000000..f72490954653 + + /* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture timing SEI message */ + .pic_struct = h->sei.picture_timing.picture_struct, -+ -+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */ -+ .num_rps_poc_st_curr_before = h->rps[ST_CURR_BEF].nb_refs, -+ .num_rps_poc_st_curr_after = h->rps[ST_CURR_AFT].nb_refs, -+ .num_rps_poc_lt_curr = h->rps[LT_CURR].nb_refs, + }; + + if (sh->slice_sample_adaptive_offset_flag[0]) @@ -2745,33 +2795,19 @@ index 000000000000..f72490954653 + if (sh->slice_loop_filter_across_slices_enabled_flag) + slice_params->flags |= V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_LOOP_FILTER_ACROSS_SLICES_ENABLED; + -+ for (i = 0; i < FF_ARRAY_ELEMS(h->DPB); i++) { -+ const HEVCFrame *frame = &h->DPB[i]; -+ if (frame != pic && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF))) { -+ struct v4l2_hevc_dpb_entry *entry = &slice_params->dpb[entries++]; -+ -+ entry->timestamp = ff_v4l2_request_get_capture_timestamp(frame->frame); -+ entry->rps = find_frame_rps_type(h, entry->timestamp); -+ entry->field_pic = frame->frame->interlaced_frame; -+ -+ /* TODO: Interleaved: Get the POC for each field. */ -+ entry->pic_order_cnt[0] = frame->poc; -+ entry->pic_order_cnt[1] = frame->poc; -+ } -+ } -+ -+ slice_params->num_active_dpb_entries = entries; ++ if (sh->dependent_slice_segment_flag) ++ slice_params->flags |= V4L2_HEVC_SLICE_PARAMS_FLAG_DEPENDENT_SLICE_SEGMENT; + + if (sh->slice_type != HEVC_SLICE_I) { + rpl = &h->ref->refPicList[0]; + for (i = 0; i < rpl->nb_refs; i++) -+ slice_params->ref_idx_l0[i] = get_ref_pic_index(h, rpl->ref[i], slice_params); ++ slice_params->ref_idx_l0[i] = get_ref_pic_index(h, rpl->ref[i], dec_params); + } + + if (sh->slice_type == HEVC_SLICE_B) { + rpl = &h->ref->refPicList[1]; + for (i = 0; i < rpl->nb_refs; i++) -+ slice_params->ref_idx_l1[i] = get_ref_pic_index(h, rpl->ref[i], slice_params); ++ slice_params->ref_idx_l1[i] = get_ref_pic_index(h, rpl->ref[i], dec_params); + } + + v4l2_request_hevc_fill_pred_table(h, &slice_params->pred_weight_table); @@ -2783,7 +2819,6 @@ index 000000000000..f72490954653 + + /* ISO/IEC 23008-2, ITU-T Rec. H.265: Sequence parameter set */ + *ctrl = (struct v4l2_ctrl_hevc_sps) { -+ .chroma_format_idc = sps->chroma_format_idc, + .pic_width_in_luma_samples = sps->width, + .pic_height_in_luma_samples = sps->height, + .bit_depth_luma_minus8 = sps->bit_depth - 8, @@ -2804,6 +2839,8 @@ index 000000000000..f72490954653 + .log2_diff_max_min_pcm_luma_coding_block_size = sps->pcm.log2_max_pcm_cb_size - sps->pcm.log2_min_pcm_cb_size, + .num_short_term_ref_pic_sets = sps->nb_st_rps, + .num_long_term_ref_pics_sps = sps->num_long_term_ref_pics_sps, ++ .chroma_format_idc = sps->chroma_format_idc, ++ .sps_max_sub_layers_minus1 = sps->max_sub_layers - 1, + }; + + if (sps->separate_colour_plane_flag) @@ -2839,19 +2876,17 @@ index 000000000000..f72490954653 + av_unused uint32_t size) +{ + const HEVCContext *h = avctx->priv_data; -+ const HEVCSPS *sps = h->ps.sps; + const HEVCPPS *pps = h->ps.pps; -+ const ScalingList *sl = pps->scaling_list_data_present_flag ? -+ &pps->scaling_list : -+ sps->scaling_list_enable_flag ? -+ &sps->scaling_list : NULL; + V4L2RequestControlsHEVC *controls = h->ref->hwaccel_picture_private; + + fill_sps(&controls->sps, h); ++ fill_dec_params(&controls->dec_params, h); + + /* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */ + controls->pps = (struct v4l2_ctrl_hevc_pps) { + .num_extra_slice_header_bits = pps->num_extra_slice_header_bits, ++ .num_ref_idx_l0_default_active_minus1 = pps->num_ref_idx_l0_default_active - 1, ++ .num_ref_idx_l1_default_active_minus1 = pps->num_ref_idx_l1_default_active - 1, + .init_qp_minus26 = pps->pic_init_qp_minus26, + .diff_cu_qp_delta_depth = pps->diff_cu_qp_delta_depth, + .pps_cb_qp_offset = pps->cb_qp_offset, @@ -2862,7 +2897,7 @@ index 000000000000..f72490954653 + }; + + if (pps->dependent_slice_segments_enabled_flag) -+ controls->pps.flags |= V4L2_HEVC_PPS_FLAG_DEPENDENT_SLICE_SEGMENT; ++ controls->pps.flags |= V4L2_HEVC_PPS_FLAG_DEPENDENT_SLICE_SEGMENT_ENABLED; + + if (pps->output_flag_present_flag) + controls->pps.flags |= V4L2_HEVC_PPS_FLAG_OUTPUT_FLAG_PRESENT; @@ -2918,6 +2953,12 @@ index 000000000000..f72490954653 + if (pps->slice_header_extension_present_flag) + controls->pps.flags |= V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT; + ++ if (pps->deblocking_filter_control_present_flag) ++ controls->pps.flags |= V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT; ++ ++ if (pps->uniform_spacing_flag) ++ controls->pps.flags |= V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING; ++ + if (pps->tiles_enabled_flag) { + controls->pps.num_tile_columns_minus1 = pps->num_tile_columns - 1; + controls->pps.num_tile_rows_minus1 = pps->num_tile_rows - 1; @@ -2953,6 +2994,11 @@ index 000000000000..f72490954653 + .size = sizeof(controls->pps), + }, + { ++ .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS, ++ .ptr = &controls->dec_params, ++ .size = sizeof(controls->dec_params), ++ }, ++ { + .id = V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS, + .ptr = &controls->slice_params, + .size = sizeof(controls->slice_params[0]) * FFMAX(FFMIN(controls->num_slices, MAX_SLICES), ctx->max_slices), @@ -2983,7 +3029,7 @@ index 000000000000..f72490954653 + controls->first_slice = 0; + } + -+ v4l2_request_hevc_fill_slice_params(h, &controls->slice_params[slice]); ++ v4l2_request_hevc_fill_slice_params(h, &controls->dec_params, &controls->slice_params[slice]); + + if (ctx->start_code == V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B) { + ret = ff_v4l2_request_append_output_buffer(avctx, h->ref->frame, nalu_slice_start_code, 3); @@ -3087,26 +3133,23 @@ index 000000000000..f72490954653 + .caps_internal = HWACCEL_CAP_ASYNC_SAFE, +}; -From 298f65eb9d5d1bae35e5940e27641b1674af884d Mon Sep 17 00:00:00 2001 +From 7f7d8dd75d175f9f6944ed334c67380b6b4c8cbf Mon Sep 17 00:00:00 2001 From: Jernej Skrabec Date: Thu, 14 Feb 2019 23:20:05 +0100 -Subject: [PATCH 09/19] Add and use private linux v5.13 headers for V4L2 +Subject: [PATCH 09/18] Add and use private linux v5.14 headers for V4L2 request API ctrls Signed-off-by: Jernej Skrabec Signed-off-by: Jonas Karlman --- - configure | 4 +- - libavcodec/hevc-ctrls.h | 212 ++++++++++++++++++++++++++++++++ - libavcodec/mpeg2-ctrls.h | 82 ++++++++++++ - libavcodec/v4l2_request_hevc.c | 1 + - libavcodec/v4l2_request_mpeg2.c | 1 + - 5 files changed, 298 insertions(+), 2 deletions(-) + configure | 2 +- + libavcodec/hevc-ctrls.h | 240 +++++++++++++++++++++++++++++++++ + libavcodec/v4l2_request_hevc.c | 1 + + 3 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 libavcodec/hevc-ctrls.h - create mode 100644 libavcodec/mpeg2-ctrls.h diff --git a/configure b/configure -index 94476afd5df1..b24fb36a26c7 100755 +index 94476afd5df1..e90c9b913dcb 100755 --- a/configure +++ b/configure @@ -2941,7 +2941,7 @@ hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC" @@ -3118,21 +3161,12 @@ index 94476afd5df1..b24fb36a26c7 100755 hevc_v4l2request_hwaccel_select="hevc_decoder" hevc_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferHEVC" hevc_vaapi_hwaccel_select="hevc_decoder" -@@ -2971,7 +2971,7 @@ mpeg2_dxva2_hwaccel_deps="dxva2" - mpeg2_dxva2_hwaccel_select="mpeg2video_decoder" - mpeg2_nvdec_hwaccel_deps="nvdec" - mpeg2_nvdec_hwaccel_select="mpeg2video_decoder" --mpeg2_v4l2request_hwaccel_deps="v4l2_request mpeg2_v4l2_request" -+mpeg2_v4l2request_hwaccel_deps="v4l2_request" - mpeg2_v4l2request_hwaccel_select="mpeg2video_decoder" - mpeg2_vaapi_hwaccel_deps="vaapi" - mpeg2_vaapi_hwaccel_select="mpeg2video_decoder" diff --git a/libavcodec/hevc-ctrls.h b/libavcodec/hevc-ctrls.h new file mode 100644 -index 000000000000..b4cb2ef02f17 +index 000000000000..53c0038c792b --- /dev/null +++ b/libavcodec/hevc-ctrls.h -@@ -0,0 +1,212 @@ +@@ -0,0 +1,240 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * These are the HEVC state controls for use with stateless HEVC @@ -3154,6 +3188,7 @@ index 000000000000..b4cb2ef02f17 +#define V4L2_CID_MPEG_VIDEO_HEVC_SPS (V4L2_CID_CODEC_BASE + 1008) +#define V4L2_CID_MPEG_VIDEO_HEVC_PPS (V4L2_CID_CODEC_BASE + 1009) +#define V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (V4L2_CID_CODEC_BASE + 1010) ++#define V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (V4L2_CID_CODEC_BASE + 1012) +#define V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE (V4L2_CID_CODEC_BASE + 1015) +#define V4L2_CID_MPEG_VIDEO_HEVC_START_CODE (V4L2_CID_CODEC_BASE + 1016) + @@ -3161,6 +3196,7 @@ index 000000000000..b4cb2ef02f17 +#define V4L2_CTRL_TYPE_HEVC_SPS 0x0120 +#define V4L2_CTRL_TYPE_HEVC_PPS 0x0121 +#define V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS 0x0122 ++#define V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS 0x0124 + +enum v4l2_mpeg_video_hevc_decode_mode { + V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_SLICE_BASED, @@ -3210,13 +3246,12 @@ index 000000000000..b4cb2ef02f17 + __u8 num_short_term_ref_pic_sets; + __u8 num_long_term_ref_pics_sps; + __u8 chroma_format_idc; -+ -+ __u8 padding; ++ __u8 sps_max_sub_layers_minus1; + + __u64 flags; +}; + -+#define V4L2_HEVC_PPS_FLAG_DEPENDENT_SLICE_SEGMENT (1ULL << 0) ++#define V4L2_HEVC_PPS_FLAG_DEPENDENT_SLICE_SEGMENT_ENABLED (1ULL << 0) +#define V4L2_HEVC_PPS_FLAG_OUTPUT_FLAG_PRESENT (1ULL << 1) +#define V4L2_HEVC_PPS_FLAG_SIGN_DATA_HIDING_ENABLED (1ULL << 2) +#define V4L2_HEVC_PPS_FLAG_CABAC_INIT_PRESENT (1ULL << 3) @@ -3235,10 +3270,14 @@ index 000000000000..b4cb2ef02f17 +#define V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER (1ULL << 16) +#define V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT (1ULL << 17) +#define V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT (1ULL << 18) ++#define V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT (1ULL << 19) ++#define V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING (1ULL << 20) + +struct v4l2_ctrl_hevc_pps { + /* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */ + __u8 num_extra_slice_header_bits; ++ __u8 num_ref_idx_l0_default_active_minus1; ++ __u8 num_ref_idx_l1_default_active_minus1; + __s8 init_qp_minus26; + __u8 diff_cu_qp_delta_depth; + __s8 pps_cb_qp_offset; @@ -3295,6 +3334,7 @@ index 000000000000..b4cb2ef02f17 +#define V4L2_HEVC_SLICE_PARAMS_FLAG_USE_INTEGER_MV (1ULL << 6) +#define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_DEBLOCKING_FILTER_DISABLED (1ULL << 7) +#define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_LOOP_FILTER_ACROSS_SLICES_ENABLED (1ULL << 8) ++#define V4L2_HEVC_SLICE_PARAMS_FLAG_DEPENDENT_SLICE_SEGMENT (1ULL << 9) + +struct v4l2_ctrl_hevc_slice_params { + __u32 bit_size; @@ -3325,18 +3365,10 @@ index 000000000000..b4cb2ef02f17 + __u8 pic_struct; + + /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */ -+ __u8 num_active_dpb_entries; + __u8 ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + __u8 ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + -+ __u8 num_rps_poc_st_curr_before; -+ __u8 num_rps_poc_st_curr_after; -+ __u8 num_rps_poc_lt_curr; -+ -+ __u8 padding; -+ -+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */ -+ struct v4l2_hevc_dpb_entry dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; ++ __u8 padding[5]; + + /* ISO/IEC 23008-2, ITU-T Rec. H.265: Weighted prediction parameter */ + struct v4l2_hevc_pred_weight_table pred_weight_table; @@ -3344,97 +3376,39 @@ index 000000000000..b4cb2ef02f17 + __u64 flags; +}; + -+#endif -diff --git a/libavcodec/mpeg2-ctrls.h b/libavcodec/mpeg2-ctrls.h -new file mode 100644 -index 000000000000..2a4ae6701166 ---- /dev/null -+++ b/libavcodec/mpeg2-ctrls.h -@@ -0,0 +1,82 @@ -+/* SPDX-License-Identifier: GPL-2.0 */ ++#define V4L2_HEVC_DECODE_PARAM_FLAG_IRAP_PIC 0x1 ++#define V4L2_HEVC_DECODE_PARAM_FLAG_IDR_PIC 0x2 ++#define V4L2_HEVC_DECODE_PARAM_FLAG_NO_OUTPUT_OF_PRIOR 0x4 ++ ++struct v4l2_ctrl_hevc_decode_params { ++ __s32 pic_order_cnt_val; ++ __u8 num_active_dpb_entries; ++ struct v4l2_hevc_dpb_entry dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; ++ __u8 num_poc_st_curr_before; ++ __u8 num_poc_st_curr_after; ++ __u8 num_poc_lt_curr; ++ __u8 poc_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; ++ __u8 poc_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; ++ __u8 poc_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; ++ __u64 flags; ++}; ++ ++/* MPEG-class control IDs specific to the Hantro driver as defined by V4L2 */ ++#define V4L2_CID_CODEC_HANTRO_BASE (V4L2_CTRL_CLASS_CODEC | 0x1200) +/* -+ * These are the MPEG2 state controls for use with stateless MPEG-2 -+ * codec drivers. -+ * -+ * It turns out that these structs are not stable yet and will undergo -+ * more changes. So keep them private until they are stable and ready to -+ * become part of the official public API. ++ * V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP - ++ * the number of data (in bits) to skip in the ++ * slice segment header. ++ * If non-IDR, the bits to be skipped go from syntax element "pic_output_flag" ++ * to before syntax element "slice_temporal_mvp_enabled_flag". ++ * If IDR, the skipped bits are just "pic_output_flag" ++ * (separate_colour_plane_flag is not supported). + */ -+ -+#ifndef _MPEG2_CTRLS_H_ -+#define _MPEG2_CTRLS_H_ -+ -+#define V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS (V4L2_CID_CODEC_BASE+250) -+#define V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION (V4L2_CID_CODEC_BASE+251) -+ -+/* enum v4l2_ctrl_type type values */ -+#define V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS 0x0103 -+#define V4L2_CTRL_TYPE_MPEG2_QUANTIZATION 0x0104 -+ -+#define V4L2_MPEG2_PICTURE_CODING_TYPE_I 1 -+#define V4L2_MPEG2_PICTURE_CODING_TYPE_P 2 -+#define V4L2_MPEG2_PICTURE_CODING_TYPE_B 3 -+#define V4L2_MPEG2_PICTURE_CODING_TYPE_D 4 -+ -+struct v4l2_mpeg2_sequence { -+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Sequence header */ -+ __u16 horizontal_size; -+ __u16 vertical_size; -+ __u32 vbv_buffer_size; -+ -+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Sequence extension */ -+ __u16 profile_and_level_indication; -+ __u8 progressive_sequence; -+ __u8 chroma_format; -+}; -+ -+struct v4l2_mpeg2_picture { -+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Picture header */ -+ __u8 picture_coding_type; -+ -+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Picture coding extension */ -+ __u8 f_code[2][2]; -+ __u8 intra_dc_precision; -+ __u8 picture_structure; -+ __u8 top_field_first; -+ __u8 frame_pred_frame_dct; -+ __u8 concealment_motion_vectors; -+ __u8 q_scale_type; -+ __u8 intra_vlc_format; -+ __u8 alternate_scan; -+ __u8 repeat_first_field; -+ __u16 progressive_frame; -+}; -+ -+struct v4l2_ctrl_mpeg2_slice_params { -+ __u32 bit_size; -+ __u32 data_bit_offset; -+ __u64 backward_ref_ts; -+ __u64 forward_ref_ts; -+ -+ struct v4l2_mpeg2_sequence sequence; -+ struct v4l2_mpeg2_picture picture; -+ -+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Slice */ -+ __u32 quantiser_scale_code; -+}; -+ -+struct v4l2_ctrl_mpeg2_quantization { -+ /* ISO/IEC 13818-2, ITU-T Rec. H.262: Quant matrix extension */ -+ __u8 load_intra_quantiser_matrix; -+ __u8 load_non_intra_quantiser_matrix; -+ __u8 load_chroma_intra_quantiser_matrix; -+ __u8 load_chroma_non_intra_quantiser_matrix; -+ -+ __u8 intra_quantiser_matrix[64]; -+ __u8 non_intra_quantiser_matrix[64]; -+ __u8 chroma_intra_quantiser_matrix[64]; -+ __u8 chroma_non_intra_quantiser_matrix[64]; -+}; ++#define V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (V4L2_CID_CODEC_HANTRO_BASE + 0) + +#endif diff --git a/libavcodec/v4l2_request_hevc.c b/libavcodec/v4l2_request_hevc.c -index f72490954653..c16f8a868e38 100644 +index d385c2f03615..ad555c3bb836 100644 --- a/libavcodec/v4l2_request_hevc.c +++ b/libavcodec/v4l2_request_hevc.c @@ -19,6 +19,7 @@ @@ -3445,23 +3419,11 @@ index f72490954653..c16f8a868e38 100644 #define MAX_SLICES 16 -diff --git a/libavcodec/v4l2_request_mpeg2.c b/libavcodec/v4l2_request_mpeg2.c -index 88d86cc4c23f..bc251a6fd2c4 100644 ---- a/libavcodec/v4l2_request_mpeg2.c -+++ b/libavcodec/v4l2_request_mpeg2.c -@@ -19,6 +19,7 @@ - #include "hwconfig.h" - #include "mpegvideo.h" - #include "v4l2_request.h" -+#include "mpeg2-ctrls.h" - - typedef struct V4L2RequestControlsMPEG2 { - struct v4l2_ctrl_mpeg2_slice_params slice_params; -From dc55fcd8644515c6986b73ce340ceff4856acc3f Mon Sep 17 00:00:00 2001 +From 838ed5b6317f13d17b5890d769df325a3aaf0c98 Mon Sep 17 00:00:00 2001 From: Jonas Karlman Date: Mon, 29 Apr 2019 22:08:59 +0000 -Subject: [PATCH 10/19] HACK: hwcontext_drm: do not require drm device +Subject: [PATCH 10/18] HACK: hwcontext_drm: do not require drm device Signed-off-by: Jonas Karlman --- @@ -3485,19 +3447,19 @@ index 32cbde82ebfa..aa4794c5e665 100644 if (hwctx->fd < 0) return AVERROR(errno); -From 5793e491ca4057fa9baa797e354439c9e67b129a Mon Sep 17 00:00:00 2001 +From 72db468e754b14ea76ad00fea2deaf55f47fac26 Mon Sep 17 00:00:00 2001 From: Jernej Skrabec Date: Sat, 15 Dec 2018 22:32:16 +0100 -Subject: [PATCH 11/19] WIP: hevc scaling matrix +Subject: [PATCH 11/18] WIP: hevc scaling matrix Signed-off-by: Jernej Skrabec --- libavcodec/hevc-ctrls.h | 11 +++++++++++ - libavcodec/v4l2_request_hevc.c | 22 ++++++++++++++++++++++ - 2 files changed, 33 insertions(+) + libavcodec/v4l2_request_hevc.c | 27 +++++++++++++++++++++++++++ + 2 files changed, 38 insertions(+) diff --git a/libavcodec/hevc-ctrls.h b/libavcodec/hevc-ctrls.h -index b4cb2ef02f17..2dc250edaa2f 100644 +index 53c0038c792b..0e5c4a2eecff 100644 --- a/libavcodec/hevc-ctrls.h +++ b/libavcodec/hevc-ctrls.h @@ -19,6 +19,7 @@ @@ -3505,18 +3467,18 @@ index b4cb2ef02f17..2dc250edaa2f 100644 #define V4L2_CID_MPEG_VIDEO_HEVC_PPS (V4L2_CID_CODEC_BASE + 1009) #define V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (V4L2_CID_CODEC_BASE + 1010) +#define V4L2_CID_MPEG_VIDEO_HEVC_SCALING_MATRIX (V4L2_CID_CODEC_BASE + 1011) + #define V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (V4L2_CID_CODEC_BASE + 1012) #define V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE (V4L2_CID_CODEC_BASE + 1015) #define V4L2_CID_MPEG_VIDEO_HEVC_START_CODE (V4L2_CID_CODEC_BASE + 1016) - -@@ -26,6 +27,7 @@ +@@ -27,6 +28,7 @@ #define V4L2_CTRL_TYPE_HEVC_SPS 0x0120 #define V4L2_CTRL_TYPE_HEVC_PPS 0x0121 #define V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS 0x0122 +#define V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX 0x0123 + #define V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS 0x0124 enum v4l2_mpeg_video_hevc_decode_mode { - V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_SLICE_BASED, -@@ -209,4 +211,13 @@ struct v4l2_ctrl_hevc_slice_params { +@@ -224,6 +226,15 @@ struct v4l2_ctrl_hevc_decode_params { __u64 flags; }; @@ -3529,22 +3491,34 @@ index b4cb2ef02f17..2dc250edaa2f 100644 + __u8 scaling_list_dc_coef_32x32[2]; +}; + - #endif + /* MPEG-class control IDs specific to the Hantro driver as defined by V4L2 */ + #define V4L2_CID_CODEC_HANTRO_BASE (V4L2_CTRL_CLASS_CODEC | 0x1200) + /* diff --git a/libavcodec/v4l2_request_hevc.c b/libavcodec/v4l2_request_hevc.c -index c16f8a868e38..f400bf4f3c82 100644 +index ad555c3bb836..b6c191120e44 100644 --- a/libavcodec/v4l2_request_hevc.c +++ b/libavcodec/v4l2_request_hevc.c -@@ -26,6 +26,7 @@ - typedef struct V4L2RequestControlsHEVC { +@@ -27,6 +27,7 @@ typedef struct V4L2RequestControlsHEVC { struct v4l2_ctrl_hevc_sps sps; struct v4l2_ctrl_hevc_pps pps; + struct v4l2_ctrl_hevc_decode_params dec_params; + struct v4l2_ctrl_hevc_scaling_matrix scaling_matrix; struct v4l2_ctrl_hevc_slice_params slice_params[MAX_SLICES]; int first_slice; int num_slices; //TODO: this should be in control -@@ -295,6 +296,22 @@ static int v4l2_request_hevc_start_frame(AVCodecContext *avctx, +@@ -318,11 +319,32 @@ static int v4l2_request_hevc_start_frame(AVCodecContext *avctx, + { + const HEVCContext *h = avctx->priv_data; + const HEVCPPS *pps = h->ps.pps; ++ const HEVCSPS *sps = h->ps.sps; ++ const ScalingList *sl = pps->scaling_list_data_present_flag ? ++ &pps->scaling_list : ++ sps->scaling_list_enable_flag ? ++ &sps->scaling_list : NULL; + V4L2RequestControlsHEVC *controls = h->ref->hwaccel_picture_private; fill_sps(&controls->sps, h); + fill_dec_params(&controls->dec_params, h); + if (sl) { + for (int i = 0; i < 6; i++) { @@ -3565,9 +3539,9 @@ index c16f8a868e38..f400bf4f3c82 100644 /* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */ controls->pps = (struct v4l2_ctrl_hevc_pps) { .num_extra_slice_header_bits = pps->num_extra_slice_header_bits, -@@ -398,6 +415,11 @@ static int v4l2_request_hevc_queue_decode(AVCodecContext *avctx, int last_slice) - .ptr = &controls->pps, - .size = sizeof(controls->pps), +@@ -439,6 +461,11 @@ static int v4l2_request_hevc_queue_decode(AVCodecContext *avctx, int last_slice) + .ptr = &controls->dec_params, + .size = sizeof(controls->dec_params), }, + { + .id = V4L2_CID_MPEG_VIDEO_HEVC_SCALING_MATRIX, @@ -3578,45 +3552,34 @@ index c16f8a868e38..f400bf4f3c82 100644 .id = V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS, .ptr = &controls->slice_params, -From 1b22861c6aebebcc404da0192a1b17bec4e0365d Mon Sep 17 00:00:00 2001 +From fb279e99271bed8ba6bb3a01fad6cf9232567ff8 Mon Sep 17 00:00:00 2001 From: Jernej Skrabec Date: Sat, 15 Dec 2018 22:32:16 +0100 -Subject: [PATCH 12/19] WIP: hevc segment address +Subject: [PATCH 12/18] WIP: hevc segment address Signed-off-by: Jernej Skrabec --- - libavcodec/hevc-ctrls.h | 5 ++++- + libavcodec/hevc-ctrls.h | 1 + libavcodec/v4l2_request_hevc.c | 3 +++ - 2 files changed, 7 insertions(+), 1 deletion(-) + 2 files changed, 4 insertions(+) diff --git a/libavcodec/hevc-ctrls.h b/libavcodec/hevc-ctrls.h -index 2dc250edaa2f..f252286f7d9a 100644 +index 0e5c4a2eecff..42ad0fe81e66 100644 --- a/libavcodec/hevc-ctrls.h +++ b/libavcodec/hevc-ctrls.h -@@ -167,6 +167,9 @@ struct v4l2_ctrl_hevc_slice_params { - __u32 bit_size; - __u32 data_bit_offset; - -+ /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */ -+ __u32 slice_segment_addr; -+ - /* ISO/IEC 23008-2, ITU-T Rec. H.265: NAL unit header */ - __u8 nal_unit_type; - __u8 nuh_temporal_id_plus1; -@@ -200,7 +203,7 @@ struct v4l2_ctrl_hevc_slice_params { - __u8 num_rps_poc_st_curr_after; - __u8 num_rps_poc_lt_curr; - -- __u8 padding; -+ __u8 padding[5]; +@@ -198,6 +198,7 @@ struct v4l2_ctrl_hevc_slice_params { + __u8 pic_struct; /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */ - struct v4l2_hevc_dpb_entry dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; ++ __u32 slice_segment_addr; + __u8 ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + __u8 ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + diff --git a/libavcodec/v4l2_request_hevc.c b/libavcodec/v4l2_request_hevc.c -index f400bf4f3c82..98222fc74c36 100644 +index b6c191120e44..f645c538c25c 100644 --- a/libavcodec/v4l2_request_hevc.c +++ b/libavcodec/v4l2_request_hevc.c -@@ -138,6 +138,9 @@ static void v4l2_request_hevc_fill_slice_params(const HEVCContext *h, +@@ -188,6 +188,9 @@ static void v4l2_request_hevc_fill_slice_params(const HEVCContext *h, .bit_size = 0, .data_bit_offset = get_bits_count(&h->HEVClc->gb), @@ -3627,45 +3590,37 @@ index f400bf4f3c82..98222fc74c36 100644 .nal_unit_type = h->nal_unit_type, .nuh_temporal_id_plus1 = h->temporal_id + 1, -From 19d9b2cf64743085edf06be00a3924384f13f4dc Mon Sep 17 00:00:00 2001 +From 55a85bb6be2b1661c4830b5d085e5657579436a4 Mon Sep 17 00:00:00 2001 From: Jernej Skrabec Date: Sat, 15 Dec 2018 22:32:16 +0100 -Subject: [PATCH 13/19] WIP: hevc entry point offsets +Subject: [PATCH 13/18] WIP: hevc entry point offsets Signed-off-by: Jernej Skrabec --- - libavcodec/hevc-ctrls.h | 5 ++++- + libavcodec/hevc-ctrls.h | 4 +++- libavcodec/v4l2_request_hevc.c | 9 +++++++++ - 2 files changed, 13 insertions(+), 1 deletion(-) + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libavcodec/hevc-ctrls.h b/libavcodec/hevc-ctrls.h -index f252286f7d9a..eb83c1d61b8d 100644 +index 42ad0fe81e66..a24916603017 100644 --- a/libavcodec/hevc-ctrls.h +++ b/libavcodec/hevc-ctrls.h -@@ -169,6 +169,7 @@ struct v4l2_ctrl_hevc_slice_params { - - /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */ - __u32 slice_segment_addr; -+ __u32 num_entry_point_offsets; - - /* ISO/IEC 23008-2, ITU-T Rec. H.265: NAL unit header */ - __u8 nal_unit_type; -@@ -203,7 +204,9 @@ struct v4l2_ctrl_hevc_slice_params { - __u8 num_rps_poc_st_curr_after; - __u8 num_rps_poc_lt_curr; +@@ -202,7 +202,9 @@ struct v4l2_ctrl_hevc_slice_params { + __u8 ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + __u8 ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; - __u8 padding[5]; -+ __u8 padding; -+ ++ __u32 num_entry_point_offsets; + __u32 entry_point_offset_minus1[256]; ++ __u8 padding[8]; - /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */ - struct v4l2_hevc_dpb_entry dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + /* ISO/IEC 23008-2, ITU-T Rec. H.265: Weighted prediction parameter */ + struct v4l2_hevc_pred_weight_table pred_weight_table; diff --git a/libavcodec/v4l2_request_hevc.c b/libavcodec/v4l2_request_hevc.c -index 98222fc74c36..7e77c83e4e4b 100644 +index f645c538c25c..601202a77d7a 100644 --- a/libavcodec/v4l2_request_hevc.c +++ b/libavcodec/v4l2_request_hevc.c -@@ -225,6 +225,15 @@ static void v4l2_request_hevc_fill_slice_params(const HEVCContext *h, +@@ -256,6 +256,15 @@ static void v4l2_request_hevc_fill_slice_params(const HEVCContext *h, } v4l2_request_hevc_fill_pred_table(h, &slice_params->pred_weight_table); @@ -3682,10 +3637,10 @@ index 98222fc74c36..7e77c83e4e4b 100644 static void fill_sps(struct v4l2_ctrl_hevc_sps *ctrl, const HEVCContext *h) -From 0aab6ac62a36c7f2c439e3182abc501aa70b19ea Mon Sep 17 00:00:00 2001 +From 4c1dd736399c6c4f0dbc5510616b16773b892832 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Thu, 12 Dec 2019 16:13:55 +0100 -Subject: [PATCH 14/19] WIP: Add V4L2 request API vp9 hwaccel +Subject: [PATCH 14/18] WIP: Add V4L2 request API vp9 hwaccel Signed-off-by: Boris Brezillon --- @@ -3699,7 +3654,7 @@ Signed-off-by: Boris Brezillon create mode 100644 libavcodec/v4l2_request_vp9.c diff --git a/configure b/configure -index b24fb36a26c7..9acb9235ef7b 100755 +index e90c9b913dcb..33c8ed54679a 100755 --- a/configure +++ b/configure @@ -3015,6 +3015,8 @@ vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9" @@ -4166,10 +4121,10 @@ index 54726df742f9..fee3568736f7 100644 uint8_t pred_prob[3]; struct { -From 324ec7647aa25c85b1dae47b86e11fbc4637ceac Mon Sep 17 00:00:00 2001 +From b4ce2068a1ba8723908fd39c1b2099b286715dde Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Thu, 12 Dec 2019 16:13:55 +0100 -Subject: [PATCH 15/19] WIP: Add and use vp9 private linux header +Subject: [PATCH 15/18] WIP: Add and use vp9 private linux header Signed-off-by: Boris Brezillon --- @@ -4180,7 +4135,7 @@ Signed-off-by: Boris Brezillon create mode 100644 libavcodec/vp9-ctrls.h diff --git a/configure b/configure -index 9acb9235ef7b..9942d74f1f09 100755 +index 33c8ed54679a..921e74470145 100755 --- a/configure +++ b/configure @@ -3015,7 +3015,7 @@ vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9" @@ -4696,10 +4651,10 @@ index 000000000000..0cdea8a18b72 + +#endif /* _VP9_CTRLS_H_ */ -From a787b57927be77f29178de8fb00afef0b7468c25 Mon Sep 17 00:00:00 2001 +From 5ba520963c60bb72e9e418a4392724c619e95f89 Mon Sep 17 00:00:00 2001 From: Jonas Karlman Date: Fri, 15 May 2020 16:54:05 +0000 -Subject: [PATCH 16/19] WIP: add NV15 and NV20 support +Subject: [PATCH 16/18] WIP: add NV15 and NV20 support Signed-off-by: Jonas Karlman --- @@ -4783,10 +4738,10 @@ index 5234b5049b0d..0b294feff2eb 100644 default: return -1; -From 8de8b20b540b68355e54a6e97b5543d0ae67cda3 Mon Sep 17 00:00:00 2001 +From ea35c24c6c19e90e8a33bf9415cf3b90143221f7 Mon Sep 17 00:00:00 2001 From: Jonas Karlman Date: Mon, 27 Jul 2020 23:15:45 +0000 -Subject: [PATCH 17/19] HACK: define drm NV15 and NV20 format +Subject: [PATCH 17/18] HACK: define drm NV15 and NV20 format --- libavcodec/v4l2_request.c | 8 ++++++++ @@ -4812,92 +4767,49 @@ index 0b294feff2eb..a8f0ee79eeef 100644 { V4L2RequestDescriptor *req = (V4L2RequestDescriptor*)frame->data[0]; -From b4ef09e9b03a4cdb442d87f5c3951ea406ff09e0 Mon Sep 17 00:00:00 2001 -From: Jernej Skrabec -Date: Sun, 11 Apr 2021 08:40:57 +0000 -Subject: [PATCH 18/19] WIP: hevc: slice dependent flag - ---- - libavcodec/hevc-ctrls.h | 1 + - libavcodec/v4l2_request_hevc.c | 3 +++ - 2 files changed, 4 insertions(+) - -diff --git a/libavcodec/hevc-ctrls.h b/libavcodec/hevc-ctrls.h -index eb83c1d61b8d..cd51fb6df1f0 100644 ---- a/libavcodec/hevc-ctrls.h -+++ b/libavcodec/hevc-ctrls.h -@@ -162,6 +162,7 @@ struct v4l2_hevc_pred_weight_table { - #define V4L2_HEVC_SLICE_PARAMS_FLAG_USE_INTEGER_MV (1ULL << 6) - #define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_DEBLOCKING_FILTER_DISABLED (1ULL << 7) - #define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_LOOP_FILTER_ACROSS_SLICES_ENABLED (1ULL << 8) -+#define V4L2_HEVC_SLICE_PARAMS_FLAG_DEPENDENT_SLICE_SEGMENT (1ULL << 9) - - struct v4l2_ctrl_hevc_slice_params { - __u32 bit_size; -diff --git a/libavcodec/v4l2_request_hevc.c b/libavcodec/v4l2_request_hevc.c -index 7e77c83e4e4b..116a69340af3 100644 ---- a/libavcodec/v4l2_request_hevc.c -+++ b/libavcodec/v4l2_request_hevc.c -@@ -195,6 +195,9 @@ static void v4l2_request_hevc_fill_slice_params(const HEVCContext *h, - if (sh->slice_loop_filter_across_slices_enabled_flag) - slice_params->flags |= V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_LOOP_FILTER_ACROSS_SLICES_ENABLED; - -+ if (sh->dependent_slice_segment_flag) -+ slice_params->flags |= V4L2_HEVC_SLICE_PARAMS_FLAG_DEPENDENT_SLICE_SEGMENT; -+ - for (i = 0; i < FF_ARRAY_ELEMS(h->DPB); i++) { - const HEVCFrame *frame = &h->DPB[i]; - if (frame != pic && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF))) { - -From 6a200d38c3ff00cfdecd92bb7b7083b590403017 Mon Sep 17 00:00:00 2001 +From 36dbf222487a459156f1752436530b3fae39d35c Mon Sep 17 00:00:00 2001 From: Jonas Karlman Date: Wed, 13 May 2020 22:51:21 +0000 -Subject: [PATCH 19/19] WIP: hevc rkvdec fields +Subject: [PATCH 18/18] WIP: hevc rkvdec fields Signed-off-by: Jonas Karlman --- - libavcodec/hevc-ctrls.h | 17 +++++++++++++---- + libavcodec/hevc-ctrls.h | 11 ++++++++++- libavcodec/v4l2_request_hevc.c | 12 ++++++++++++ - 2 files changed, 25 insertions(+), 4 deletions(-) + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libavcodec/hevc-ctrls.h b/libavcodec/hevc-ctrls.h -index cd51fb6df1f0..4d51c148d0ba 100644 +index a24916603017..cd143526685f 100644 --- a/libavcodec/hevc-ctrls.h +++ b/libavcodec/hevc-ctrls.h -@@ -56,6 +56,9 @@ enum v4l2_mpeg_video_hevc_start_code { +@@ -58,6 +58,8 @@ enum v4l2_mpeg_video_hevc_start_code { /* The controls are not stable at the moment and will likely be reworked. */ struct v4l2_ctrl_hevc_sps { /* ISO/IEC 23008-2, ITU-T Rec. H.265: Sequence parameter set */ + __u8 video_parameter_set_id; + __u8 seq_parameter_set_id; -+ __u8 chroma_format_idc; __u16 pic_width_in_luma_samples; __u16 pic_height_in_luma_samples; __u8 bit_depth_luma_minus8; -@@ -76,9 +79,9 @@ struct v4l2_ctrl_hevc_sps { - __u8 log2_diff_max_min_pcm_luma_coding_block_size; - __u8 num_short_term_ref_pic_sets; - __u8 num_long_term_ref_pics_sps; -- __u8 chroma_format_idc; +@@ -81,6 +83,9 @@ struct v4l2_ctrl_hevc_sps { + __u8 chroma_format_idc; + __u8 sps_max_sub_layers_minus1; -- __u8 padding; + __u8 num_slices; -+ __u8 padding[6]; - ++ __u8 padding[5]; ++ __u64 flags; }; -@@ -105,7 +108,10 @@ struct v4l2_ctrl_hevc_sps { + +@@ -108,6 +113,7 @@ struct v4l2_ctrl_hevc_sps { struct v4l2_ctrl_hevc_pps { /* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */ + __u8 pic_parameter_set_id; __u8 num_extra_slice_header_bits; -+ __u8 num_ref_idx_l0_default_active_minus1; -+ __u8 num_ref_idx_l1_default_active_minus1; - __s8 init_qp_minus26; - __u8 diff_cu_qp_delta_depth; - __s8 pps_cb_qp_offset; -@@ -118,7 +124,7 @@ struct v4l2_ctrl_hevc_pps { + __u8 num_ref_idx_l0_default_active_minus1; + __u8 num_ref_idx_l1_default_active_minus1; +@@ -123,7 +129,7 @@ struct v4l2_ctrl_hevc_pps { __s8 pps_tc_offset_div2; __u8 log2_parallel_merge_level_minus2; @@ -4906,33 +4818,31 @@ index cd51fb6df1f0..4d51c148d0ba 100644 __u64 flags; }; -@@ -205,7 +211,10 @@ struct v4l2_ctrl_hevc_slice_params { - __u8 num_rps_poc_st_curr_after; - __u8 num_rps_poc_lt_curr; +@@ -202,6 +208,9 @@ struct v4l2_ctrl_hevc_slice_params { + __u8 ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + __u8 ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; -- __u8 padding; + __u16 short_term_ref_pic_set_size; + __u16 long_term_ref_pic_set_size; -+ -+ __u8 padding[5]; - ++ + __u32 num_entry_point_offsets; __u32 entry_point_offset_minus1[256]; - + __u8 padding[8]; diff --git a/libavcodec/v4l2_request_hevc.c b/libavcodec/v4l2_request_hevc.c -index 116a69340af3..eb493b309fe9 100644 +index 601202a77d7a..be7838244447 100644 --- a/libavcodec/v4l2_request_hevc.c +++ b/libavcodec/v4l2_request_hevc.c -@@ -169,6 +169,9 @@ static void v4l2_request_hevc_fill_slice_params(const HEVCContext *h, - .num_rps_poc_st_curr_before = h->rps[ST_CURR_BEF].nb_refs, - .num_rps_poc_st_curr_after = h->rps[ST_CURR_AFT].nb_refs, - .num_rps_poc_lt_curr = h->rps[LT_CURR].nb_refs, +@@ -214,6 +214,9 @@ static void v4l2_request_hevc_fill_slice_params(const HEVCContext *h, + + /* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture timing SEI message */ + .pic_struct = h->sei.picture_timing.picture_struct, + + .short_term_ref_pic_set_size = sh->short_term_ref_pic_set_size, + .long_term_ref_pic_set_size = sh->long_term_ref_pic_set_size, }; if (sh->slice_sample_adaptive_offset_flag[0]) -@@ -242,9 +245,12 @@ static void v4l2_request_hevc_fill_slice_params(const HEVCContext *h, +@@ -270,9 +273,12 @@ static void v4l2_request_hevc_fill_slice_params(const HEVCContext *h, static void fill_sps(struct v4l2_ctrl_hevc_sps *ctrl, const HEVCContext *h) { const HEVCSPS *sps = h->ps.sps; @@ -4942,18 +4852,18 @@ index 116a69340af3..eb493b309fe9 100644 *ctrl = (struct v4l2_ctrl_hevc_sps) { + .video_parameter_set_id = sps->vps_id, + .seq_parameter_set_id = pps->sps_id, - .chroma_format_idc = sps->chroma_format_idc, .pic_width_in_luma_samples = sps->width, .pic_height_in_luma_samples = sps->height, -@@ -303,6 +309,7 @@ static int v4l2_request_hevc_start_frame(AVCodecContext *avctx, - const HEVCContext *h = avctx->priv_data; - const HEVCSPS *sps = h->ps.sps; - const HEVCPPS *pps = h->ps.pps; -+ const SliceHeader *sh = &h->sh; - const ScalingList *sl = pps->scaling_list_data_present_flag ? + .bit_depth_luma_minus8 = sps->bit_depth - 8, +@@ -336,6 +342,7 @@ static int v4l2_request_hevc_start_frame(AVCodecContext *avctx, &pps->scaling_list : sps->scaling_list_enable_flag ? -@@ -329,6 +336,9 @@ static int v4l2_request_hevc_start_frame(AVCodecContext *avctx, + &sps->scaling_list : NULL; ++ const SliceHeader *sh = &h->sh; + V4L2RequestControlsHEVC *controls = h->ref->hwaccel_picture_private; + + fill_sps(&controls->sps, h); +@@ -359,6 +366,9 @@ static int v4l2_request_hevc_start_frame(AVCodecContext *avctx, /* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */ controls->pps = (struct v4l2_ctrl_hevc_pps) { @@ -4961,9 +4871,9 @@ index 116a69340af3..eb493b309fe9 100644 + .num_ref_idx_l0_default_active_minus1 = pps->num_ref_idx_l0_default_active - 1, + .num_ref_idx_l1_default_active_minus1 = pps->num_ref_idx_l1_default_active - 1, .num_extra_slice_header_bits = pps->num_extra_slice_header_bits, - .init_qp_minus26 = pps->pic_init_qp_minus26, - .diff_cu_qp_delta_depth = pps->diff_cu_qp_delta_depth, -@@ -445,6 +455,8 @@ static int v4l2_request_hevc_queue_decode(AVCodecContext *avctx, int last_slice) + .num_ref_idx_l0_default_active_minus1 = pps->num_ref_idx_l0_default_active - 1, + .num_ref_idx_l1_default_active_minus1 = pps->num_ref_idx_l1_default_active - 1, +@@ -488,6 +498,8 @@ static int v4l2_request_hevc_queue_decode(AVCodecContext *avctx, int last_slice) if (ctx->decode_mode == V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_SLICE_BASED) return ff_v4l2_request_decode_slice(avctx, h->ref->frame, control, FF_ARRAY_ELEMS(control), controls->first_slice, last_slice);