35 #define IS_VIDEO_MEMORY(mode) (mode & (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | \
36 MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
37 #define IS_OPAQUE_MEMORY(mode) (mode & MFX_MEMTYPE_OPAQUE_FRAME)
38 #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
72 MFX_HANDLE_VA_DISPLAY,
73 MFX_HANDLE_D3D9_DEVICE_MANAGER,
74 MFX_HANDLE_D3D11_DEVICE,
83 {MFX_IOPATTERN_IN_VIDEO_MEMORY,
"input is video memory surface" },
84 {MFX_IOPATTERN_IN_SYSTEM_MEMORY,
"input is system memory surface" },
85 {MFX_IOPATTERN_IN_OPAQUE_MEMORY,
"input is opaque memory surface" },
86 {MFX_IOPATTERN_OUT_VIDEO_MEMORY,
"output is video memory surface" },
87 {MFX_IOPATTERN_OUT_SYSTEM_MEMORY,
"output is system memory surface" },
88 {MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
"output is opaque memory surface" },
92 const char *extra_string)
102 desc =
"unknown iopattern";
108 static const struct {
113 { MFX_ERR_NONE, 0,
"success" },
115 { MFX_ERR_NULL_PTR,
AVERROR(EINVAL),
"NULL pointer" },
116 { MFX_ERR_UNSUPPORTED,
AVERROR(ENOSYS),
"unsupported" },
117 { MFX_ERR_MEMORY_ALLOC,
AVERROR(ENOMEM),
"failed to allocate memory" },
118 { MFX_ERR_NOT_ENOUGH_BUFFER,
AVERROR(ENOMEM),
"insufficient input/output buffer" },
119 { MFX_ERR_INVALID_HANDLE,
AVERROR(EINVAL),
"invalid handle" },
120 { MFX_ERR_LOCK_MEMORY,
AVERROR(EIO),
"failed to lock the memory block" },
121 { MFX_ERR_NOT_INITIALIZED,
AVERROR_BUG,
"not initialized" },
122 { MFX_ERR_NOT_FOUND,
AVERROR(ENOSYS),
"specified object was not found" },
126 { MFX_ERR_MORE_SURFACE,
AVERROR_UNKNOWN,
"expect more surface at output" },
127 { MFX_ERR_MORE_BITSTREAM,
AVERROR_UNKNOWN,
"expect more bitstream at output" },
129 { MFX_ERR_DEVICE_LOST,
AVERROR(EIO),
"device lost" },
130 { MFX_ERR_INCOMPATIBLE_VIDEO_PARAM,
AVERROR(EINVAL),
"incompatible video parameters" },
131 { MFX_ERR_INVALID_VIDEO_PARAM,
AVERROR(EINVAL),
"invalid video parameters" },
132 { MFX_ERR_UNDEFINED_BEHAVIOR,
AVERROR_BUG,
"undefined behavior" },
133 { MFX_ERR_DEVICE_FAILED,
AVERROR(EIO),
"device failed" },
134 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM,
AVERROR(EINVAL),
"incompatible audio parameters" },
135 { MFX_ERR_INVALID_AUDIO_PARAM,
AVERROR(EINVAL),
"invalid audio parameters" },
137 { MFX_WRN_IN_EXECUTION, 0,
"operation in execution" },
138 { MFX_WRN_DEVICE_BUSY, 0,
"device busy" },
139 { MFX_WRN_VIDEO_PARAM_CHANGED, 0,
"video parameters changed" },
140 { MFX_WRN_PARTIAL_ACCELERATION, 0,
"partial acceleration" },
141 { MFX_WRN_INCOMPATIBLE_VIDEO_PARAM, 0,
"incompatible video parameters" },
142 { MFX_WRN_VALUE_NOT_CHANGED, 0,
"value is saturated" },
143 { MFX_WRN_OUT_OF_RANGE, 0,
"value out of range" },
144 { MFX_WRN_FILTER_SKIPPED, 0,
"filter skipped" },
145 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,
"incompatible audio parameters" },
159 *
desc =
"unknown error";
164 const char *error_string)
174 const char *warning_string)
184 static mfxStatus
frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
185 mfxFrameAllocResponse *resp)
190 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
191 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
192 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
193 return MFX_ERR_UNSUPPORTED;
195 if (req->Type & MFX_MEMTYPE_FROM_VPPIN) {
196 resp->mids =
av_mallocz(
s->nb_surface_ptrs_in *
sizeof(*resp->mids));
200 for (
i = 0;
i <
s->nb_surface_ptrs_in;
i++)
201 resp->mids[
i] =
s->surface_ptrs_in[
i]->Data.MemId;
203 resp->NumFrameActual =
s->nb_surface_ptrs_in;
205 resp->mids =
av_mallocz(
s->nb_surface_ptrs_out *
sizeof(*resp->mids));
209 for (
i = 0;
i <
s->nb_surface_ptrs_out;
i++)
210 resp->mids[
i] =
s->surface_ptrs_out[
i]->Data.MemId;
212 resp->NumFrameActual =
s->nb_surface_ptrs_out;
218 static mfxStatus
frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
224 static mfxStatus
frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
226 return MFX_ERR_UNSUPPORTED;
229 static mfxStatus
frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
231 return MFX_ERR_UNSUPPORTED;
244 return MFX_FOURCC_YV12;
246 return MFX_FOURCC_NV12;
248 return MFX_FOURCC_YUY2;
250 return MFX_FOURCC_RGB4;
253 return MFX_FOURCC_NV12;
281 return MFX_ERR_UNSUPPORTED;
301 frames_hwctx = frames_ctx->
hwctx;
302 *frameinfo = frames_hwctx->
surfaces[0].Info;
309 frameinfo->CropX = 0;
310 frameinfo->CropY = 0;
311 frameinfo->Width =
FFALIGN(link->
w, 32);
312 frameinfo->Height =
FFALIGN(link->
h, 32);
313 frameinfo->PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
315 frameinfo->BitDepthLuma =
desc->comp[0].depth;
316 frameinfo->BitDepthChroma =
desc->comp[0].depth;
317 frameinfo->Shift =
desc->comp[0].depth > 8;
318 if (
desc->log2_chroma_w &&
desc->log2_chroma_h)
319 frameinfo->ChromaFormat = MFX_CHROMAFORMAT_YUV420;
320 else if (
desc->log2_chroma_w)
321 frameinfo->ChromaFormat = MFX_CHROMAFORMAT_YUV422;
323 frameinfo->ChromaFormat = MFX_CHROMAFORMAT_YUV444;
326 frameinfo->CropW = link->
w;
327 frameinfo->CropH = link->
h;
353 *list = (*list)->
next;
412 if (!qsv_frame->
frame)
439 qsv_frame->
surface->Info.PicStruct =
442 MFX_PICSTRUCT_FIELD_BFF);
444 qsv_frame->
surface->Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
446 qsv_frame->
surface->Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
448 qsv_frame->
surface->Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
470 if (!out_frame->
frame)
486 if (!out_frame->
frame)
500 out_frame->
surface->Info =
s->vpp_param.vpp.Out;
526 in_frames_hwctx = frames_ctx->
hwctx;
531 sizeof(*
s->surface_ptrs_in));
532 if (!
s->surface_ptrs_in)
536 s->surface_ptrs_in[
i] = in_frames_hwctx->
surfaces +
i;
541 s->in_mem_mode = MFX_MEMTYPE_SYSTEM_MEMORY;
548 device_hwctx = device_ctx->
hwctx;
557 MFX_MEMTYPE_OPAQUE_FRAME :
558 MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
561 out_frames_hwctx = out_frames_ctx->
hwctx;
580 sizeof(*
s->surface_ptrs_out));
581 if (!
s->surface_ptrs_out) {
587 s->surface_ptrs_out[
i] = out_frames_hwctx->
surfaces +
i;
593 s->out_mem_mode = MFX_MEMTYPE_SYSTEM_MEMORY;
596 ret = MFXQueryIMPL(device_hwctx->
session, &impl);
597 if (ret == MFX_ERR_NONE)
598 ret = MFXQueryVersion(device_hwctx->
session, &ver);
599 if (ret != MFX_ERR_NONE) {
606 if (ret == MFX_ERR_NONE) {
620 ret = MFXInit(impl, &ver, &
s->session);
629 ret = MFXVideoCORE_SetHandle(
s->session,
handle_type, handle);
630 if (ret != MFX_ERR_NONE)
635 ret = MFXJoinSession(device_hwctx->
session,
s->session);
636 if (ret != MFX_ERR_NONE)
641 s->opaque_alloc.In.Surfaces =
s->surface_ptrs_in;
642 s->opaque_alloc.In.NumSurface =
s->nb_surface_ptrs_in;
643 s->opaque_alloc.In.Type =
s->in_mem_mode;
645 s->opaque_alloc.Out.Surfaces =
s->surface_ptrs_out;
646 s->opaque_alloc.Out.NumSurface =
s->nb_surface_ptrs_out;
647 s->opaque_alloc.Out.Type =
s->out_mem_mode;
649 s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
650 s->opaque_alloc.Header.BufferSz =
sizeof(
s->opaque_alloc);
652 mfxFrameAllocator frame_allocator = {
661 ret = MFXVideoCORE_SetFrameAllocator(
s->session, &frame_allocator);
662 if (ret != MFX_ERR_NONE)
680 if (!
s->filter_frame)
690 if (!
s->frame_infos) {
709 s->frame_infos[crop->
in_idx].CropX = crop->
x;
710 s->frame_infos[crop->
in_idx].CropY = crop->
y;
711 s->frame_infos[crop->
in_idx].CropW = crop->
w;
712 s->frame_infos[crop->
in_idx].CropH = crop->
h;
715 s->vpp_param.vpp.In =
s->frame_infos[0];
726 if (!
s->ext_buffers) {
731 s->ext_buffers[0] = (mfxExtBuffer *)&
s->opaque_alloc;
734 s->vpp_param.ExtParam =
s->ext_buffers;
735 s->vpp_param.NumExtParam =
s->nb_ext_buffers;
738 s->vpp_param.ExtParam = param->
ext_buf;
741 s->vpp_param.AsyncDepth = 1;
744 s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_SYSTEM_MEMORY;
746 s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_VIDEO_MEMORY;
748 s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_OPAQUE_MEMORY;
751 s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
753 s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_VIDEO_MEMORY;
755 s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
761 ret = MFXVideoVPP_Init(
s->session, &
s->vpp_param);
785 MFXVideoVPP_Close(
s->session);
786 MFXClose(
s->session);
824 ret = MFXVideoVPP_RunFrameVPPAsync(
s->session, in_frame->
surface,
826 if (ret == MFX_WRN_DEVICE_BUSY)
828 }
while (ret == MFX_WRN_DEVICE_BUSY);
830 if (ret < 0 && ret != MFX_ERR_MORE_SURFACE) {
832 if (ret == MFX_ERR_MORE_DATA)
837 if (MFXVideoCORE_SyncOperation(
s->session, sync, 1000) < 0)
843 filter_ret =
s->filter_frame(outlink, out_frame->
frame);
844 if (filter_ret < 0) {
850 }
while(ret == MFX_ERR_MORE_SURFACE);
static const char *const format[]
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
common internal and external API header
static enum AVPixelFormat pix_fmt
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
mfxHandleType handle_type
An API-specific header for AV_HWDEVICE_TYPE_QSV.
#define FF_INLINK_IDX(link)
Find the index of a link.
common internal API header
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
@ 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...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
static QSVFrame * query_frame(QSVVPPContext *s, AVFilterLink *outlink)
static const AVRational default_tb
#define IS_VIDEO_MEMORY(mode)
static int qsv_map_error(mfxStatus mfx_err, const char **desc)
static int pix_fmt_to_mfx_fourcc(int format)
static QSVFrame * submit_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picref)
static void clear_frame_list(QSVFrame **list)
int ff_qsvvpp_print_iopattern(void *log_ctx, int mfx_iopattern, const char *extra_string)
static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
#define IS_OPAQUE_MEMORY(mode)
static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
static int fill_frameinfo_by_link(mfxFrameInfo *frameinfo, AVFilterLink *link)
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *param)
#define IS_SYSTEM_MEMORY(mode)
static int map_frame_to_surface(AVFrame *frame, mfxFrameSurface1 *surface)
int ff_qsvvpp_free(QSVVPPContext **vpp)
static void clear_unused_frames(QSVFrame *list)
int ff_qsvvpp_print_error(void *log_ctx, mfxStatus err, const char *error_string)
static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
static const mfxHandleType handle_types[]
int ff_qsvvpp_print_warning(void *log_ctx, mfxStatus err, const char *warning_string)
static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
static const struct @212 qsv_errors[]
static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
static const struct @211 qsv_iopatterns[]
static QSVFrame * get_free_frame(QSVFrame **list)
int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picref)
Intel Quick Sync Video VPP base function.
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
uint8_t * data
The data buffer.
int extra_hw_frames
Sets the number of extra hardware frames which the filter will allocate on its output links for use i...
unsigned nb_inputs
number of input pads
AVFilterLink ** inputs
array of pointers to input links
AVBufferRef * hw_device_ctx
For filters which will create hardware frames, sets the device the filter should create them in.
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
AVFilterContext * dst
dest filter
int format
agreed upon media format
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int top_field_first
If the content is interlaced, is top field displayed first.
int interlaced_frame
The content of the picture is interlaced.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
int repeat_pict
When decoding, this signals how much the picture must be delayed.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int initial_pool_size
Initial size of the frame pool.
int width
The allocated dimensions of the frames in this pool.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
This struct is allocated as AVHWDeviceContext.hwctx.
This struct is allocated as AVHWFramesContext.hwctx.
mfxFrameSurface1 * surfaces
int frame_type
A combination of MFX_MEMTYPE_* describing the frame pool.
Rational number (pair of numerator and denominator).
mfxFrameSurface1 * surface
mfxFrameSurface1 surface_internal
mfxExtOpaqueSurfaceAlloc opaque_alloc
mfxFrameSurface1 ** surface_ptrs_in
enum AVPixelFormat out_sw_format
mfxFrameSurface1 ** surface_ptrs_out
mfxFrameInfo * frame_infos
QSVFrame * out_frame_list
int(* filter_frame)(AVFilterLink *outlink, AVFrame *frame)
mfxExtBuffer ** ext_buffers
int(* filter_frame)(AVFilterLink *outlink, AVFrame *frame)
enum AVPixelFormat out_sw_format
int av_usleep(unsigned usec)
Sleep for a period of time.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.