[FFmpeg-devel] [PATCH 1/5] avutil/qsv: move ff_qsv_error function from libavcodec into libavutil, because it's going to be shared between libavcodec (existing QSV encoders & decoders), libavfilter (upcoming QSV VPP filter) and libavutil itself (upcoming hwcontext_qsv implementation). prefix changed to avpriv since it's now shared between multiple libraries.
nablet developer
sdk at nablet.com
Wed May 25 14:20:47 CEST 2016
Signed-off-by: nablet developer <sdk at nablet.com>
---
libavcodec/qsv.c | 41 ++++-----------------------------
libavcodec/qsv_internal.h | 5 ----
libavcodec/qsvdec.c | 7 +++---
libavcodec/qsvenc.c | 11 +++++----
libavutil/Makefile | 1 +
libavutil/qsv_internal.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++
libavutil/qsv_internal.h | 27 ++++++++++++++++++++++
7 files changed, 100 insertions(+), 50 deletions(-)
create mode 100644 libavutil/qsv_internal.c
create mode 100644 libavutil/qsv_internal.h
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 11d453d..8cd03e8 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -29,6 +29,7 @@
#include "avcodec.h"
#include "qsv_internal.h"
+#include "libavutil/qsv_internal.h"
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
{
@@ -51,40 +52,6 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
return AVERROR(ENOSYS);
}
-int ff_qsv_error(int mfx_err)
-{
- switch (mfx_err) {
- case MFX_ERR_NONE:
- return 0;
- case MFX_ERR_MEMORY_ALLOC:
- case MFX_ERR_NOT_ENOUGH_BUFFER:
- return AVERROR(ENOMEM);
- case MFX_ERR_INVALID_HANDLE:
- return AVERROR(EINVAL);
- case MFX_ERR_DEVICE_FAILED:
- case MFX_ERR_DEVICE_LOST:
- case MFX_ERR_LOCK_MEMORY:
- return AVERROR(EIO);
- case MFX_ERR_NULL_PTR:
- case MFX_ERR_UNDEFINED_BEHAVIOR:
- case MFX_ERR_NOT_INITIALIZED:
- return AVERROR_BUG;
- case MFX_ERR_UNSUPPORTED:
- case MFX_ERR_NOT_FOUND:
- return AVERROR(ENOSYS);
- case MFX_ERR_MORE_DATA:
- case MFX_ERR_MORE_SURFACE:
- case MFX_ERR_MORE_BITSTREAM:
- return AVERROR(EAGAIN);
- case MFX_ERR_INCOMPATIBLE_VIDEO_PARAM:
- case MFX_ERR_INVALID_VIDEO_PARAM:
- return AVERROR(EINVAL);
- case MFX_ERR_ABORTED:
- case MFX_ERR_UNKNOWN:
- default:
- return AVERROR_UNKNOWN;
- }
-}
static int ff_qsv_set_display_handle(AVCodecContext *avctx, QSVSession *qs)
{
// this code is only required for Linux. It searches for a valid
@@ -145,7 +112,7 @@ static int ff_qsv_set_display_handle(AVCodecContext *avctx, QSVSession *qs)
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR,
"Error %d during set display handle\n", ret);
- return ff_qsv_error(ret);
+ return avpriv_qsv_error(ret);
}
break;
}
@@ -180,7 +147,7 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
ret = MFXInit(impl, &ver, &qs->session);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Error initializing an internal MFX session\n");
- return ff_qsv_error(ret);
+ return avpriv_qsv_error(ret);
}
ret = ff_qsv_set_display_handle(avctx, qs);
@@ -215,7 +182,7 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Could not load the requested plugin: %s\n",
plugin);
- err = ff_qsv_error(ret);
+ err = avpriv_qsv_error(ret);
goto load_plugin_fail;
}
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index f289a2b..ce2531b 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -73,11 +73,6 @@ typedef struct QSVSession {
#endif
} QSVSession;
-/**
- * Convert a libmfx error code into a ffmpeg error code.
- */
-int ff_qsv_error(int mfx_err);
-
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index c17606d..5253a57 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -36,6 +36,7 @@
#include "internal.h"
#include "qsv.h"
#include "qsv_internal.h"
+#include "libavutil/qsv_internal.h"
#include "qsvdec.h"
int ff_qsv_map_pixfmt(enum AVPixelFormat format)
@@ -108,7 +109,7 @@ static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q, AVPacket *avpkt
return avpkt->size;
} else if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Decode header error %d\n", ret);
- return ff_qsv_error(ret);
+ return avpriv_qsv_error(ret);
}
param.IOPattern = q->iopattern;
param.AsyncDepth = q->async_depth;
@@ -126,7 +127,7 @@ static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q, AVPacket *avpkt
av_log(avctx, AV_LOG_ERROR,
"Error initializing the MFX video decoder %d\n", ret);
}
- return ff_qsv_error(ret);
+ return avpriv_qsv_error(ret);
}
avctx->profile = param.mfx.CodecProfile;
@@ -425,7 +426,7 @@ static int do_qsv_decode(AVCodecContext *avctx, QSVContext *q,
if (MFX_ERR_MORE_DATA!=ret && ret < 0) {
av_freep(&sync);
av_log(avctx, AV_LOG_ERROR, "Error %d during QSV decoding.\n", ret);
- return ff_qsv_error(ret);
+ return avpriv_qsv_error(ret);
}
n_out_frames = av_fifo_size(q->async_fifo) / (sizeof(out_frame)+sizeof(sync));
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 132cf47..6145121 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -36,6 +36,7 @@
#include "internal.h"
#include "qsv.h"
#include "qsv_internal.h"
+#include "libavutil/qsv_internal.h"
#include "qsvenc.h"
static const struct {
@@ -603,7 +604,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q)
ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param);
if (ret < 0)
- return ff_qsv_error(ret);
+ return avpriv_qsv_error(ret);
q->packet_size = q->param.mfx.BufferSizeInKB * 1000;
@@ -713,13 +714,13 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
av_log(avctx, AV_LOG_WARNING, "Encoder will work with partial HW acceleration\n");
} else if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Error %d querying encoder params\n", ret);
- return ff_qsv_error(ret);
+ return avpriv_qsv_error(ret);
}
ret = MFXVideoENCODE_QueryIOSurf(q->session, &q->param, &q->req);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Error querying the encoding parameters\n");
- return ff_qsv_error(ret);
+ return avpriv_qsv_error(ret);
}
if (opaque_alloc) {
@@ -762,7 +763,7 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
av_log(avctx, AV_LOG_WARNING, "Encoder will work with partial HW acceleration\n");
} else if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Error initializing the encoder\n");
- return ff_qsv_error(ret);
+ return avpriv_qsv_error(ret);
}
ret = qsv_retrieve_enc_params(avctx, q);
@@ -983,7 +984,7 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
if (ret == MFX_ERR_MORE_DATA)
return 0;
av_log(avctx, AV_LOG_ERROR, "EncodeFrameAsync returned %d\n", ret);
- return ff_qsv_error(ret);
+ return avpriv_qsv_error(ret);
}
if (ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM) {
diff --git a/libavutil/Makefile b/libavutil/Makefile
index a35deb6..e358767 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -154,6 +154,7 @@ OBJS-$(!HAVE_ATOMICS_NATIVE) += atomic.o \
OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
OBJS-$(CONFIG_LZO) += lzo.o
OBJS-$(CONFIG_OPENCL) += opencl.o opencl_internal.o
+OBJS-$(CONFIG_QSV) += qsv_internal.o
OBJS-$(CONFIG_VAAPI) += hwcontext_vaapi.o
OBJS-$(CONFIG_VDPAU) += hwcontext_vdpau.o
diff --git a/libavutil/qsv_internal.c b/libavutil/qsv_internal.c
new file mode 100644
index 0000000..08e3bba
--- /dev/null
+++ b/libavutil/qsv_internal.c
@@ -0,0 +1,58 @@
+/*
+ * 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
+ */
+
+#include <errno.h>
+#include "avutil.h"
+#include "qsv_internal.h"
+
+#include <mfx/mfxvideo.h>
+
+int avpriv_qsv_error(int mfx_err)
+{
+ switch (mfx_err) {
+ case MFX_ERR_NONE:
+ return 0;
+ case MFX_ERR_MEMORY_ALLOC:
+ case MFX_ERR_NOT_ENOUGH_BUFFER:
+ return AVERROR(ENOMEM);
+ case MFX_ERR_INVALID_HANDLE:
+ return AVERROR(EINVAL);
+ case MFX_ERR_DEVICE_FAILED:
+ case MFX_ERR_DEVICE_LOST:
+ case MFX_ERR_LOCK_MEMORY:
+ return AVERROR(EIO);
+ case MFX_ERR_NULL_PTR:
+ case MFX_ERR_UNDEFINED_BEHAVIOR:
+ case MFX_ERR_NOT_INITIALIZED:
+ return AVERROR_BUG;
+ case MFX_ERR_UNSUPPORTED:
+ case MFX_ERR_NOT_FOUND:
+ return AVERROR(ENOSYS);
+ case MFX_ERR_MORE_DATA:
+ case MFX_ERR_MORE_SURFACE:
+ case MFX_ERR_MORE_BITSTREAM:
+ return AVERROR(EAGAIN);
+ case MFX_ERR_INCOMPATIBLE_VIDEO_PARAM:
+ case MFX_ERR_INVALID_VIDEO_PARAM:
+ return AVERROR(EINVAL);
+ case MFX_ERR_ABORTED:
+ case MFX_ERR_UNKNOWN:
+ default:
+ return AVERROR_UNKNOWN;
+ }
+}
diff --git a/libavutil/qsv_internal.h b/libavutil/qsv_internal.h
new file mode 100644
index 0000000..c309419
--- /dev/null
+++ b/libavutil/qsv_internal.h
@@ -0,0 +1,27 @@
+/*
+ * 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 AVUTIL_QSV_INTERNAL_H
+#define AVUTIL_QSV_INTERNAL_H
+
+/**
+ * Convert a libmfx error code into a ffmpeg error code.
+ */
+int avpriv_qsv_error(int mfx_err);
+
+#endif /* AVUTIL_QSV_INTERNAL_H */
--
1.8.3.1
More information about the ffmpeg-devel
mailing list