diff options
author | wm4 <wm4@nowhere> | 2017-01-17 10:56:16 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2017-01-17 15:48:56 +0100 |
commit | cda31b71debdd52cfe9a36e8eea318899acdd0d2 (patch) | |
tree | 76f4abd393b15075b7922b1c02dd5c5cf5bfc1f9 /video/decode/hw_vaapi.c | |
parent | a4cdd8bb823dbb8f981a4b5efcfcb0f9d118844e (diff) | |
download | mpv-cda31b71debdd52cfe9a36e8eea318899acdd0d2.tar.bz2 mpv-cda31b71debdd52cfe9a36e8eea318899acdd0d2.tar.xz |
vaapi: move AVHWFramesContext setup code to common code
In a way it can be reused. For now, sw_format and initial_pool_size
determination are still vaapi-specific. I'm hoping this can be eventally
moved to libavcodec in some way. Checking the supported_formats array is
not really vaapi-specific, and could be moved to the generic code path
too, but for now it would make things more complex.
hw_cuda.c can't use this, but hw_vdpau.c will in the following commit.
Diffstat (limited to 'video/decode/hw_vaapi.c')
-rw-r--r-- | video/decode/hw_vaapi.c | 57 |
1 files changed, 5 insertions, 52 deletions
diff --git a/video/decode/hw_vaapi.c b/video/decode/hw_vaapi.c index 13e38f2258..45558cd6e7 100644 --- a/video/decode/hw_vaapi.c +++ b/video/decode/hw_vaapi.c @@ -40,24 +40,19 @@ struct priv { struct mp_log *log; struct mp_vaapi_ctx *ctx; struct mp_hwdec_ctx *hwdev; - - AVBufferRef *frames_ref; }; - static int init_decoder(struct lavc_ctx *ctx, int w, int h) { struct priv *p = ctx->hwdec_priv; // From avconv_vaapi.c. Disgusting, but apparently this is the best we get. - int required_sw_format = ctx->avctx->sw_pix_fmt == AV_PIX_FMT_YUV420P10 ? - AV_PIX_FMT_P010 : AV_PIX_FMT_NV12; - - assert(!ctx->avctx->hw_frames_ctx); + int sw_format = ctx->avctx->sw_pix_fmt == AV_PIX_FMT_YUV420P10 ? + AV_PIX_FMT_P010 : AV_PIX_FMT_NV12; // The video output might not support all formats. // Note that supported_formats==NULL means any are accepted. if (p->hwdev && p->hwdev->supported_formats) { - int mp_format = pixfmt2imgfmt(required_sw_format); + int mp_format = pixfmt2imgfmt(sw_format); bool found = false; for (int n = 0; p->hwdev->supported_formats[n]; n++) { if (p->hwdev->supported_formats[n] == mp_format) { @@ -72,48 +67,8 @@ static int init_decoder(struct lavc_ctx *ctx, int w, int h) } } - if (p->frames_ref) { - AVHWFramesContext *fctx = (void *)p->frames_ref->data; - if (fctx->width != w || fctx->height != h || - fctx->sw_format != required_sw_format) - { - av_buffer_unref(&p->frames_ref); - } - } - - if (!p->frames_ref) { - p->frames_ref = av_hwframe_ctx_alloc(p->ctx->av_device_ref); - if (!p->frames_ref) - return -1; - - AVHWFramesContext *fctx = (void *)p->frames_ref->data; - - fctx->format = AV_PIX_FMT_VAAPI; - fctx->sw_format = required_sw_format; - fctx->width = w; - fctx->height = h; - - fctx->initial_pool_size = hwdec_get_max_refs(ctx) + ADDITIONAL_SURFACES; - - // Some mpv downstream code uses this. - fctx->user_opaque = p->ctx; - - va_lock(p->ctx); - int res = av_hwframe_ctx_init(p->frames_ref); - va_unlock(p->ctx); - - if (res > 0) { - MP_ERR(ctx, "Failed to allocate hw frames.\n"); - av_buffer_unref(&p->frames_ref); - return -1; - } - } - - ctx->avctx->hw_frames_ctx = av_buffer_ref(p->frames_ref); - if (!ctx->avctx->hw_frames_ctx) - return -1; - - return 0; + return hwdec_setup_hw_frames_ctx(ctx, p->ctx->av_device_ref, sw_format, + hwdec_get_max_refs(ctx) + ADDITIONAL_SURFACES); } static void uninit(struct lavc_ctx *ctx) @@ -123,8 +78,6 @@ static void uninit(struct lavc_ctx *ctx) if (!p) return; - av_buffer_unref(&p->frames_ref); - if (!p->hwdev) va_destroy(p->ctx); |