示例#1
0
/** Fill in VA API reference frames array. */
static int fill_vaapi_ReferenceFrames(VAPictureParameterBufferH264 *pic_param,
                                      const H264Context            *h)
{
    DPB dpb;
    int i;

    dpb.size     = 0;
    dpb.max_size = FF_ARRAY_ELEMS(pic_param->ReferenceFrames);
    dpb.va_pics  = pic_param->ReferenceFrames;
    for (i = 0; i < dpb.max_size; i++)
        init_vaapi_pic(&dpb.va_pics[i]);

    for (i = 0; i < h->short_ref_count; i++) {
        const H264Picture *pic = h->short_ref[i];
        if (pic && pic->reference && dpb_add(&dpb, pic) < 0)
            return -1;
    }

    for (i = 0; i < 16; i++) {
        const H264Picture *pic = h->long_ref[i];
        if (pic && pic->reference && dpb_add(&dpb, pic) < 0)
            return -1;
    }
    return 0;
}
示例#2
0
文件: cuvid_h264.c 项目: libav/libav
static int cuvid_h264_start_frame(AVCodecContext *avctx,
                                  const uint8_t *buffer, uint32_t size)
{
    const H264Context *h = avctx->priv_data;
    const PPS *pps = h->ps.pps;
    const SPS *sps = h->ps.sps;

    CUVIDContext       *ctx = avctx->internal->hwaccel_priv_data;
    CUVIDPICPARAMS      *pp = &ctx->pic_params;
    CUVIDH264PICPARAMS *ppc = &pp->CodecSpecific.h264;
    FrameDecodeData *fdd;
    CUVIDFrame *cf;

    int i, dpb_size, ret;

    ret = ff_cuvid_start_frame(avctx, h->cur_pic_ptr->f);
    if (ret < 0)
        return ret;

    fdd = (FrameDecodeData*)h->cur_pic_ptr->f->opaque_ref->data;
    cf  = (CUVIDFrame*)fdd->hwaccel_priv;

    *pp = (CUVIDPICPARAMS) {
        .PicWidthInMbs     = h->mb_width,
        .FrameHeightInMbs  = h->mb_height,
        .CurrPicIdx        = cf->idx,
        .field_pic_flag    = FIELD_PICTURE(h),
        .bottom_field_flag = h->picture_structure == PICT_BOTTOM_FIELD,
        .second_field      = FIELD_PICTURE(h) && !h->first_field,
        .ref_pic_flag      = h->nal_ref_idc != 0,
        .intra_pic_flag    = 0,

        .CodecSpecific.h264 = {
            .log2_max_frame_num_minus4            = sps->log2_max_frame_num - 4,
            .pic_order_cnt_type                   = sps->poc_type,
            .log2_max_pic_order_cnt_lsb_minus4    = FFMAX(sps->log2_max_poc_lsb - 4, 0),
            .delta_pic_order_always_zero_flag     = sps->delta_pic_order_always_zero_flag,
            .frame_mbs_only_flag                  = sps->frame_mbs_only_flag,
            .direct_8x8_inference_flag            = sps->direct_8x8_inference_flag,
            .num_ref_frames                       = sps->ref_frame_count,
            .residual_colour_transform_flag       = sps->residual_color_transform_flag,
            .bit_depth_luma_minus8                = sps->bit_depth_luma - 8,
            .bit_depth_chroma_minus8              = sps->bit_depth_chroma - 8,
            .qpprime_y_zero_transform_bypass_flag = sps->transform_bypass,

            .entropy_coding_mode_flag               = pps->cabac,
            .pic_order_present_flag                 = pps->pic_order_present,
            .num_ref_idx_l0_active_minus1           = pps->ref_count[0] - 1,
            .num_ref_idx_l1_active_minus1           = pps->ref_count[1] - 1,
            .weighted_pred_flag                     = pps->weighted_pred,
            .weighted_bipred_idc                    = pps->weighted_bipred_idc,
            .pic_init_qp_minus26                    = pps->init_qp - 26,
            .deblocking_filter_control_present_flag = pps->deblocking_filter_parameters_present,
            .redundant_pic_cnt_present_flag         = pps->redundant_pic_cnt_present,
            .transform_8x8_mode_flag                = pps->transform_8x8_mode,
            .MbaffFrameFlag                         = sps->mb_aff && !FIELD_PICTURE(h),
            .constrained_intra_pred_flag            = pps->constrained_intra_pred,
            .chroma_qp_index_offset                 = pps->chroma_qp_index_offset[0],
            .second_chroma_qp_index_offset          = pps->chroma_qp_index_offset[1],
            .ref_pic_flag                           = h->nal_ref_idc != 0,
            .frame_num                              = h->poc.frame_num,
            .CurrFieldOrderCnt[0]                   = h->cur_pic_ptr->field_poc[0],
            .CurrFieldOrderCnt[1]                   = h->cur_pic_ptr->field_poc[1],
        },
    };

    memcpy(ppc->WeightScale4x4,    pps->scaling_matrix4,    sizeof(ppc->WeightScale4x4));
    memcpy(ppc->WeightScale8x8[0], pps->scaling_matrix8[0], sizeof(ppc->WeightScale8x8[0]));
    memcpy(ppc->WeightScale8x8[1], pps->scaling_matrix8[3], sizeof(ppc->WeightScale8x8[0]));

    dpb_size = 0;
    for (i = 0; i < h->short_ref_count; i++)
        dpb_add(h, &ppc->dpb[dpb_size++], h->short_ref[i], h->short_ref[i]->frame_num);
    for (i = 0; i < 16; i++) {
        if (h->long_ref[i])
            dpb_add(h, &ppc->dpb[dpb_size++], h->long_ref[i], i);
    }

    for (i = dpb_size; i < FF_ARRAY_ELEMS(ppc->dpb); i++)
        ppc->dpb[i].PicIdx = -1;

    return 0;
}
示例#3
0
文件: cuvid_hevc.c 项目: libav/libav
static int cuvid_hevc_start_frame(AVCodecContext *avctx,
                                  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;

    CUVIDContext       *ctx = avctx->internal->hwaccel_priv_data;
    CUVIDPICPARAMS      *pp = &ctx->pic_params;
    CUVIDHEVCPICPARAMS *ppc = &pp->CodecSpecific.hevc;
    FrameDecodeData *fdd;
    CUVIDFrame *cf;

    int i, j, dpb_size, ret;

    ret = ff_cuvid_start_frame(avctx, s->ref->frame);
    if (ret < 0)
        return ret;

    fdd = (FrameDecodeData*)s->ref->frame->opaque_ref->data;
    cf  = (CUVIDFrame*)fdd->hwaccel_priv;

    *pp = (CUVIDPICPARAMS) {
        .PicWidthInMbs     = sps->width  / 16,
        .FrameHeightInMbs  = sps->height / 16,
        .CurrPicIdx        = cf->idx,
        .ref_pic_flag      = 1,
        .intra_pic_flag    = 0,

        .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,
            .pcm_enabled_flag                             = sps->pcm_enabled_flag,
            .log2_min_pcm_luma_coding_block_size_minus3   = sps->pcm_enabled_flag ? sps->pcm.log2_min_pcm_cb_size - 3 : 0,
            .log2_diff_max_min_pcm_luma_coding_block_size = sps->pcm.log2_max_pcm_cb_size - sps->pcm.log2_min_pcm_cb_size,
            .pcm_sample_bit_depth_luma_minus1             = sps->pcm_enabled_flag ? sps->pcm.bit_depth - 1 : 0,
            .pcm_sample_bit_depth_chroma_minus1           = sps->pcm_enabled_flag ? sps->pcm.bit_depth_chroma - 1 : 0,
            .pcm_loop_filter_disabled_flag                = sps->pcm.loop_filter_disable_flag,
            .strong_intra_smoothing_enabled_flag          = sps->sps_strong_intra_smoothing_enable_flag,
            .max_transform_hierarchy_depth_intra          = sps->max_transform_hierarchy_depth_intra,
            .max_transform_hierarchy_depth_inter          = sps->max_transform_hierarchy_depth_inter,
            .amp_enabled_flag                             = sps->amp_enabled_flag,
            .separate_colour_plane_flag                   = sps->separate_colour_plane_flag,
            .log2_max_pic_order_cnt_lsb_minus4            = sps->log2_max_poc_lsb - 4,
            .num_short_term_ref_pic_sets                  = sps->nb_st_rps,
            .long_term_ref_pics_present_flag              = sps->long_term_ref_pics_present_flag,
            .num_long_term_ref_pics_sps                   = sps->num_long_term_ref_pics_sps,
            .sps_temporal_mvp_enabled_flag                = sps->sps_temporal_mvp_enabled_flag,
            .sample_adaptive_offset_enabled_flag          = sps->sao_enabled,
            .scaling_list_enable_flag                     = sps->scaling_list_enable_flag,
            .IrapPicFlag                                  = IS_IRAP(s),
            .IdrPicFlag                                   = IS_IDR(s),
            .bit_depth_luma_minus8                        = sps->bit_depth - 8,
            .bit_depth_chroma_minus8                      = sps->bit_depth - 8,

            .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,

            .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,
            .NumPocTotalCurr                              = s->rps[ST_CURR_BEF].nb_refs + s->rps[ST_CURR_AFT].nb_refs +
                                                            s->rps[LT_CURR].nb_refs,
            .NumPocStCurrBefore                           = s->rps[ST_CURR_BEF].nb_refs,
            .NumPocStCurrAfter                            = s->rps[ST_CURR_AFT].nb_refs,
            .NumPocLtCurr                                 = s->rps[LT_CURR].nb_refs,
            .CurrPicOrderCntVal                           = s->ref->poc,
        },
    };

    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;

    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;
}