FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
qsvdec.c File Reference
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include <mfx/mfxvideo.h>
#include "libavutil/common.h"
#include "libavutil/fifo.h"
#include "libavutil/frame.h"
#include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_qsv.h"
#include "libavutil/mem.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavutil/pixfmt.h"
#include "libavutil/time.h"
#include "libavutil/imgutils.h"
#include "avcodec.h"
#include "internal.h"
#include "decode.h"
#include "hwconfig.h"
#include "qsv.h"
#include "qsv_internal.h"

Go to the source code of this file.

Data Structures

struct  QSVContext
 
struct  QSVDecContext
 

Macros

#define OFFSET(x)   offsetof(QSVDecContext, x)
 
#define VD   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
 
#define DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, opt)
 
#define DEFINE_QSV_DECODER(x, X, bsf_name)   DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, options)
 

Enumerations

enum  LoadPlugin {
  LOAD_PLUGIN_NONE, LOAD_PLUGIN_HEVC_SW, LOAD_PLUGIN_HEVC_HW, LOAD_PLUGIN_NONE,
  LOAD_PLUGIN_HEVC_SW, LOAD_PLUGIN_HEVC_HW
}
 

Functions

static int qsv_get_continuous_buffer (AVCodecContext *avctx, AVFrame *frame, AVBufferPool *pool)
 
static int qsv_init_session (AVCodecContext *avctx, QSVContext *q, mfxSession session, AVBufferRef *hw_frames_ref, AVBufferRef *hw_device_ref)
 
static unsigned int qsv_fifo_item_size (void)
 
static unsigned int qsv_fifo_size (const AVFifoBuffer *fifo)
 
static int qsv_decode_preinit (AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
 
static int qsv_decode_init_context (AVCodecContext *avctx, QSVContext *q, mfxVideoParam *param)
 
static int qsv_decode_header (AVCodecContext *avctx, QSVContext *q, const AVPacket *avpkt, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
 
static int alloc_frame (AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
 
static void qsv_clear_unused_frames (QSVContext *q)
 
static int get_surface (AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
 
static QSVFramefind_frame (QSVContext *q, mfxFrameSurface1 *surf)
 
static int qsv_decode (AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, const AVPacket *avpkt)
 
static void qsv_decode_close_qsvcontext (QSVContext *q)
 
static int qsv_process_data (AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, const AVPacket *pkt)
 
static void qsv_clear_buffers (QSVDecContext *s)
 
static av_cold int qsv_decode_close (AVCodecContext *avctx)
 
static av_cold int qsv_decode_init (AVCodecContext *avctx)
 
static int qsv_decode_frame (AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
 
static void qsv_decode_flush (AVCodecContext *avctx)
 

Variables

static const AVCodecHWConfigInternal *const qsv_hw_configs []
 
static const AVOption options []
 

Macro Definition Documentation

◆ OFFSET

#define OFFSET (   x)    offsetof(QSVDecContext, x)

Definition at line 827 of file qsvdec.c.

◆ VD

Definition at line 828 of file qsvdec.c.

◆ DEFINE_QSV_DECODER_WITH_OPTION

#define DEFINE_QSV_DECODER_WITH_OPTION (   x,
  X,
  bsf_name,
  opt 
)
Value:
static const AVClass x##_qsv_class = { \
.class_name = #x "_qsv", \
.item_name = av_default_item_name, \
.option = opt, \
.version = LIBAVUTIL_VERSION_INT, \
}; \
AVCodec ff_##x##_qsv_decoder = { \
.name = #x "_qsv", \
.long_name = NULL_IF_CONFIG_SMALL(#X " video (Intel Quick Sync Video acceleration)"), \
.priv_data_size = sizeof(QSVDecContext), \
.id = AV_CODEC_ID_##X, \
.close = qsv_decode_close, \
.bsfs = bsf_name, \
.priv_class = &x##_qsv_class, \
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, \
AV_PIX_FMT_P010, \
AV_PIX_FMT_QSV, \
AV_PIX_FMT_NONE }, \
.hw_configs = qsv_hw_configs, \
.wrapper_name = "qsv", \
}; \

Definition at line 830 of file qsvdec.c.

◆ DEFINE_QSV_DECODER

#define DEFINE_QSV_DECODER (   x,
  X,
  bsf_name 
)    DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, options)

