2017-02-11 17:49:34 +02:00
|
|
|
/*
|
2017-11-11 01:38:36 +02:00
|
|
|
* HEVC HW decode acceleration through NVDEC
|
2017-02-11 17:49:34 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Anton Khirnov
|
|
|
|
*
|
2017-11-11 02:06:58 +02:00
|
|
|
* This file is part of FFmpeg.
|
2017-02-11 17:49:34 +02:00
|
|
|
*
|
2017-11-11 02:06:58 +02:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2017-02-11 17:49:34 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2017-11-11 02:06:58 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2017-02-11 17:49:34 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2017-11-11 02:06:58 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2017-02-11 17:49:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2024-03-25 02:30:37 +02:00
|
|
|
#include "libavutil/mem.h"
|
2017-02-11 17:49:34 +02:00
|
|
|
#include "avcodec.h"
|
2017-11-11 01:38:36 +02:00
|
|
|
#include "nvdec.h"
|
2017-02-11 17:49:34 +02:00
|
|
|
#include "decode.h"
|
|
|
|
#include "internal.h"
|
2024-05-29 09:50:48 +02:00
|
|
|
#include "hevc/hevcdec.h"
|
|
|
|
#include "hevc/data.h"
|
2023-08-01 19:44:22 +02:00
|
|
|
#include "hwaccel_internal.h"
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
static void dpb_add(CUVIDHEVCPICPARAMS *pp, int idx, const HEVCFrame *src)
|
|
|
|
{
|
2024-05-29 08:38:27 +02:00
|
|
|
FrameDecodeData *fdd = (FrameDecodeData*)src->f->private_ref->data;
|
2017-11-11 01:38:36 +02:00
|
|
|
const NVDECFrame *cf = fdd->hwaccel_priv;
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
pp->RefPicIdx[idx] = cf ? cf->idx : -1;
|
|
|
|
pp->PicOrderCntVal[idx] = src->poc;
|
|
|
|
pp->IsLongTerm[idx] = !!(src->flags & HEVC_FRAME_FLAG_LONG_REF);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fill_scaling_lists(CUVIDHEVCPICPARAMS *ppc, const HEVCContext *s)
|
|
|
|
{
|
|
|
|
const ScalingList *sl = s->ps.pps->scaling_list_data_present_flag ?
|
|
|
|
&s->ps.pps->scaling_list : &s->ps.sps->scaling_list;
|
|
|
|
int i, j, pos;
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
pos = 4 * ff_hevc_diag_scan4x4_y[j] + ff_hevc_diag_scan4x4_x[j];
|
|
|
|
ppc->ScalingList4x4[i][j] = sl->sl[0][i][pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < 64; j++) {
|
|
|
|
pos = 8 * ff_hevc_diag_scan8x8_y[j] + ff_hevc_diag_scan8x8_x[j];
|
|
|
|
ppc->ScalingList8x8[i][j] = sl->sl[1][i][pos];
|
|
|
|
ppc->ScalingList16x16[i][j] = sl->sl[2][i][pos];
|
|
|
|
|
|
|
|
if (i < 2)
|
2018-05-10 03:48:59 +02:00
|
|
|
ppc->ScalingList32x32[i][j] = sl->sl[3][i * 3][pos];
|
2017-02-11 17:49:34 +02:00
|
|
|
}
|
|
|
|
|
2018-05-10 03:48:59 +02:00
|
|
|
ppc->ScalingListDCCoeff16x16[i] = sl->sl_dc[0][i];
|
|
|
|
if (i < 2)
|
|
|
|
ppc->ScalingListDCCoeff32x32[i] = sl->sl_dc[1][i * 3];
|
|
|
|
}
|
2017-02-11 17:49:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-11 01:38:36 +02:00
|
|
|
static int nvdec_hevc_start_frame(AVCodecContext *avctx,
|
2017-02-11 17:49:34 +02:00
|
|
|
const uint8_t *buffer, uint32_t size)
|
|
|
|
{
|
|
|
|
const HEVCContext *s = avctx->priv_data;
|
|
|
|
const HEVCPPS *pps = s->ps.pps;
|
|
|
|
const HEVCSPS *sps = s->ps.sps;
|
|
|
|
|
2017-11-11 01:38:36 +02:00
|
|
|
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
|
2017-02-11 17:49:34 +02:00
|
|
|
CUVIDPICPARAMS *pp = &ctx->pic_params;
|
|
|
|
CUVIDHEVCPICPARAMS *ppc = &pp->CodecSpecific.hevc;
|
|
|
|
FrameDecodeData *fdd;
|
2017-11-11 01:38:36 +02:00
|
|
|
NVDECFrame *cf;
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
int i, j, dpb_size, ret;
|
|
|
|
|
2024-05-29 08:38:27 +02:00
|
|
|
ret = ff_nvdec_start_frame(avctx, s->cur_frame->f);
|
2017-02-11 17:49:34 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2024-05-29 08:38:27 +02:00
|
|
|
fdd = (FrameDecodeData*)s->cur_frame->f->private_ref->data;
|
2017-11-11 01:38:36 +02:00
|
|
|
cf = (NVDECFrame*)fdd->hwaccel_priv;
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
*pp = (CUVIDPICPARAMS) {
|
|
|
|
.PicWidthInMbs = sps->width / 16,
|
|
|
|
.FrameHeightInMbs = sps->height / 16,
|
|
|
|
.CurrPicIdx = cf->idx,
|
|
|
|
.ref_pic_flag = 1,
|
2018-04-13 19:39:24 +02:00
|
|
|
.intra_pic_flag = IS_IRAP(s),
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
.CodecSpecific.hevc = {
|
|
|
|
.pic_width_in_luma_samples = sps->width,
|
|
|
|
.pic_height_in_luma_samples = sps->height,
|
|
|
|
.log2_min_luma_coding_block_size_minus3 = sps->log2_min_cb_size - 3,
|
|
|
|
.log2_diff_max_min_luma_coding_block_size = sps->log2_diff_max_min_coding_block_size,
|
|
|
|
.log2_min_transform_block_size_minus2 = sps->log2_min_tb_size - 2,
|
|
|
|
.log2_diff_max_min_transform_block_size = sps->log2_max_trafo_size - sps->log2_min_tb_size,
|
2024-04-10 12:28:09 +02:00
|
|
|
.pcm_enabled_flag = sps->pcm_enabled,
|
|
|
|
.log2_min_pcm_luma_coding_block_size_minus3 = sps->pcm_enabled ? sps->pcm.log2_min_pcm_cb_size - 3 : 0,
|
2017-02-11 17:49:34 +02:00
|
|
|
.log2_diff_max_min_pcm_luma_coding_block_size = sps->pcm.log2_max_pcm_cb_size - sps->pcm.log2_min_pcm_cb_size,
|
2024-04-10 12:28:09 +02:00
|
|
|
.pcm_sample_bit_depth_luma_minus1 = sps->pcm_enabled ? sps->pcm.bit_depth - 1 : 0,
|
|
|
|
.pcm_sample_bit_depth_chroma_minus1 = sps->pcm_enabled ? sps->pcm.bit_depth_chroma - 1 : 0,
|
2018-04-13 09:36:49 +02:00
|
|
|
#if NVDECAPI_CHECK_VERSION(8, 1)
|
2018-04-11 13:47:27 +02:00
|
|
|
.log2_max_transform_skip_block_size_minus2 = pps->log2_max_transform_skip_block_size - 2,
|
|
|
|
.log2_sao_offset_scale_luma = pps->log2_sao_offset_scale_luma,
|
|
|
|
.log2_sao_offset_scale_chroma = pps->log2_sao_offset_scale_chroma,
|
2024-04-10 12:28:09 +02:00
|
|
|
.high_precision_offsets_enabled_flag = sps->high_precision_offsets_enabled,
|
2018-04-11 13:47:27 +02:00
|
|
|
#endif
|
2024-04-10 12:28:09 +02:00
|
|
|
.pcm_loop_filter_disabled_flag = sps->pcm_loop_filter_disabled,
|
|
|
|
.strong_intra_smoothing_enabled_flag = sps->strong_intra_smoothing_enabled,
|
2017-02-11 17:49:34 +02:00
|
|
|
.max_transform_hierarchy_depth_intra = sps->max_transform_hierarchy_depth_intra,
|
|
|
|
.max_transform_hierarchy_depth_inter = sps->max_transform_hierarchy_depth_inter,
|
2024-04-10 12:28:09 +02:00
|
|
|
.amp_enabled_flag = sps->amp_enabled,
|
|
|
|
.separate_colour_plane_flag = sps->separate_colour_plane,
|
2017-02-11 17:49:34 +02:00
|
|
|
.log2_max_pic_order_cnt_lsb_minus4 = sps->log2_max_poc_lsb - 4,
|
|
|
|
.num_short_term_ref_pic_sets = sps->nb_st_rps,
|
2024-04-10 12:28:09 +02:00
|
|
|
.long_term_ref_pics_present_flag = sps->long_term_ref_pics_present,
|
2017-02-11 17:49:34 +02:00
|
|
|
.num_long_term_ref_pics_sps = sps->num_long_term_ref_pics_sps,
|
2024-04-10 12:28:09 +02:00
|
|
|
.sps_temporal_mvp_enabled_flag = sps->temporal_mvp_enabled,
|
2017-02-11 17:49:34 +02:00
|
|
|
.sample_adaptive_offset_enabled_flag = sps->sao_enabled,
|
2024-04-10 12:28:09 +02:00
|
|
|
.scaling_list_enable_flag = sps->scaling_list_enabled,
|
2017-02-11 17:49:34 +02:00
|
|
|
.IrapPicFlag = IS_IRAP(s),
|
|
|
|
.IdrPicFlag = IS_IDR(s),
|
|
|
|
.bit_depth_luma_minus8 = sps->bit_depth - 8,
|
|
|
|
.bit_depth_chroma_minus8 = sps->bit_depth - 8,
|
2018-10-07 03:11:52 +02:00
|
|
|
#if NVDECAPI_CHECK_VERSION(9, 0)
|
2024-04-10 12:28:09 +02:00
|
|
|
.sps_range_extension_flag = sps->range_extension,
|
|
|
|
.transform_skip_rotation_enabled_flag = sps->transform_skip_rotation_enabled,
|
|
|
|
.transform_skip_context_enabled_flag = sps->transform_skip_context_enabled,
|
|
|
|
.implicit_rdpcm_enabled_flag = sps->implicit_rdpcm_enabled,
|
|
|
|
.explicit_rdpcm_enabled_flag = sps->explicit_rdpcm_enabled,
|
|
|
|
.extended_precision_processing_flag = sps->extended_precision_processing,
|
|
|
|
.intra_smoothing_disabled_flag = sps->intra_smoothing_disabled,
|
|
|
|
.persistent_rice_adaptation_enabled_flag = sps->persistent_rice_adaptation_enabled,
|
|
|
|
.cabac_bypass_alignment_enabled_flag = sps->cabac_bypass_alignment_enabled,
|
2018-10-07 03:11:52 +02:00
|
|
|
#endif
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
.dependent_slice_segments_enabled_flag = pps->dependent_slice_segments_enabled_flag,
|
|
|
|
.slice_segment_header_extension_present_flag = pps->slice_header_extension_present_flag,
|
|
|
|
.sign_data_hiding_enabled_flag = pps->sign_data_hiding_flag,
|
|
|
|
.cu_qp_delta_enabled_flag = pps->cu_qp_delta_enabled_flag,
|
|
|
|
.diff_cu_qp_delta_depth = pps->diff_cu_qp_delta_depth,
|
|
|
|
.init_qp_minus26 = pps->pic_init_qp_minus26,
|
|
|
|
.pps_cb_qp_offset = pps->cb_qp_offset,
|
|
|
|
.pps_cr_qp_offset = pps->cr_qp_offset,
|
|
|
|
.constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
|
|
|
|
.weighted_pred_flag = pps->weighted_pred_flag,
|
|
|
|
.weighted_bipred_flag = pps->weighted_bipred_flag,
|
|
|
|
.transform_skip_enabled_flag = pps->transform_skip_enabled_flag,
|
|
|
|
.transquant_bypass_enabled_flag = pps->transquant_bypass_enable_flag,
|
|
|
|
.entropy_coding_sync_enabled_flag = pps->entropy_coding_sync_enabled_flag,
|
|
|
|
.log2_parallel_merge_level_minus2 = pps->log2_parallel_merge_level - 2,
|
|
|
|
.num_extra_slice_header_bits = pps->num_extra_slice_header_bits,
|
|
|
|
.loop_filter_across_tiles_enabled_flag = pps->loop_filter_across_tiles_enabled_flag,
|
|
|
|
.loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag,
|
|
|
|
.output_flag_present_flag = pps->output_flag_present_flag,
|
|
|
|
.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,
|
|
|
|
.lists_modification_present_flag = pps->lists_modification_present_flag,
|
|
|
|
.cabac_init_present_flag = pps->cabac_init_present_flag,
|
|
|
|
.pps_slice_chroma_qp_offsets_present_flag = pps->pic_slice_level_chroma_qp_offsets_present_flag,
|
|
|
|
.deblocking_filter_override_enabled_flag = pps->deblocking_filter_override_enabled_flag,
|
|
|
|
.pps_deblocking_filter_disabled_flag = pps->disable_dbf,
|
|
|
|
.pps_beta_offset_div2 = pps->beta_offset / 2,
|
|
|
|
.pps_tc_offset_div2 = pps->tc_offset / 2,
|
|
|
|
.tiles_enabled_flag = pps->tiles_enabled_flag,
|
|
|
|
.uniform_spacing_flag = pps->uniform_spacing_flag,
|
|
|
|
.num_tile_columns_minus1 = pps->num_tile_columns - 1,
|
|
|
|
.num_tile_rows_minus1 = pps->num_tile_rows - 1,
|
2018-10-07 03:11:52 +02:00
|
|
|
#if NVDECAPI_CHECK_VERSION(9, 0)
|
|
|
|
.pps_range_extension_flag = pps->pps_range_extensions_flag,
|
|
|
|
.cross_component_prediction_enabled_flag = pps->cross_component_prediction_enabled_flag,
|
|
|
|
.chroma_qp_offset_list_enabled_flag = pps->chroma_qp_offset_list_enabled_flag,
|
|
|
|
.diff_cu_chroma_qp_offset_depth = pps->diff_cu_chroma_qp_offset_depth,
|
|
|
|
.chroma_qp_offset_list_len_minus1 = pps->chroma_qp_offset_list_len_minus1,
|
|
|
|
#endif
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
.NumBitsForShortTermRPSInSlice = s->sh.short_term_rps ? s->sh.short_term_ref_pic_set_size : 0,
|
|
|
|
.NumDeltaPocsOfRefRpsIdx = s->sh.short_term_rps ? s->sh.short_term_rps->rps_idx_num_delta_pocs : 0,
|
2018-05-10 03:48:59 +02:00
|
|
|
.NumPocTotalCurr = ff_hevc_frame_nb_refs(s),
|
2017-02-11 17:49:34 +02:00
|
|
|
.NumPocStCurrBefore = s->rps[ST_CURR_BEF].nb_refs,
|
|
|
|
.NumPocStCurrAfter = s->rps[ST_CURR_AFT].nb_refs,
|
|
|
|
.NumPocLtCurr = s->rps[LT_CURR].nb_refs,
|
2024-05-29 08:38:27 +02:00
|
|
|
.CurrPicOrderCntVal = s->cur_frame->poc,
|
2017-02-11 17:49:34 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (pps->num_tile_columns > FF_ARRAY_ELEMS(ppc->column_width_minus1) ||
|
|
|
|
pps->num_tile_rows > FF_ARRAY_ELEMS(ppc->row_height_minus1)) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Too many tiles\n");
|
|
|
|
return AVERROR(ENOSYS);
|
|
|
|
}
|
|
|
|
for (i = 0; i < pps->num_tile_columns; i++)
|
|
|
|
ppc->column_width_minus1[i] = pps->column_width[i] - 1;
|
|
|
|
for (i = 0; i < pps->num_tile_rows; i++)
|
|
|
|
ppc->row_height_minus1[i] = pps->row_height[i] - 1;
|
|
|
|
|
2018-10-07 03:11:52 +02:00
|
|
|
#if NVDECAPI_CHECK_VERSION(9, 0)
|
2022-08-06 07:55:14 +02:00
|
|
|
if (pps->chroma_qp_offset_list_len_minus1 >= FF_ARRAY_ELEMS(ppc->cb_qp_offset_list) ||
|
|
|
|
pps->chroma_qp_offset_list_len_minus1 >= FF_ARRAY_ELEMS(ppc->cr_qp_offset_list)) {
|
2018-10-07 03:11:52 +02:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Too many chroma_qp_offsets\n");
|
|
|
|
return AVERROR(ENOSYS);
|
|
|
|
}
|
|
|
|
for (i = 0; i <= pps->chroma_qp_offset_list_len_minus1; i++) {
|
|
|
|
ppc->cb_qp_offset_list[i] = pps->cb_qp_offset_list[i];
|
|
|
|
ppc->cr_qp_offset_list[i] = pps->cr_qp_offset_list[i];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-02-11 17:49:34 +02:00
|
|
|
if (s->rps[LT_CURR].nb_refs > FF_ARRAY_ELEMS(ppc->RefPicSetLtCurr) ||
|
|
|
|
s->rps[ST_CURR_BEF].nb_refs > FF_ARRAY_ELEMS(ppc->RefPicSetStCurrBefore) ||
|
|
|
|
s->rps[ST_CURR_AFT].nb_refs > FF_ARRAY_ELEMS(ppc->RefPicSetStCurrAfter)) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Too many reference frames\n");
|
|
|
|
return AVERROR(ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
dpb_size = 0;
|
|
|
|
for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
|
|
|
|
const HEVCFrame *ref = &s->DPB[i];
|
|
|
|
if (!(ref->flags & (HEVC_FRAME_FLAG_SHORT_REF | HEVC_FRAME_FLAG_LONG_REF)))
|
|
|
|
continue;
|
|
|
|
if (dpb_size >= FF_ARRAY_ELEMS(ppc->RefPicIdx)) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Too many reference frames\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
dpb_add(ppc, dpb_size++, ref);
|
|
|
|
|
|
|
|
}
|
|
|
|
for (i = dpb_size; i < FF_ARRAY_ELEMS(ppc->RefPicIdx); i++)
|
|
|
|
ppc->RefPicIdx[i] = -1;
|
|
|
|
|
|
|
|
for (i = 0; i < s->rps[ST_CURR_BEF].nb_refs; i++) {
|
|
|
|
for (j = 0; j < dpb_size; j++) {
|
|
|
|
if (ppc->PicOrderCntVal[j] == s->rps[ST_CURR_BEF].list[i]) {
|
|
|
|
ppc->RefPicSetStCurrBefore[i] = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < s->rps[ST_CURR_AFT].nb_refs; i++) {
|
|
|
|
for (j = 0; j < dpb_size; j++) {
|
|
|
|
if (ppc->PicOrderCntVal[j] == s->rps[ST_CURR_AFT].list[i]) {
|
|
|
|
ppc->RefPicSetStCurrAfter[i] = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < s->rps[LT_CURR].nb_refs; i++) {
|
|
|
|
for (j = 0; j < dpb_size; j++) {
|
|
|
|
if (ppc->PicOrderCntVal[j] == s->rps[LT_CURR].list[i]) {
|
|
|
|
ppc->RefPicSetLtCurr[i] = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fill_scaling_lists(ppc, s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-11 01:38:36 +02:00
|
|
|
static int nvdec_hevc_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
|
2017-02-11 17:49:34 +02:00
|
|
|
uint32_t size)
|
|
|
|
{
|
2017-11-11 01:38:36 +02:00
|
|
|
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
|
2017-02-11 17:49:34 +02:00
|
|
|
void *tmp;
|
|
|
|
|
2024-02-07 00:50:33 +02:00
|
|
|
tmp = av_fast_realloc(ctx->bitstream_internal, &ctx->bitstream_allocated,
|
2017-02-11 17:49:34 +02:00
|
|
|
ctx->bitstream_len + size + 3);
|
|
|
|
if (!tmp)
|
|
|
|
return AVERROR(ENOMEM);
|
2024-02-07 00:50:33 +02:00
|
|
|
ctx->bitstream = ctx->bitstream_internal = tmp;
|
2017-02-11 17:49:34 +02:00
|
|
|
|
|
|
|
tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated,
|
|
|
|
(ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets));
|
|
|
|
if (!tmp)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
ctx->slice_offsets = tmp;
|
|
|
|
|
2024-02-07 17:01:04 +02:00
|
|
|
AV_WB24(ctx->bitstream_internal + ctx->bitstream_len, 1);
|
|
|
|
memcpy(ctx->bitstream_internal + ctx->bitstream_len + 3, buffer, size);
|
2017-02-11 17:49:34 +02:00
|
|
|
ctx->slice_offsets[ctx->nb_slices] = ctx->bitstream_len ;
|
|
|
|
ctx->bitstream_len += size + 3;
|
|
|
|
ctx->nb_slices++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-28 19:53:38 +02:00
|
|
|
static int nvdec_hevc_frame_params(AVCodecContext *avctx,
|
|
|
|
AVBufferRef *hw_frames_ctx)
|
2017-02-11 17:49:34 +02:00
|
|
|
{
|
|
|
|
const HEVCContext *s = avctx->priv_data;
|
|
|
|
const HEVCSPS *sps = s->ps.sps;
|
2018-10-07 05:20:58 +02:00
|
|
|
return ff_nvdec_frame_params(avctx, hw_frames_ctx, sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering + 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nvdec_hevc_decode_init(AVCodecContext *avctx) {
|
|
|
|
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
|
|
|
|
ctx->supports_444 = 1;
|
2023-10-10 17:34:47 +02:00
|
|
|
|
|
|
|
if (avctx->profile != AV_PROFILE_HEVC_MAIN &&
|
|
|
|
avctx->profile != AV_PROFILE_HEVC_MAIN_10 &&
|
|
|
|
avctx->profile != AV_PROFILE_HEVC_MAIN_STILL_PICTURE &&
|
|
|
|
avctx->profile != AV_PROFILE_HEVC_REXT) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Unsupported HEVC profile: %d\n", avctx->profile);
|
|
|
|
return AVERROR(ENOTSUP);
|
|
|
|
}
|
|
|
|
|
2018-10-07 05:20:58 +02:00
|
|
|
return ff_nvdec_decode_init(avctx);
|
2017-02-11 17:49:34 +02:00
|
|
|
}
|
|
|
|
|
2023-08-01 19:44:22 +02:00
|
|
|
const FFHWAccel ff_hevc_nvdec_hwaccel = {
|
|
|
|
.p.name = "hevc_nvdec",
|
|
|
|
.p.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.p.id = AV_CODEC_ID_HEVC,
|
|
|
|
.p.pix_fmt = AV_PIX_FMT_CUDA,
|
2017-11-11 01:38:36 +02:00
|
|
|
.start_frame = nvdec_hevc_start_frame,
|
|
|
|
.end_frame = ff_nvdec_end_frame,
|
|
|
|
.decode_slice = nvdec_hevc_decode_slice,
|
2017-10-28 19:53:38 +02:00
|
|
|
.frame_params = nvdec_hevc_frame_params,
|
2018-10-07 05:20:58 +02:00
|
|
|
.init = nvdec_hevc_decode_init,
|
2017-11-11 01:38:36 +02:00
|
|
|
.uninit = ff_nvdec_decode_uninit,
|
|
|
|
.priv_data_size = sizeof(NVDECContext),
|
2017-02-11 17:49:34 +02:00
|
|
|
};
|