From patchwork Tue Jan 5 07:02:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 24799 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9DF21449BCE for ; Tue, 5 Jan 2021 09:03:53 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 67CE268AA8A; Tue, 5 Jan 2021 09:03:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A3B4068A5B5 for ; Tue, 5 Jan 2021 09:03:46 +0200 (EET) IronPort-SDR: y8J8E2EZ6PhSbiPPoooUq6s0QbnZNTWXqOvDX1/GOZbanKfW1KaMWW0wRmo+gveh2dB3eH3Qmi /S4p5Rq/smlg== X-IronPort-AV: E=McAfee;i="6000,8403,9854"; a="177163944" X-IronPort-AV: E=Sophos;i="5.78,476,1599548400"; d="scan'208";a="177163944" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2021 23:03:43 -0800 IronPort-SDR: 3NbHTAY6yPabPAogt0Ap8vPuv9LsQ8cwpX8Cpj8JI2XtHnb+a6gIfn94YZvzPXiH2i3tp0JxhM iv0gbZIctLpQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,476,1599548400"; d="scan'208";a="569618180" Received: from xhh-tgl64.sh.intel.com ([10.239.159.152]) by fmsmga005.fm.intel.com with ESMTP; 04 Jan 2021 23:03:42 -0800 From: Haihao Xiang To: ffmpeg-devel@ffmpeg.org Date: Tue, 5 Jan 2021 15:02:55 +0800 Message-Id: <20210105070256.1150486-1-haihao.xiang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 1/2] lavf/qsv: Add functions to print mfx iopattern, warning and error X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Haihao Xiang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" It is a copy of the relevant part in lavc/qsv but use different function names to avoid multiple definition when linking lavc and lavf statically. Signed-off-by: Haihao Xiang --- v4: rename the new functions to avoid multiple definition libavfilter/qsvvpp.c | 104 +++++++++++++++++++++++++++++++++++++++++++ libavfilter/qsvvpp.h | 9 ++++ 2 files changed, 113 insertions(+) diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index 8d5ff2eb65..b31082db03 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) diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h index c2bcce7548..b4baeedf9e 100644 --- a/libavfilter/qsvvpp.h +++ b/libavfilter/qsvvpp.h @@ -71,4 +71,13 @@ int ff_qsvvpp_free(QSVVPPContext **vpp); /* vpp filter frame and call the cb if needed */ int ff_qsvvpp_filter_frame(QSVVPPContext *vpp, AVFilterLink *inlink, AVFrame *frame); +int ff_qsvvpp_print_iopattern(void *log_ctx, int mfx_iopattern, + const char *extra_string); + +int ff_qsvvpp_print_error(void *log_ctx, mfxStatus err, + const char *error_string); + +int ff_qsvvpp_print_warning(void *log_ctx, mfxStatus err, + const char *warning_string); + #endif /* AVFILTER_QSVVPP_H */ From patchwork Tue Jan 5 07:02:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 24800 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id EDB7F449BCE for ; Tue, 5 Jan 2021 09:03:59 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D164568AAEA; Tue, 5 Jan 2021 09:03:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 999ED68AA98 for ; Tue, 5 Jan 2021 09:03:52 +0200 (EET) IronPort-SDR: oEuy8RLnQwnr0Cq+11VavbswAsv0pMdylD62GgkwLuH4GATV3zIlPB03fWpHbV0r7QtsUi5OV/ MYGdI4AlvVzQ== X-IronPort-AV: E=McAfee;i="6000,8403,9854"; a="177163946" X-IronPort-AV: E=Sophos;i="5.78,476,1599548400"; d="scan'208";a="177163946" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2021 23:03:45 -0800 IronPort-SDR: 12fWxYeHEKzt3N/qR4Gre7XVEdotgJduGl93g0AqN0ZzD4hF/2HxQaQIVekLf6hnw4wZdKf6Q/ Y4mUn1NwvUyw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,476,1599548400"; d="scan'208";a="569618188" Received: from xhh-tgl64.sh.intel.com ([10.239.159.152]) by fmsmga005.fm.intel.com with ESMTP; 04 Jan 2021 23:03:44 -0800 From: Haihao Xiang To: ffmpeg-devel@ffmpeg.org Date: Tue, 5 Jan 2021 15:02:56 +0800 Message-Id: <20210105070256.1150486-2-haihao.xiang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210105070256.1150486-1-haihao.xiang@intel.com> References: <20210105070256.1150486-1-haihao.xiang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 2/2] qsv: dump more info in error, debug and verbose mode X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Haihao Xiang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Dump iopattern mode and the SDK error/warning desciptions for qsv based filters and iopattern mode for qsvenc Signed-off-by: Haihao Xiang --- libavcodec/qsvenc.c | 1 + libavfilter/qsvvpp.c | 21 +++++++++++++------ libavfilter/vf_deinterlace_qsv.c | 36 +++++++++++++++++++++++--------- libavfilter/vf_scale_qsv.c | 30 +++++++++++++++++++------- 4 files changed, 64 insertions(+), 24 deletions(-) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 2bd2a56227..566a5c8552 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -1132,6 +1132,7 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q) if (!iopattern) iopattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY; q->param.IOPattern = iopattern; + ff_qsv_print_iopattern(avctx, iopattern, "Encoder"); ret = qsvenc_init_session(avctx, q); if (ret < 0) diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index b31082db03..f216b3f248 100644 --- a/libavfilter/qsvvpp.c +++ b/libavfilter/qsvvpp.c @@ -609,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; } @@ -750,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; diff --git a/libavfilter/vf_deinterlace_qsv.c b/libavfilter/vf_deinterlace_qsv.c index 80217c8419..89a282f99e 100644 --- a/libavfilter/vf_deinterlace_qsv.c +++ b/libavfilter/vf_deinterlace_qsv.c @@ -202,16 +202,20 @@ static int init_out_session(AVFilterContext *ctx) } } - if (err != MFX_ERR_NONE) { - av_log(ctx, AV_LOG_ERROR, "Error getting the session handle\n"); + if (err < 0) + return ff_qsvvpp_print_error(ctx, err, "Error getting the session handle"); + else if (err > 0) { + ff_qsvvpp_print_warning(ctx, err, "Warning in getting the session handle"); return AVERROR_UNKNOWN; } /* create a "slave" session with those same properties, to be used for * actual deinterlacing */ err = MFXInit(impl, &ver, &s->session); - if (err != MFX_ERR_NONE) { - av_log(ctx, AV_LOG_ERROR, "Error initializing a session for deinterlacing\n"); + if (err < 0) + return ff_qsvvpp_print_error(ctx, err, "Error initializing a session for deinterlacing"); + else if (err > 0) { + ff_qsvvpp_print_warning(ctx, err, "Warning in session initialization"); return AVERROR_UNKNOWN; } @@ -309,9 +313,17 @@ static int init_out_session(AVFilterContext *ctx) par.vpp.Out.FrameRateExtD = ctx->outputs[0]->time_base.den; } + /* Print input memory mode */ + ff_qsvvpp_print_iopattern(ctx, par.IOPattern & 0x0F, "VPP"); + /* Print output memory mode */ + ff_qsvvpp_print_iopattern(ctx, par.IOPattern & 0xF0, "VPP"); err = MFXVideoVPP_Init(s->session, &par); - if (err != MFX_ERR_NONE) { - av_log(ctx, AV_LOG_ERROR, "Error opening the VPP for deinterlacing: %d\n", err); + if (err < 0) + return ff_qsvvpp_print_error(ctx, err, + "Error opening the VPP for deinterlacing"); + else if (err > 0) { + ff_qsvvpp_print_warning(ctx, err, + "Warning in VPP initialization"); return AVERROR_UNKNOWN; } @@ -482,8 +494,13 @@ static int process_frame(AVFilterContext *ctx, const AVFrame *in, return QSVDEINT_MORE_INPUT; } - if ((err < 0 && err != MFX_ERR_MORE_SURFACE) || !sync) { - av_log(ctx, AV_LOG_ERROR, "Error during deinterlacing: %d\n", err); + if (err < 0 && err != MFX_ERR_MORE_SURFACE) { + ret = ff_qsvvpp_print_error(ctx, err, "Error during deinterlacing"); + goto fail; + } + + if (!sync) { + av_log(ctx, AV_LOG_ERROR, "No sync during deinterlacing\n"); ret = AVERROR_UNKNOWN; goto fail; } @@ -494,8 +511,7 @@ static int process_frame(AVFilterContext *ctx, const AVFrame *in, err = MFXVideoCORE_SyncOperation(s->session, sync, 1000); } while (err == MFX_WRN_IN_EXECUTION); if (err < 0) { - av_log(ctx, AV_LOG_ERROR, "Error synchronizing the operation: %d\n", err); - ret = AVERROR_UNKNOWN; + ret = ff_qsvvpp_print_error(ctx, err, "Error synchronizing the operation"); goto fail; } diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c index 5064dcbb60..2ac2373955 100644 --- a/libavfilter/vf_scale_qsv.c +++ b/libavfilter/vf_scale_qsv.c @@ -313,8 +313,10 @@ static int init_out_session(AVFilterContext *ctx) } } - if (err != MFX_ERR_NONE) { - av_log(ctx, AV_LOG_ERROR, "Error getting the session handle\n"); + if (err < 0) + return ff_qsvvpp_print_error(ctx, err, "Error getting the session handle"); + else if (err > 0) { + ff_qsvvpp_print_warning(ctx, err, "Warning in getting the session handle"); return AVERROR_UNKNOWN; } @@ -430,9 +432,17 @@ static int init_out_session(AVFilterContext *ctx) par.vpp.Out.FrameRateExtN = 25; par.vpp.Out.FrameRateExtD = 1; + /* Print input memory mode */ + ff_qsvvpp_print_iopattern(ctx, par.IOPattern & 0x0F, "VPP"); + /* Print output memory mode */ + ff_qsvvpp_print_iopattern(ctx, par.IOPattern & 0xF0, "VPP"); err = MFXVideoVPP_Init(s->session, &par); - if (err != MFX_ERR_NONE) { - av_log(ctx, AV_LOG_ERROR, "Error opening the VPP for scaling\n"); + if (err < 0) + return ff_qsvvpp_print_error(ctx, err, + "Error opening the VPP for scaling"); + else if (err > 0) { + ff_qsvvpp_print_warning(ctx, err, + "Warning in VPP initialization"); return AVERROR_UNKNOWN; } @@ -573,8 +583,13 @@ static int qsvscale_filter_frame(AVFilterLink *link, AVFrame *in) av_usleep(1); } while (err == MFX_WRN_DEVICE_BUSY); - if (err < 0 || !sync) { - av_log(ctx, AV_LOG_ERROR, "Error during scaling\n"); + if (err < 0) { + ret = ff_qsvvpp_print_error(ctx, err, "Error during scaling"); + goto fail; + } + + if (!sync) { + av_log(ctx, AV_LOG_ERROR, "No sync during scaling\n"); ret = AVERROR_UNKNOWN; goto fail; } @@ -583,8 +598,7 @@ static int qsvscale_filter_frame(AVFilterLink *link, AVFrame *in) err = MFXVideoCORE_SyncOperation(s->session, sync, 1000); } while (err == MFX_WRN_IN_EXECUTION); if (err < 0) { - av_log(ctx, AV_LOG_ERROR, "Error synchronizing the operation: %d\n", err); - ret = AVERROR_UNKNOWN; + ret = ff_qsvvpp_print_error(ctx, err, "Error synchronizing the operation"); goto fail; }