21 #include <mfx/mfxvideo.h> 22 #include <mfx/mfxplugin.h> 41 #if QSV_VERSION_ATLEAST(1, 8) 43 return MFX_CODEC_HEVC;
47 return MFX_CODEC_MPEG2;
62 { MFX_ERR_NONE, 0,
"success" },
64 { MFX_ERR_NULL_PTR,
AVERROR(EINVAL),
"NULL pointer" },
65 { MFX_ERR_UNSUPPORTED,
AVERROR(ENOSYS),
"unsupported" },
66 { MFX_ERR_MEMORY_ALLOC,
AVERROR(ENOMEM),
"failed to allocate memory" },
67 { MFX_ERR_NOT_ENOUGH_BUFFER,
AVERROR(ENOMEM),
"insufficient input/output buffer" },
68 { MFX_ERR_INVALID_HANDLE,
AVERROR(EINVAL),
"invalid handle" },
69 { MFX_ERR_LOCK_MEMORY,
AVERROR(EIO),
"failed to lock the memory block" },
70 { MFX_ERR_NOT_INITIALIZED,
AVERROR_BUG,
"not initialized" },
71 { MFX_ERR_NOT_FOUND,
AVERROR(ENOSYS),
"specified object was not found" },
75 { MFX_ERR_MORE_SURFACE,
AVERROR_UNKNOWN,
"expect more surface at output" },
76 { MFX_ERR_MORE_BITSTREAM,
AVERROR_UNKNOWN,
"expect more bitstream at output" },
78 { MFX_ERR_DEVICE_LOST,
AVERROR(EIO),
"device lost" },
79 { MFX_ERR_INCOMPATIBLE_VIDEO_PARAM,
AVERROR(EINVAL),
"incompatible video parameters" },
80 { MFX_ERR_INVALID_VIDEO_PARAM,
AVERROR(EINVAL),
"invalid video parameters" },
81 { MFX_ERR_UNDEFINED_BEHAVIOR,
AVERROR_BUG,
"undefined behavior" },
82 { MFX_ERR_DEVICE_FAILED,
AVERROR(EIO),
"device failed" },
83 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM,
AVERROR(EINVAL),
"incompatible audio parameters" },
84 { MFX_ERR_INVALID_AUDIO_PARAM,
AVERROR(EINVAL),
"invalid audio parameters" },
86 { MFX_WRN_IN_EXECUTION, 0,
"operation in execution" },
87 { MFX_WRN_DEVICE_BUSY, 0,
"device busy" },
88 { MFX_WRN_VIDEO_PARAM_CHANGED, 0,
"video parameters changed" },
89 { MFX_WRN_PARTIAL_ACCELERATION, 0,
"partial acceleration" },
90 { MFX_WRN_INCOMPATIBLE_VIDEO_PARAM, 0,
"incompatible video parameters" },
91 { MFX_WRN_VALUE_NOT_CHANGED, 0,
"value is saturated" },
92 { MFX_WRN_OUT_OF_RANGE, 0,
"value out of range" },
93 { MFX_WRN_FILTER_SKIPPED, 0,
"filter skipped" },
94 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,
"incompatible audio parameters" },
108 *desc =
"unknown error";
113 const char *error_string)
123 const char *warning_string)
138 *fourcc = MFX_FOURCC_NV12;
142 *fourcc = MFX_FOURCC_P010;
152 if (!load_plugins || !*load_plugins)
155 while (*load_plugins) {
163 if (strlen(plugin) != 2 *
sizeof(uid.Data)) {
166 goto load_plugin_fail;
169 for (i = 0; i <
sizeof(uid.Data); i++) {
170 err = sscanf(plugin + 2 * i,
"%2hhx", uid.Data + i);
174 goto load_plugin_fail;
179 ret = MFXVideoUSER_Load(session, &uid, 1);
182 snprintf(errorbuf,
sizeof(errorbuf),
183 "Could not load the requested plugin '%s'", plugin);
185 goto load_plugin_fail;
201 const char *load_plugins)
203 mfxIMPL impl = MFX_IMPL_AUTO_ANY;
209 ret = MFXInit(impl, &ver, session);
212 "Error initializing an internal MFX session");
220 MFXQueryIMPL(*session, &impl);
222 switch (MFX_IMPL_BASETYPE(impl)) {
223 case MFX_IMPL_SOFTWARE:
226 case MFX_IMPL_HARDWARE:
227 case MFX_IMPL_HARDWARE2:
228 case MFX_IMPL_HARDWARE3:
229 case MFX_IMPL_HARDWARE4:
230 desc =
"hardware accelerated";
237 "Initialized an internal MFX session using %s implementation\n",
244 mfxFrameAllocResponse *resp)
247 mfxFrameInfo *i = &req->Info;
248 mfxFrameInfo *i1 = &ctx->
info;
250 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET) ||
251 !(req->Type & (MFX_MEMTYPE_FROM_DECODE | MFX_MEMTYPE_FROM_ENCODE)) ||
252 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
253 return MFX_ERR_UNSUPPORTED;
254 if (i->Width != i1->Width || i->Height != i1->Height ||
255 i->FourCC != i1->FourCC || i->ChromaFormat != i1->ChromaFormat) {
257 "allocation request: %dx%d %d %d vs %dx%d %d %d\n",
258 i->Width, i->Height, i->FourCC, i->ChromaFormat,
259 i1->Width, i1->Height, i1->FourCC, i1->ChromaFormat);
260 return MFX_ERR_UNSUPPORTED;
263 resp->mids = ctx->
mids;
264 resp->NumFrameActual = ctx->
nb_mids;
276 return MFX_ERR_UNSUPPORTED;
281 return MFX_ERR_UNSUPPORTED;
292 const char *load_plugins,
int opaque)
295 MFX_HANDLE_VA_DISPLAY,
296 MFX_HANDLE_D3D9_DEVICE_MANAGER,
297 MFX_HANDLE_D3D11_DEVICE,
299 mfxFrameAllocator frame_allocator = {
300 .pthis = qsv_frames_ctx,
311 mfxSession parent_session = device_hwctx->session;
316 mfxHDL handle =
NULL;
322 err = MFXQueryIMPL(parent_session, &impl);
323 if (err == MFX_ERR_NONE)
324 err = MFXQueryVersion(parent_session, &ver);
325 if (err != MFX_ERR_NONE)
327 "Error querying the session attributes");
330 err = MFXVideoCORE_GetHandle(parent_session, handle_types[i], &handle);
331 if (err == MFX_ERR_NONE) {
339 "from the session\n");
342 err = MFXInit(impl, &ver, &session);
343 if (err != MFX_ERR_NONE)
345 "Error initializing a child MFX session");
348 err = MFXVideoCORE_SetHandle(session,
handle_type, handle);
349 if (err != MFX_ERR_NONE)
351 "Error setting a HW handle");
363 sizeof(*qsv_frames_ctx->
mids));
364 if (!qsv_frames_ctx->
mids)
367 qsv_frames_ctx->
info = frames_hwctx->surfaces[0].Info;
368 qsv_frames_ctx->
nb_mids = frames_hwctx->nb_surfaces;
369 for (i = 0; i < frames_hwctx->nb_surfaces; i++)
370 qsv_frames_ctx->
mids[i] = frames_hwctx->surfaces[i].Data.MemId;
372 err = MFXVideoCORE_SetFrameAllocator(session, &frame_allocator);
373 if (err != MFX_ERR_NONE)
375 "Error setting a frame allocator");
static mfxStatus qsv_frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
static mfxStatus qsv_frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
#define AV_LOG_WARNING
Something somehow does not look correct.
mfxHandleType handle_type
This struct is allocated as AVHWFramesContext.hwctx.
static int qsv_load_plugins(mfxSession session, const char *load_plugins, void *logctx)
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
#define FF_ARRAY_ELEMS(a)
int ff_qsv_init_session_hwcontext(AVCodecContext *avctx, mfxSession *psession, QSVFramesContext *qsv_frames_ctx, const char *load_plugins, int opaque)
AVBufferRef * hw_frames_ctx
int ff_qsv_print_error(void *log_ctx, mfxStatus err, const char *error_string)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
#define AV_LOG_VERBOSE
Detailed information.
int ff_qsv_map_error(mfxStatus mfx_err, const char **desc)
Convert a libmfx error code into a libav error code.
This struct is allocated as AVHWDeviceContext.hwctx.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static mfxStatus qsv_frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
int ff_qsv_print_warning(void *log_ctx, mfxStatus err, const char *warning_string)
int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc)
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define QSV_VERSION_MINOR
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
static mfxStatus qsv_frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
preferred ID for MPEG-1/2 video decoding
static const mfxHandleType handle_types[]
Libavcodec external API header.
main external API structure.
uint8_t * data
The data buffer.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
#define AVERROR_BUG
Bug detected, please report the issue.
#define AV_PIX_FMT_YUV420P10
This struct describes a set or pool of "hardware" frames (i.e.
static const struct @65 qsv_errors[]
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal and external API header
static mfxStatus qsv_frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session, const char *load_plugins)
#define QSV_VERSION_MAJOR
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static void * av_mallocz_array(size_t nmemb, size_t size)
An API-specific header for AV_HWDEVICE_TYPE_QSV.
AVPixelFormat
Pixel format.