22 #include <mfx/mfxvideo.h> 71 mfxExtBuffer *ext_buffers[1];
107 if (err == MFX_ERR_NONE) {
116 "from the session\n");
120 if (err == MFX_ERR_NONE)
121 err = MFXQueryVersion(hwctx->
session, &s->
ver);
122 if (err != MFX_ERR_NONE) {
185 if (!device_priv->
handle) {
187 "Cannot create a non-opaque internal surface pool without " 188 "a hardware handle\n");
193 if (!child_device_ref)
200 child_device_hwctx->
display = (VADisplay)device_priv->
handle;
206 child_device_hwctx->
devmgr = (IDirect3DDeviceManager9*)device_priv->
handle;
217 if (!child_frames_ref) {
232 if (hwctx->
frame_type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET)
233 child_frames_hwctx->
surface_type = DXVA2_VideoProcessorRenderTarget;
235 child_frames_hwctx->
surface_type = DXVA2_VideoDecoderRenderTarget;
250 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
258 if (child_frames_hwctx->
surface_type == DXVA2_VideoProcessorRenderTarget)
259 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
261 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
266 child_frames_ref =
NULL;
299 surf->Info.BitDepthLuma = desc->
comp[0].
depth;
300 surf->Info.BitDepthChroma = desc->
comp[0].
depth;
301 surf->Info.Shift = desc->
comp[0].
depth > 8;
304 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
306 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV422;
308 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV444;
310 surf->Info.FourCC =
fourcc;
311 surf->Info.Width = ctx->
width;
312 surf->Info.CropW = ctx->
width;
313 surf->Info.Height = ctx->
height;
314 surf->Info.CropH = ctx->
height;
315 surf->Info.FrameRateExtN = 25;
316 surf->Info.FrameRateExtD = 1;
319 if (!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME)) {
336 static mfxStatus
frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
337 mfxFrameAllocResponse *resp)
342 mfxFrameInfo *i = &req->Info;
343 mfxFrameInfo *i1 = &hwctx->
surfaces[0].Info;
345 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
346 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
347 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
348 return MFX_ERR_UNSUPPORTED;
349 if (i->Width != i1->Width || i->Height != i1->Height ||
350 i->FourCC != i1->FourCC || i->ChromaFormat != i1->ChromaFormat) {
352 "allocation request: %dx%d %d %d vs %dx%d %d %d\n",
353 i->Width, i->Height, i->FourCC, i->ChromaFormat,
354 i1->Width, i1->Height, i1->FourCC, i1->ChromaFormat);
355 return MFX_ERR_UNSUPPORTED;
364 static mfxStatus
frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
369 static mfxStatus
frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
371 return MFX_ERR_UNSUPPORTED;
374 static mfxStatus
frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
376 return MFX_ERR_UNSUPPORTED;
386 mfxSession *session,
int upload)
391 int opaque = !!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
393 mfxFrameAllocator frame_allocator = {
405 err = MFXInit(device_priv->
impl, &device_priv->
ver, session);
406 if (err != MFX_ERR_NONE) {
411 if (device_priv->
handle) {
412 err = MFXVideoCORE_SetHandle(*session, device_priv->
handle_type,
414 if (err != MFX_ERR_NONE)
419 err = MFXVideoCORE_SetFrameAllocator(*session, &frame_allocator);
420 if (err != MFX_ERR_NONE)
424 memset(&par, 0,
sizeof(par));
429 par.IOPattern = upload ? MFX_IOPATTERN_OUT_OPAQUE_MEMORY :
430 MFX_IOPATTERN_IN_OPAQUE_MEMORY;
432 par.IOPattern = upload ? MFX_IOPATTERN_OUT_VIDEO_MEMORY :
433 MFX_IOPATTERN_IN_VIDEO_MEMORY;
436 par.IOPattern |= upload ? MFX_IOPATTERN_IN_SYSTEM_MEMORY :
437 MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
440 par.vpp.In = frames_hwctx->
surfaces[0].Info;
446 par.vpp.In.FrameRateExtN = 25;
447 par.vpp.In.FrameRateExtD = 1;
448 par.vpp.Out = par.vpp.In;
450 err = MFXVideoVPP_Init(*session, &par);
451 if (err != MFX_ERR_NONE) {
464 int opaque = !!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
503 s->
opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
563 mfxFrameSurface1
out = {{ 0 }};
564 mfxFrameSurface1 *
in = (mfxFrameSurface1*)src->
data[3];
570 out.Data.PitchLow = dst->
linesize[0];
571 out.Data.Y = dst->
data[0];
572 out.Data.U = dst->
data[1];
573 out.Data.V = dst->
data[2];
574 out.Data.A = dst->
data[3];
578 if (err == MFX_WRN_DEVICE_BUSY)
580 }
while (err == MFX_WRN_DEVICE_BUSY);
582 if (err < 0 || !
sync) {
588 err = MFXVideoCORE_SyncOperation(s->session_download,
sync, 1000);
589 }
while (err == MFX_WRN_IN_EXECUTION);
602 mfxFrameSurface1
in = {{ 0 }};
603 mfxFrameSurface1 *
out = (mfxFrameSurface1*)dst->
data[3];
609 in.Data.PitchLow = src->
linesize[0];
610 in.Data.Y = src->
data[0];
611 in.Data.U = src->
data[1];
612 in.Data.V = src->
data[2];
613 in.Data.A = src->
data[3];
617 if (err == MFX_WRN_DEVICE_BUSY)
619 }
while (err == MFX_WRN_DEVICE_BUSY);
621 if (err < 0 || !
sync) {
627 err = MFXVideoCORE_SyncOperation(s->session_upload,
sync, 1000);
628 }
while (err == MFX_WRN_IN_EXECUTION);
638 const void *hwconfig,
676 static const struct {
680 {
"auto", MFX_IMPL_AUTO },
681 {
"sw", MFX_IMPL_SOFTWARE },
682 {
"hw", MFX_IMPL_HARDWARE },
683 {
"auto_any", MFX_IMPL_AUTO_ANY },
684 {
"hw_any", MFX_IMPL_HARDWARE_ANY },
685 {
"hw2", MFX_IMPL_HARDWARE2 },
686 {
"hw3", MFX_IMPL_HARDWARE3 },
687 {
"hw4", MFX_IMPL_HARDWARE4 },
690 mfxIMPL impl = MFX_IMPL_AUTO_ANY;
695 if (!strcmp(device, impl_map[i].
name)) {
696 impl = impl_map[i].impl;
700 impl = strtol(device,
NULL, 0);
714 mfxVersion ver = { { 3, 1 } };
748 handle_type = MFX_HANDLE_VA_DISPLAY;
749 handle = (mfxHDL)child_device_hwctx->display;
752 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
753 handle = (mfxHDL)child_device_hwctx->
devmgr;
759 err = MFXInit(impl, &ver, &hwctx->
session);
760 if (err != MFX_ERR_NONE) {
765 err = MFXVideoCORE_SetHandle(hwctx->
session, handle_type, handle);
766 if (err != MFX_ERR_NONE)
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
static int qsv_init_child_ctx(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...
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
VAAPI-specific data associated with a frame pool.
This structure describes decoded (raw) audio or video data.
static int qsv_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
mfxFrameSurface1 * surfaces_internal
int frame_type
A combination of MFX_MEMTYPE_* describing the frame pool.
mfxExtBuffer * ext_buffers[1]
This struct is allocated as AVHWFramesContext.hwctx.
memory handling functions
mfxHandleType handle_type
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
This struct is allocated as AVHWFramesContext.hwctx.
An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
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)
static int sync(AVFormatContext *s, uint8_t *header)
Read input until we find the next ident.
static enum AVSampleFormat formats[]
int width
The allocated dimensions of the frames in this pool.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
mfxHandleType handle_type
#define FF_ARRAY_ELEMS(a)
int av_usleep(unsigned usec)
Sleep for a period of time.
static const struct @163 supported_handle_types[]
static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
static int qsv_init_pool(AVHWFramesContext *ctx, uint32_t fourcc)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
API-specific header for AV_HWDEVICE_TYPE_VAAPI.
AVBufferPool * pool_internal
static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
DWORD surface_type
The surface type (e.g.
enum AVHWDeviceType child_device_type
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
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.
#define AV_LOG_VERBOSE
Detailed information.
static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
static int qsv_frames_init(AVHWFramesContext *ctx)
This struct is allocated as AVHWDeviceContext.hwctx.
static int qsv_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
enum AVHWDeviceType device_type
static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
IDirect3DDeviceManager9 * devmgr
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
static int qsv_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
int initial_pool_size
Initial size of the frame pool.
static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
mfxFrameSurface1 ** surface_ptrs
mfxSession session_download
AVBufferPool * av_buffer_pool_init2(int size, void *opaque, AVBufferRef *(*alloc)(void *opaque, int size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
if(ac->has_optimized_func)
VADisplay display
The VADisplay handle, to be filled by the user.
static void qsv_frames_uninit(AVHWFramesContext *ctx)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
AVBufferRef * av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
Allocate an AVHWDeviceContext for a given pixel format.
static const struct @164 supported_pixel_formats[]
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
const HWContextType ff_hwcontext_type_qsv
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
mfxFrameSurface1 * surfaces
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
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.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
int av_hwdevice_ctx_init(AVBufferRef *ref)
Finalize the device context before use.
static int qsv_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
static int qsv_init_internal_session(AVHWFramesContext *ctx, mfxSession *session, int upload)
This struct describes a set or pool of "hardware" frames (i.e.
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
static mfxIMPL choose_implementation(const char *device)
refcounted data buffer API
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
mfxExtOpaqueSurfaceAlloc opaque_alloc
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
AVHWFramesInternal * internal
Private data used internally by libavutil.
static AVBufferRef * qsv_pool_alloc(void *opaque, int size)
static void * av_malloc_array(size_t nmemb, size_t size)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void * user_opaque
Arbitrary user data, to be used e.g.
A reference to a data buffer.
static void qsv_device_free(AVHWDeviceContext *ctx)
common internal and external API header
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
static int qsv_device_init(AVHWDeviceContext *ctx)
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
enum AVPixelFormat child_pix_fmt
IDirect3DSurface9 ** surfaces
The surface pool.
AVHWFrameTransferDirection
AVBufferPool * pool
A pool from which the frames are allocated by av_hwframe_get_buffer().
This struct is allocated as AVHWDeviceContext.hwctx.
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
VAAPI connection details.
static void * av_mallocz_array(size_t nmemb, size_t size)
void(* free)(struct AVHWDeviceContext *ctx)
This field may be set by the caller before calling av_hwdevice_ctx_init().
VASurfaceID * surface_ids
The surfaces IDs of all surfaces in the pool after creation.
An API-specific header for AV_HWDEVICE_TYPE_QSV.
AVBufferRef * child_device_ctx
AVBufferRef * child_frames_ref
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
AVHWDeviceInternal * internal
Private data used internally by libavutil.
int depth
Number of bits in the component.
static void qsv_pool_release_dummy(void *opaque, uint8_t *data)
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVPixelFormat
Pixel format.
enum AVPixelFormat pix_fmt
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
mfxSession session_upload