]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/qsv.c
cinepakenc: misc small changes
[ffmpeg] / libavcodec / qsv.c
index 6c53489373f43ecd78c89a747aafd61af4a417af..30d612f0e1dac080625789fc0351d067ce0de9b7 100644 (file)
 #include "avcodec.h"
 #include "qsv_internal.h"
 
+#if QSV_VERSION_ATLEAST(1, 12)
+#include "mfx/mfxvp8.h"
+#endif
+
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 {
     switch (codec_id) {
@@ -48,6 +52,10 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
         return MFX_CODEC_MPEG2;
     case AV_CODEC_ID_VC1:
         return MFX_CODEC_VC1;
+#if QSV_VERSION_ATLEAST(1, 12)
+    case AV_CODEC_ID_VP8:
+        return MFX_CODEC_VP8;
+#endif
     default:
         break;
     }
@@ -55,6 +63,22 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
     return AVERROR(ENOSYS);
 }
 
+int ff_qsv_profile_to_mfx(enum AVCodecID codec_id, int profile)
+{
+    if (profile == FF_PROFILE_UNKNOWN)
+        return MFX_PROFILE_UNKNOWN;
+    switch (codec_id) {
+    case AV_CODEC_ID_H264:
+    case AV_CODEC_ID_HEVC:
+        return profile;
+    case AV_CODEC_ID_VC1:
+        return 4 * profile + 1;
+    case AV_CODEC_ID_MPEG2VIDEO:
+        return 0x10 * profile;
+    }
+    return MFX_PROFILE_UNKNOWN;
+}
+
 static const struct {
     mfxStatus   mfxerr;
     int         averr;
@@ -70,15 +94,17 @@ static const struct {
     { 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"       },
-    { MFX_ERR_MORE_DATA,                AVERROR(EAGAIN), "expect more data at input"            },
-    { MFX_ERR_MORE_SURFACE,             AVERROR(EAGAIN), "expect more surface at output"        },
+    /* 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_MORE_BITSTREAM,           AVERROR(EAGAIN), "expect more bitstream at output"      },
     { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio parameters"        },
     { MFX_ERR_INVALID_AUDIO_PARAM,      AVERROR(EINVAL), "invalid audio parameters"             },
 
@@ -442,9 +468,7 @@ static mfxStatus qsv_frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
     QSVMid *qsv_mid = mid;
     AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)qsv_mid->hw_frames_ref->data;
     AVQSVFramesContext *hw_frames_hwctx = hw_frames_ctx->hwctx;
-    int size;
     int ret;
-    mfxStatus err;
 
     if (qsv_mid->locked_frame)
         return MFX_ERR_UNDEFINED_BEHAVIOR;
@@ -499,7 +523,6 @@ fail:
 static mfxStatus qsv_frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
 {
     QSVMid *qsv_mid = mid;
-    int ret;
 
     av_frame_free(&qsv_mid->locked_frame);
     av_frame_free(&qsv_mid->hw_frame);
@@ -514,27 +537,16 @@ static mfxStatus qsv_frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
     return MFX_ERR_NONE;
 }
 
-int ff_qsv_init_session_hwcontext(AVCodecContext *avctx, mfxSession *psession,
-                                  QSVFramesContext *qsv_frames_ctx,
-                                  const char *load_plugins, int opaque)
+int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession,
+                               AVBufferRef *device_ref, const char *load_plugins)
 {
     static const mfxHandleType handle_types[] = {
         MFX_HANDLE_VA_DISPLAY,
         MFX_HANDLE_D3D9_DEVICE_MANAGER,
         MFX_HANDLE_D3D11_DEVICE,
     };
-    mfxFrameAllocator frame_allocator = {
-        .pthis  = qsv_frames_ctx,
-        .Alloc  = qsv_frame_alloc,
-        .Lock   = qsv_frame_lock,
-        .Unlock = qsv_frame_unlock,
-        .GetHDL = qsv_frame_get_hdl,
-        .Free   = qsv_frame_free,
-    };
-
-    AVHWFramesContext    *frames_ctx = (AVHWFramesContext*)qsv_frames_ctx->hw_frames_ctx->data;
-    AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
-    AVQSVDeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
+    AVHWDeviceContext    *device_ctx = (AVHWDeviceContext*)device_ref->data;
+    AVQSVDeviceContext *device_hwctx = device_ctx->hwctx;
     mfxSession        parent_session = device_hwctx->session;
 
     mfxSession    session;
@@ -584,6 +596,36 @@ int ff_qsv_init_session_hwcontext(AVCodecContext *avctx, mfxSession *psession,
         return ret;
     }
 
+    *psession = session;
+    return 0;
+}
+
+int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *psession,
+                               QSVFramesContext *qsv_frames_ctx,
+                               const char *load_plugins, int opaque)
+{
+    mfxFrameAllocator frame_allocator = {
+        .pthis  = qsv_frames_ctx,
+        .Alloc  = qsv_frame_alloc,
+        .Lock   = qsv_frame_lock,
+        .Unlock = qsv_frame_unlock,
+        .GetHDL = qsv_frame_get_hdl,
+        .Free   = qsv_frame_free,
+    };
+
+    AVHWFramesContext    *frames_ctx = (AVHWFramesContext*)qsv_frames_ctx->hw_frames_ctx->data;
+    AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
+
+    mfxSession    session;
+    mfxStatus err;
+
+    int ret;
+
+    ret = ff_qsv_init_session_device(avctx, &session,
+                                     frames_ctx->device_ref, load_plugins);
+    if (ret < 0)
+        return ret;
+
     if (!opaque) {
         qsv_frames_ctx->logctx = avctx;