Definition at line 858 of file qsvdec.c.

Enumeration Type Documentation

◆ LoadPlugin

enum LoadPlugin
Enumerator
LOAD_PLUGIN_NONE 
LOAD_PLUGIN_HEVC_SW 
LOAD_PLUGIN_HEVC_HW 
LOAD_PLUGIN_NONE 
LOAD_PLUGIN_HEVC_SW 
LOAD_PLUGIN_HEVC_HW 

Definition at line 673 of file qsvdec.c.

Function Documentation

◆ qsv_get_continuous_buffer()

static int qsv_get_continuous_buffer ( AVCodecContext avctx,
AVFrame frame,
AVBufferPool pool 
)
static

Definition at line 100 of file qsvdec.c.

Referenced by alloc_frame().

◆ qsv_init_session()

static int qsv_init_session ( AVCodecContext avctx,
QSVContext q,
mfxSession  session,
AVBufferRef hw_frames_ref,
AVBufferRef hw_device_ref 
)
static

Definition at line 138 of file qsvdec.c.

Referenced by qsv_decode_preinit().

◆ qsv_fifo_item_size()

static unsigned int qsv_fifo_item_size ( void  )
inlinestatic

Definition at line 201 of file qsvdec.c.

Referenced by qsv_decode_preinit(), and qsv_fifo_size().

◆ qsv_fifo_size()

static unsigned int qsv_fifo_size ( const AVFifoBuffer fifo)
inlinestatic

Definition at line 206 of file qsvdec.c.

Referenced by qsv_decode().

◆ qsv_decode_preinit()

static int qsv_decode_preinit ( AVCodecContext avctx,
QSVContext q,
enum AVPixelFormat  pix_fmt,
mfxVideoParam *  param 
)
static

Definition at line 211 of file qsvdec.c.

Referenced by qsv_decode_header(), and qsv_process_data().

◆ qsv_decode_init_context()

static int qsv_decode_init_context ( AVCodecContext avctx,
QSVContext q,
mfxVideoParam *  param 
)
static

Definition at line 273 of file qsvdec.c.

Referenced by qsv_process_data().

◆ qsv_decode_header()

static int qsv_decode_header ( AVCodecContext avctx,
QSVContext q,
const AVPacket avpkt,
enum AVPixelFormat  pix_fmt,
mfxVideoParam *  param 
)
static

Definition at line 299 of file qsvdec.c.

Referenced by qsv_process_data().

◆ alloc_frame()

static int alloc_frame ( AVCodecContext avctx,
QSVContext q,
QSVFrame frame 
)
static

Definition at line 340 of file qsvdec.c.

Referenced by get_surface().

◆ qsv_clear_unused_frames()

static void qsv_clear_unused_frames ( QSVContext q)
static

Definition at line 380 of file qsvdec.c.

Referenced by get_surface().

◆ get_surface()

static int get_surface ( AVCodecContext avctx,
QSVContext q,
mfxFrameSurface1 **  surf 
)
static

Definition at line 392 of file qsvdec.c.

Referenced by qsv_decode().

◆ find_frame()

static QSVFrame* find_frame ( QSVContext q,
mfxFrameSurface1 *  surf 
)
static

Definition at line 433 of file qsvdec.c.

Referenced by qsv_decode().

◆ qsv_decode()

static int qsv_decode ( AVCodecContext avctx,
QSVContext q,
AVFrame frame,
int got_frame,
const AVPacket avpkt 
)
static

Definition at line 444 of file qsvdec.c.

Referenced by qsv_process_data().

◆ qsv_decode_close_qsvcontext()

static void qsv_decode_close_qsvcontext ( QSVContext q)
static

Definition at line 577 of file qsvdec.c.

Referenced by qsv_decode_close().

◆ qsv_process_data()

static int qsv_process_data ( AVCodecContext avctx,
QSVContext q,
AVFrame frame,
int got_frame,
const AVPacket pkt 
)
static

