25 #include <sys/types.h> 
   27 #include <mfx/mfxvideo.h> 
   72     mfxSession session = 
NULL;
 
   73     mfxVideoParam param = { { 0 } };
 
   74     mfxBitstream bs   = { { { 0 } } };
 
   86     q->
iopattern  = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
 
  103         bs.Data       = avpkt->
data;
 
  104         bs.DataLength = avpkt->
size;
 
  105         bs.MaxLength  = bs.DataLength;
 
  106         bs.TimeStamp  = avpkt->
pts;
 
  116     param.mfx.CodecId = ret;
 
  118     ret = MFXVideoDECODE_DecodeHeader(q->
session, &bs, ¶m);
 
  119     if (MFX_ERR_MORE_DATA==ret) {
 
  124     } 
else if (ret < 0) {
 
  132     param.mfx.FrameInfo.BitDepthLuma   = 8;
 
  133     param.mfx.FrameInfo.BitDepthChroma = 8;
 
  135     ret = MFXVideoDECODE_Init(q->
session, ¶m);
 
  137         if (MFX_ERR_INVALID_VIDEO_PARAM==ret) {
 
  139                    "Error initializing the MFX video decoder, unsupported video\n");
 
  142                    "Error initializing the MFX video decoder %d\n", ret);
 
  147     avctx->
profile      = param.mfx.CodecProfile;
 
  148     avctx->
level        = param.mfx.CodecLevel;
 
  151     avctx->
width        = param.mfx.FrameInfo.CropW - param.mfx.FrameInfo.CropX;
 
  152     avctx->
height       = param.mfx.FrameInfo.CropH - param.mfx.FrameInfo.CropY;
 
  160                                       (
sizeof(mfxSyncPoint) + 
sizeof(
QSVFrame*)));
 
  292             if ( (f->
end - f->
rptr) < data_size) {
 
  293                 data_rest = data_size - (f->
end - f->
rptr);
 
  294                 data_size-=data_rest;
 
  298             data_size+= data_rest;
 
  313         MFXVideoDECODE_Close(q->
session);
 
  332     mfxFrameSurface1 *insurf;
 
  333     mfxFrameSurface1 *outsurf;
 
  335     mfxBitstream bs = { { { 0 } } };
 
  360             bs.Data       = avpkt->
data;
 
  361             bs.DataLength = avpkt->
size;
 
  363         bs.MaxLength  = bs.DataLength;
 
  364         bs.TimeStamp  = avpkt->
pts;
 
  372             ret = MFXVideoDECODE_DecodeFrameAsync(q->
session, flush ? 
NULL : &bs,
 
  373                                                   insurf, &outsurf, &sync);
 
  374             if (ret != MFX_WRN_DEVICE_BUSY)
 
  379         if (MFX_WRN_VIDEO_PARAM_CHANGED==ret) {
 
  381         } 
else if (MFX_ERR_INCOMPATIBLE_VIDEO_PARAM==ret) {
 
  392                        "The returned surface does not correspond to any frame\n");
 
  402         if (MFX_ERR_MORE_SURFACE != ret && ret < 0)
 
  408     if (!sync && !bs.DataOffset && !flush) {
 
  410         bs.DataOffset = avpkt->
size;
 
  415     } 
else if (bs.DataOffset!=avpkt->
size) {
 
  421     if (MFX_ERR_MORE_DATA!=ret && ret < 0) {
 
  427     if (n_out_frames > q->
async_depth || (flush && n_out_frames) ) {
 
  435             ret = MFXVideoCORE_SyncOperation(q->
session, sync, 1000);
 
  436         } 
while (ret == MFX_WRN_IN_EXECUTION);
 
  438         src_frame = out_frame->
frame;
 
  448         frame->
pkt_pts = outsurf->Data.TimeStamp;
 
  451         frame->
pts = outsurf->Data.TimeStamp;
 
  454             outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_TRIPLING ? 4 :
 
  455             outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_DOUBLING ? 2 :
 
  456             outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_REPEATED ? 1 : 0;
 
  458             outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
 
  460             !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
 
  552     mfxVideoParam param = { { 0 } };
 
  557         ret = MFXVideoDECODE_GetVideoParam(q->
session, ¶m);
 
  562         ret = MFXVideoDECODE_Reset(q->
session, ¶m);
 
static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q, AVPacket *avpkt)
 
int av_fifo_grow(AVFifoBuffer *f, unsigned int size)
Enlarge an AVFifoBuffer. 
 
#define AVERROR_INVALIDDATA
Invalid data found when processing input. 
 
int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, AVPacket *avpkt)
 
AVFifoBuffer * input_fifo
 
This structure describes decoded (raw) audio or video data. 
 
static void flush(AVCodecContext *avctx)
 
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. 
 
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. 
 
mfxFrameSurface1 * surface
 
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 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. 
 
void ff_qsv_decode_reset(AVCodecContext *avctx, QSVContext *q)
 
static int do_qsv_decode(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, AVPacket *avpkt)
 
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values. 
 
void * hwaccel_context
Hardware accelerator context. 
 
mfxExtBuffer * ext_buffers[1]
 
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 av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet. 
 
static QSVFrame * find_frame(QSVContext *q, mfxFrameSurface1 *surf)
 
#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. 
 
static void qsv_packet_push_front(QSVContext *q, AVPacket *avpkt)
 
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 iopattern
The IO pattern to use. 
 
int ff_qsv_close_internal_session(QSVSession *qs)
 
static void qsv_fifo_relocate(AVFifoBuffer *f, int bytes_to_free)
 
static void close_decoder(QSVContext *q)
 
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
 
int width
picture width / height. 
 
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 
mfxFrameSurface1 surface_internal
 
int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs, const char *load_plugins)
Initialize a MSDK session. 
 
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...
 
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. 
 
main external API structure. 
 
void av_packet_unref(AVPacket *pkt)
Wipe the packet. 
 
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. 
 
static const char * format
 
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure. 
 
static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session)
 
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. 
 
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples) 
 
#define FF_DISABLE_DEPRECATION_WARNINGS
 
common internal api header. 
 
common internal and external API header 
 
int ff_qsv_map_pixfmt(enum AVPixelFormat format)
 
int ff_qsv_error(int mfx_err)
Convert a libmfx error code into a ffmpeg error code. 
 
#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. 
 
AVFifoBuffer * async_fifo
 
static int alloc_frame(AVCodecContext *avctx, QSVFrame *frame)
 
void av_fifo_reset(AVFifoBuffer *f)
Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied...
 
void av_fifo_drain(AVFifoBuffer *f, int size)
Discard data from the FIFO. 
 
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...