25 #include <sys/types.h>
27 #include <mfx/mfxvideo.h>
44 case MFX_ERR_MEMORY_ALLOC:
45 case MFX_ERR_NOT_ENOUGH_BUFFER:
47 case MFX_ERR_INVALID_HANDLE:
49 case MFX_ERR_DEVICE_FAILED:
50 case MFX_ERR_DEVICE_LOST:
51 case MFX_ERR_LOCK_MEMORY:
53 case MFX_ERR_NULL_PTR:
54 case MFX_ERR_UNDEFINED_BEHAVIOR:
55 case MFX_ERR_NOT_INITIALIZED:
57 case MFX_ERR_UNSUPPORTED:
58 case MFX_ERR_NOT_FOUND:
60 case MFX_ERR_MORE_DATA:
61 case MFX_ERR_MORE_SURFACE:
62 case MFX_ERR_MORE_BITSTREAM:
64 case MFX_ERR_INCOMPATIBLE_VIDEO_PARAM:
65 case MFX_ERR_INVALID_VIDEO_PARAM:
92 return MFX_CODEC_MPEG2;
106 mfxIMPL impl = MFX_IMPL_AUTO_ANY;
120 if (impl & MFX_IMPL_SOFTWARE)
122 else if (impl & MFX_IMPL_HARDWARE)
123 desc =
"hardware accelerated";
128 "Initialized an internal MFX session using %s implementation\n",
138 MFXVideoDECODE_Close(q->
session);
145 mfxVideoParam param = { { 0 } };
159 param.mfx.CodecId =
ret;
160 param.mfx.CodecProfile = avctx->
profile;
161 param.mfx.CodecLevel = avctx->
level;
163 param.mfx.FrameInfo.BitDepthLuma = 8;
164 param.mfx.FrameInfo.BitDepthChroma = 8;
165 param.mfx.FrameInfo.Shift = 0;
166 param.mfx.FrameInfo.FourCC = MFX_FOURCC_NV12;
169 param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
176 ret = MFXVideoDECODE_Init(q->
session, ¶m);
281 mfxFrameSurface1 *insurf;
282 mfxFrameSurface1 *outsurf;
284 mfxBitstream bs = { { { 0 } } };
288 bs.Data = avpkt->
data;
289 bs.DataLength = avpkt->
size;
290 bs.MaxLength = bs.DataLength;
291 bs.TimeStamp = avpkt->
pts;
299 ret = MFXVideoDECODE_DecodeFrameAsync(q->
session, avpkt->
size ? &bs :
NULL,
300 insurf, &outsurf, &sync);
301 if (ret == MFX_WRN_DEVICE_BUSY)
304 }
while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
306 if (ret != MFX_ERR_NONE &&
307 ret != MFX_ERR_MORE_DATA &&
308 ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
309 ret != MFX_ERR_MORE_SURFACE) {
317 MFXVideoCORE_SyncOperation(q->
session, sync, 60000);
322 "The returned surface does not correspond to any frame\n");
330 frame->
pkt_pts = frame->
pts = outsurf->Data.TimeStamp;
333 outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_TRIPLING ? 4 :
334 outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_DOUBLING ? 2 :
335 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_REPEATED ? 1 : 0;
337 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
339 !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
344 return bs.DataOffset;
This structure describes decoded (raw) audio or video data.
int coded_width
Bitstream width / height, may be different from width/height e.g.
int ff_qsv_map_pixfmt(enum AVPixelFormat format)
memory handling functions
static AVFrame * find_frame(QSVContext *q, mfxFrameSurface1 *surf)
int repeat_pict
When decoding, this signals how much the picture must be delayed.
static int codec_id_to_mfx(enum AVCodecID codec_id)
mfxExtBuffer ** ext_buffers
mfxFrameSurface1 * surface
int av_usleep(unsigned usec)
Sleep for a period of time.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
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 ff_qsv_close(QSVContext *q)
#define AV_LOG_VERBOSE
Detailed information.
int interlaced_frame
The content of the picture is interlaced.
int ff_qsv_init(AVCodecContext *avctx, QSVContext *q, mfxSession session)
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Libavcodec external API header.
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
#define QSV_VERSION_MINOR
mfxFrameSurface1 surface_internal
preferred ID for MPEG-1/2 video decoding
static void qsv_clear_unused_frames(QSVContext *q)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session)
mfxSession internal_session
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, AVPacket *avpkt)
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
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.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
common internal and external API header
int ff_qsv_error(int mfx_err)
Convert a libmfx error code into a ffmpeg error code.
#define QSV_VERSION_MAJOR
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
int top_field_first
If the content is interlaced, is top field displayed first.
static int alloc_frame(AVCodecContext *avctx, QSVFrame *frame)
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.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...