Skip to content

Commit

Permalink
lavc/vaapi_av1: Avoid sending the same slice buffer multiple times
Browse files Browse the repository at this point in the history
When there are multiple tiles in one slice buffer, use multiple slice
params to avoid sending the same slice buffer multiple times and thus
increasing the bitstream size the driver will need to upload to hw.
  • Loading branch information
nowrep authored and xhaihao committed May 8, 2024
1 parent 5a59489 commit 17206cc
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions libavcodec/vaapi_av1.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include "libavutil/frame.h"
#include "libavutil/mem.h"
#include "hwaccel_internal.h"
#include "vaapi_decode.h"
#include "internal.h"
Expand Down Expand Up @@ -393,13 +394,17 @@ 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;
VASliceParameterBufferAV1 *slice_params;
int err = 0, nb_params = 0;

for (int i = s->tg_start; i <= s->tg_end; i++) {
memset(&slice_param, 0, sizeof(VASliceParameterBufferAV1));
slice_params = av_calloc(s->tg_end - s->tg_start + 1, sizeof(*slice_params));
if (!slice_params) {
err = AVERROR(ENOMEM);
goto fail;
}

slice_param = (VASliceParameterBufferAV1) {
for (int i = s->tg_start; i <= s->tg_end; i++) {
slice_params[nb_params++] = (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,
Expand All @@ -408,18 +413,22 @@ 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, 1,
sizeof(VASliceParameterBufferAV1),
buffer,
size);
if (err) {
ff_vaapi_decode_cancel(avctx, pic);
return err;
}
}

err = ff_vaapi_decode_make_slice_buffer(avctx, pic, slice_params, nb_params,
sizeof(VASliceParameterBufferAV1),
buffer,
size);
av_free(slice_params);

if (err)
goto fail;

return 0;

fail:
ff_vaapi_decode_cancel(avctx, pic);
return err;
}

const FFHWAccel ff_av1_vaapi_hwaccel = {
Expand Down

0 comments on commit 17206cc

Please sign in to comment.