Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vaapi_decode: support dynamically frame pool resizing. #397

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions libavcodec/vaapi_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,22 +572,24 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
if (err < 0)
goto fail;

frames->initial_pool_size = 1;
// Add per-codec number of surfaces used for storing reference frames.
switch (avctx->codec_id) {
case AV_CODEC_ID_H264:
case AV_CODEC_ID_HEVC:
frames->initial_pool_size += 16;
break;
case AV_CODEC_ID_VP9:
case AV_CODEC_ID_AV1:
frames->initial_pool_size += 8;
break;
case AV_CODEC_ID_VP8:
frames->initial_pool_size += 3;
break;
default:
frames->initial_pool_size += 2;
if (hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING) {
frames->initial_pool_size = 1;
// Add per-codec number of surfaces used for storing reference frames.
switch (avctx->codec_id) {
case AV_CODEC_ID_H264:
case AV_CODEC_ID_HEVC:
frames->initial_pool_size += 16;
break;
case AV_CODEC_ID_VP9:
case AV_CODEC_ID_AV1:
frames->initial_pool_size += 8;
break;
case AV_CODEC_ID_VP8:
frames->initial_pool_size += 3;
break;
default:
frames->initial_pool_size += 2;
}
}
}

Expand Down
20 changes: 13 additions & 7 deletions libavutil/hwcontext_vaapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,23 +331,26 @@ static const struct {
const char *match_string;
unsigned int quirks;
} vaapi_driver_quirks_table[] = {
#if !VA_CHECK_VERSION(1, 0, 0)
// The i965 driver did not conform before version 2.0.
// The i965 driver did not conform RENDER_PARAM_BUFFERS before version 2.0.
{
"Intel i965 (Quick Sync)",
"i965",
AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS,
},
#if !VA_CHECK_VERSION(1, 0, 0)
AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS | AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING,
#else
AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING,
#endif
},

{
"Intel iHD",
"ubit",
AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE,
AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE | AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING,
},
{
"VDPAU wrapper",
"Splitted-Desktop Systems VDPAU backend for VA-API",
AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES,
AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES | AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING,
},
};

Expand Down Expand Up @@ -475,8 +478,11 @@ static AVBufferRef *vaapi_pool_alloc(void *opaque, size_t size)
AVBufferRef *ref;

if (hwfc->initial_pool_size > 0 &&
avfc->nb_surfaces >= hwfc->initial_pool_size)
avfc->nb_surfaces >= hwfc->initial_pool_size) {
av_log(hwfc, AV_LOG_ERROR, "allocated surfaces count(%d) > pool_size(%d)\n",
avfc->nb_surfaces, hwfc->initial_pool_size);
return NULL;
}

vas = vaCreateSurfaces(hwctx->display, ctx->rt_format,
hwfc->width, hwfc->height,
Expand Down
6 changes: 6 additions & 0 deletions libavutil/hwcontext_vaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ enum {
* and the results of the vaQuerySurfaceAttributes() call will be faked.
*/
AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES = (1 << 3),

/**
* The driver does not support dynamically frame pool resizing.
* We need to provide all va surfaces at vaCreateContext
*/
AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING = (1 << 4),
};

/**
Expand Down