@ -1,5 +1,5 @@
/*
/*
* Intel MediaSDK QSV based H .264 decoder
* Intel MediaSDK QSV based H .264 / HEVC decoder
*
*
* copyright ( c ) 2013 Luca Barbato
* copyright ( c ) 2013 Luca Barbato
* copyright ( c ) 2015 Anton Khirnov
* copyright ( c ) 2015 Anton Khirnov
@ -37,10 +37,17 @@
# include "qsvdec.h"
# include "qsvdec.h"
# include "qsv.h"
# include "qsv.h"
typedef struct QSVH264Context {
enum LoadPlugin {
LOAD_PLUGIN_NONE ,
LOAD_PLUGIN_HEVC_SW ,
} ;
typedef struct QSVH2645Context {
AVClass * class ;
AVClass * class ;
QSVContext qsv ;
QSVContext qsv ;
int load_plugin ;
// the filter for converting to Annex B
// the filter for converting to Annex B
AVBitStreamFilterContext * bsf ;
AVBitStreamFilterContext * bsf ;
@ -49,9 +56,9 @@ typedef struct QSVH264Context {
AVPacket input_ref ;
AVPacket input_ref ;
AVPacket pkt_filtered ;
AVPacket pkt_filtered ;
uint8_t * filtered_data ;
uint8_t * filtered_data ;
} QSVH264Context ;
} QSVH2645 Context ;
static void qsv_clear_buffers ( QSVH264Context * s )
static void qsv_clear_buffers ( QSVH2645 Context * s )
{
{
AVPacket pkt ;
AVPacket pkt ;
while ( av_fifo_size ( s - > packet_fifo ) > = sizeof ( pkt ) ) {
while ( av_fifo_size ( s - > packet_fifo ) > = sizeof ( pkt ) ) {
@ -67,7 +74,7 @@ static void qsv_clear_buffers(QSVH264Context *s)
static av_cold int qsv_decode_close ( AVCodecContext * avctx )
static av_cold int qsv_decode_close ( AVCodecContext * avctx )
{
{
QSVH264Context * s = avctx - > priv_data ;
QSVH2645 Context * s = avctx - > priv_data ;
ff_qsv_decode_close ( & s - > qsv ) ;
ff_qsv_decode_close ( & s - > qsv ) ;
@ -82,9 +89,23 @@ static av_cold int qsv_decode_close(AVCodecContext *avctx)
static av_cold int qsv_decode_init ( AVCodecContext * avctx )
static av_cold int qsv_decode_init ( AVCodecContext * avctx )
{
{
QSVH264Context * s = avctx - > priv_data ;
QSVH2645 Context * s = avctx - > priv_data ;
int ret ;
int ret ;
if ( avctx - > codec_id = = AV_CODEC_ID_HEVC & & s - > load_plugin ! = LOAD_PLUGIN_NONE ) {
static const char * uid_hevcenc_sw = " 15dd936825ad475ea34e35f3f54217a6 " ;
if ( s - > qsv . load_plugins [ 0 ] ) {
av_log ( avctx , AV_LOG_WARNING ,
" load_plugins is not empty, but load_plugin is not set to 'none'. "
" The load_plugin value will be ignored. \n " ) ;
} else {
av_freep ( & s - > qsv . load_plugins ) ;
s - > qsv . load_plugins = av_strdup ( uid_hevcenc_sw ) ;
if ( ! s - > qsv . load_plugins )
return AVERROR ( ENOMEM ) ;
}
}
s - > packet_fifo = av_fifo_alloc ( sizeof ( AVPacket ) ) ;
s - > packet_fifo = av_fifo_alloc ( sizeof ( AVPacket ) ) ;
if ( ! s - > packet_fifo ) {
if ( ! s - > packet_fifo ) {
@ -92,7 +113,10 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx)
goto fail ;
goto fail ;
}
}
s - > bsf = av_bitstream_filter_init ( " h264_mp4toannexb " ) ;
if ( avctx - > codec_id = = AV_CODEC_ID_H264 )
s - > bsf = av_bitstream_filter_init ( " h264_mp4toannexb " ) ;
else
s - > bsf = av_bitstream_filter_init ( " hevc_mp4toannexb " ) ;
if ( ! s - > bsf ) {
if ( ! s - > bsf ) {
ret = AVERROR ( ENOMEM ) ;
ret = AVERROR ( ENOMEM ) ;
goto fail ;
goto fail ;
@ -109,7 +133,7 @@ fail:
static int qsv_decode_frame ( AVCodecContext * avctx , void * data ,
static int qsv_decode_frame ( AVCodecContext * avctx , void * data ,
int * got_frame , AVPacket * avpkt )
int * got_frame , AVPacket * avpkt )
{
{
QSVH264Context * s = avctx - > priv_data ;
QSVH2645 Context * s = avctx - > priv_data ;
AVFrame * frame = data ;
AVFrame * frame = data ;
int ret ;
int ret ;
@ -171,12 +195,58 @@ static int qsv_decode_frame(AVCodecContext *avctx, void *data,
static void qsv_decode_flush ( AVCodecContext * avctx )
static void qsv_decode_flush ( AVCodecContext * avctx )
{
{
QSVH264Context * s = avctx - > priv_data ;
QSVH2645 Context * s = avctx - > priv_data ;
qsv_clear_buffers ( s ) ;
qsv_clear_buffers ( s ) ;
ff_qsv_decode_flush ( avctx , & s - > qsv ) ;
ff_qsv_decode_flush ( avctx , & s - > qsv ) ;
}
}
# define OFFSET(x) offsetof(QSVH2645Context, x)
# define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
# if CONFIG_HEVC_QSV_DECODER
AVHWAccel ff_hevc_qsv_hwaccel = {
. name = " hevc_qsv " ,
. type = AVMEDIA_TYPE_VIDEO ,
. id = AV_CODEC_ID_HEVC ,
. pix_fmt = AV_PIX_FMT_QSV ,
} ;
static const AVOption hevc_options [ ] = {
{ " 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 } , 0 , INT_MAX , VD } ,
{ " load_plugin " , " A user plugin to load in an internal session " , OFFSET ( load_plugin ) , AV_OPT_TYPE_INT , { . i64 = LOAD_PLUGIN_HEVC_SW } , LOAD_PLUGIN_NONE , LOAD_PLUGIN_HEVC_SW , VD , " load_plugin " } ,
{ " none " , NULL , 0 , AV_OPT_TYPE_CONST , { . i64 = LOAD_PLUGIN_NONE } , 0 , 0 , VD , " load_plugin " } ,
{ " hevc_sw " , NULL , 0 , AV_OPT_TYPE_CONST , { . i64 = LOAD_PLUGIN_HEVC_SW } , 0 , 0 , VD , " load_plugin " } ,
{ " load_plugins " , " A :-separate list of hexadecimal plugin UIDs to load in an internal session " ,
OFFSET ( qsv . load_plugins ) , AV_OPT_TYPE_STRING , { . str = " " } , 0 , 0 , VD } ,
{ NULL } ,
} ;
static const AVClass hevc_class = {
. class_name = " hevc_qsv " ,
. item_name = av_default_item_name ,
. option = hevc_options ,
. version = LIBAVUTIL_VERSION_INT ,
} ;
AVCodec ff_hevc_qsv_decoder = {
. name = " hevc_qsv " ,
. long_name = NULL_IF_CONFIG_SMALL ( " HEVC (Intel Quick Sync Video acceleration) " ) ,
. priv_data_size = sizeof ( QSVH2645Context ) ,
. type = AVMEDIA_TYPE_VIDEO ,
. id = AV_CODEC_ID_HEVC ,
. init = qsv_decode_init ,
. decode = qsv_decode_frame ,
. flush = qsv_decode_flush ,
. close = qsv_decode_close ,
. capabilities = CODEC_CAP_DELAY ,
. priv_class = & hevc_class ,
} ;
# endif
# if CONFIG_H264_QSV_DECODER
AVHWAccel ff_h264_qsv_hwaccel = {
AVHWAccel ff_h264_qsv_hwaccel = {
. name = " h264_qsv " ,
. name = " h264_qsv " ,
. type = AVMEDIA_TYPE_VIDEO ,
. type = AVMEDIA_TYPE_VIDEO ,
@ -184,8 +254,6 @@ AVHWAccel ff_h264_qsv_hwaccel = {
. pix_fmt = AV_PIX_FMT_QSV ,
. pix_fmt = AV_PIX_FMT_QSV ,
} ;
} ;
# define OFFSET(x) offsetof(QSVH264Context, x)
# define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
static const AVOption options [ ] = {
static const AVOption options [ ] = {
{ " 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 } , 0 , INT_MAX , VD } ,
{ " 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 } , 0 , INT_MAX , VD } ,
{ NULL } ,
{ NULL } ,
@ -201,7 +269,7 @@ static const AVClass class = {
AVCodec ff_h264_qsv_decoder = {
AVCodec ff_h264_qsv_decoder = {
. name = " h264_qsv " ,
. name = " h264_qsv " ,
. long_name = NULL_IF_CONFIG_SMALL ( " H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (Intel Quick Sync Video acceleration) " ) ,
. long_name = NULL_IF_CONFIG_SMALL ( " H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (Intel Quick Sync Video acceleration) " ) ,
. priv_data_size = sizeof ( QSVH264Context ) ,
. priv_data_size = sizeof ( QSVH2645 Context ) ,
. type = AVMEDIA_TYPE_VIDEO ,
. type = AVMEDIA_TYPE_VIDEO ,
. id = AV_CODEC_ID_H264 ,
. id = AV_CODEC_ID_H264 ,
. init = qsv_decode_init ,
. init = qsv_decode_init ,
@ -211,3 +279,4 @@ AVCodec ff_h264_qsv_decoder = {
. capabilities = CODEC_CAP_DELAY ,
. capabilities = CODEC_CAP_DELAY ,
. priv_class = & class ,
. priv_class = & class ,
} ;
} ;
# endif