diff mbox series

[FFmpeg-devel,v2,1/2] lavc/qsv: make some functions inline

Message ID 20201207015905.305080-1-haihao.xiang@intel.com
State New
Headers show
Series [FFmpeg-devel,v2,1/2] lavc/qsv: make some functions inline | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Xiang, Haihao Dec. 7, 2020, 1:59 a.m. UTC
ff_qsv_print_iopattern, ff_qsv_print_error, ff_qsv_print_warning and
ff_qsv_map_error can be used outside of lavc, make them inline in a
private header so that other libraries may include this private header.
In addition, QSV_VERSION_ATLEAST() and QSV_RUNTIME_VERSION_ATLEAST() can
be used across libraries as well.

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
Per the comments from Anton and James, I used inline functions instead
of avpriv functions in this patch

 libavcodec/Makefile            |   2 +-
 libavcodec/qsv.c               | 132 ++++---------------------------
 libavcodec/qsv_core_internal.h | 139 +++++++++++++++++++++++++++++++++
 libavcodec/qsv_internal.h      |  24 +-----
 libavcodec/qsvdec.c            |  16 ++--
 libavcodec/qsvenc.c            |  36 ++++-----
 6 files changed, 181 insertions(+), 168 deletions(-)
 create mode 100644 libavcodec/qsv_core_internal.h

Comments

