Go to the documentation of this file.
22 #include <mfx/mfxvideo.h>
52 #define QSV_VERSION_ATLEAST(MAJOR, MINOR) \
53 (MFX_VERSION_MAJOR > (MAJOR) || \
54 MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
56 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
108 #if QSV_VERSION_ATLEAST(1, 27)
126 static uint32_t qsv_get_d3d11va_bind_flags(
int mem_type)
128 uint32_t bind_flags = 0;
130 if ((mem_type & MFX_MEMTYPE_VIDEO_MEMORY_ENCODER_TARGET) && (mem_type & MFX_MEMTYPE_INTERNAL_FRAME))
131 bind_flags = D3D11_BIND_DECODER | D3D11_BIND_VIDEO_ENCODER;
133 bind_flags = D3D11_BIND_DECODER;
135 if ((MFX_MEMTYPE_FROM_VPPOUT & mem_type) || (MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET & mem_type))
136 bind_flags = D3D11_BIND_RENDER_TARGET;
145 int i, planes_nb = 0;
151 for (
i = 0;
i <
desc->nb_components;
i++)
152 planes_nb =
FFMAX(planes_nb,
desc->comp[
i].plane + 1);
154 for (
i = 0;
i < planes_nb;
i++) {
155 int sheight, dheight, y;
163 if (swidth < 0 || dwidth < 0) {
167 sheight =
src->height;
174 for (y = 0; y < sheight; y++) {
177 comp.depth > 8 ? 2 : 1,
181 for (y = sheight; y < dheight; y++) {
194 int hw_handle_supported = 0;
195 mfxHandleType handle_type;
200 err = MFXQueryIMPL(hwctx->
session, &
s->impl);
201 if (err == MFX_ERR_NONE)
202 err = MFXQueryVersion(hwctx->
session, &
s->ver);
203 if (err != MFX_ERR_NONE) {
210 handle_type = MFX_HANDLE_VA_DISPLAY;
213 hw_handle_supported = 1;
217 handle_type = MFX_HANDLE_D3D11_DEVICE;
220 hw_handle_supported = 1;
224 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
227 hw_handle_supported = 1;
231 if (hw_handle_supported) {
232 err = MFXVideoCORE_GetHandle(hwctx->
session, handle_type, &
s->handle);
233 if (err == MFX_ERR_NONE) {
234 s->handle_type = handle_type;
235 s->child_device_type = device_type;
241 "from the session\n");
250 if (
s->session_download) {
251 MFXVideoVPP_Close(
s->session_download);
252 MFXClose(
s->session_download);
254 s->session_download =
NULL;
255 s->session_download_init = 0;
257 if (
s->session_upload) {
258 MFXVideoVPP_Close(
s->session_upload);
259 MFXClose(
s->session_upload);
261 s->session_upload =
NULL;
262 s->session_upload_init = 0;
288 s->nb_surfaces_used++;
310 if (!device_priv->
handle) {
312 "Cannot create a non-opaque internal surface pool without "
313 "a hardware handle\n");
318 if (!child_device_ref)
325 child_device_hwctx->
display = (VADisplay)device_priv->
handle;
338 child_device_hwctx->
devmgr = (IDirect3DDeviceManager9*)device_priv->
handle;
349 if (!child_frames_ref) {
365 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
366 if (hwctx->
frame_type & MFX_MEMTYPE_SHARED_RESOURCE)
367 child_frames_hwctx->
MiscFlags = D3D11_RESOURCE_MISC_SHARED;
374 if (hwctx->
frame_type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET)
375 child_frames_hwctx->
surface_type = DXVA2_VideoProcessorRenderTarget;
377 child_frames_hwctx->
surface_type = DXVA2_VideoDecoderRenderTarget;
390 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
391 s->handle_pairs_internal[
i].first = child_frames_hwctx->
surface_ids +
i;
392 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
393 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
395 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
401 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
403 if(child_frames_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
404 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
408 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
410 if (child_frames_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
411 hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
413 hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
420 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
421 s->handle_pairs_internal[
i].first = (mfxMemId)child_frames_hwctx->
surfaces[
i];
422 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
423 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
425 if (child_frames_hwctx->
surface_type == DXVA2_VideoProcessorRenderTarget)
426 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
428 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
432 s->child_frames_ref = child_frames_ref;
433 child_frames_ref =
NULL;
454 surf->Info.BitDepthLuma =
desc->comp[0].depth;
455 surf->Info.BitDepthChroma =
desc->comp[0].depth;
456 surf->Info.Shift =
desc->comp[0].depth > 8;
458 if (
desc->log2_chroma_w &&
desc->log2_chroma_h)
459 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
460 else if (
desc->log2_chroma_w)
461 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV422;
463 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV444;
465 surf->Info.FourCC =
fourcc;
467 surf->Info.CropW =
ctx->width;
469 surf->Info.CropH =
ctx->height;
470 surf->Info.FrameRateExtN = 25;
471 surf->Info.FrameRateExtD = 1;
472 surf->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
484 if (
ctx->initial_pool_size <= 0) {
490 sizeof(*
s->handle_pairs_internal));
491 if (!
s->handle_pairs_internal)
495 sizeof(*
s->surfaces_internal));
496 if (!
s->surfaces_internal)
499 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
505 if (!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME)) {
513 if (!
ctx->internal->pool_internal)
516 frames_hwctx->
surfaces =
s->surfaces_internal;
522 static mfxStatus
frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
523 mfxFrameAllocResponse *resp)
528 mfxFrameInfo *
i = &req->Info;
529 mfxFrameInfo *i1 = &hwctx->
surfaces[0].Info;
531 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
532 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
533 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
534 return MFX_ERR_UNSUPPORTED;
535 if (
i->Width > i1->Width ||
i->Height > i1->Height ||
536 i->FourCC != i1->FourCC ||
i->ChromaFormat != i1->ChromaFormat) {
538 "allocation request: %dx%d %d %d vs %dx%d %d %d\n",
539 i->Width,
i->Height,
i->FourCC,
i->ChromaFormat,
540 i1->Width, i1->Height, i1->FourCC, i1->ChromaFormat);
541 return MFX_ERR_UNSUPPORTED;
544 resp->mids =
s->mem_ids;
550 static mfxStatus
frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
555 static mfxStatus
frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
557 return MFX_ERR_UNSUPPORTED;
560 static mfxStatus
frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
562 return MFX_ERR_UNSUPPORTED;
567 mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
568 mfxHDLPair *pair_src = (mfxHDLPair*)mid;
570 pair_dst->first = pair_src->first;
572 if (pair_src->second != (mfxMemId)MFX_INFINITE)
573 pair_dst->second = pair_src->second;
578 mfxSession *session,
int upload)
583 int opaque = !!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
585 mfxFrameAllocator frame_allocator = {
597 err = MFXInit(device_priv->
impl, &device_priv->
ver, session);
598 if (err != MFX_ERR_NONE) {
603 if (device_priv->
handle) {
604 err = MFXVideoCORE_SetHandle(*session, device_priv->
handle_type,
606 if (err != MFX_ERR_NONE)
611 err = MFXVideoCORE_SetFrameAllocator(*session, &frame_allocator);
612 if (err != MFX_ERR_NONE)
616 memset(&par, 0,
sizeof(par));
619 par.ExtParam =
s->ext_buffers;
621 par.IOPattern = upload ? MFX_IOPATTERN_OUT_OPAQUE_MEMORY :
622 MFX_IOPATTERN_IN_OPAQUE_MEMORY;
624 par.IOPattern = upload ? MFX_IOPATTERN_OUT_VIDEO_MEMORY :
625 MFX_IOPATTERN_IN_VIDEO_MEMORY;
628 par.IOPattern |= upload ? MFX_IOPATTERN_IN_SYSTEM_MEMORY :
629 MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
632 par.vpp.In = frames_hwctx->
surfaces[0].Info;
638 par.vpp.In.FrameRateExtN = 25;
639 par.vpp.In.FrameRateExtD = 1;
640 par.vpp.Out = par.vpp.In;
642 err = MFXVideoVPP_Init(*session, &par);
643 if (err != MFX_ERR_NONE) {
645 "Surface upload/download will not be possible\n");
658 int opaque = !!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
679 sizeof(*
s->surface_ptrs));
680 if (!
s->surface_ptrs)
686 s->opaque_alloc.In.Surfaces =
s->surface_ptrs;
687 s->opaque_alloc.In.NumSurface = frames_hwctx->
nb_surfaces;
688 s->opaque_alloc.In.Type = frames_hwctx->
frame_type;
690 s->opaque_alloc.Out =
s->opaque_alloc.In;
692 s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
693 s->opaque_alloc.Header.BufferSz =
sizeof(
s->opaque_alloc);
695 s->ext_buffers[0] = (mfxExtBuffer*)&
s->opaque_alloc;
702 s->mem_ids[
i] = frames_hwctx->
surfaces[
i].Data.MemId;
705 s->session_download =
NULL;
706 s->session_upload =
NULL;
708 s->session_download_init = 0;
709 s->session_upload_init = 0;
743 fmts[0] =
ctx->sw_format;
767 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
778 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
779 dst_hwctx->
texture = (ID3D11Texture2D*)pair->first;
780 if (src_hwctx->
frame_type & MFX_MEMTYPE_SHARED_RESOURCE)
781 dst_hwctx->
MiscFlags = D3D11_RESOURCE_MISC_SHARED;
795 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
796 dst_hwctx->
surfaces[
i] = (IDirect3DSurface9*)pair->first;
799 if (src_hwctx->
frame_type == MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
800 dst_hwctx->
surface_type = DXVA2_VideoDecoderRenderTarget;
802 dst_hwctx->
surface_type = DXVA2_VideoProcessorRenderTarget;
817 mfxFrameSurface1 *surf = (mfxFrameSurface1*)
src->data[3];
824 if (!
s->child_frames_ref)
828 switch (child_frames_ctx->device_ctx->type) {
832 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
837 child_data = (uint8_t*)(intptr_t)*(VASurfaceID*)pair->first;
844 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
845 child_data = pair->first;
852 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
853 child_data = pair->first;
861 if (dst->
format == child_frames_ctx->format) {
871 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
872 dst->
data[0] = pair->first;
873 dst->
data[1] = pair->second;
875 dst->
data[3] = child_data;
896 dummy->format = child_frames_ctx->format;
901 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
902 dummy->data[0] = pair->first;
903 dummy->data[1] = pair->second;
905 dummy->data[3] = child_data;
921 int download = !!
src->hw_frames_ctx;
922 mfxFrameSurface1 *surf = (mfxFrameSurface1*)(download ?
src->data[3] : dst->
data[3]);
934 dummy->buf[0] = download ?
src->buf[0] : dst->
buf[0];
935 dummy->data[3] = surf->Data.MemId;
936 dummy->hw_frames_ctx =
s->child_frames_ref;
952 switch (
frame->format) {
955 surface->Data.Y =
frame->data[0];
956 surface->Data.UV =
frame->data[1];
960 surface->Data.Y =
frame->data[0];
961 surface->Data.U =
frame->data[1];
962 surface->Data.V =
frame->data[2];
966 surface->Data.B =
frame->data[0];
967 surface->Data.G =
frame->data[0] + 1;
968 surface->Data.R =
frame->data[0] + 2;
969 surface->Data.A =
frame->data[0] + 3;
973 surface->Data.Y =
frame->data[0];
974 surface->Data.U =
frame->data[0] + 1;
975 surface->Data.V =
frame->data[0] + 3;
979 surface->Data.Y16 = (mfxU16 *)
frame->data[0];
980 surface->Data.U16 = (mfxU16 *)
frame->data[0] + 1;
981 surface->Data.V16 = (mfxU16 *)
frame->data[0] + 3;
985 return MFX_ERR_UNSUPPORTED;
987 surface->Data.Pitch =
frame->linesize[0];
988 surface->Data.TimeStamp =
frame->pts;
997 mfxFrameSurface1
out = {{ 0 }};
998 mfxFrameSurface1 *in = (mfxFrameSurface1*)
src->data[3];
1000 mfxSyncPoint sync =
NULL;
1004 while (!
s->session_download_init && !
s->session_download && !
ret) {
1006 if (pthread_mutex_trylock(&
s->session_lock) == 0) {
1008 if (!
s->session_download_init) {
1010 if (
s->session_download)
1011 s->session_download_init = 1;
1018 while (!
s->session_download_init && !
s->session_download) {
1029 if (!
s->session_download) {
1030 if (
s->child_frames_ref)
1037 out.Info = in->Info;
1041 err = MFXVideoVPP_RunFrameVPPAsync(
s->session_download, in, &
out,
NULL, &sync);
1042 if (err == MFX_WRN_DEVICE_BUSY)
1044 }
while (err == MFX_WRN_DEVICE_BUSY);
1046 if (err < 0 || !sync) {
1052 err = MFXVideoCORE_SyncOperation(
s->session_download, sync, 1000);
1053 }
while (err == MFX_WRN_IN_EXECUTION);
1066 mfxFrameSurface1 in = {{ 0 }};
1067 mfxFrameSurface1 *
out = (mfxFrameSurface1*)dst->
data[3];
1068 mfxFrameInfo tmp_info;
1070 mfxSyncPoint sync =
NULL;
1074 AVFrame *tmp_frame = &
s->realigned_tmp_frame;
1079 while (!
s->session_upload_init && !
s->session_upload && !
ret) {
1081 if (pthread_mutex_trylock(&
s->session_lock) == 0) {
1083 if (!
s->session_upload_init) {
1085 if (
s->session_upload)
1086 s->session_upload_init = 1;
1093 while (!
s->session_upload_init && !
s->session_upload) {
1106 if (
src->height & 15 ||
src->linesize[0] & 15) {
1108 if (tmp_frame->format !=
src->format ||
1109 tmp_frame->width !=
FFALIGN(
src->width, 16) ||
1110 tmp_frame->height !=
FFALIGN(
src->height, 16)) {
1113 tmp_frame->format =
src->format;
1115 tmp_frame->height =
FFALIGN(
src->height, 16);
1131 tmp_info =
out->Info;
1132 out->Info.CropW =
FFMIN(
out->Info.Width, tmp_frame->width);
1133 out->Info.CropH =
FFMIN(
out->Info.Height, tmp_frame->height);
1136 src_frame = realigned ? tmp_frame :
src;
1138 if (!
s->session_upload) {
1139 if (
s->child_frames_ref)
1146 in.Info =
out->Info;
1150 err = MFXVideoVPP_RunFrameVPPAsync(
s->session_upload, &in,
out,
NULL, &sync);
1151 if (err == MFX_WRN_DEVICE_BUSY)
1153 }
while (err == MFX_WRN_DEVICE_BUSY);
1155 if (err < 0 || !sync) {
1161 err = MFXVideoCORE_SyncOperation(
s->session_upload, sync, 1000);
1162 }
while (err == MFX_WRN_IN_EXECUTION);
1169 out->Info.CropW = tmp_info.CropW;
1170 out->Info.CropH = tmp_info.CropH;
1185 "mapped to QSV frames.\n");
1195 sizeof(*
s->handle_pairs_internal));
1196 if (!
s->handle_pairs_internal)
1199 sizeof(*
s->surfaces_internal));
1200 if (!
s->surfaces_internal)
1205 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1206 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1209 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1218 sizeof(*
s->handle_pairs_internal));
1219 if (!
s->handle_pairs_internal)
1222 sizeof(*
s->surfaces_internal));
1223 if (!
s->surfaces_internal)
1228 if (src_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
1229 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1233 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1236 if (src_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
1237 dst_hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1239 dst_hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1249 sizeof(*
s->handle_pairs_internal));
1250 if (!
s->handle_pairs_internal)
1253 sizeof(*
s->surfaces_internal));
1254 if (!
s->surfaces_internal)
1258 s->handle_pairs_internal[
i].first = (mfxMemId)src_hwctx->
surfaces[
i];
1259 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1260 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1263 if (src_hwctx->
surface_type == DXVA2_VideoProcessorRenderTarget)
1264 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1266 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1274 dst_hwctx->
surfaces =
s->surfaces_internal;
1286 switch(
src->format) {
1290 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1291 if (*(VASurfaceID*)pair->first == (VASurfaceID)
src->data[3]) {
1300 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1301 if (pair->first ==
src->data[0]
1302 && pair->second ==
src->data[1]) {
1311 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1312 if (pair->first ==
src->data[3]) {
1322 "is not in the mapped frames context.\n");
1339 const void *hwconfig,
1377 static const struct {
1381 {
"auto", MFX_IMPL_AUTO },
1382 {
"sw", MFX_IMPL_SOFTWARE },
1383 {
"hw", MFX_IMPL_HARDWARE },
1384 {
"auto_any", MFX_IMPL_AUTO_ANY },
1385 {
"hw_any", MFX_IMPL_HARDWARE_ANY },
1386 {
"hw2", MFX_IMPL_HARDWARE2 },
1387 {
"hw3", MFX_IMPL_HARDWARE3 },
1388 {
"hw4", MFX_IMPL_HARDWARE4 },
1391 mfxIMPL impl = MFX_IMPL_AUTO_ANY;
1396 if (!strcmp(device, impl_map[
i].
name)) {
1397 impl = impl_map[
i].impl;
1401 impl = strtol(device,
NULL, 0);
1404 if (impl != MFX_IMPL_SOFTWARE) {
1406 impl |= MFX_IMPL_VIA_D3D11;
1408 impl |= MFX_IMPL_VIA_D3D9;
1415 mfxIMPL implementation,
1421 mfxVersion ver = { { 3, 1 } };
1423 mfxHandleType handle_type;
1427 switch (child_device_ctx->
type) {
1432 handle_type = MFX_HANDLE_VA_DISPLAY;
1433 handle = (mfxHDL)child_device_hwctx->
display;
1441 handle_type = MFX_HANDLE_D3D11_DEVICE;
1442 handle = (mfxHDL)child_device_hwctx->
device;
1450 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
1451 handle = (mfxHDL)child_device_hwctx->
devmgr;
1460 err = MFXInit(implementation, &ver, &hwctx->
session);
1461 if (err != MFX_ERR_NONE) {
1468 err = MFXQueryVersion(hwctx->
session, &ver);
1469 if (err != MFX_ERR_NONE) {
1476 "Initialize MFX session: API version is %d.%d, implementation version is %d.%d\n",
1477 MFX_VERSION_MAJOR, MFX_VERSION_MINOR, ver.Major, ver.Minor);
1481 err = MFXInit(implementation, &ver, &hwctx->
session);
1482 if (err != MFX_ERR_NONE) {
1484 "Error initializing an MFX session: %d.\n", err);
1489 err = MFXVideoCORE_SetHandle(hwctx->
session, handle_type, handle);
1490 if (err != MFX_ERR_NONE) {
1512 child_device_ctx,
flags);
1531 ctx->user_opaque = priv;
1539 "\"%s\".\n", e->
value);
1542 }
else if (CONFIG_VAAPI) {
1544 }
else if (CONFIG_DXVA2) {
1546 "WARNING: defaulting child_device_type to AV_HWDEVICE_TYPE_DXVA2 for compatibility "
1547 "with old commandlines. This behaviour will be removed "
1548 "in the future. Please explicitly set device type via \"-init_hw_device\" option.\n");
1550 }
else if (CONFIG_D3D11VA) {
1557 child_device_opts =
NULL;
1558 switch (child_device_type) {
1567 av_dict_set(&child_device_opts,
"kernel_driver",
"i915", 0);
1568 av_dict_set(&child_device_opts,
"driver",
"iHD", 0);
1590 e ? e->
value :
NULL, child_device_opts, 0);
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
static int qsv_transfer_data_child(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
int frame_type
A combination of MFX_MEMTYPE_* describing the frame pool.
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
AVBufferRef * child_frames_ref
static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
uint8_t * data
The data buffer.
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
static int qsv_map_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
static uint32_t qsv_fourcc_from_pix_fmt(enum AVPixelFormat pix_fmt)
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
static int qsv_fill_border(AVFrame *dst, const AVFrame *src)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
This structure describes decoded (raw) audio or video data.
This struct is allocated as AVHWDeviceContext.hwctx.
UINT MiscFlags
D3D11_TEXTURE2D_DESC.MiscFlags used for texture creation.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
static int qsv_device_derive(AVHWDeviceContext *ctx, AVHWDeviceContext *child_device_ctx, AVDictionary *opts, int flags)
This struct is allocated as AVHWFramesContext.hwctx.
static int qsv_frames_derive_from(AVHWFramesContext *dst_ctx, AVHWFramesContext *src_ctx, int flags)
int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags)
Map a hardware frame.
static int qsv_init_surface(AVHWFramesContext *ctx, mfxFrameSurface1 *surf)
static mfxIMPL choose_implementation(const char *device, enum AVHWDeviceType child_device_type)
enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
Look up an AVHWDeviceType by name.
IDirect3DDeviceManager9 * devmgr
#define AV_LOG_VERBOSE
Detailed information.
VADisplay display
The VADisplay handle, to be filled by the user.
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
AVHWFramesInternal * internal
Private data used internally by libavutil.
int ff_hwframe_map_create(AVBufferRef *hwframe_ref, AVFrame *dst, const AVFrame *src, void(*unmap)(AVHWFramesContext *ctx, HWMapDescriptor *hwmap), void *priv)
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
int width
The allocated dimensions of the frames in this pool.
int av_hwdevice_ctx_init(AVBufferRef *ref)
Finalize the device context before use.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
mfxHandleType handle_type
static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
UINT BindFlags
D3D11_TEXTURE2D_DESC.BindFlags used for texture creation.
VASurfaceID * surface_ids
The surfaces IDs of all surfaces in the pool after creation.
ID3D11Texture2D * texture
The texture in which the frame is located.
enum AVHWDeviceType child_device_type
static int qsv_init_child_ctx(AVHWFramesContext *ctx)
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
@ AV_HWDEVICE_TYPE_D3D11VA
static int qsv_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
AVBufferPool * av_buffer_pool_init2(size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, size_t size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx, AVHWFramesContext *src_ctx, int flags)
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
AVBufferRef * av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
Allocate an AVHWDeviceContext for a given hardware type.
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
mfxExtBuffer * ext_buffers[1]
static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
AVBufferRef * child_device_ctx
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
ID3D11Device * device
Device used for texture creation and access.
#define AV_CEIL_RSHIFT(a, b)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int av_usleep(unsigned usec)
Sleep for a period of time.
const HWContextType ff_hwcontext_type_qsv
AVD3D11FrameDescriptor * texture_infos
In case if texture structure member above is not NULL contains the same texture pointer for all eleme...
mfxFrameSurface1 * surfaces
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
static void qsv_frames_uninit(AVHWFramesContext *ctx)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
#define MFX_IMPL_VIA_MASK(impl)
static int qsv_frames_init(AVHWFramesContext *ctx)
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
static int map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface)
static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
#define pthread_mutex_unlock(a)
This struct is allocated as AVHWFramesContext.hwctx.
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
static int qsv_init_internal_session(AVHWFramesContext *ctx, mfxSession *session, int upload)
mfxExtOpaqueSurfaceAlloc opaque_alloc
static int qsv_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
DWORD surface_type
The surface type (e.g.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
int session_download_init
static void qsv_device_free(AVHWDeviceContext *ctx)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
static int qsv_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
ID3D11Texture2D * texture
The canonical texture used for pool allocation.
static int qsv_device_derive_from_child(AVHWDeviceContext *ctx, mfxIMPL implementation, AVHWDeviceContext *child_device_ctx, int flags)
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane.
static int qsv_device_init(AVHWDeviceContext *ctx)
#define i(width, name, range_min, range_max)
This struct is allocated as AVHWDeviceContext.hwctx.
#define av_malloc_array(a, b)
This struct is allocated as AVHWDeviceContext.hwctx.
mfxHDLPair * handle_pairs_internal
intptr_t index
The index into the array texture element representing the frame, or 0 if the texture is not an array ...
mfxFrameSurface1 ** surface_ptrs
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
mfxSession session_download
IDirect3DSurface9 ** surfaces
The surface pool.
void * av_calloc(size_t nmemb, size_t size)
AVHWFrameTransferDirection
This struct describes a set or pool of "hardware" frames (i.e.
static int qsv_map_to(AVHWFramesContext *dst_ctx, AVFrame *dst, const AVFrame *src, int flags)
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
enum AVPixelFormat pix_fmt
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it.
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface.
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
static const struct @304 supported_pixel_formats[]
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
static void qsv_pool_release_dummy(void *opaque, uint8_t *data)
enum AVPixelFormat child_pix_fmt
mfxSession session_upload
static int qsv_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
This struct is allocated as AVHWFramesContext.hwctx.
int initial_pool_size
Initial size of the frame pool.
A reference to a data buffer.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
VAAPI-specific data associated with a frame pool.
mfxFrameSurface1 * surfaces_internal
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
AVFrame realigned_tmp_frame
#define flags(name, subs,...)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
static AVBufferRef * qsv_pool_alloc(void *opaque, size_t size)
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
VAAPI connection details.
static int qsv_init_pool(AVHWFramesContext *ctx, uint32_t fourcc)
#define pthread_mutex_lock(a)