X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Fqsvvpp.c;h=f216b3f248d9295fddd0d493d338e584075cd066;hb=eed2125f3f1762f940bb42d49ae608b90a7f79ae;hp=06efdf50891d006fa5e93345da186388bd125e16;hpb=d6b62ce1aced9e2456582870382f384581cc7cbb;p=ffmpeg diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index 06efdf50891..f216b3f248d 100644 --- a/libavfilter/qsvvpp.c +++ b/libavfilter/qsvvpp.c @@ -76,6 +76,110 @@ static const mfxHandleType handle_types[] = { static const AVRational default_tb = { 1, 90000 }; +static const struct { + int mfx_iopattern; + const char *desc; +} qsv_iopatterns[] = { + {MFX_IOPATTERN_IN_VIDEO_MEMORY, "input is video memory surface" }, + {MFX_IOPATTERN_IN_SYSTEM_MEMORY, "input is system memory surface" }, + {MFX_IOPATTERN_IN_OPAQUE_MEMORY, "input is opaque memory surface" }, + {MFX_IOPATTERN_OUT_VIDEO_MEMORY, "output is video memory surface" }, + {MFX_IOPATTERN_OUT_SYSTEM_MEMORY, "output is system memory surface" }, + {MFX_IOPATTERN_OUT_OPAQUE_MEMORY, "output is opaque memory surface" }, +}; + +int ff_qsvvpp_print_iopattern(void *log_ctx, int mfx_iopattern, + const char *extra_string) +{ + const char *desc = NULL; + + for (int i = 0; i < FF_ARRAY_ELEMS(qsv_iopatterns); i++) { + if (qsv_iopatterns[i].mfx_iopattern == mfx_iopattern) { + desc = qsv_iopatterns[i].desc; + } + } + if (!desc) + desc = "unknown iopattern"; + + av_log(log_ctx, AV_LOG_VERBOSE, "%s: %s\n", extra_string, desc); + return 0; +} + +static const struct { + mfxStatus mfxerr; + int averr; + const char *desc; +} qsv_errors[] = { + { MFX_ERR_NONE, 0, "success" }, + { MFX_ERR_UNKNOWN, AVERROR_UNKNOWN, "unknown error" }, + { MFX_ERR_NULL_PTR, AVERROR(EINVAL), "NULL pointer" }, + { MFX_ERR_UNSUPPORTED, AVERROR(ENOSYS), "unsupported" }, + { MFX_ERR_MEMORY_ALLOC, AVERROR(ENOMEM), "failed to allocate memory" }, + { MFX_ERR_NOT_ENOUGH_BUFFER, AVERROR(ENOMEM), "insufficient input/output buffer" }, + { MFX_ERR_INVALID_HANDLE, AVERROR(EINVAL), "invalid handle" }, + { MFX_ERR_LOCK_MEMORY, AVERROR(EIO), "failed to lock the memory block" }, + { MFX_ERR_NOT_INITIALIZED, AVERROR_BUG, "not initialized" }, + { MFX_ERR_NOT_FOUND, AVERROR(ENOSYS), "specified object was not found" }, + /* the following 3 errors should always be handled explicitly, so those "mappings" + * are for completeness only */ + { MFX_ERR_MORE_DATA, AVERROR_UNKNOWN, "expect more data at input" }, + { MFX_ERR_MORE_SURFACE, AVERROR_UNKNOWN, "expect more surface at output" }, + { MFX_ERR_MORE_BITSTREAM, AVERROR_UNKNOWN, "expect more bitstream at output" }, + { MFX_ERR_ABORTED, AVERROR_UNKNOWN, "operation aborted" }, + { MFX_ERR_DEVICE_LOST, AVERROR(EIO), "device lost" }, + { MFX_ERR_INCOMPATIBLE_VIDEO_PARAM, AVERROR(EINVAL), "incompatible video parameters" }, + { MFX_ERR_INVALID_VIDEO_PARAM, AVERROR(EINVAL), "invalid video parameters" }, + { MFX_ERR_UNDEFINED_BEHAVIOR, AVERROR_BUG, "undefined behavior" }, + { MFX_ERR_DEVICE_FAILED, AVERROR(EIO), "device failed" }, + { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio parameters" }, + { MFX_ERR_INVALID_AUDIO_PARAM, AVERROR(EINVAL), "invalid audio parameters" }, + + { MFX_WRN_IN_EXECUTION, 0, "operation in execution" }, + { MFX_WRN_DEVICE_BUSY, 0, "device busy" }, + { MFX_WRN_VIDEO_PARAM_CHANGED, 0, "video parameters changed" }, + { MFX_WRN_PARTIAL_ACCELERATION, 0, "partial acceleration" }, + { MFX_WRN_INCOMPATIBLE_VIDEO_PARAM, 0, "incompatible video parameters" }, + { MFX_WRN_VALUE_NOT_CHANGED, 0, "value is saturated" }, + { MFX_WRN_OUT_OF_RANGE, 0, "value out of range" }, + { MFX_WRN_FILTER_SKIPPED, 0, "filter skipped" }, + { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0, "incompatible audio parameters" }, +}; + +static int qsv_map_error(mfxStatus mfx_err, const char **desc) +{ + int i; + for (i = 0; i < FF_ARRAY_ELEMS(qsv_errors); i++) { + if (qsv_errors[i].mfxerr == mfx_err) { + if (desc) + *desc = qsv_errors[i].desc; + return qsv_errors[i].averr; + } + } + if (desc) + *desc = "unknown error"; + return AVERROR_UNKNOWN; +} + +int ff_qsvvpp_print_error(void *log_ctx, mfxStatus err, + const char *error_string) +{ + const char *desc; + int ret; + ret = qsv_map_error(err, &desc); + av_log(log_ctx, AV_LOG_ERROR, "%s: %s (%d)\n", error_string, desc, err); + return ret; +} + +int ff_qsvvpp_print_warning(void *log_ctx, mfxStatus err, + const char *warning_string) +{ + const char *desc; + int ret; + ret = qsv_map_error(err, &desc); + av_log(log_ctx, AV_LOG_WARNING, "%s: %s (%d)\n", warning_string, desc, err); + return ret; +} + /* functions for frameAlloc */ static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp) @@ -153,6 +257,7 @@ static int map_frame_to_surface(AVFrame *frame, mfxFrameSurface1 *surface) { switch (frame->format) { case AV_PIX_FMT_NV12: + case AV_PIX_FMT_P010: surface->Data.Y = frame->data[0]; surface->Data.UV = frame->data[1]; break; @@ -316,7 +421,6 @@ static QSVFrame *submit_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *p } av_frame_copy_props(qsv_frame->frame, picref); - av_frame_free(&picref); } else qsv_frame->frame = av_frame_clone(picref); @@ -461,6 +565,8 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s) out_frames_ctx->height = FFALIGN(outlink->h, 32); out_frames_ctx->sw_format = s->out_sw_format; out_frames_ctx->initial_pool_size = 64; + if (avctx->extra_hw_frames > 0) + out_frames_ctx->initial_pool_size += avctx->extra_hw_frames; out_frames_hwctx->frame_type = s->out_mem_mode; ret = av_hwframe_ctx_init(out_frames_ref); @@ -503,15 +609,19 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s) } } - if (ret != MFX_ERR_NONE) { - av_log(avctx, AV_LOG_ERROR, "Error getting the session handle\n"); + if (ret < 0) + return ff_qsvvpp_print_error(avctx, ret, "Error getting the session handle"); + else if (ret > 0) { + ff_qsvvpp_print_warning(avctx, ret, "Warning in getting the session handle"); return AVERROR_UNKNOWN; } /* create a "slave" session with those same properties, to be used for vpp */ ret = MFXInit(impl, &ver, &s->session); - if (ret != MFX_ERR_NONE) { - av_log(avctx, AV_LOG_ERROR, "Error initializing a session for scaling\n"); + if (ret < 0) + return ff_qsvvpp_print_error(avctx, ret, "Error initializing a session"); + else if (ret > 0) { + ff_qsvvpp_print_warning(avctx, ret, "Warning in session initialization"); return AVERROR_UNKNOWN; } @@ -644,11 +754,16 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *p else if (IS_OPAQUE_MEMORY(s->out_mem_mode)) s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_OPAQUE_MEMORY; + /* Print input memory mode */ + ff_qsvvpp_print_iopattern(avctx, s->vpp_param.IOPattern & 0x0F, "VPP"); + /* Print output memory mode */ + ff_qsvvpp_print_iopattern(avctx, s->vpp_param.IOPattern & 0xF0, "VPP"); ret = MFXVideoVPP_Init(s->session, &s->vpp_param); if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, "Failed to create a qsvvpp, ret = %d.\n", ret); + ret = ff_qsvvpp_print_error(avctx, ret, "Failed to create a qsvvpp"); goto failed; - } + } else if (ret > 0) + ff_qsvvpp_print_warning(avctx, ret, "Warning When creating qsvvpp"); *vpp = s; return 0;