[FFmpeg-devel] [PATCH 1/2] lavc/qsv: use avpriv_ instead of ff_ as prefix for some functions

Haihao Xiang haihao.xiang at intel.com
Mon Nov 23 10:16:13 EET 2020


ff_qsv_print_iopattern, ff_qsv_print_error and ff_qsv_print_warning can be
used outside of lavc. In addition, ff_qsv_map_error is used in
libavcodec/qsv.c only, so remove ff_ from ff_qsv_map_error and make it
static.

Signed-off-by: Haihao Xiang <haihao.xiang at intel.com>
---
 libavcodec/Makefile            |  2 +-
 libavcodec/qsv.c               | 46 +++++++++++++++++-----------------
 libavcodec/qsv_core_internal.h | 43 +++++++++++++++++++++++++++++++
 libavcodec/qsv_internal.h      | 24 +-----------------
 libavcodec/qsvdec.c            | 16 ++++++------
 libavcodec/qsvenc.c            | 36 +++++++++++++-------------
 6 files changed, 94 insertions(+), 73 deletions(-)
 create mode 100644 libavcodec/qsv_core_internal.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b4777be4d4..d1e744b954 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1193,7 +1193,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..99ec1cab9e 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -101,8 +101,8 @@ static const struct {
     {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)
+int avpriv_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
+                               const char *extra_string)
 {
     const char *desc = NULL;
 
@@ -158,7 +158,7 @@ static const struct {
     { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,               "incompatible audio parameters"        },
 };
 
-int ff_qsv_map_error(mfxStatus mfx_err, const char **desc)
+static int qsv_map_error(mfxStatus mfx_err, const char **desc)
 {
     int i;
     for (i = 0; i < FF_ARRAY_ELEMS(qsv_errors); i++) {
@@ -173,22 +173,22 @@ int ff_qsv_map_error(mfxStatus mfx_err, const char **desc)
     return AVERROR_UNKNOWN;
 }
 
-int ff_qsv_print_error(void *log_ctx, mfxStatus err,
-                       const char *error_string)
+int avpriv_qsv_print_error(void *log_ctx, mfxStatus err,
+                           const char *error_string)
 {
     const char *desc;
     int ret;
-    ret = ff_qsv_map_error(err, &desc);
+    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_qsv_print_warning(void *log_ctx, mfxStatus err,
-                         const char *warning_string)
+int avpriv_qsv_print_warning(void *log_ctx, mfxStatus err,
+                             const char *warning_string)
 {
     const char *desc;
     int ret;
-    ret = ff_qsv_map_error(err, &desc);
+    ret = qsv_map_error(err, &desc);
     av_log(log_ctx, AV_LOG_WARNING, "%s: %s (%d)\n", warning_string, desc, err);
     return ret;
 }
@@ -331,7 +331,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 = avpriv_qsv_print_error(logctx, ret, errorbuf);
             goto load_plugin_fail;
         }
 
@@ -372,7 +372,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 avpriv_qsv_print_error(avctx, ret, "Error during set display handle\n");
         }
     }
 
@@ -397,8 +397,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 avpriv_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 +713,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 avpriv_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 +736,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 avpriv_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 avpriv_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 avpriv_qsv_print_error(avctx, err,
+                                          "Error joining session");
     }
 
     ret = qsv_load_plugins(session, load_plugins, avctx);
@@ -802,8 +802,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 avpriv_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..0ca87be05a
--- /dev/null
+++ b/libavcodec/qsv_core_internal.h
@@ -0,0 +1,43 @@
+/*
+ * 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)))
+
+int avpriv_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
+                               const char *extra_string);
+
+int avpriv_qsv_print_error(void *log_ctx, mfxStatus err,
+                           const char *error_string);
+
+int avpriv_qsv_print_warning(void *log_ctx, mfxStatus err,
+                             const char *warning_string);
+
+#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..c543e958c4 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");
+    avpriv_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 avpriv_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 avpriv_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 avpriv_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");
+            avpriv_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..cdb527608b 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 avpriv_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 avpriv_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 avpriv_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 avpriv_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 avpriv_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 avpriv_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 avpriv_qsv_print_error(avctx, ret,
+                                      "Error initializing the encoder");
     else if (ret > 0)
-        ff_qsv_print_warning(avctx, ret,
-                             "Warning in encoder initialization");
+        avpriv_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");
+        avpriv_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 : avpriv_qsv_print_error(avctx, ret, "Error during encoding");
     }
 
     if (ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM && frame->interlaced_frame)
-- 
2.25.1



More information about the ffmpeg-devel mailing list