Andreas Rheinhardt Dec. 7, 2020, 2:10 a.m. UTC | #1
Haihao Xiang:
> ff_qsv_print_iopattern, ff_qsv_print_error, ff_qsv_print_warning and
> ff_qsv_map_error can be used outside of lavc, make them inline in a
> private header so that other libraries may include this private header.
> In addition, QSV_VERSION_ATLEAST() and QSV_RUNTIME_VERSION_ATLEAST() can
> be used across libraries as well.
> 
> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> ---
> Per the comments from Anton and James, I used inline functions instead
> of avpriv functions in this patch
> 
>  libavcodec/Makefile            |   2 +-
>  libavcodec/qsv.c               | 132 ++++---------------------------
>  libavcodec/qsv_core_internal.h | 139 +++++++++++++++++++++++++++++++++
>  libavcodec/qsv_internal.h      |  24 +-----
>  libavcodec/qsvdec.c            |  16 ++--
>  libavcodec/qsvenc.c            |  36 ++++-----
>  6 files changed, 181 insertions(+), 168 deletions(-)
>  create mode 100644 libavcodec/qsv_core_internal.h
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 33e08548f5..20d9e5159a 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1196,7 +1196,7 @@ SKIPHEADERS-$(CONFIG_MEDIACODEC)       += mediacodecdec_common.h mediacodec_surf
>  SKIPHEADERS-$(CONFIG_MEDIAFOUNDATION)  += mf_utils.h
>  SKIPHEADERS-$(CONFIG_NVDEC)            += nvdec.h
>  SKIPHEADERS-$(CONFIG_NVENC)            += nvenc.h
> -SKIPHEADERS-$(CONFIG_QSV)              += qsv.h qsv_internal.h
> +SKIPHEADERS-$(CONFIG_QSV)              += qsv.h qsv_internal.h qsv_core_internal.h
>  SKIPHEADERS-$(CONFIG_QSVDEC)           += qsvdec.h
>  SKIPHEADERS-$(CONFIG_QSVENC)           += qsvenc.h
>  SKIPHEADERS-$(CONFIG_XVMC)             += xvmc.h
> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> index 6e3154e1a3..76be7b2e77 100644
> --- a/libavcodec/qsv.c
> +++ b/libavcodec/qsv.c
> @@ -89,110 +89,6 @@ int ff_qsv_level_to_mfx(enum AVCodecID codec_id, int level)
>      }
>  }
>  
> -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_qsv_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"        },
> -};
> -
> -int ff_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_qsv_print_error(void *log_ctx, mfxStatus err,
> -                       const char *error_string)
> -{
> -    const char *desc;
> -    int ret;
> -    ret = ff_qsv_map_error(err, &desc);
> -    av_log(log_ctx, AV_LOG_ERROR, "%s: %s (%d)\n", error_string, desc, err);
> -    return ret;
> -}
> -
> -int ff_qsv_print_warning(void *log_ctx, mfxStatus err,
> -                         const char *warning_string)
> -{
> -    const char *desc;
> -    int ret;
> -    ret = ff_qsv_map_error(err, &desc);
> -    av_log(log_ctx, AV_LOG_WARNING, "%s: %s (%d)\n", warning_string, desc, err);
> -    return ret;
> -}
> -
>  enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc)
>  {
>      switch (fourcc) {
> @@ -331,7 +227,7 @@ static int qsv_load_plugins(mfxSession session, const char *load_plugins,
>              char errorbuf[128];
>              snprintf(errorbuf, sizeof(errorbuf),
>                       "Could not load the requested plugin '%s'", plugin);
> -            err = ff_qsv_print_error(logctx, ret, errorbuf);
> +            err = qsv_print_error(logctx, ret, errorbuf);
>              goto load_plugin_fail;
>          }
>  
> @@ -372,7 +268,7 @@ static int ff_qsv_set_display_handle(AVCodecContext *avctx, QSVSession *qs)
>          ret = MFXVideoCORE_SetHandle(qs->session,
>                  (mfxHandleType)MFX_HANDLE_VA_DISPLAY, (mfxHDL)hwctx->display);
>          if (ret < 0) {
> -            return ff_qsv_print_error(avctx, ret, "Error during set display handle\n");
> +            return qsv_print_error(avctx, ret, "Error during set display handle\n");
>          }
>      }
>  
> @@ -397,8 +293,8 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
>      init_par.Version        = ver;
>      ret = MFXInitEx(init_par, &qs->session);
>      if (ret < 0)
> -        return ff_qsv_print_error(avctx, ret,
> -                                  "Error initializing an internal MFX session");
> +        return qsv_print_error(avctx, ret,
> +                               "Error initializing an internal MFX session");
>  
>  #ifdef AVCODEC_QSV_LINUX_SESSION_HANDLE
>      ret = ff_qsv_set_display_handle(avctx, qs);
> @@ -713,8 +609,8 @@ int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession,
>      if (err == MFX_ERR_NONE)
>          err = MFXQueryVersion(parent_session, &ver);
>      if (err != MFX_ERR_NONE)
> -        return ff_qsv_print_error(avctx, err,
> -                                  "Error querying the session attributes");
> +        return qsv_print_error(avctx, err,
> +                               "Error querying the session attributes");
>  
>      for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
>          err = MFXVideoCORE_GetHandle(parent_session, handle_types[i], &handle);
> @@ -736,21 +632,21 @@ int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession,
>      init_par.Version        = ver;
>      err = MFXInitEx(init_par, &session);
>      if (err != MFX_ERR_NONE)
> -        return ff_qsv_print_error(avctx, err,
> -                                  "Error initializing a child MFX session");
> +        return qsv_print_error(avctx, err,
> +                               "Error initializing a child MFX session");
>  
>      if (handle) {
>          err = MFXVideoCORE_SetHandle(session, handle_type, handle);
>          if (err != MFX_ERR_NONE)
> -            return ff_qsv_print_error(avctx, err,
> -                                      "Error setting a HW handle");
> +            return qsv_print_error(avctx, err,
> +                                   "Error setting a HW handle");
>      }
>  
>      if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
>          err = MFXJoinSession(parent_session, session);
>          if (err != MFX_ERR_NONE)
> -            return ff_qsv_print_error(avctx, err,
> -                                      "Error joining session");
> +            return qsv_print_error(avctx, err,
> +                                   "Error joining session");
>      }
>  
>      ret = qsv_load_plugins(session, load_plugins, avctx);
> @@ -802,8 +698,8 @@ int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *psession,
>  
>          err = MFXVideoCORE_SetFrameAllocator(session, &frame_allocator);
>          if (err != MFX_ERR_NONE)
> -            return ff_qsv_print_error(avctx, err,
> -                                      "Error setting a frame allocator");
> +            return qsv_print_error(avctx, err,
> +                                   "Error setting a frame allocator");
>      }
>  
>      *psession = session;
> diff --git a/libavcodec/qsv_core_internal.h b/libavcodec/qsv_core_internal.h
> new file mode 100644
> index 0000000000..6cd694f4f2
> --- /dev/null
> +++ b/libavcodec/qsv_core_internal.h
> @@ -0,0 +1,139 @@
> +/*
> + * Intel MediaSDK QSV encoder/decoder/filter shared code
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#ifndef AVCODEC_QSV_CORE_INTERNAL_H
> +#define AVCODEC_QSV_CORE_INTERNAL_H
> +
> +#include <mfx/mfxvideo.h>
> +
> +#define QSV_VERSION_ATLEAST(MAJOR, MINOR)   \
> +    (MFX_VERSION_MAJOR > (MAJOR) ||         \
> +     MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
> +
> +#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR) \
> +    ((MFX_VERSION.Major > (MAJOR)) ||                           \
> +    (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
> +
> +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"       },
> +};
> +
> +static inline int qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
> +                                      const char *extra_string)
> +{
> +    const char *desc = NULL;
> +    int i;
> +
> +    for (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 inline 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;
> +}
> +
> +static inline int qsv_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;
> +}
> +
> +static inline int qsv_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;
> +}
> +
> +#endif /* AVCODEC_QSV_CORE_INTERNAL_H */
> diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
> index 6b2fbbe252..e563c54068 100644
> --- a/libavcodec/qsv_internal.h
> +++ b/libavcodec/qsv_internal.h
> @@ -39,7 +39,7 @@
>  #include "libavutil/hwcontext_vaapi.h"
>  #endif
>  
> -#include <mfx/mfxvideo.h>
> +#include "qsv_core_internal.h"
>  
>  #include "libavutil/frame.h"
>  
> @@ -52,14 +52,6 @@
>  
>  #define QSV_MAX_ENC_PAYLOAD 2       // # of mfxEncodeCtrl payloads supported
>  
> -#define QSV_VERSION_ATLEAST(MAJOR, MINOR)   \
> -    (MFX_VERSION_MAJOR > (MAJOR) ||         \
> -     MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
> -
> -#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR) \
> -    ((MFX_VERSION.Major > (MAJOR)) ||                           \
> -    (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
> -
>  typedef struct QSVMid {
>      AVBufferRef *hw_frames_ref;
>      mfxHDL handle;
> @@ -103,20 +95,6 @@ typedef struct QSVFramesContext {
>      int  nb_mids;
>  } QSVFramesContext;
>  
> -int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
> -                           const char *extra_string);
> -
> -/**
> - * Convert a libmfx error code into an ffmpeg error code.
> - */
> -int ff_qsv_map_error(mfxStatus mfx_err, const char **desc);
> -
> -int ff_qsv_print_error(void *log_ctx, mfxStatus err,
> -                       const char *error_string);
> -
> -int ff_qsv_print_warning(void *log_ctx, mfxStatus err,
> -                         const char *warning_string);
> -
>  int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
>  int ff_qsv_level_to_mfx(enum AVCodecID codec_id, int level);
>  
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index c666aaeb52..adfea08a51 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -212,7 +212,7 @@ static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixel
>          iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
>      q->iopattern = iopattern;
>  
> -    ff_qsv_print_iopattern(avctx, q->iopattern, "Decoder");
> +    qsv_print_iopattern(avctx, q->iopattern, "Decoder");
>  
>      ret = qsv_init_session(avctx, q, session, avctx->hw_frames_ctx, avctx->hw_device_ctx);
>      if (ret < 0) {
> @@ -243,8 +243,8 @@ static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q, mfxVideoParam *
>  
>      ret = MFXVideoDECODE_Init(q->session, param);
>      if (ret < 0)
> -        return ff_qsv_print_error(avctx, ret,
> -                                  "Error initializing the MFX video decoder");
> +        return qsv_print_error(avctx, ret,
> +                               "Error initializing the MFX video decoder");
>  
>      q->frame_info = param->mfx.FrameInfo;
>  
> @@ -287,8 +287,8 @@ static int qsv_decode_header(AVCodecContext *avctx, QSVContext *q, AVPacket *avp
>         return AVERROR(EAGAIN);
>      }
>      if (ret < 0)
> -        return ff_qsv_print_error(avctx, ret,
> -                "Error decoding stream header");
> +        return qsv_print_error(avctx, ret,
> +                               "Error decoding stream header");
>  
>      return 0;
>  }
> @@ -442,8 +442,8 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
>          ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
>          ret != MFX_ERR_MORE_SURFACE) {
>          av_freep(&sync);
> -        return ff_qsv_print_error(avctx, ret,
> -                                  "Error during QSV decoding.");
> +        return qsv_print_error(avctx, ret,
> +                               "Error during QSV decoding.");
>      }
>  
>      /* make sure we do not enter an infinite loop if the SDK
> @@ -452,7 +452,7 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
>          bs.DataOffset = avpkt->size;
>          ++q->zero_consume_run;
>          if (q->zero_consume_run > 1)
> -            ff_qsv_print_warning(avctx, ret, "A decode call did not consume any data");
> +            qsv_print_warning(avctx, ret, "A decode call did not consume any data");
>      } else if (!*sync && bs.DataOffset) {
>          ++q->buffered_count;
>      } else {
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 2bd2a56227..53377fbf26 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -820,8 +820,8 @@ static int qsv_retrieve_enc_jpeg_params(AVCodecContext *avctx, QSVEncContext *q)
>  
>      ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param);
>      if (ret < 0)
> -        return ff_qsv_print_error(avctx, ret,
> -                                  "Error calling GetVideoParam");
> +        return qsv_print_error(avctx, ret,
> +                               "Error calling GetVideoParam");
>  
>      q->packet_size = q->param.mfx.BufferSizeInKB * q->param.mfx.BRCParamMultiplier * 1000;
>  
> @@ -873,8 +873,8 @@ static int qsv_retrieve_enc_vp9_params(AVCodecContext *avctx, QSVEncContext *q)
>  
>      ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param);
>      if (ret < 0)
> -        return ff_qsv_print_error(avctx, ret,
> -                                  "Error calling GetVideoParam");
> +        return qsv_print_error(avctx, ret,
> +                               "Error calling GetVideoParam");
>  
>      q->packet_size = q->param.mfx.BufferSizeInKB * q->param.mfx.BRCParamMultiplier * 1000;
>  
> @@ -957,8 +957,8 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q)
>  
>      ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param);
>      if (ret < 0)
> -        return ff_qsv_print_error(avctx, ret,
> -                                  "Error calling GetVideoParam");
> +        return qsv_print_error(avctx, ret,
> +                               "Error calling GetVideoParam");
>  
>      q->packet_size = q->param.mfx.BufferSizeInKB * q->param.mfx.BRCParamMultiplier * 1000;
>  
> @@ -1139,8 +1139,8 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
>  
>      ret = MFXQueryVersion(q->session,&q->ver);
>      if (ret < 0) {
> -        return ff_qsv_print_error(avctx, ret,
> -                                  "Error querying mfx version");
> +        return qsv_print_error(avctx, ret,
> +                               "Error querying mfx version");
>      }
>  
>      // in the mfxInfoMFX struct, JPEG is different from other codecs
> @@ -1188,14 +1188,14 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
>      if (ret == MFX_WRN_PARTIAL_ACCELERATION) {
>          av_log(avctx, AV_LOG_WARNING, "Encoder will work with partial HW acceleration\n");
>      } else if (ret < 0) {
> -        return ff_qsv_print_error(avctx, ret,
> -                                  "Error querying encoder params");
> +        return qsv_print_error(avctx, ret,
> +                               "Error querying encoder params");
>      }
>  
>      ret = MFXVideoENCODE_QueryIOSurf(q->session, &q->param, &q->req);
>      if (ret < 0)
> -        return ff_qsv_print_error(avctx, ret,
> -                                  "Error querying (IOSurf) the encoding parameters");
> +        return qsv_print_error(avctx, ret,
> +                               "Error querying (IOSurf) the encoding parameters");
>  
>      if (opaque_alloc) {
>          ret = qsv_init_opaque_alloc(avctx, q);
> @@ -1205,11 +1205,11 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
>  
>      ret = MFXVideoENCODE_Init(q->session, &q->param);
>      if (ret < 0)
> -        return ff_qsv_print_error(avctx, ret,
> -                                  "Error initializing the encoder");
> +        return qsv_print_error(avctx, ret,
> +                               "Error initializing the encoder");
>      else if (ret > 0)
> -        ff_qsv_print_warning(avctx, ret,
> -                             "Warning in encoder initialization");
> +        qsv_print_warning(avctx, ret,
> +                          "Warning in encoder initialization");
>  
>      switch (avctx->codec_id) {
>      case AV_CODEC_ID_MJPEG:
> @@ -1479,7 +1479,7 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
>      } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_WRN_IN_EXECUTION);
>  
>      if (ret > 0)
> -        ff_qsv_print_warning(avctx, ret, "Warning during encoding");
> +        qsv_print_warning(avctx, ret, "Warning during encoding");
>  
>      if (ret < 0) {
>          av_packet_unref(&new_pkt);
> @@ -1492,7 +1492,7 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
>  #endif
>          av_freep(&sync);
>          return (ret == MFX_ERR_MORE_DATA) ?
> -               0 : ff_qsv_print_error(avctx, ret, "Error during encoding");
> +               0 : qsv_print_error(avctx, ret, "Error during encoding");
>      }
>  
>      if (ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM && frame->interlaced_frame)
> 
This will duplicate the tables of error messages even inside the same
library. Can't you make it so that only one copy exists per library (and
of course only one for static builds)?

- Andreas
Xiang, Haihao Dec. 7, 2020, 4:55 a.m. UTC | #2
On Mon, 2020-12-07 at 03:10 +0100, Andreas Rheinhardt wrote:
> Haihao Xiang:
> > ff_qsv_print_iopattern, ff_qsv_print_error, ff_qsv_print_warning and
> > ff_qsv_map_error can be used outside of lavc, make them inline in a
> > private header so that other libraries may include this private header.
> > In addition, QSV_VERSION_ATLEAST() and QSV_RUNTIME_VERSION_ATLEAST() can
> > be used across libraries as well.
> > 
> > Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> > ---
> > Per the comments from Anton and James, I used inline functions instead
> > of avpriv functions in this patch
> > 
> >  libavcodec/Makefile            |   2 +-
> >  libavcodec/qsv.c               | 132 ++++---------------------------
> >  libavcodec/qsv_core_internal.h | 139 +++++++++++++++++++++++++++++++++
> >  libavcodec/qsv_internal.h      |  24 +-----
> >  libavcodec/qsvdec.c            |  16 ++--
> >  libavcodec/qsvenc.c            |  36 ++++-----
> >  6 files changed, 181 insertions(+), 168 deletions(-)
> >  create mode 100644 libavcodec/qsv_core_internal.h
> > 
> > diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> > index 33e08548f5..20d9e5159a 100644
> > --- a/libavcodec/Makefile
> > +++ b/libavcodec/Makefile
> > @@ -1196,7 +1196,7 @@ SKIPHEADERS-$(CONFIG_MEDIACODEC)       +=
> > mediacodecdec_common.h mediacodec_surf
> >  SKIPHEADERS-$(CONFIG_MEDIAFOUNDATION)  += mf_utils.h
> >  SKIPHEADERS-$(CONFIG_NVDEC)            += nvdec.h
> >  SKIPHEADERS-$(CONFIG_NVENC)            += nvenc.h
> > -SKIPHEADERS-$(CONFIG_QSV)              += qsv.h qsv_internal.h
> > +SKIPHEADERS-$(CONFIG_QSV)              += qsv.h qsv_internal.h
> > qsv_core_internal.h
> >  SKIPHEADERS-$(CONFIG_QSVDEC)           += qsvdec.h
> >  SKIPHEADERS-$(CONFIG_QSVENC)           += qsvenc.h
> >  SKIPHEADERS-$(CONFIG_XVMC)             += xvmc.h
> > diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> > index 6e3154e1a3..76be7b2e77 100644
> > --- a/libavcodec/qsv.c
> > +++ b/libavcodec/qsv.c
> > @@ -89,110 +89,6 @@ int ff_qsv_level_to_mfx(enum AVCodecID codec_id, int
> > level)
> >      }
> >  }
> >  
> > -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_qsv_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"        },
> > -};
> > -
> > -int ff_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_qsv_print_error(void *log_ctx, mfxStatus err,
> > -                       const char *error_string)
> > -{
> > -    const char *desc;
> > -    int ret;
> > -    ret = ff_qsv_map_error(err, &desc);
> > -    av_log(log_ctx, AV_LOG_ERROR, "%s: %s (%d)\n", error_string, desc,
> > err);
> > -    return ret;
> > -}
> > -
> > -int ff_qsv_print_warning(void *log_ctx, mfxStatus err,
> > -                         const char *warning_string)
> > -{
> > -    const char *desc;
> > -    int ret;
> > -    ret = ff_qsv_map_error(err, &desc);
> > -    av_log(log_ctx, AV_LOG_WARNING, "%s: %s (%d)\n", warning_string, desc,
> > err);
> > -    return ret;
> > -}
> > -
> >  enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc)
> >  {
> >      switch (fourcc) {
> > @@ -331,7 +227,7 @@ static int qsv_load_plugins(mfxSession session, const
> > char *load_plugins,
> >              char errorbuf[128];
> >              snprintf(errorbuf, sizeof(errorbuf),
> >                       "Could not load the requested plugin '%s'", plugin);
> > -            err = ff_qsv_print_error(logctx, ret, errorbuf);
> > +            err = qsv_print_error(logctx, ret, errorbuf);
> >              goto load_plugin_fail;
> >          }
> >  
> > @@ -372,7 +268,7 @@ static int ff_qsv_set_display_handle(AVCodecContext
> > *avctx, QSVSession *qs)
> >          ret = MFXVideoCORE_SetHandle(qs->session,
> >                  (mfxHandleType)MFX_HANDLE_VA_DISPLAY, (mfxHDL)hwctx-
> > >display);
> >          if (ret < 0) {
> > -            return ff_qsv_print_error(avctx, ret, "Error during set display
> > handle\n");
> > +            return qsv_print_error(avctx, ret, "Error during set display
> > handle\n");
> >          }
> >      }
> >  
> > @@ -397,8 +293,8 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx,
> > QSVSession *qs,
> >      init_par.Version        = ver;
> >      ret = MFXInitEx(init_par, &qs->session);
> >      if (ret < 0)
> > -        return ff_qsv_print_error(avctx, ret,
> > -                                  "Error initializing an internal MFX
> > session");
> > +        return qsv_print_error(avctx, ret,
> > +                               "Error initializing an internal MFX
> > session");
> >  
> >  #ifdef AVCODEC_QSV_LINUX_SESSION_HANDLE
> >      ret = ff_qsv_set_display_handle(avctx, qs);
> > @@ -713,8 +609,8 @@ int ff_qsv_init_session_device(AVCodecContext *avctx,
> > mfxSession *psession,
> >      if (err == MFX_ERR_NONE)
> >          err = MFXQueryVersion(parent_session, &ver);
> >      if (err != MFX_ERR_NONE)
> > -        return ff_qsv_print_error(avctx, err,
> > -                                  "Error querying the session attributes");
> > +        return qsv_print_error(avctx, err,
> > +                               "Error querying the session attributes");
> >  
> >      for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
> >          err = MFXVideoCORE_GetHandle(parent_session, handle_types[i],
> > &handle);
> > @@ -736,21 +632,21 @@ int ff_qsv_init_session_device(AVCodecContext *avctx,
> > mfxSession *psession,
> >      init_par.Version        = ver;
> >      err = MFXInitEx(init_par, &session);
> >      if (err != MFX_ERR_NONE)
> > -        return ff_qsv_print_error(avctx, err,
> > -                                  "Error initializing a child MFX
> > session");
> > +        return qsv_print_error(avctx, err,
> > +                               "Error initializing a child MFX session");
> >  
> >      if (handle) {
> >          err = MFXVideoCORE_SetHandle(session, handle_type, handle);
> >          if (err != MFX_ERR_NONE)
> > -            return ff_qsv_print_error(avctx, err,
> > -                                      "Error setting a HW handle");
> > +            return qsv_print_error(avctx, err,
> > +                                   "Error setting a HW handle");
> >      }
> >  
> >      if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
> >          err = MFXJoinSession(parent_session, session);
> >          if (err != MFX_ERR_NONE)
> > -            return ff_qsv_print_error(avctx, err,
> > -                                      "Error joining session");
> > +            return qsv_print_error(avctx, err,
> > +                                   "Error joining session");
> >      }
> >  
> >      ret = qsv_load_plugins(session, load_plugins, avctx);
> > @@ -802,8 +698,8 @@ int ff_qsv_init_session_frames(AVCodecContext *avctx,
> > mfxSession *psession,
> >  
> >          err = MFXVideoCORE_SetFrameAllocator(session, &frame_allocator);
> >          if (err != MFX_ERR_NONE)
> > -            return ff_qsv_print_error(avctx, err,
> > -                                      "Error setting a frame allocator");
> > +            return qsv_print_error(avctx, err,
> > +                                   "Error setting a frame allocator");
> >      }
> >  
> >      *psession = session;
> > diff --git a/libavcodec/qsv_core_internal.h b/libavcodec/qsv_core_internal.h
> > new file mode 100644
> > index 0000000000..6cd694f4f2
> > --- /dev/null
> > +++ b/libavcodec/qsv_core_internal.h
> > @@ -0,0 +1,139 @@
> > +/*
> > + * Intel MediaSDK QSV encoder/decoder/filter shared code
> > + *
> > + * This file is part of FFmpeg.
> > + *
> > + * FFmpeg is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU Lesser General Public
> > + * License as published by the Free Software Foundation; either
> > + * version 2.1 of the License, or (at your option) any later version.
> > + *
> > + * FFmpeg is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > + * Lesser General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU Lesser General Public
> > + * License along with FFmpeg; if not, write to the Free Software
> > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> > USA
> > + */
> > +
> > +#ifndef AVCODEC_QSV_CORE_INTERNAL_H
> > +#define AVCODEC_QSV_CORE_INTERNAL_H
> > +
> > +#include <mfx/mfxvideo.h>
> > +
> > +#define QSV_VERSION_ATLEAST(MAJOR, MINOR)   \
> > +    (MFX_VERSION_MAJOR > (MAJOR) ||         \
> > +     MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
> > +
> > +#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR) \
> > +    ((MFX_VERSION.Major > (MAJOR)) ||                           \
> > +    (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
> > +
> > +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"       },
> > +};
> > +
> > +static inline int qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
> > +                                      const char *extra_string)
> > +{
> > +    const char *desc = NULL;
> > +    int i;
> > +
> > +    for (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 inline 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;
> > +}
> > +
> > +static inline int qsv_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;
> > +}
> > +
> > +static inline int qsv_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;
> > +}
> > +
> > +#endif /* AVCODEC_QSV_CORE_INTERNAL_H */
> > diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
> > index 6b2fbbe252..e563c54068 100644
> > --- a/libavcodec/qsv_internal.h
> > +++ b/libavcodec/qsv_internal.h
> > @@ -39,7 +39,7 @@
> >  #include "libavutil/hwcontext_vaapi.h"
> >  #endif
> >  
> > -#include <mfx/mfxvideo.h>
> > +#include "qsv_core_internal.h"
> >  
> >  #include "libavutil/frame.h"
> >  
> > @@ -52,14 +52,6 @@
> >  
> >  #define QSV_MAX_ENC_PAYLOAD 2       // # of mfxEncodeCtrl payloads
> > supported
> >  
> > -#define QSV_VERSION_ATLEAST(MAJOR, MINOR)   \
> > -    (MFX_VERSION_MAJOR > (MAJOR) ||         \
> > -     MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
> > -
> > -#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR) \
> > -    ((MFX_VERSION.Major > (MAJOR)) ||                           \
> > -    (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
> > -
> >  typedef struct QSVMid {
> >      AVBufferRef *hw_frames_ref;
> >      mfxHDL handle;
> > @@ -103,20 +95,6 @@ typedef struct QSVFramesContext {
> >      int  nb_mids;
> >  } QSVFramesContext;
> >  
> > -int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
> > -                           const char *extra_string);
> > -
> > -/**
> > - * Convert a libmfx error code into an ffmpeg error code.
> > - */
> > -int ff_qsv_map_error(mfxStatus mfx_err, const char **desc);
> > -
> > -int ff_qsv_print_error(void *log_ctx, mfxStatus err,
> > -                       const char *error_string);
> > -
> > -int ff_qsv_print_warning(void *log_ctx, mfxStatus err,
> > -                         const char *warning_string);
> > -
> >  int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
> >  int ff_qsv_level_to_mfx(enum AVCodecID codec_id, int level);
> >  
> > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> > index c666aaeb52..adfea08a51 100644
> > --- a/libavcodec/qsvdec.c
> > +++ b/libavcodec/qsvdec.c
> > @@ -212,7 +212,7 @@ static int qsv_decode_preinit(AVCodecContext *avctx,
> > QSVContext *q, enum AVPixel
> >          iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
> >      q->iopattern = iopattern;
> >  
> > -    ff_qsv_print_iopattern(avctx, q->iopattern, "Decoder");
> > +    qsv_print_iopattern(avctx, q->iopattern, "Decoder");
> >  
> >      ret = qsv_init_session(avctx, q, session, avctx->hw_frames_ctx, avctx-
> > >hw_device_ctx);
> >      if (ret < 0) {
> > @@ -243,8 +243,8 @@ static int qsv_decode_init(AVCodecContext *avctx,
> > QSVContext *q, mfxVideoParam *
> >  
> >      ret = MFXVideoDECODE_Init(q->session, param);
> >      if (ret < 0)
> > -        return ff_qsv_print_error(avctx, ret,
> > -                                  "Error initializing the MFX video
> > decoder");
> > +        return qsv_print_error(avctx, ret,
> > +                               "Error initializing the MFX video decoder");
> >  
> >      q->frame_info = param->mfx.FrameInfo;
> >  
> > @@ -287,8 +287,8 @@ static int qsv_decode_header(AVCodecContext *avctx,
> > QSVContext *q, AVPacket *avp
> >         return AVERROR(EAGAIN);
> >      }
> >      if (ret < 0)
> > -        return ff_qsv_print_error(avctx, ret,
> > -                "Error decoding stream header");
> > +        return qsv_print_error(avctx, ret,
> > +                               "Error decoding stream header");
> >  
> >      return 0;
> >  }
> > @@ -442,8 +442,8 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext
> > *q,
> >          ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
> >          ret != MFX_ERR_MORE_SURFACE) {
> >          av_freep(&sync);
> > -        return ff_qsv_print_error(avctx, ret,
> > -                                  "Error during QSV decoding.");
> > +        return qsv_print_error(avctx, ret,
> > +                               "Error during QSV decoding.");
> >      }
> >  
> >      /* make sure we do not enter an infinite loop if the SDK
> > @@ -452,7 +452,7 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext
> > *q,
> >          bs.DataOffset = avpkt->size;
> >          ++q->zero_consume_run;
> >          if (q->zero_consume_run > 1)
> > -            ff_qsv_print_warning(avctx, ret, "A decode call did not consume
> > any data");
> > +            qsv_print_warning(avctx, ret, "A decode call did not consume
> > any data");
> >      } else if (!*sync && bs.DataOffset) {
> >          ++q->buffered_count;
> >      } else {
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> > index 2bd2a56227..53377fbf26 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -820,8 +820,8 @@ static int qsv_retrieve_enc_jpeg_params(AVCodecContext
> > *avctx, QSVEncContext *q)
> >  
> >      ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param);
> >      if (ret < 0)
> > -        return ff_qsv_print_error(avctx, ret,
> > -                                  "Error calling GetVideoParam");
> > +        return qsv_print_error(avctx, ret,
> > +                               "Error calling GetVideoParam");
> >  
> >      q->packet_size = q->param.mfx.BufferSizeInKB * q-
> > >param.mfx.BRCParamMultiplier * 1000;
> >  
> > @@ -873,8 +873,8 @@ static int qsv_retrieve_enc_vp9_params(AVCodecContext
> > *avctx, QSVEncContext *q)
> >  
> >      ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param);
> >      if (ret < 0)
> > -        return ff_qsv_print_error(avctx, ret,
> > -                                  "Error calling GetVideoParam");
> > +        return qsv_print_error(avctx, ret,
> > +                               "Error calling GetVideoParam");
> >  
> >      q->packet_size = q->param.mfx.BufferSizeInKB * q-
> > >param.mfx.BRCParamMultiplier * 1000;
> >  
> > @@ -957,8 +957,8 @@ static int qsv_retrieve_enc_params(AVCodecContext
> > *avctx, QSVEncContext *q)
> >  
> >      ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param);
> >      if (ret < 0)
> > -        return ff_qsv_print_error(avctx, ret,
> > -                                  "Error calling GetVideoParam");
> > +        return qsv_print_error(avctx, ret,
> > +                               "Error calling GetVideoParam");
> >  
> >      q->packet_size = q->param.mfx.BufferSizeInKB * q-
> > >param.mfx.BRCParamMultiplier * 1000;
> >  
> > @@ -1139,8 +1139,8 @@ int ff_qsv_enc_init(AVCodecContext *avctx,
> > QSVEncContext *q)
> >  
> >      ret = MFXQueryVersion(q->session,&q->ver);
> >      if (ret < 0) {
> > -        return ff_qsv_print_error(avctx, ret,
> > -                                  "Error querying mfx version");
> > +        return qsv_print_error(avctx, ret,
> > +                               "Error querying mfx version");
> >      }
> >  
> >      // in the mfxInfoMFX struct, JPEG is different from other codecs
> > @@ -1188,14 +1188,14 @@ int ff_qsv_enc_init(AVCodecContext *avctx,
> > QSVEncContext *q)
> >      if (ret == MFX_WRN_PARTIAL_ACCELERATION) {
> >          av_log(avctx, AV_LOG_WARNING, "Encoder will work with partial HW
> > acceleration\n");
> >      } else if (ret < 0) {
> > -        return ff_qsv_print_error(avctx, ret,
> > -                                  "Error querying encoder params");
> > +        return qsv_print_error(avctx, ret,
> > +                               "Error querying encoder params");
> >      }
> >  
> >      ret = MFXVideoENCODE_QueryIOSurf(q->session, &q->param, &q->req);
> >      if (ret < 0)
> > -        return ff_qsv_print_error(avctx, ret,
> > -                                  "Error querying (IOSurf) the encoding
> > parameters");
> > +        return qsv_print_error(avctx, ret,
> > +                               "Error querying (IOSurf) the encoding
> > parameters");
> >  
> >      if (opaque_alloc) {
> >          ret = qsv_init_opaque_alloc(avctx, q);
> > @@ -1205,11 +1205,11 @@ int ff_qsv_enc_init(AVCodecContext *avctx,
> > QSVEncContext *q)
> >  
> >      ret = MFXVideoENCODE_Init(q->session, &q->param);
> >      if (ret < 0)
> > -        return ff_qsv_print_error(avctx, ret,
> > -                                  "Error initializing the encoder");
> > +        return qsv_print_error(avctx, ret,
> > +                               "Error initializing the encoder");
> >      else if (ret > 0)
> > -        ff_qsv_print_warning(avctx, ret,
> > -                             "Warning in encoder initialization");
> > +        qsv_print_warning(avctx, ret,
> > +                          "Warning in encoder initialization");
> >  
> >      switch (avctx->codec_id) {
> >      case AV_CODEC_ID_MJPEG:
> > @@ -1479,7 +1479,7 @@ static int encode_frame(AVCodecContext *avctx,
> > QSVEncContext *q,
> >      } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_WRN_IN_EXECUTION);
> >  
> >      if (ret > 0)
> > -        ff_qsv_print_warning(avctx, ret, "Warning during encoding");
> > +        qsv_print_warning(avctx, ret, "Warning during encoding");
> >  
> >      if (ret < 0) {
> >          av_packet_unref(&new_pkt);
> > @@ -1492,7 +1492,7 @@ static int encode_frame(AVCodecContext *avctx,
> > QSVEncContext *q,
> >  #endif
> >          av_freep(&sync);
> >          return (ret == MFX_ERR_MORE_DATA) ?
> > -               0 : ff_qsv_print_error(avctx, ret, "Error during encoding");
> > +               0 : qsv_print_error(avctx, ret, "Error during encoding");
> >      }
> >  
> >      if (ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM && frame->interlaced_frame)
> > 
> 
> This will duplicate the tables of error messages even inside the same
> library. Can't you make it so that only one copy exists per library (and
> of course only one for static builds)?

Seems the better way is not to change the tables and functions in lavc and
duplicate the corresponding tables and functions in lavf, I will send a new
patch if you are fine with this way.

Thanks
Haihao



> 
> - Andreas
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 33e08548f5..20d9e5159a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1196,7 +1196,7 @@  SKIPHEADERS-$(CONFIG_MEDIACODEC)       += mediacodecdec_common.h mediacodec_surf
 SKIPHEADERS-$(CONFIG_MEDIAFOUNDATION)  += mf_utils.h
 SKIPHEADERS-$(CONFIG_NVDEC)            += nvdec.h
 SKIPHEADERS-$(CONFIG_NVENC)            += nvenc.h
-SKIPHEADERS-$(CONFIG_QSV)              += qsv.h qsv_internal.h
+SKIPHEADERS-$(CONFIG_QSV)              += qsv.h qsv_internal.h qsv_core_internal.h
 SKIPHEADERS-$(CONFIG_QSVDEC)           += qsvdec.h
 SKIPHEADERS-$(CONFIG_QSVENC)           += qsvenc.h
 SKIPHEADERS-$(CONFIG_XVMC)             += xvmc.h
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 6e3154e1a3..76be7b2e77 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -89,110 +89,6 @@  int ff_qsv_level_to_mfx(enum AVCodecID codec_id, int level)
     }
 }
 
-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_qsv_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"        },
-};
-
-int ff_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_qsv_print_error(void *log_ctx, mfxStatus err,
-                       const char *error_string)
-{
-    const char *desc;
-    int ret;
-    ret = ff_qsv_map_error(err, &desc);
-    av_log(log_ctx, AV_LOG_ERROR, "%s: %s (%d)\n", error_string, desc, err);
-    return ret;
-}
-
-int ff_qsv_print_warning(void *log_ctx, mfxStatus err,
-                         const char *warning_string)
-{
-    const char *desc;
-    int ret;
-    ret = ff_qsv_map_error(err, &desc);
-    av_log(log_ctx, AV_LOG_WARNING, "%s: %s (%d)\n", warning_string, desc, err);
-    return ret;
-}
-
 enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc)
 {
     switch (fourcc) {
@@ -331,7 +227,7 @@  static int qsv_load_plugins(mfxSession session, const char *load_plugins,
             char errorbuf[128];
             snprintf(errorbuf, sizeof(errorbuf),
                      "Could not load the requested plugin '%s'", plugin);
-            err = ff_qsv_print_error(logctx, ret, errorbuf);
+            err = qsv_print_error(logctx, ret, errorbuf);
             goto load_plugin_fail;
         }
 
@@ -372,7 +268,7 @@  static int ff_qsv_set_display_handle(AVCodecContext *avctx, QSVSession *qs)
         ret = MFXVideoCORE_SetHandle(qs->session,
                 (mfxHandleType)MFX_HANDLE_VA_DISPLAY, (mfxHDL)hwctx->display);
         if (ret < 0) {
-            return ff_qsv_print_error(avctx, ret, "Error during set display handle\n");
+            return qsv_print_error(avctx, ret, "Error during set display handle\n");
         }
     }
 
@@ -397,8 +293,8 @@  int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
     init_par.Version        = ver;
     ret = MFXInitEx(init_par, &qs->session);
     if (ret < 0)
-        return ff_qsv_print_error(avctx, ret,
-                                  "Error initializing an internal MFX session");
+        return qsv_print_error(avctx, ret,
+                               "Error initializing an internal MFX session");
 
 #ifdef AVCODEC_QSV_LINUX_SESSION_HANDLE
     ret = ff_qsv_set_display_handle(avctx, qs);
@@ -713,8 +609,8 @@  int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession,
     if (err == MFX_ERR_NONE)
         err = MFXQueryVersion(parent_session, &ver);
     if (err != MFX_ERR_NONE)
-        return ff_qsv_print_error(avctx, err,
-                                  "Error querying the session attributes");
+        return qsv_print_error(avctx, err,
+                               "Error querying the session attributes");
 
     for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
         err = MFXVideoCORE_GetHandle(parent_session, handle_types[i], &handle);
@@ -736,21 +632,21 @@  int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession,
     init_par.Version        = ver;
     err = MFXInitEx(init_par, &session);
     if (err != MFX_ERR_NONE)
-        return ff_qsv_print_error(avctx, err,
-                                  "Error initializing a child MFX session");
+        return qsv_print_error(avctx, err,
+                               "Error initializing a child MFX session");
 
     if (handle) {
         err = MFXVideoCORE_SetHandle(session, handle_type, handle);
         if (err != MFX_ERR_NONE)
-            return ff_qsv_print_error(avctx, err,
-                                      "Error setting a HW handle");
+            return qsv_print_error(avctx, err,
+                                   "Error setting a HW handle");
     }
 
     if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
         err = MFXJoinSession(parent_session, session);
         if (err != MFX_ERR_NONE)
-            return ff_qsv_print_error(avctx, err,
-                                      "Error joining session");
+            return qsv_print_error(avctx, err,
+                                   "Error joining session");
     }
 
     ret = qsv_load_plugins(session, load_plugins, avctx);
@@ -802,8 +698,8 @@  int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *psession,
 
         err = MFXVideoCORE_SetFrameAllocator(session, &frame_allocator);
         if (err != MFX_ERR_NONE)
-            return ff_qsv_print_error(avctx, err,
-                                      "Error setting a frame allocator");
+            return qsv_print_error(avctx, err,
+                                   "Error setting a frame allocator");
     }
 
     *psession = session;
diff --git a/libavcodec/qsv_core_internal.h b/libavcodec/qsv_core_internal.h
new file mode 100644
index 0000000000..6cd694f4f2
--- /dev/null
+++ b/libavcodec/qsv_core_internal.h
@@ -0,0 +1,139 @@ 
+/*
+ * Intel MediaSDK QSV encoder/decoder/filter shared code
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_QSV_CORE_INTERNAL_H
+#define AVCODEC_QSV_CORE_INTERNAL_H
+
+#include <mfx/mfxvideo.h>
+
+#define QSV_VERSION_ATLEAST(MAJOR, MINOR)   \
+    (MFX_VERSION_MAJOR > (MAJOR) ||         \
+     MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
+
+#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR) \
+    ((MFX_VERSION.Major > (MAJOR)) ||                           \
+    (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
+
+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"       },
+};
+
+static inline int qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
+                                      const char *extra_string)
+{
+    const char *desc = NULL;
+    int i;
+
+    for (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 inline 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;
+}
+
+static inline int qsv_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;
+}
+
+static inline int qsv_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;
+}
+
+#endif /* AVCODEC_QSV_CORE_INTERNAL_H */
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 6b2fbbe252..e563c54068 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -39,7 +39,7 @@ 
 #include "libavutil/hwcontext_vaapi.h"
 #endif
 
-#include <mfx/mfxvideo.h>
+#include "qsv_core_internal.h"
 
 #include "libavutil/frame.h"
 
@@ -52,14 +52,6 @@ 
 
 #define QSV_MAX_ENC_PAYLOAD 2       // # of mfxEncodeCtrl payloads supported
 
-#define QSV_VERSION_ATLEAST(MAJOR, MINOR)   \
-    (MFX_VERSION_MAJOR > (MAJOR) ||         \
-     MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
-
-#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR) \
-    ((MFX_VERSION.Major > (MAJOR)) ||                           \
-    (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
-
 typedef struct QSVMid {
     AVBufferRef *hw_frames_ref;
     mfxHDL handle;
@@ -103,20 +95,6 @@  typedef struct QSVFramesContext {
     int  nb_mids;
 } QSVFramesContext;
 
-int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
-                           const char *extra_string);
-
-/**
- * Convert a libmfx error code into an ffmpeg error code.
- */
-int ff_qsv_map_error(mfxStatus mfx_err, const char **desc);
-
-int ff_qsv_print_error(void *log_ctx, mfxStatus err,
-                       const char *error_string);
-
-int ff_qsv_print_warning(void *log_ctx, mfxStatus err,
-                         const char *warning_string);
-
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
 int ff_qsv_level_to_mfx(enum AVCodecID codec_id, int level);
 
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index c666aaeb52..adfea08a51 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -212,7 +212,7 @@  static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixel
         iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
     q->iopattern = iopattern;
 
-    ff_qsv_print_iopattern(avctx, q->iopattern, "Decoder");
+    qsv_print_iopattern(avctx, q->iopattern, "Decoder");
 
     ret = qsv_init_session(avctx, q, session, avctx->hw_frames_ctx, avctx->hw_device_ctx);
     if (ret < 0) {
@@ -243,8 +243,8 @@  static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q, mfxVideoParam *
 
     ret = MFXVideoDECODE_Init(q->session, param);
     if (ret < 0)
-        return ff_qsv_print_error(avctx, ret,
-                                  "Error initializing the MFX video decoder");
+        return qsv_print_error(avctx, ret,
+                               "Error initializing the MFX video decoder");
 
     q->frame_info = param->mfx.FrameInfo;
 
@@ -287,8 +287,8 @@  static int qsv_decode_header(AVCodecContext *avctx, QSVContext *q, AVPacket *avp
        return AVERROR(EAGAIN);
     }
     if (ret < 0)
-        return ff_qsv_print_error(avctx, ret,
-                "Error decoding stream header");
+        return qsv_print_error(avctx, ret,
+                               "Error decoding stream header");
 
     return 0;
 }
@@ -442,8 +442,8 @@  static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
         ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
         ret != MFX_ERR_MORE_SURFACE) {
         av_freep(&sync);
-        return ff_qsv_print_error(avctx, ret,
-                                  "Error during QSV decoding.");
+        return qsv_print_error(avctx, ret,
+                               "Error during QSV decoding.");
     }
 
     /* make sure we do not enter an infinite loop if the SDK
@@ -452,7 +452,7 @@  static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
         bs.DataOffset = avpkt->size;
         ++q->zero_consume_run;
         if (q->zero_consume_run > 1)
-            ff_qsv_print_warning(avctx, ret, "A decode call did not consume any data");
+            qsv_print_warning(avctx, ret, "A decode call did not consume any data");
     } else if (!*sync && bs.DataOffset) {
         ++q->buffered_count;
     } else {
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 2bd2a56227..53377fbf26 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -820,8 +820,8 @@  static int qsv_retrieve_enc_jpeg_params(AVCodecContext *avctx, QSVEncContext *q)
 
     ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param);
     if (ret < 0)
-        return ff_qsv_print_error(avctx, ret,
-                                  "Error calling GetVideoParam");
+        return qsv_print_error(avctx, ret,
+                               "Error calling GetVideoParam");
 
     q->packet_size = q->param.mfx.BufferSizeInKB * q->param.mfx.BRCParamMultiplier * 1000;
 
@@ -873,8 +873,8 @@  static int qsv_retrieve_enc_vp9_params(AVCodecContext *avctx, QSVEncContext *q)
 
     ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param);
     if (ret < 0)
-        return ff_qsv_print_error(avctx, ret,
-                                  "Error calling GetVideoParam");
+        return qsv_print_error(avctx, ret,
+                               "Error calling GetVideoParam");
 
     q->packet_size = q->param.mfx.BufferSizeInKB * q->param.mfx.BRCParamMultiplier * 1000;
 
@@ -957,8 +957,8 @@  static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q)
 
     ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param);
     if (ret < 0)
-        return ff_qsv_print_error(avctx, ret,
-                                  "Error calling GetVideoParam");
+        return qsv_print_error(avctx, ret,
+                               "Error calling GetVideoParam");
 
     q->packet_size = q->param.mfx.BufferSizeInKB * q->param.mfx.BRCParamMultiplier * 1000;
 
@@ -1139,8 +1139,8 @@  int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
 
     ret = MFXQueryVersion(q->session,&q->ver);
     if (ret < 0) {
-        return ff_qsv_print_error(avctx, ret,
-                                  "Error querying mfx version");
+        return qsv_print_error(avctx, ret,
+                               "Error querying mfx version");
     }
 
     // in the mfxInfoMFX struct, JPEG is different from other codecs
@@ -1188,14 +1188,14 @@  int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
     if (ret == MFX_WRN_PARTIAL_ACCELERATION) {
         av_log(avctx, AV_LOG_WARNING, "Encoder will work with partial HW acceleration\n");
     } else if (ret < 0) {
-        return ff_qsv_print_error(avctx, ret,
-                                  "Error querying encoder params");
+        return qsv_print_error(avctx, ret,
+                               "Error querying encoder params");
     }
 
     ret = MFXVideoENCODE_QueryIOSurf(q->session, &q->param, &q->req);
     if (ret < 0)
-        return ff_qsv_print_error(avctx, ret,
-                                  "Error querying (IOSurf) the encoding parameters");
+        return qsv_print_error(avctx, ret,
+                               "Error querying (IOSurf) the encoding parameters");
 
     if (opaque_alloc) {
         ret = qsv_init_opaque_alloc(avctx, q);
@@ -1205,11 +1205,11 @@  int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
 
     ret = MFXVideoENCODE_Init(q->session, &q->param);
     if (ret < 0)
-        return ff_qsv_print_error(avctx, ret,
-                                  "Error initializing the encoder");
+        return qsv_print_error(avctx, ret,
+                               "Error initializing the encoder");
     else if (ret > 0)
-        ff_qsv_print_warning(avctx, ret,
-                             "Warning in encoder initialization");
+        qsv_print_warning(avctx, ret,
+                          "Warning in encoder initialization");
 
     switch (avctx->codec_id) {
     case AV_CODEC_ID_MJPEG:
@@ -1479,7 +1479,7 @@  static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
     } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_WRN_IN_EXECUTION);
 
     if (ret > 0)
-        ff_qsv_print_warning(avctx, ret, "Warning during encoding");
+        qsv_print_warning(avctx, ret, "Warning during encoding");
 
     if (ret < 0) {
         av_packet_unref(&new_pkt);
@@ -1492,7 +1492,7 @@  static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
 #endif
         av_freep(&sync);
         return (ret == MFX_ERR_MORE_DATA) ?
-               0 : ff_qsv_print_error(avctx, ret, "Error during encoding");
+               0 : qsv_print_error(avctx, ret, "Error during encoding");
     }
 
     if (ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM && frame->interlaced_frame)