Definition at line 611 of file qsvdec.c.

Referenced by qsv_decode_frame().

◆ qsv_clear_buffers()

static void qsv_clear_buffers ( QSVDecContext s)
static

Definition at line 690 of file qsvdec.c.

Referenced by qsv_decode_close(), and qsv_decode_flush().

◆ qsv_decode_close()

static av_cold int qsv_decode_close ( AVCodecContext avctx)
static

Definition at line 701 of file qsvdec.c.

Referenced by qsv_decode_init().

◆ qsv_decode_init()

static av_cold int qsv_decode_init ( AVCodecContext avctx)
static

Definition at line 716 of file qsvdec.c.

◆ qsv_decode_frame()

static int qsv_decode_frame ( AVCodecContext avctx,
void *  data,
int got_frame,
AVPacket avpkt 
)
static

Definition at line 762 of file qsvdec.c.

◆ qsv_decode_flush()

static void qsv_decode_flush ( AVCodecContext avctx)
static

Definition at line 817 of file qsvdec.c.

Variable Documentation

◆ qsv_hw_configs

const AVCodecHWConfigInternal* const qsv_hw_configs[]
static
Initial value:
= {
.public = {
.pix_fmt = AV_PIX_FMT_QSV,
.device_type = AV_HWDEVICE_TYPE_QSV,
},
.hwaccel = NULL,
},
}

Definition at line 87 of file qsvdec.c.

◆ options

const AVOption options[]
static
Initial value:
= {
{ "async_depth", "Internal parallelization depth, the higher the value the higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VD },
{ "gpu_copy", "A GPU-accelerated copy between video and system memory", OFFSET(qsv.gpu_copy), AV_OPT_TYPE_INT, { .i64 = MFX_GPUCOPY_DEFAULT }, MFX_GPUCOPY_DEFAULT, MFX_GPUCOPY_OFF, VD, "gpu_copy"},
{ "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 0, 0, VD, "gpu_copy"},
{ "on", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON }, 0, 0, VD, "gpu_copy"},
{ "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 0, 0, VD, "gpu_copy"},
{ NULL },
}

Definition at line 881 of file qsvdec.c.

AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
X
@ X
Definition: vf_addroi.c:26
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
ASYNC_DEPTH_DEFAULT
#define ASYNC_DEPTH_DEFAULT
Definition: qsv_internal.h:51
QSVDecContext
Definition: qsvdec.c:679
AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
@ AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
The codec supports this format via the hw_frames_ctx interface.
Definition: codec.h:424
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
qsv_decode_init
static av_cold int qsv_decode_init(AVCodecContext *avctx)
Definition: qsvdec.c:716
qsv_decode_frame
static int qsv_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: qsvdec.c:762
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
flush
static void flush(AVCodecContext *avctx)
Definition: aacdec_template.c:592
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
AV_PIX_FMT_QSV
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:222
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AVCodecHWConfigInternal
Definition: hwconfig.h:29
qsv_decode_close
static av_cold int qsv_decode_close(AVCodecContext *avctx)
Definition: qsvdec.c:701
AV_CODEC_HW_CONFIG_METHOD_AD_HOC
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
Definition: codec.h:440
OFFSET
#define OFFSET(x)
Definition: qsvdec.c:827
AV_PIX_FMT_NV12
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:89
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
AV_HWDEVICE_TYPE_QSV
@ AV_HWDEVICE_TYPE_QSV
Definition: hwcontext.h:33
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:77
VD
#define VD
Definition: qsvdec.c:828
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_CODEC_CAP_HYBRID
#define AV_CODEC_CAP_HYBRID
Codec is potentially backed by a hardware implementation, but not necessarily.
Definition: codec.h:164
AV_CODEC_CAP_AVOID_PROBING
#define AV_CODEC_CAP_AVOID_PROBING
Decoder is not a preferred choice for probing.
Definition: codec.h:139
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
qsv_decode_flush
static void qsv_decode_flush(AVCodecContext *avctx)
Definition: qsvdec.c:817
qsv_hw_configs
static const AVCodecHWConfigInternal *const qsv_hw_configs[]
Definition: qsvdec.c:87