25 #include <sys/types.h>
27 #include <mfx/mfxvideo.h>
51 }
else if (hw_frames_ref) {
64 q->
iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY);
83 MFXVideoDECODE_Close(q->
session);
91 mfxSession session =
NULL;
93 mfxVideoParam param = { 0 };
104 (
sizeof(mfxSyncPoint*) +
sizeof(
QSVFrame*)));
122 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
123 iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
124 else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
125 iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
128 frame_width = frames_hwctx->surfaces[0].Info.Width;
129 frame_height = frames_hwctx->surfaces[0].Info.Height;
133 iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
146 param.mfx.CodecId = ret;
150 param.mfx.FrameInfo.BitDepthLuma = desc->
comp[0].
depth;
151 param.mfx.FrameInfo.BitDepthChroma = desc->
comp[0].
depth;
152 param.mfx.FrameInfo.Shift = desc->
comp[0].
depth > 8;
153 param.mfx.FrameInfo.FourCC = q->
fourcc;
154 param.mfx.FrameInfo.Width = frame_width;
155 param.mfx.FrameInfo.Height = frame_height;
156 param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
160 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
163 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
166 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
169 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_UNKNOWN;
178 ret = MFXVideoDECODE_Init(q->
session, ¶m);
181 "Error initializing the MFX video decoder");
288 mfxFrameSurface1 *insurf;
289 mfxFrameSurface1 *outsurf;
291 mfxBitstream bs = { { { 0 } } };
295 bs.Data = avpkt->
data;
296 bs.DataLength = avpkt->
size;
297 bs.MaxLength = bs.DataLength;
298 bs.TimeStamp = avpkt->
pts;
314 ret = MFXVideoDECODE_DecodeFrameAsync(q->
session, avpkt->
size ? &bs :
NULL,
315 insurf, &outsurf, sync);
316 if (ret == MFX_WRN_DEVICE_BUSY)
319 }
while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
321 if (ret != MFX_ERR_NONE &&
322 ret != MFX_ERR_MORE_DATA &&
323 ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
324 ret != MFX_ERR_MORE_SURFACE) {
327 "Error during QSV decoding.");
332 if (!*sync && !bs.DataOffset) {
333 bs.DataOffset = avpkt->
size;
346 "The returned surface does not correspond to any frame\n");
367 ret = MFXVideoCORE_SyncOperation(q->
session, *sync, 1000);
368 }
while (ret == MFX_WRN_IN_EXECUTION);
372 src_frame = out_frame->
frame;
382 frame->
pkt_pts = outsurf->Data.TimeStamp;
385 frame->
pts = outsurf->Data.TimeStamp;
388 outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_TRIPLING ? 4 :
389 outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_DOUBLING ? 2 :
390 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_REPEATED ? 1 : 0;
392 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
394 !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
398 ((mfxFrameSurface1*)frame->
data[3])->Info = outsurf->Info;
403 return bs.DataOffset;
411 MFXVideoDECODE_Close(q->
session);
466 return qsv_decode(avctx, q, frame, got_frame, pkt);
471 &dummy_data, &dummy_size,
485 if (qsv_format < 0) {
487 "Decoding pixel format '%s' is not supported\n",
494 avctx->
pix_fmt = pix_fmts[1] = qsv_format;
514 return qsv_decode(avctx, q, frame, got_frame, pkt);
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.
int ff_qsv_init_session_hwcontext(AVCodecContext *avctx, mfxSession *psession, QSVFramesContext *qsv_frames_ctx, const char *load_plugins, int opaque)
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.
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 ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
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.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
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
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
static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session, AVBufferRef *hw_frames_ref)
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.
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.