]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/qsvdec.c
avcodec/hqx: Use av_clip_uintp2()
[ffmpeg] / libavcodec / qsvdec.c
index 762f158fff558836a224a4c1aa83150632fa4c50..47709b50f4e311fb8d359a1b1456e569dd93b5d2 100644 (file)
 
 #include "avcodec.h"
 #include "internal.h"
+#include "qsv_internal.h"
 #include "qsvdec.h"
 
-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;
-    }
-}
-
 int ff_qsv_map_pixfmt(enum AVPixelFormat format)
 {
     switch (format) {
@@ -82,58 +48,13 @@ int ff_qsv_map_pixfmt(enum AVPixelFormat format)
     }
 }
 
-static int codec_id_to_mfx(enum AVCodecID codec_id)
-{
-    switch (codec_id) {
-    case AV_CODEC_ID_H264:
-        return MFX_CODEC_AVC;
-    case AV_CODEC_ID_MPEG1VIDEO:
-    case AV_CODEC_ID_MPEG2VIDEO:
-        return MFX_CODEC_MPEG2;
-    case AV_CODEC_ID_VC1:
-        return MFX_CODEC_VC1;
-    default:
-        break;
-    }
-
-    return AVERROR(ENOSYS);
-}
-
 static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session)
 {
     if (!session) {
         if (!q->internal_session) {
-            mfxIMPL impl   = MFX_IMPL_AUTO_ANY;
-            mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } };
-
-            const char *desc;
-            int ret;
-
-            ret = MFXInit(impl, &ver, &q->internal_session);
-            if (ret < 0) {
-                av_log(avctx, AV_LOG_ERROR, "Error initializing an internal MFX session\n");
-                return ff_qsv_error(ret);
-            }
-
-            MFXQueryIMPL(q->internal_session, &impl);
-
-            switch (MFX_IMPL_BASETYPE(impl)) {
-            case MFX_IMPL_SOFTWARE:
-                desc = "software";
-                break;
-            case MFX_IMPL_HARDWARE:
-            case MFX_IMPL_HARDWARE2:
-            case MFX_IMPL_HARDWARE3:
-            case MFX_IMPL_HARDWARE4:
-                desc = "hardware accelerated";
-                break;
-            default:
-                desc = "unknown";
-            }
-
-            av_log(avctx, AV_LOG_VERBOSE,
-                   "Initialized an internal MFX session using %s implementation\n",
-                   desc);
+            int ret = ff_qsv_init_internal_session(avctx, &q->internal_session);
+            if (ret < 0)
+                return ret;
         }
 
         q->session = q->internal_session;
@@ -147,7 +68,7 @@ static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession ses
     return 0;
 }
 
-int ff_qsv_init(AVCodecContext *avctx, QSVContext *q, mfxSession session)
+int ff_qsv_decode_init(AVCodecContext *avctx, QSVContext *q, mfxSession session)
 {
     mfxVideoParam param = { { 0 } };
     int ret;
@@ -159,7 +80,7 @@ int ff_qsv_init(AVCodecContext *avctx, QSVContext *q, mfxSession session)
     }
 
 
-    ret = codec_id_to_mfx(avctx->codec_id);
+    ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
     if (ret < 0)
         return ret;
 
@@ -351,7 +272,7 @@ int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q,
     return bs.DataOffset;
 }
 
-int ff_qsv_close(QSVContext *q)
+int ff_qsv_decode_close(QSVContext *q)
 {
     QSVFrame *cur = q->work_frames;