mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 04:41:11 +00:00
Bug 1902227 [Linux/VA-API] Backport AV1/VA-API playback fix for AMD/mesa > 24.0.7 r=padenot
Backport of https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29400 Allows to use multiple slices for AV1 VA-API decode. Differential Revision: https://phabricator.services.mozilla.com/D216919
This commit is contained in:
parent
95321ce35e
commit
b265f5c618
@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "libavutil/frame.h"
|
||||
#include "libavutil/mem.h"
|
||||
#include "hwaccel_internal.h"
|
||||
#include "vaapi_decode.h"
|
||||
#include "internal.h"
|
||||
@ -42,6 +43,9 @@ typedef struct VAAPIAV1DecContext {
|
||||
*/
|
||||
VAAPIAV1FrameRef ref_tab[AV1_NUM_REF_FRAMES];
|
||||
AVFrame *tmp_frame;
|
||||
|
||||
int nb_slice_params;
|
||||
VASliceParameterBufferAV1 *slice_params;
|
||||
} VAAPIAV1DecContext;
|
||||
|
||||
static VASurfaceID vaapi_av1_surface_id(AV1Frame *vf)
|
||||
@ -97,6 +101,8 @@ static int vaapi_av1_decode_uninit(AVCodecContext *avctx)
|
||||
for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++)
|
||||
av_frame_free(&ctx->ref_tab[i].frame);
|
||||
|
||||
av_freep(&ctx->slice_params);
|
||||
|
||||
return ff_vaapi_decode_uninit(avctx);
|
||||
}
|
||||
|
||||
@ -393,13 +399,24 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
|
||||
{
|
||||
const AV1DecContext *s = avctx->priv_data;
|
||||
VAAPIDecodePicture *pic = s->cur_frame.hwaccel_picture_private;
|
||||
VASliceParameterBufferAV1 slice_param;
|
||||
int err = 0;
|
||||
VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data;
|
||||
int err, nb_params;
|
||||
|
||||
nb_params = s->tg_end - s->tg_start + 1;
|
||||
if (ctx->nb_slice_params < nb_params) {
|
||||
ctx->slice_params = av_realloc_array(ctx->slice_params,
|
||||
nb_params,
|
||||
sizeof(*ctx->slice_params));
|
||||
if (!ctx->slice_params) {
|
||||
ctx->nb_slice_params = 0;
|
||||
err = AVERROR(ENOMEM);
|
||||
goto fail;
|
||||
}
|
||||
ctx->nb_slice_params = nb_params;
|
||||
}
|
||||
|
||||
for (int i = s->tg_start; i <= s->tg_end; i++) {
|
||||
memset(&slice_param, 0, sizeof(VASliceParameterBufferAV1));
|
||||
|
||||
slice_param = (VASliceParameterBufferAV1) {
|
||||
ctx->slice_params[i - s->tg_start] = (VASliceParameterBufferAV1) {
|
||||
.slice_data_size = s->tile_group_info[i].tile_size,
|
||||
.slice_data_offset = s->tile_group_info[i].tile_offset,
|
||||
.slice_data_flag = VA_SLICE_DATA_FLAG_ALL,
|
||||
@ -408,18 +425,20 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
|
||||
.tg_start = s->tg_start,
|
||||
.tg_end = s->tg_end,
|
||||
};
|
||||
|
||||
err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param,
|
||||
sizeof(VASliceParameterBufferAV1),
|
||||
buffer,
|
||||
size);
|
||||
if (err) {
|
||||
ff_vaapi_decode_cancel(avctx, pic);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
err = ff_vaapi_decode_make_slice_buffer(avctx, pic, ctx->slice_params, nb_params,
|
||||
sizeof(VASliceParameterBufferAV1),
|
||||
buffer,
|
||||
size);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
ff_vaapi_decode_cancel(avctx, pic);
|
||||
return err;
|
||||
}
|
||||
|
||||
const FFHWAccel ff_av1_vaapi_hwaccel = {
|
||||
|
@ -63,6 +63,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
|
||||
int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
|
||||
VAAPIDecodePicture *pic,
|
||||
const void *params_data,
|
||||
int nb_params,
|
||||
size_t params_size,
|
||||
const void *slice_data,
|
||||
size_t slice_size)
|
||||
@ -88,7 +89,7 @@ int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
|
||||
|
||||
vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
|
||||
VASliceParameterBufferType,
|
||||
params_size, 1, (void*)params_data,
|
||||
params_size, nb_params, (void*)params_data,
|
||||
&pic->slice_buffers[index]);
|
||||
if (vas != VA_STATUS_SUCCESS) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Failed to create slice "
|
||||
|
@ -73,6 +73,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
|
||||
int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
|
||||
VAAPIDecodePicture *pic,
|
||||
const void *params_data,
|
||||
int nb_params,
|
||||
size_t params_size,
|
||||
const void *slice_data,
|
||||
size_t slice_size);
|
||||
|
@ -209,7 +209,7 @@ static int vaapi_vp8_decode_slice(AVCodecContext *avctx,
|
||||
for (i = 0; i < 8; i++)
|
||||
sp.partition_size[i+1] = s->coeff_partition_size[i];
|
||||
|
||||
err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, sizeof(sp), data, data_size);
|
||||
err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, 1, sizeof(sp), data, data_size);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
|
@ -158,7 +158,7 @@ static int vaapi_vp9_decode_slice(AVCodecContext *avctx,
|
||||
}
|
||||
|
||||
err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
|
||||
&slice_param, sizeof(slice_param),
|
||||
&slice_param, 1, sizeof(slice_param),
|
||||
buffer, size);
|
||||
if (err) {
|
||||
ff_vaapi_decode_cancel(avctx, pic);
|
||||
|
Loading…
Reference in New Issue
Block a user