25 #include <sys/types.h>
27 #include <mfx/mfxvideo.h>
51 }
else if (hw_frames_ref) {
64 q->
iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY);
71 }
else if (hw_device_ref) {
95 MFXVideoDECODE_Close(q->
session);
103 mfxSession session =
NULL;
105 mfxVideoParam param = { 0 };
116 (
sizeof(mfxSyncPoint*) +
sizeof(
QSVFrame*)));
134 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
135 iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
136 else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
137 iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
140 frame_width = frames_hwctx->surfaces[0].Info.Width;
141 frame_height = frames_hwctx->surfaces[0].Info.Height;
145 iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
158 param.mfx.CodecId = ret;
162 param.mfx.FrameInfo.BitDepthLuma = desc->
comp[0].
depth;
163 param.mfx.FrameInfo.BitDepthChroma = desc->
comp[0].
depth;
164 param.mfx.FrameInfo.Shift = desc->
comp[0].
depth > 8;
165 param.mfx.FrameInfo.FourCC = q->
fourcc;
166 param.mfx.FrameInfo.Width = frame_width;
167 param.mfx.FrameInfo.Height = frame_height;
168 param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
172 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
175 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
178 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
181 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_UNKNOWN;
190 ret = MFXVideoDECODE_Init(q->
session, ¶m);
193 "Error initializing the MFX video decoder");
300 mfxFrameSurface1 *insurf;
301 mfxFrameSurface1 *outsurf;
303 mfxBitstream bs = { { { 0 } } };
307 bs.Data = avpkt->
data;
308 bs.DataLength = avpkt->
size;
309 bs.MaxLength = bs.DataLength;
310 bs.TimeStamp = avpkt->
pts;
326 ret = MFXVideoDECODE_DecodeFrameAsync(q->
session, avpkt->
size ? &bs :
NULL,
327 insurf, &outsurf, sync);
328 if (ret == MFX_WRN_DEVICE_BUSY)
331 }
while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
333 if (ret != MFX_ERR_NONE &&
334 ret != MFX_ERR_MORE_DATA &&
335 ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
336 ret != MFX_ERR_MORE_SURFACE) {
339 "Error during QSV decoding.");
344 if (!*sync && !bs.DataOffset) {
345 bs.DataOffset = avpkt->
size;
358 "The returned surface does not correspond to any frame\n");
380 ret = MFXVideoCORE_SyncOperation(q->
session, *sync, 1000);
381 }
while (ret == MFX_WRN_IN_EXECUTION);
386 src_frame = out_frame->
frame;
396 frame->
pkt_pts = outsurf->Data.TimeStamp;
399 frame->
pts = outsurf->Data.TimeStamp;
402 outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_TRIPLING ? 4 :
403 outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_DOUBLING ? 2 :
404 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_REPEATED ? 1 : 0;
406 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
408 !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
412 ((mfxFrameSurface1*)frame->
data[3])->Info = outsurf->Info;
417 return bs.DataOffset;
425 MFXVideoDECODE_Close(q->
session);
480 return qsv_decode(avctx, q, frame, got_frame, pkt);
485 &dummy_data, &dummy_size,
499 if (qsv_format < 0) {
501 "Decoding pixel format '%s' is not supported\n",
508 avctx->
pix_fmt = pix_fmts[1] = qsv_format;
528 return qsv_decode(avctx, q, frame, got_frame, pkt);
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
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)
This structure describes decoded (raw) audio or video data.
int coded_width
Bitstream width / height, may be different from width/height e.g.
Memory handling functions.
int64_t pos
byte position in stream, -1 if unknown
This struct is allocated as AVHWFramesContext.hwctx.
int width
Dimensions of the decoded video intended for presentation.
enum AVFieldOrder field_order
int repeat_pict
When decoding, this signals how much the picture must be delayed.
int coded_width
Dimensions of the coded video.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
mfxExtBuffer ** ext_buffers
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int av_usleep(unsigned usec)
Sleep for a period of time.
static int qsv_decode(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, AVPacket *avpkt)
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)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
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).
int av_fifo_space(const AVFifoBuffer *f)
Return the amount of space in bytes in the AVFifoBuffer, that is the amount of data you can write int...
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
int interlaced_frame
The content of the picture is interlaced.
int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *psession, QSVFramesContext *qsv_frames_ctx, const char *load_plugins, int opaque)
static QSVFrame * find_frame(QSVContext *q, mfxFrameSurface1 *surf)
AVCodecParserContext * parser
#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.
int iopattern
The IO pattern to use.
void ff_qsv_decode_flush(AVCodecContext *avctx, QSVContext *q)
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)
int ff_qsv_profile_to_mfx(enum AVCodecID codec_id, int profile)
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts, int64_t pos)
Parse a packet.
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)
void av_parser_close(AVCodecParserContext *s)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
enum AVPixelFormat orig_pix_fmt
AVCodecParserContext * av_parser_init(int codec_id)
Libavcodec external API header.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
mfxSession internal_session
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.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
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.
static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
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.
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
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.
int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session, const char *load_plugins)
#define PARSER_FLAG_COMPLETE_FRAMES
AVCodecContext * avctx_internal
#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
int format
The format of the coded data, corresponds to enum AVPixelFormat for video and for enum AVSampleFormat...
AVFifoBuffer * async_fifo
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
enum AVFieldOrder field_order
Field order.
An API-specific header for AV_HWDEVICE_TYPE_QSV.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
int depth
Number of bits in the component.
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
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 sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession, AVBufferRef *device_ref, const char *load_plugins)