Ejemplo n.º 1
0
/**
 * Append picture to the decoded picture buffer, in a VA API form that
 * merges the second field picture attributes with the first, if
 * available.  The decoded picture buffer's size must be large enough
 * to receive the new VA API picture object.
 */
static int dpb_add(DPB *dpb, const H264Picture *pic)
{
    int i;

    if (dpb->size >= dpb->max_size)
        return -1;

    for (i = 0; i < dpb->size; i++) {
        VAPictureH264 * const va_pic = &dpb->va_pics[i];
        if (va_pic->picture_id == ff_vaapi_get_surface_id(pic->f)) {
            VAPictureH264 temp_va_pic;
            fill_vaapi_pic(&temp_va_pic, pic, 0);

            if ((temp_va_pic.flags ^ va_pic->flags) & (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD)) {
                va_pic->flags |= temp_va_pic.flags & (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD);
                /* Merge second field */
                if (temp_va_pic.flags & VA_PICTURE_H264_TOP_FIELD) {
                    va_pic->TopFieldOrderCnt    = temp_va_pic.TopFieldOrderCnt;
                } else {
                    va_pic->BottomFieldOrderCnt = temp_va_pic.BottomFieldOrderCnt;
                }
            }
            return 0;
        }
    }

    fill_vaapi_pic(&dpb->va_pics[dpb->size++], pic, 0);
    return 0;
}
Ejemplo n.º 2
0
/**
 * Fill in VA API reference picture lists from the Libav reference
 * picture list.
 *
 * @param[out] RefPicList  VA API internal reference picture list
 * @param[in]  ref_list    A pointer to the Libav reference list
 * @param[in]  ref_count   The number of reference pictures in ref_list
 */
static void fill_vaapi_RefPicList(VAPictureH264 RefPicList[32],
                                  const H264Ref *ref_list,
                                  unsigned int  ref_count)
{
    unsigned int i, n = 0;
    for (i = 0; i < ref_count; i++)
        if (ref_list[i].reference)
            fill_vaapi_pic(&RefPicList[n++], ref_list[i].parent, 0);

    for (; n < 32; n++)
        init_vaapi_pic(&RefPicList[n]);
}
Ejemplo n.º 3
0
static void fill_vaapi_ReferenceFrames(const HEVCContext *h, VAPictureParameterBufferHEVC *pp)
{
    const HEVCFrame *current_picture = h->ref;
    int i, j, rps_type;

    for (i = 0, j = 0; i < FF_ARRAY_ELEMS(pp->ReferenceFrames); i++) {
        const HEVCFrame *frame = NULL;

        while (!frame && j < FF_ARRAY_ELEMS(h->DPB)) {
            if (&h->DPB[j] != current_picture && (h->DPB[j].flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF)))
                frame = &h->DPB[j];
            j++;
        }

        init_vaapi_pic(&pp->ReferenceFrames[i]);

        if (frame) {
            rps_type = find_frame_rps_type(h, frame);
            fill_vaapi_pic(&pp->ReferenceFrames[i], frame, rps_type);
        }
    }
}
Ejemplo n.º 4
0
static void fill_picture_parameters(const HEVCContext *h, VAPictureParameterBufferHEVC *pp)
{
    int i;

    pp->pic_fields.value = 0;
    pp->slice_parsing_fields.value = 0;

    fill_vaapi_pic(&pp->CurrPic, h->ref, 0);
    fill_vaapi_ReferenceFrames(h, pp);

    pp->pic_width_in_luma_samples  = h->ps.sps->width;
    pp->pic_height_in_luma_samples = h->ps.sps->height;

    pp->log2_min_luma_coding_block_size_minus3 = h->ps.sps->log2_min_cb_size - 3;

    pp->pic_fields.bits.chroma_format_idc = h->ps.sps->chroma_format_idc;

    pp->sps_max_dec_pic_buffering_minus1 = h->ps.sps->temporal_layer[h->ps.sps->max_sub_layers - 1].max_dec_pic_buffering - 1;
    pp->log2_diff_max_min_luma_coding_block_size = h->ps.sps->log2_diff_max_min_coding_block_size;
    pp->log2_min_transform_block_size_minus2 = h->ps.sps->log2_min_tb_size - 2;
    pp->log2_diff_max_min_transform_block_size = h->ps.sps->log2_max_trafo_size  - h->ps.sps->log2_min_tb_size;
    pp->max_transform_hierarchy_depth_inter = h->ps.sps->max_transform_hierarchy_depth_inter;
    pp->max_transform_hierarchy_depth_intra = h->ps.sps->max_transform_hierarchy_depth_intra;
    pp->num_short_term_ref_pic_sets = h->ps.sps->nb_st_rps;
    pp->num_long_term_ref_pic_sps = h->ps.sps->num_long_term_ref_pics_sps;

    pp->num_ref_idx_l0_default_active_minus1 = h->ps.pps->num_ref_idx_l0_default_active - 1;
    pp->num_ref_idx_l1_default_active_minus1 = h->ps.pps->num_ref_idx_l1_default_active - 1;
    pp->init_qp_minus26 = h->ps.pps->pic_init_qp_minus26;

    pp->pps_cb_qp_offset = h->ps.pps->cb_qp_offset;
    pp->pps_cr_qp_offset = h->ps.pps->cr_qp_offset;

    pp->pic_fields.bits.tiles_enabled_flag = h->ps.pps->tiles_enabled_flag;
    pp->pic_fields.bits.separate_colour_plane_flag = h->ps.sps->separate_colour_plane_flag;
    pp->pic_fields.bits.pcm_enabled_flag = h->ps.sps->pcm_enabled_flag;
    pp->pic_fields.bits.scaling_list_enabled_flag = h->ps.sps->scaling_list_enable_flag;
    pp->pic_fields.bits.transform_skip_enabled_flag = h->ps.pps->transform_skip_enabled_flag;
    pp->pic_fields.bits.amp_enabled_flag = h->ps.sps->amp_enabled_flag;
    pp->pic_fields.bits.strong_intra_smoothing_enabled_flag = h->ps.sps->sps_strong_intra_smoothing_enable_flag;
    pp->pic_fields.bits.sign_data_hiding_enabled_flag = h->ps.pps->sign_data_hiding_flag;
    pp->pic_fields.bits.constrained_intra_pred_flag = h->ps.pps->constrained_intra_pred_flag;
    pp->pic_fields.bits.cu_qp_delta_enabled_flag = h->ps.pps->cu_qp_delta_enabled_flag;
    pp->pic_fields.bits.weighted_pred_flag = h->ps.pps->weighted_pred_flag;
    pp->pic_fields.bits.weighted_bipred_flag = h->ps.pps->weighted_bipred_flag;
    pp->pic_fields.bits.transquant_bypass_enabled_flag = h->ps.pps->transquant_bypass_enable_flag;
    pp->pic_fields.bits.entropy_coding_sync_enabled_flag = h->ps.pps->entropy_coding_sync_enabled_flag;
    pp->pic_fields.bits.pps_loop_filter_across_slices_enabled_flag = h->ps.pps->seq_loop_filter_across_slices_enabled_flag;
    pp->pic_fields.bits.loop_filter_across_tiles_enabled_flag = h->ps.pps->loop_filter_across_tiles_enabled_flag;

    pp->pic_fields.bits.pcm_loop_filter_disabled_flag = h->ps.sps->pcm.loop_filter_disable_flag;
    pp->pcm_sample_bit_depth_luma_minus1 = h->ps.sps->pcm.bit_depth - 1;
    pp->pcm_sample_bit_depth_chroma_minus1 = h->ps.sps->pcm.bit_depth_chroma - 1;
    pp->log2_min_pcm_luma_coding_block_size_minus3 = h->ps.sps->pcm.log2_min_pcm_cb_size - 3;
    pp->log2_diff_max_min_pcm_luma_coding_block_size = h->ps.sps->pcm.log2_max_pcm_cb_size - h->ps.sps->pcm.log2_min_pcm_cb_size;

    memset(pp->column_width_minus1, 0, sizeof(pp->column_width_minus1));
    memset(pp->row_height_minus1, 0, sizeof(pp->row_height_minus1));

    if (h->ps.pps->tiles_enabled_flag) {
        pp->num_tile_columns_minus1 = h->ps.pps->num_tile_columns - 1;
        pp->num_tile_rows_minus1 = h->ps.pps->num_tile_rows - 1;

        for (i = 0; i < h->ps.pps->num_tile_columns; i++)
            pp->column_width_minus1[i] = h->ps.pps->column_width[i] - 1;

        for (i = 0; i < h->ps.pps->num_tile_rows; i++)
            pp->row_height_minus1[i] = h->ps.pps->row_height[i] - 1;
    }

    pp->diff_cu_qp_delta_depth = h->ps.pps->diff_cu_qp_delta_depth;
    pp->pps_beta_offset_div2 = h->ps.pps->beta_offset / 2;
    pp->pps_tc_offset_div2 = h->ps.pps->tc_offset / 2;
    pp->log2_parallel_merge_level_minus2 = h->ps.pps->log2_parallel_merge_level - 2;

    /* Different chroma/luma bit depths are currently not supported by ffmpeg. */
    pp->bit_depth_luma_minus8 = h->ps.sps->bit_depth - 8;
    pp->bit_depth_chroma_minus8 = h->ps.sps->bit_depth - 8;

    pp->slice_parsing_fields.bits.lists_modification_present_flag = h->ps.pps->lists_modification_present_flag;
    pp->slice_parsing_fields.bits.long_term_ref_pics_present_flag = h->ps.sps->long_term_ref_pics_present_flag;
    pp->slice_parsing_fields.bits.sps_temporal_mvp_enabled_flag = h->ps.sps->sps_temporal_mvp_enabled_flag;
    pp->slice_parsing_fields.bits.cabac_init_present_flag = h->ps.pps->cabac_init_present_flag;
    pp->slice_parsing_fields.bits.output_flag_present_flag = h->ps.pps->output_flag_present_flag;
    pp->slice_parsing_fields.bits.dependent_slice_segments_enabled_flag = h->ps.pps->dependent_slice_segments_enabled_flag;
    pp->slice_parsing_fields.bits.pps_slice_chroma_qp_offsets_present_flag = h->ps.pps->pic_slice_level_chroma_qp_offsets_present_flag;
    pp->slice_parsing_fields.bits.sample_adaptive_offset_enabled_flag = h->ps.sps->sao_enabled;
    pp->slice_parsing_fields.bits.deblocking_filter_override_enabled_flag = h->ps.pps->deblocking_filter_override_enabled_flag;
    pp->slice_parsing_fields.bits.pps_disable_deblocking_filter_flag = h->ps.pps->disable_dbf;
    pp->slice_parsing_fields.bits.slice_segment_header_extension_present_flag = h->ps.pps->slice_header_extension_present_flag;

    pp->log2_max_pic_order_cnt_lsb_minus4 = h->ps.sps->log2_max_poc_lsb - 4;
    pp->num_extra_slice_header_bits = h->ps.pps->num_extra_slice_header_bits;

    if (h->nal_unit_type >= NAL_BLA_W_LP && h->nal_unit_type <= NAL_CRA_NUT) {
        pp->slice_parsing_fields.bits.RapPicFlag = 1;
    } else {
        pp->slice_parsing_fields.bits.RapPicFlag = 0;
    }

    if (IS_IDR(h)) {
        pp->slice_parsing_fields.bits.IdrPicFlag = 1;
    } else {
        pp->slice_parsing_fields.bits.IdrPicFlag = 0;
    }

    if (IS_IRAP(h)) {
        pp->slice_parsing_fields.bits.IntraPicFlag = 1;
    } else {
        pp->slice_parsing_fields.bits.IntraPicFlag = 0;
    }

    if (h->sh.short_term_ref_pic_set_sps_flag == 0 && h->sh.short_term_rps) {
        pp->st_rps_bits = h->sh.short_term_ref_pic_set_size;
    } else {
        pp->st_rps_bits = 0;
    }

    /* TODO */
    pp->pic_fields.bits.NoPicReorderingFlag = 0;
    pp->pic_fields.bits.NoBiPredFlag = 0;
}
Ejemplo n.º 5
0
/** Initialize and start decoding a frame with VA API. */
static int start_frame(AVCodecContext          *avctx,
                       av_unused const uint8_t *buffer,
                       av_unused uint32_t       size)
{
    H264Context * const h = avctx->priv_data;
    MpegEncContext * const s = &h->s;
    struct vaapi_context * const vactx = avctx->hwaccel_context;
    VAPictureParameterBufferH264 *pic_param;
    VAIQMatrixBufferH264 *iq_matrix;

    av_dlog(avctx, "start_frame()\n");

    vactx->slice_param_size = sizeof(VASliceParameterBufferH264);

    /* Fill in VAPictureParameterBufferH264. */
    pic_param = ff_vaapi_alloc_pic_param(vactx, sizeof(VAPictureParameterBufferH264));
    if (!pic_param)
        return -1;
    fill_vaapi_pic(&pic_param->CurrPic, s->current_picture_ptr, s->picture_structure);
    if (fill_vaapi_ReferenceFrames(pic_param, h) < 0)
        return -1;
    pic_param->picture_width_in_mbs_minus1                      = s->mb_width - 1;
    pic_param->picture_height_in_mbs_minus1                     = s->mb_height - 1;
    pic_param->bit_depth_luma_minus8                            = h->sps.bit_depth_luma - 8;
    pic_param->bit_depth_chroma_minus8                          = h->sps.bit_depth_chroma - 8;
    pic_param->num_ref_frames                                   = h->sps.ref_frame_count;
    pic_param->seq_fields.value                                 = 0; /* reset all bits */
    pic_param->seq_fields.bits.chroma_format_idc                = h->sps.chroma_format_idc;
    pic_param->seq_fields.bits.residual_colour_transform_flag   = h->sps.residual_color_transform_flag; /* XXX: only for 4:4:4 high profile? */
    pic_param->seq_fields.bits.gaps_in_frame_num_value_allowed_flag = h->sps.gaps_in_frame_num_allowed_flag;
    pic_param->seq_fields.bits.frame_mbs_only_flag              = h->sps.frame_mbs_only_flag;
    pic_param->seq_fields.bits.mb_adaptive_frame_field_flag     = h->sps.mb_aff;
    pic_param->seq_fields.bits.direct_8x8_inference_flag        = h->sps.direct_8x8_inference_flag;
    pic_param->seq_fields.bits.MinLumaBiPredSize8x8             = h->sps.level_idc >= 31; /* A.3.3.2 */
    pic_param->seq_fields.bits.log2_max_frame_num_minus4        = h->sps.log2_max_frame_num - 4;
    pic_param->seq_fields.bits.pic_order_cnt_type               = h->sps.poc_type;
    pic_param->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4 = h->sps.log2_max_poc_lsb - 4;
    pic_param->seq_fields.bits.delta_pic_order_always_zero_flag = h->sps.delta_pic_order_always_zero_flag;
    pic_param->num_slice_groups_minus1                          = h->pps.slice_group_count - 1;
    pic_param->slice_group_map_type                             = h->pps.mb_slice_group_map_type;
    pic_param->slice_group_change_rate_minus1                   = 0; /* XXX: unimplemented in FFmpeg */
    pic_param->pic_init_qp_minus26                              = h->pps.init_qp - 26;
    pic_param->pic_init_qs_minus26                              = h->pps.init_qs - 26;
    pic_param->chroma_qp_index_offset                           = h->pps.chroma_qp_index_offset[0];
    pic_param->second_chroma_qp_index_offset                    = h->pps.chroma_qp_index_offset[1];
    pic_param->pic_fields.value                                 = 0; /* reset all bits */
    pic_param->pic_fields.bits.entropy_coding_mode_flag         = h->pps.cabac;
    pic_param->pic_fields.bits.weighted_pred_flag               = h->pps.weighted_pred;
    pic_param->pic_fields.bits.weighted_bipred_idc              = h->pps.weighted_bipred_idc;
    pic_param->pic_fields.bits.transform_8x8_mode_flag          = h->pps.transform_8x8_mode;
    pic_param->pic_fields.bits.field_pic_flag                   = s->picture_structure != PICT_FRAME;
    pic_param->pic_fields.bits.constrained_intra_pred_flag      = h->pps.constrained_intra_pred;
    pic_param->pic_fields.bits.pic_order_present_flag           = h->pps.pic_order_present;
    pic_param->pic_fields.bits.deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present;
    pic_param->pic_fields.bits.redundant_pic_cnt_present_flag   = h->pps.redundant_pic_cnt_present;
    pic_param->pic_fields.bits.reference_pic_flag               = h->nal_ref_idc != 0;
    pic_param->frame_num                                        = h->frame_num;

    /* Fill in VAIQMatrixBufferH264. */
    iq_matrix = ff_vaapi_alloc_iq_matrix(vactx, sizeof(VAIQMatrixBufferH264));
    if (!iq_matrix)
        return -1;
    memcpy(iq_matrix->ScalingList4x4, h->pps.scaling_matrix4, sizeof(iq_matrix->ScalingList4x4));
    memcpy(iq_matrix->ScalingList8x8, h->pps.scaling_matrix8, sizeof(iq_matrix->ScalingList8x8));
    return 0;
}