25 #include <sys/types.h> 27 #include <mfx/mfxvideo.h> 101 if (q->
gpu_copy == MFX_GPUCOPY_ON &&
102 !(q->
iopattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY)) {
104 "only works in system memory mode.\n");
109 }
else if (hw_frames_ref) {
122 q->
iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
130 }
else if (hw_device_ref) {
154 MFXVideoDECODE_Close(q->
session);
161 return sizeof(mfxSyncPoint*) +
sizeof(
QSVFrame*);
171 mfxSession session =
NULL;
204 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
205 iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
206 else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
207 iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
212 iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
235 avctx->
width = param->mfx.FrameInfo.CropW;
236 avctx->
height = param->mfx.FrameInfo.CropH;
239 avctx->
level = param->mfx.CodecLevel;
240 avctx->
profile = param->mfx.CodecProfile;
244 ret = MFXVideoDECODE_Init(q->
session, param);
247 "Error initializing the MFX video decoder");
261 mfxBitstream bs = { 0 };
264 bs.Data = avpkt->
data;
265 bs.DataLength = avpkt->
size;
266 bs.MaxLength = bs.DataLength;
267 bs.TimeStamp = avpkt->
pts;
269 bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
284 param->mfx.CodecId = ret;
285 ret = MFXVideoDECODE_DecodeHeader(q->
session, &bs, param);
286 if (MFX_ERR_MORE_DATA == ret) {
291 "Error decoding stream header");
326 frame->
surface.Data.NumExtParam = 1;
328 frame->
dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
405 mfxFrameSurface1 *insurf;
406 mfxFrameSurface1 *outsurf;
408 mfxBitstream bs = { { { 0 } } };
412 bs.Data = avpkt->
data;
413 bs.DataLength = avpkt->
size;
414 bs.MaxLength = bs.DataLength;
415 bs.TimeStamp = avpkt->
pts;
417 bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
433 ret = MFXVideoDECODE_DecodeFrameAsync(q->
session, avpkt->
size ? &bs :
NULL,
434 insurf, &outsurf, sync);
435 if (ret == MFX_WRN_DEVICE_BUSY)
438 }
while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
440 if (ret != MFX_ERR_NONE &&
441 ret != MFX_ERR_MORE_DATA &&
442 ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
443 ret != MFX_ERR_MORE_SURFACE) {
446 "Error during QSV decoding.");
451 if (!*sync && !bs.DataOffset) {
452 bs.DataOffset = avpkt->
size;
456 }
else if (!*sync && bs.DataOffset) {
467 "The returned surface does not correspond to any frame\n");
489 ret = MFXVideoCORE_SyncOperation(q->
session, *sync, 1000);
490 }
while (ret == MFX_WRN_IN_EXECUTION);
495 src_frame = out_frame->
frame;
505 frame->
pkt_pts = outsurf->Data.TimeStamp;
508 frame->
pts = outsurf->Data.TimeStamp;
511 outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_TRIPLING ? 4 :
512 outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_DOUBLING ? 2 :
513 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_REPEATED ? 1 : 0;
515 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
517 !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
525 ((mfxFrameSurface1*)frame->
data[3])->Info = outsurf->Info;
530 return bs.DataOffset;
538 MFXVideoDECODE_Close(q->
session);
573 mfxVideoParam param = { 0 };
577 return qsv_decode(avctx, q, frame, got_frame, pkt);
602 return qsv_decode(avctx, q, frame, got_frame, &zero_pkt);
624 return qsv_decode(avctx, q, frame, got_frame, pkt);
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
The codec supports this format via the hw_frames_ctx interface.
static enum AVPixelFormat pix_fmt
static unsigned int qsv_fifo_size(const AVFifoBuffer *fifo)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
This structure describes decoded (raw) audio or video data.
int coded_width
Bitstream width / height, may be different from width/height e.g.
#define AV_LOG_WARNING
Something somehow does not look correct.
Memory handling functions.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
This struct is allocated as AVHWFramesContext.hwctx.
int repeat_pict
When decoding, this signals how much the picture must be delayed.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
mfxExtBuffer ** ext_buffers
int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession, AVBufferRef *device_ref, const char *load_plugins, int gpu_copy)
int av_usleep(unsigned usec)
Sleep for a period of time.
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
static int qsv_decode(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, AVPacket *avpkt)
static int ff_qsv_get_continuous_buffer(AVCodecContext *avctx, AVFrame *frame, AVBufferPool *pool)
static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q, mfxVideoParam *param)
AVBufferRef * hw_frames_ctx
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
int ff_qsv_print_error(void *log_ctx, mfxStatus err, const char *error_string)
mfxExtDecodedFrameInfo dec_info
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int ff_attach_decode_data(AVFrame *frame)
void * hwaccel_context
Hardware accelerator context.
int ff_qsv_decode_close(QSVContext *q)
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
enum AVPixelFormat pix_fmt
For decoders, a hardware pixel format which that decoder may be able to decode to if suitable hardwar...
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
int interlaced_frame
The content of the picture is interlaced.
static QSVFrame * find_frame(QSVContext *q, mfxFrameSurface1 *surf)
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters...
int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *psession, QSVFramesContext *qsv_frames_ctx, const char *load_plugins, int opaque, int gpu_copy)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame *frame)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern, const char *extra_string)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int iopattern
The IO pattern to use.
int ff_qsv_close_internal_session(QSVSession *qs)
enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
void ff_qsv_decode_flush(AVCodecContext *avctx, QSVContext *q)
int ff_qsv_print_warning(void *log_ctx, mfxStatus err, const char *warning_string)
The codec supports this format by some ad-hoc method.
enum AVPictureType pict_type
Picture type of the frame.
static unsigned int qsv_fifo_item_size(void)
int width
picture width / height.
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
enum AVPixelFormat orig_pix_fmt
Libavcodec external API header.
int av_fifo_size(const AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
mfxExtBuffer ** ext_buffers
Extra buffers to pass to encoder or decoder initialization.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
main external API structure.
uint8_t * data
The data buffer.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
AVBufferRef * av_buffer_allocz(int size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
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.
int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs, const char *load_plugins, int gpu_copy)
This struct is used for communicating QSV parameters between libavcodec and the caller.
static void qsv_clear_unused_frames(QSVContext *q)
static enum AVPixelFormat pix_fmts[]
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
attribute_deprecated int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
A reference to a data buffer.
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
common internal and external API header
AVBufferPool * av_buffer_pool_init(int size, AVBufferRef *(*alloc)(int size))
Allocate and initialize a buffer pool.
static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session, AVBufferRef *hw_frames_ref, AVBufferRef *hw_device_ref)
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define FF_ENABLE_DEPRECATION_WARNINGS
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
int top_field_first
If the content is interlaced, is top field displayed first.
QSVFramesContext frames_ctx
static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
int key_frame
1 -> keyframe, 0-> not
AVFifoBuffer * async_fifo
enum AVFieldOrder ff_qsv_map_picstruct(int mfx_pic_struct)
enum AVFieldOrder field_order
Field order.
An API-specific header for AV_HWDEVICE_TYPE_QSV.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
const AVCodecHWConfigInternal * ff_qsv_hw_configs[]
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, AVPacket *pkt)
QSVFrame * work_frames
a linked list of frames currently being used by QSV
static int qsv_decode_header(AVCodecContext *avctx, QSVContext *q, AVPacket *avpkt, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
AVPixelFormat
Pixel format.
This structure stores compressed data.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
mfxSession session
If non-NULL, the session to use for encoding or decoding.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc)