From 11f44a10f977c076411a64c818fcd52de9b9c118 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 2 Sep 2015 23:10:39 +0200 Subject: vd_lavc: factor all hwdec fallbacks into the same function The fallback at initialization time was basically duplicated, maybe for the sake of showing a different error message. This doesn't matter anymore; not much can fail at initialization anymore. Most meaningful and common errors happen either at probing or in get_format (when the actual hw decoder is initialized). --- video/decode/vd_lavc.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) (limited to 'video/decode/vd_lavc.c') diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index 3ba797bd0c..d598cfe898 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -274,6 +274,20 @@ static void uninit(struct dec_video *vd) talloc_free(vd->priv); } +static bool force_fallback(struct dec_video *vd) +{ + vd_ffmpeg_ctx *ctx = vd->priv; + if (!ctx->software_fallback_decoder) + return false; + + uninit_avctx(vd); + MP_WARN(vd, "Falling back to software decoding.\n"); + const char *decoder = ctx->software_fallback_decoder; + ctx->software_fallback_decoder = NULL; + init_avctx(vd, decoder, NULL); + return true; +} + static int init(struct dec_video *vd, const char *decoder) { vd_ffmpeg_ctx *ctx; @@ -321,13 +335,7 @@ static int init(struct dec_video *vd, const char *decoder) init_avctx(vd, decoder, hwdec); if (!ctx->avctx) { - if (ctx->software_fallback_decoder) { - MP_ERR(vd, "Error initializing hardware decoding, " - "falling back to software decoding.\n"); - decoder = ctx->software_fallback_decoder; - ctx->software_fallback_decoder = NULL; - init_avctx(vd, decoder, NULL); - } + force_fallback(vd); if (!ctx->avctx) { uninit(vd); return 0; @@ -655,21 +663,6 @@ static int decode(struct dec_video *vd, struct demux_packet *packet, return 1; } -static int force_fallback(struct dec_video *vd) -{ - vd_ffmpeg_ctx *ctx = vd->priv; - if (ctx->software_fallback_decoder) { - uninit_avctx(vd); - MP_WARN(vd, "Hardware decoding failed," - " falling back to software decoding.\n"); - const char *decoder = ctx->software_fallback_decoder; - ctx->software_fallback_decoder = NULL; - init_avctx(vd, decoder, NULL); - return ctx->avctx ? CONTROL_OK : CONTROL_ERROR; - } - return CONTROL_FALSE; -} - static struct mp_image *decode_with_fallback(struct dec_video *vd, struct demux_packet *packet, int flags) { @@ -681,7 +674,7 @@ static struct mp_image *decode_with_fallback(struct dec_video *vd, int res = decode(vd, packet, flags, &mpi); if (res < 0) { // Failed hardware decoding? Try again in software. - if (force_fallback(vd) == CONTROL_OK) + if (force_fallback(vd) && ctx->avctx) decode(vd, packet, flags, &mpi); } @@ -711,7 +704,9 @@ static int control(struct dec_video *vd, int cmd, void *arg) return CONTROL_TRUE; } case VDCTRL_FORCE_HWDEC_FALLBACK: - return force_fallback(vd); + if (force_fallback(vd)) + return ctx->avctx ? CONTROL_OK : CONTROL_ERROR; + return CONTROL_FALSE; } return CONTROL_UNKNOWN; } -- cgit v1.2.3