Skip to content

Commit

Permalink
lavc/vaapi_decode: attemp to register surface
Browse files Browse the repository at this point in the history
Signed-off-by: Linjie Fu <linjie.fu@intel.com>
  • Loading branch information
fulinjie committed Jul 9, 2019
1 parent bb05f08 commit 9ed1a30
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
1 change: 1 addition & 0 deletions libavcodec/internal.h
Expand Up @@ -195,6 +195,7 @@ typedef struct AVCodecInternal {
* hwaccel-specific private data
*/
void *hwaccel_priv_data;
int keep_context;

/**
* checks API usage: after codec draining, flush is required to resume operation
Expand Down
2 changes: 2 additions & 0 deletions libavcodec/pthread_frame.c
Expand Up @@ -291,6 +291,7 @@ static int update_context_from_thread(AVCodecContext *dst, AVCodecContext *src,
dst->sample_fmt = src->sample_fmt;
dst->channel_layout = src->channel_layout;
dst->internal->hwaccel_priv_data = src->internal->hwaccel_priv_data;
dst->internal->keep_context = src->internal->keep_context;

if (!!dst->hw_frames_ctx != !!src->hw_frames_ctx ||
(dst->hw_frames_ctx && dst->hw_frames_ctx->data != src->hw_frames_ctx->data)) {
Expand Down Expand Up @@ -348,6 +349,7 @@ static int update_context_from_user(AVCodecContext *dst, AVCodecContext *src)
dst->frame_number = src->frame_number;
dst->reordered_opaque = src->reordered_opaque;
dst->thread_safe_callbacks = src->thread_safe_callbacks;
dst->internal->keep_context = src->internal->keep_context;

if (src->slice_count && src->slice_offset) {
if (dst->slice_count < src->slice_count) {
Expand Down
50 changes: 39 additions & 11 deletions libavcodec/vaapi_decode.c
Expand Up @@ -24,6 +24,7 @@
#include "decode.h"
#include "internal.h"
#include "vaapi_decode.h"
#include "vp9shared.h"


int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
Expand Down Expand Up @@ -152,11 +153,24 @@ int ff_vaapi_decode_issue(AVCodecContext *avctx,
{
VAAPIDecodeContext *ctx = avctx->internal->hwaccel_priv_data;
VAStatus vas;
int err;
int i, err;

const VP9SharedContext *h = avctx->priv_data;

av_log(avctx, AV_LOG_DEBUG, "Decode to surface %#x.\n",
pic->output_surface);

/*
if (avctx->internal->keep_context ) {
// register refs surface in context->RTtbl
for (i = 0; i < 8; i++) {
if (ff_vaapi_get_surface_id(h->refs[i].f))
vas = vaBeginPicture(ctx->hwctx->display, ctx->va_context,
ff_vaapi_get_surface_id(h->refs[i].f));
else
break;
}
}
*/
vas = vaBeginPicture(ctx->hwctx->display, ctx->va_context,
pic->output_surface);
if (vas != VA_STATUS_SUCCESS) {
Expand Down Expand Up @@ -670,17 +684,31 @@ int ff_vaapi_decode_init(AVCodecContext *avctx)
if (err)
goto fail;

if (avctx->internal->keep_context) {
// exapande surface_ids, add refs surface
ctx->hwfc->surface_ids = av_realloc_array(ctx->hwfc->surface_ids, ctx->hwfc->nb_surfaces + 8, sizeof(ctx->hwfc->surface_ids));
const VP9SharedContext *h = avctx->priv_data;
int i;
for (i = 0; i < 8; i ++) {
ctx->hwfc->surface_ids[ctx->hwfc->nb_surfaces + i] = ff_vaapi_get_surface_id(h->refs[i].f);
}

ctx->hwfc->nb_surfaces += 8;
}


vas = vaCreateContext(ctx->hwctx->display, ctx->va_config,
avctx->coded_width, avctx->coded_height,
VA_PROGRESSIVE,
ctx->hwfc->surface_ids,
ctx->hwfc->nb_surfaces,
&ctx->va_context);
avctx->coded_width, avctx->coded_height,
VA_PROGRESSIVE,
ctx->hwfc->surface_ids,
ctx->hwfc->nb_surfaces,
&ctx->va_context);

if (vas != VA_STATUS_SUCCESS) {
av_log(avctx, AV_LOG_ERROR, "Failed to create decode "
"context: %d (%s).\n", vas, vaErrorStr(vas));
err = AVERROR(EIO);
goto fail;
av_log(avctx, AV_LOG_ERROR, "Failed to create decode "
"context: %d (%s).\n", vas, vaErrorStr(vas));
err = AVERROR(EIO);
goto fail;
}

av_log(avctx, AV_LOG_DEBUG, "Decode context initialised: "
Expand Down
4 changes: 4 additions & 0 deletions libavcodec/vp9.c
Expand Up @@ -181,6 +181,7 @@ static int update_size(AVCodecContext *avctx, int w, int h)
int lflvl_len, i;

av_assert0(w > 0 && h > 0);
avctx->internal->keep_context = 0;

if (!(s->pix_fmt == s->gf_fmt && w == s->w && h == s->h)) {
if ((ret = ff_set_dimensions(avctx, w, h)) < 0)
Expand Down Expand Up @@ -216,6 +217,9 @@ static int update_size(AVCodecContext *avctx, int w, int h)
*fmtp++ = s->pix_fmt;
*fmtp = AV_PIX_FMT_NONE;

if (s->w && s->h)
avctx->internal->keep_context = 1;

ret = ff_thread_get_format(avctx, pix_fmts);
if (ret < 0)
return ret;
Expand Down

0 comments on commit 9ed1a30

Please sign in to comment.