Unified · Split
| @@ -20,11 +20,11 @@ · 19 unmodified lines | ||
| 20 | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | −#include "vaapi_internal.h" | |
| 24 | −#include "internal.h" | |
| 25 | 23 | #include "h263.h" |
| 24 | +#include "internal.h" | |
| 26 | 25 | #include "mpeg4video.h" |
| 27 | 26 | #include "mpegvideo.h" |
| 27 | +#include "vaapi_decode.h" | |
| 28 | 28 | |
| 29 | 29 | /** Reconstruct bitstream intra_dc_vlc_thr */ |
| 30 | 30 | static int mpeg4_get_intra_dc_vlc_thr(Mpeg4DecContext *s) |
| @@ -45,82 +45,116 @@ static int mpeg4_get_intra_dc_vlc_thr(Mpeg4DecContext *s) · 14 unmodified lines | ||
| 45 | 45 | static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size) |
| 46 | 46 | { |
| 47 | 47 | Mpeg4DecContext *ctx = avctx->priv_data; |
| 48 | − MpegEncContext * const s = &ctx->m; | |
| 49 | − struct vaapi_context * const vactx = avctx->hwaccel_context; | |
| 50 | − VAPictureParameterBufferMPEG4 *pic_param; | |
| 51 | − VAIQMatrixBufferMPEG4 *iq_matrix; | |
| 52 | − int i; | |
| 53 | − | |
| 54 | − vactx->slice_param_size = sizeof(VASliceParameterBufferMPEG4); | |
| 55 | − | |
| 56 | − /* Fill in VAPictureParameterBufferMPEG4 */ | |
| 57 | − pic_param = ff_vaapi_alloc_pic_param(vactx, sizeof(VAPictureParameterBufferMPEG4)); | |
| 58 | − if (!pic_param) | |
| 59 | − return -1; | |
| 60 | − pic_param->vop_width = s->width; | |
| 61 | − pic_param->vop_height = s->height; | |
| 62 | − pic_param->forward_reference_picture = VA_INVALID_ID; | |
| 63 | − pic_param->backward_reference_picture = VA_INVALID_ID; | |
| 64 | − pic_param->vol_fields.value = 0; /* reset all bits */ | |
| 65 | − pic_param->vol_fields.bits.short_video_header = avctx->codec->id == AV_CODEC_ID_H263; | |
| 66 | − pic_param->vol_fields.bits.chroma_format = CHROMA_420; | |
| 67 | − pic_param->vol_fields.bits.interlaced = !s->progressive_sequence; | |
| 68 | − pic_param->vol_fields.bits.obmc_disable = 1; | |
| 69 | − pic_param->vol_fields.bits.sprite_enable = ctx->vol_sprite_usage; | |
| 70 | − pic_param->vol_fields.bits.sprite_warping_accuracy = s->sprite_warping_accuracy; | |
| 71 | − pic_param->vol_fields.bits.quant_type = s->mpeg_quant; | |
| 72 | − pic_param->vol_fields.bits.quarter_sample = s->quarter_sample; | |
| 73 | − pic_param->vol_fields.bits.data_partitioned = s->data_partitioning; | |
| 74 | − pic_param->vol_fields.bits.reversible_vlc = ctx->rvlc; | |
| 75 | − pic_param->vol_fields.bits.resync_marker_disable = !ctx->resync_marker; | |
| 76 | − pic_param->no_of_sprite_warping_points = ctx->num_sprite_warping_points; | |
| 48 | + MpegEncContext *s = &ctx->m; | |
| 49 | + VAAPIDecodePicture *pic = s->current_picture_ptr->hwaccel_picture_private; | |
| 50 | + VAPictureParameterBufferMPEG4 pic_param; | |
| 51 | + int i, err; | |
| 52 | + | |
| 53 | + pic->output_surface = ff_vaapi_get_surface_id(s->current_picture_ptr->f); | |
| 54 | + | |
| 55 | + pic_param = (VAPictureParameterBufferMPEG4) { | |
| 56 | + .vop_width = s->width, | |
| 57 | + .vop_height = s->height, | |
| 58 | + .forward_reference_picture = VA_INVALID_ID, | |
| 59 | + .backward_reference_picture = VA_INVALID_ID, | |
| 60 | + .vol_fields.bits = { | |
| 61 | + .short_video_header = avctx->codec->id == AV_CODEC_ID_H263, | |
| 62 | + .chroma_format = CHROMA_420, | |
| 63 | + .interlaced = !s->progressive_sequence, | |
| 64 | + .obmc_disable = 1, | |
| 65 | + .sprite_enable = ctx->vol_sprite_usage, | |
| 66 | + .sprite_warping_accuracy = s->sprite_warping_accuracy, | |
| 67 | + .quant_type = s->mpeg_quant, | |
| 68 | + .quarter_sample = s->quarter_sample, | |
| 69 | + .data_partitioned = s->data_partitioning, | |
| 70 | + .reversible_vlc = ctx->rvlc, | |
| 71 | + .resync_marker_disable = !ctx->resync_marker, | |
| 72 | + }, | |
| 73 | + .no_of_sprite_warping_points = ctx->num_sprite_warping_points, | |
| 74 | + .quant_precision = s->quant_precision, | |
| 75 | + .vop_fields.bits = { | |
| 76 | + .vop_coding_type = s->pict_type - AV_PICTURE_TYPE_I, | |
| 77 | + .backward_reference_vop_coding_type = | |
| 78 | + s->pict_type == AV_PICTURE_TYPE_B ? s->next_picture.f->pict_type - AV_PICTURE_TYPE_I : 0, | |
| 79 | + .vop_rounding_type = s->no_rounding, | |
| 80 | + .intra_dc_vlc_thr = mpeg4_get_intra_dc_vlc_thr(ctx), | |
| 81 | + .top_field_first = s->top_field_first, | |
| 82 | + .alternate_vertical_scan_flag = s->alternate_scan, | |
| 83 | + }, | |
| 84 | + .vop_fcode_forward = s->f_code, | |
| 85 | + .vop_fcode_backward = s->b_code, | |
| 86 | + .vop_time_increment_resolution = avctx->framerate.num, | |
| 87 | + .num_macroblocks_in_gob = s->mb_width * H263_GOB_HEIGHT(s->height), | |
| 88 | + .num_gobs_in_vop = | |
| 89 | + (s->mb_width * s->mb_height) / (s->mb_width * H263_GOB_HEIGHT(s->height)), | |
| 90 | + .TRB = s->pb_time, | |
| 91 | + .TRD = s->pp_time, | |
| 92 | + }; | |
| 93 | + | |
| 77 | 94 | for (i = 0; i < ctx->num_sprite_warping_points && i < 3; i++) { |
| 78 | − pic_param->sprite_trajectory_du[i] = ctx->sprite_traj[i][0]; | |
| 79 | − pic_param->sprite_trajectory_dv[i] = ctx->sprite_traj[i][1]; | |
| 95 | + pic_param.sprite_trajectory_du[i] = ctx->sprite_traj[i][0]; | |
| 96 | + pic_param.sprite_trajectory_dv[i] = ctx->sprite_traj[i][1]; | |
| 80 | 97 | } |
| 81 | − pic_param->quant_precision = s->quant_precision; | |
| 82 | − pic_param->vop_fields.value = 0; /* reset all bits */ | |
| 83 | − pic_param->vop_fields.bits.vop_coding_type = s->pict_type - AV_PICTURE_TYPE_I; | |
| 84 | − pic_param->vop_fields.bits.backward_reference_vop_coding_type = s->pict_type == AV_PICTURE_TYPE_B ? s->next_picture.f->pict_type - AV_PICTURE_TYPE_I : 0; | |
| 85 | − pic_param->vop_fields.bits.vop_rounding_type = s->no_rounding; | |
| 86 | − pic_param->vop_fields.bits.intra_dc_vlc_thr = mpeg4_get_intra_dc_vlc_thr(ctx); | |
| 87 | − pic_param->vop_fields.bits.top_field_first = s->top_field_first; | |
| 88 | − pic_param->vop_fields.bits.alternate_vertical_scan_flag = s->alternate_scan; | |
| 89 | − pic_param->vop_fcode_forward = s->f_code; | |
| 90 | − pic_param->vop_fcode_backward = s->b_code; | |
| 91 | − pic_param->vop_time_increment_resolution = avctx->framerate.num; | |
| 92 | − pic_param->num_macroblocks_in_gob = s->mb_width * H263_GOB_HEIGHT(s->height); | |
| 93 | − pic_param->num_gobs_in_vop = (s->mb_width * s->mb_height) / pic_param->num_macroblocks_in_gob; | |
| 94 | − pic_param->TRB = s->pb_time; | |
| 95 | − pic_param->TRD = s->pp_time; | |
| 96 | 98 | |
| 97 | 99 | if (s->pict_type == AV_PICTURE_TYPE_B) |
| 98 | − pic_param->backward_reference_picture = ff_vaapi_get_surface_id(s->next_picture.f); | |
| 100 | + pic_param.backward_reference_picture = ff_vaapi_get_surface_id(s->next_picture.f); | |
| 99 | 101 | if (s->pict_type != AV_PICTURE_TYPE_I) |
| 100 | − pic_param->forward_reference_picture = ff_vaapi_get_surface_id(s->last_picture.f); | |
| 102 | + pic_param.forward_reference_picture = ff_vaapi_get_surface_id(s->last_picture.f); | |
| 103 | + | |
| 104 | + err = ff_vaapi_decode_make_param_buffer(avctx, pic, | |
| 105 | + VAPictureParameterBufferType, | |
| 106 | + &pic_param, sizeof(pic_param)); | |
| 107 | + if (err < 0) | |
| 108 | + goto fail; | |
| 101 | 109 | |
| 102 | − /* Fill in VAIQMatrixBufferMPEG4 */ | |
| 103 | 110 | /* Only the first inverse quantisation method uses the weighting matrices */ |
| 104 | − if (pic_param->vol_fields.bits.quant_type) { | |
| 105 | − iq_matrix = ff_vaapi_alloc_iq_matrix(vactx, sizeof(VAIQMatrixBufferMPEG4)); | |
| 106 | − if (!iq_matrix) | |
| 107 | − return -1; | |
| 108 | − iq_matrix->load_intra_quant_mat = 1; | |
| 109 | − iq_matrix->load_non_intra_quant_mat = 1; | |
| 111 | + if (pic_param.vol_fields.bits.quant_type) { | |
| 112 | + VAIQMatrixBufferMPEG4 iq_matrix; | |
| 113 | + | |
| 114 | + iq_matrix.load_intra_quant_mat = 1; | |
| 115 | + iq_matrix.load_non_intra_quant_mat = 1; | |
| 110 | 116 | |
| 111 | 117 | for (i = 0; i < 64; i++) { |
| 112 | 118 | int n = s->idsp.idct_permutation[ff_zigzag_direct[i]]; |
| 113 | − iq_matrix->intra_quant_mat[i] = s->intra_matrix[n]; | |
| 114 | − iq_matrix->non_intra_quant_mat[i] = s->inter_matrix[n]; | |
| 119 | + iq_matrix.intra_quant_mat[i] = s->intra_matrix[n]; | |
| 120 | + iq_matrix.non_intra_quant_mat[i] = s->inter_matrix[n]; | |
| 115 | 121 | } |
| 122 | + | |
| 123 | + err = ff_vaapi_decode_make_param_buffer(avctx, pic, | |
| 124 | + VAIQMatrixBufferType, | |
| 125 | + &iq_matrix, sizeof(iq_matrix)); | |
| 126 | + if (err < 0) | |
| 127 | + goto fail; | |
| 116 | 128 | } |
| 117 | 129 | return 0; |
| 130 | + | |
| 131 | +fail: | |
| 132 | + ff_vaapi_decode_cancel(avctx, pic); | |
| 133 | + return err; | |
| 134 | +} | |
| 135 | + | |
| 136 | +static int vaapi_mpeg4_end_frame(AVCodecContext *avctx) | |
| 137 | +{ | |
| 138 | + MpegEncContext *s = avctx->priv_data; | |
| 139 | + VAAPIDecodePicture *pic = s->current_picture_ptr->hwaccel_picture_private; | |
| 140 | + int ret; | |
| 141 | + | |
| 142 | + ret = ff_vaapi_decode_issue(avctx, pic); | |
| 143 | + if (ret < 0) | |
| 144 | + goto fail; | |
| 145 | + | |
| 146 | + ff_mpeg_draw_horiz_band(s, 0, s->avctx->height); | |
| 147 | + | |
| 148 | +fail: | |
| 149 | + return ret; | |
| 118 | 150 | } |
| 119 | 151 | |
| 120 | 152 | static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) |
| 121 | 153 | { |
| 122 | − MpegEncContext * const s = avctx->priv_data; | |
| 123 | − VASliceParameterBufferMPEG4 *slice_param; | |
| 154 | + MpegEncContext *s = avctx->priv_data; | |
| 155 | + VAAPIDecodePicture *pic = s->current_picture_ptr->hwaccel_picture_private; | |
| 156 | + VASliceParameterBufferMPEG4 slice_param; | |
| 157 | + int err; | |
| 124 | 158 | |
| 125 | 159 | /* video_plane_with_short_video_header() contains all GOBs |
| 126 | 160 | * in-order, and this is what VA API (Intel backend) expects: only |
| @@ -130,40 +164,57 @@ static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer · 3 unmodified lines | ||
| 130 | 164 | if (avctx->codec->id == AV_CODEC_ID_H263) |
| 131 | 165 | size = s->gb.buffer_end - buffer; |
| 132 | 166 | |
| 133 | − /* Fill in VASliceParameterBufferMPEG4 */ | |
| 134 | − slice_param = (VASliceParameterBufferMPEG4 *)ff_vaapi_alloc_slice(avctx->hwaccel_context, buffer, size); | |
| 135 | − if (!slice_param) | |
| 136 | − return -1; | |
| 137 | − slice_param->macroblock_offset = get_bits_count(&s->gb) % 8; | |
| 138 | − slice_param->macroblock_number = s->mb_y * s->mb_width + s->mb_x; | |
| 139 | − slice_param->quant_scale = s->qscale; | |
| 167 | + slice_param = (VASliceParameterBufferMPEG4) { | |
| 168 | + .slice_data_size = size, | |
| 169 | + .slice_data_offset = 0, | |
| 170 | + .slice_data_flag = VA_SLICE_DATA_FLAG_ALL, | |
| 171 | + .macroblock_offset = get_bits_count(&s->gb) % 8, | |
| 172 | + .macroblock_number = s->mb_y * s->mb_width + s->mb_x, | |
| 173 | + .quant_scale = s->qscale, | |
| 174 | + }; | |
| 140 | 175 | |
| 141 | 176 | if (avctx->codec->id == AV_CODEC_ID_H263) |
| 142 | 177 | s->mb_y = s->mb_height; |
| 143 | 178 | |
| 179 | + err = ff_vaapi_decode_make_slice_buffer(avctx, pic, | |
| 180 | + &slice_param, sizeof(slice_param), | |
| 181 | + buffer, size); | |
| 182 | + if (err < 0) { | |
| 183 | + ff_vaapi_decode_cancel(avctx, pic); | |
| 184 | + return err; | |
| 185 | + } | |
| 186 | + | |
| 144 | 187 | return 0; |
| 145 | 188 | } |
| 146 | 189 | |
| 147 | 190 | #if CONFIG_MPEG4_VAAPI_HWACCEL |
| 148 | 191 | AVHWAccel ff_mpeg4_vaapi_hwaccel = { |
| 149 | − .name = "mpeg4_vaapi", | |
| 150 | − .type = AVMEDIA_TYPE_VIDEO, | |
| 151 | − .id = AV_CODEC_ID_MPEG4, | |
| 152 | − .pix_fmt = AV_PIX_FMT_VAAPI, | |
| 153 | − .start_frame = vaapi_mpeg4_start_frame, | |
| 154 | − .end_frame = ff_vaapi_mpeg_end_frame, | |
| 155 | − .decode_slice = vaapi_mpeg4_decode_slice, | |
| 192 | + .name = "mpeg4_vaapi", | |
| 193 | + .type = AVMEDIA_TYPE_VIDEO, | |
| 194 | + .id = AV_CODEC_ID_MPEG4, | |
| 195 | + .pix_fmt = AV_PIX_FMT_VAAPI, | |
| 196 | + .start_frame = &vaapi_mpeg4_start_frame, | |
| 197 | + .end_frame = &vaapi_mpeg4_end_frame, | |
| 198 | + .decode_slice = &vaapi_mpeg4_decode_slice, | |
| 199 | + .frame_priv_data_size = sizeof(VAAPIDecodePicture), | |
| 200 | + .init = &ff_vaapi_decode_init, | |
| 201 | + .uninit = &ff_vaapi_decode_uninit, | |
| 202 | + .priv_data_size = sizeof(VAAPIDecodeContext), | |
| 156 | 203 | }; |
| 157 | 204 | #endif |
| 158 | 205 | |
| 159 | 206 | #if CONFIG_H263_VAAPI_HWACCEL |
| 160 | 207 | AVHWAccel ff_h263_vaapi_hwaccel = { |
| 161 | − .name = "h263_vaapi", | |
| 162 | − .type = AVMEDIA_TYPE_VIDEO, | |
| 163 | − .id = AV_CODEC_ID_H263, | |
| 164 | − .pix_fmt = AV_PIX_FMT_VAAPI, | |
| 165 | − .start_frame = vaapi_mpeg4_start_frame, | |
| 166 | − .end_frame = ff_vaapi_mpeg_end_frame, | |
| 167 | − .decode_slice = vaapi_mpeg4_decode_slice, | |
| 208 | + .name = "h263_vaapi", | |
| 209 | + .type = AVMEDIA_TYPE_VIDEO, | |
| 210 | + .id = AV_CODEC_ID_H263, | |
| 211 | + .pix_fmt = AV_PIX_FMT_VAAPI, | |
| 212 | + .start_frame = &vaapi_mpeg4_start_frame, | |
| 213 | + .end_frame = &vaapi_mpeg4_end_frame, | |
| 214 | + .decode_slice = &vaapi_mpeg4_decode_slice, | |
| 215 | + .frame_priv_data_size = sizeof(VAAPIDecodePicture), | |
| 216 | + .init = &ff_vaapi_decode_init, | |
| 217 | + .uninit = &ff_vaapi_decode_uninit, | |
| 218 | + .priv_data_size = sizeof(VAAPIDecodeContext), | |
| 168 | 219 | }; |
| 169 | 220 | #endif |