25 #include <sys/types.h>
27 #include <mfx/mfxvideo.h>
64 }
else if (hw_frames_ref) {
77 q->
iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY);
84 }
else if (hw_device_ref) {
108 MFXVideoDECODE_Close(q->
session);
116 mfxSession session =
NULL;
118 mfxVideoParam param = { 0 };
129 (
sizeof(mfxSyncPoint*) +
sizeof(
QSVFrame*)));
147 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
148 iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
149 else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
150 iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
155 iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
168 param.mfx.CodecId = ret;
172 param.mfx.FrameInfo.BitDepthLuma = desc->
comp[0].
depth;
173 param.mfx.FrameInfo.BitDepthChroma = desc->
comp[0].
depth;
174 param.mfx.FrameInfo.Shift = desc->
comp[0].
depth > 8;
175 param.mfx.FrameInfo.FourCC = q->
fourcc;
176 param.mfx.FrameInfo.Width = frame_width;
177 param.mfx.FrameInfo.Height = frame_height;
178 param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
182 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
185 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
188 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
191 param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_UNKNOWN;
200 ret = MFXVideoDECODE_Init(q->
session, ¶m);
203 "Error initializing the MFX video decoder");
236 frame->
surface.Data.NumExtParam = 1;
238 frame->
dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
315 mfxFrameSurface1 *insurf;
316 mfxFrameSurface1 *outsurf;
318 mfxBitstream bs = { { { 0 } } };
322 bs.Data = avpkt->
data;
323 bs.DataLength = avpkt->
size;
324 bs.MaxLength = bs.DataLength;
325 bs.TimeStamp = avpkt->
pts;
327 bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
343 ret = MFXVideoDECODE_DecodeFrameAsync(q->
session, avpkt->
size ? &bs :
NULL,
344 insurf, &outsurf, sync);
345 if (ret == MFX_WRN_DEVICE_BUSY)
348 }
while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
350 if (ret != MFX_ERR_NONE &&
351 ret != MFX_ERR_MORE_DATA &&
352 ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
353 ret != MFX_ERR_MORE_SURFACE) {
356 "Error during QSV decoding.");
361 if (!*sync && !bs.DataOffset) {
362 bs.DataOffset = avpkt->
size;
375 "The returned surface does not correspond to any frame\n");
397 ret = MFXVideoCORE_SyncOperation(q->
session, *sync, 1000);
398 }
while (ret == MFX_WRN_IN_EXECUTION);
403 src_frame = out_frame->
frame;
413 frame->
pkt_pts = outsurf->Data.TimeStamp;
416 frame->
pts = outsurf->Data.TimeStamp;
419 outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_TRIPLING ? 4 :
420 outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_DOUBLING ? 2 :
421 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_REPEATED ? 1 : 0;
423 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
425 !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
433 ((mfxFrameSurface1*)frame->
data[3])->Info = outsurf->Info;
438 return bs.DataOffset;
446 MFXVideoDECODE_Close(q->
session);
502 return qsv_decode(avctx, q, frame, got_frame, pkt);
507 &dummy_data, &dummy_size,
522 if (qsv_format < 0) {
524 "Decoding pixel format '%s' is not supported\n",
531 avctx->
pix_fmt = pix_fmts[1] = qsv_format;
559 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.
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)
mfxExtDecodedFrameInfo dec_info
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).
enum AVPixelFormat pix_fmt
A hardware pixel format which the codec can use.
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.
enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
void ff_qsv_decode_flush(AVCodecContext *avctx, QSVContext *q)
The codec supports this format by some ad-hoc method.
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)
enum AVPictureType pict_type
Picture type of the frame.
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.
The codec supports this format via the hw_frames_ctx interface.
QSVFramesContext frames_ctx
int format
The format of the coded data, corresponds to enum AVPixelFormat for video and for enum AVSampleFormat...
int key_frame
1 -> keyframe, 0-> not
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 AVCodecHWConfigInternal * ff_qsv_hw_configs[]
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)