@ -153,41 +153,14 @@ static int vaapi_frames_get_constraints(AVHWDeviceContext *hwdev,
{
{
AVVAAPIDeviceContext * hwctx = hwdev - > hwctx ;
AVVAAPIDeviceContext * hwctx = hwdev - > hwctx ;
const AVVAAPIHWConfig * config = hwconfig ;
const AVVAAPIHWConfig * config = hwconfig ;
AVVAAPIHWConfig * tmp_config ;
VAAPIDeviceContext * ctx = hwdev - > internal - > priv ;
VASurfaceAttrib * attr_list = NULL ;
VASurfaceAttrib * attr_list = NULL ;
VAStatus vas ;
VAStatus vas ;
enum AVPixelFormat pix_fmt ;
enum AVPixelFormat pix_fmt ;
unsigned int fourcc ;
unsigned int fourcc ;
int err , i , j , attr_count , pix_fmt_count ;
int err , i , j , attr_count , pix_fmt_count ;
if ( ! hwconfig ) {
if ( config ) {
// No configuration was provided, so we create a temporary pipeline
// configuration in order to query all supported image formats.
tmp_config = av_mallocz ( sizeof ( * config ) ) ;
if ( ! tmp_config )
return AVERROR ( ENOMEM ) ;
vas = vaCreateConfig ( hwctx - > display ,
VAProfileNone , VAEntrypointVideoProc ,
NULL , 0 , & tmp_config - > config_id ) ;
if ( vas ! = VA_STATUS_SUCCESS ) {
// No vpp. We might still be able to do something useful if
// codecs are supported, so try to make the most-commonly
// supported decoder configuration we can to query instead.
vas = vaCreateConfig ( hwctx - > display ,
VAProfileH264ConstrainedBaseline ,
VAEntrypointVLD , NULL , 0 ,
& tmp_config - > config_id ) ;
if ( vas ! = VA_STATUS_SUCCESS ) {
av_freep ( & tmp_config ) ;
return AVERROR ( ENOSYS ) ;
}
}
config = tmp_config ;
}
attr_count = 0 ;
attr_count = 0 ;
vas = vaQuerySurfaceAttributes ( hwctx - > display , config - > config_id ,
vas = vaQuerySurfaceAttributes ( hwctx - > display , config - > config_id ,
0 , & attr_count ) ;
0 , & attr_count ) ;
@ -262,6 +235,19 @@ static int vaapi_frames_get_constraints(AVHWDeviceContext *hwdev,
av_assert0 ( j = = pix_fmt_count ) ;
av_assert0 ( j = = pix_fmt_count ) ;
constraints - > valid_sw_formats [ j ] = AV_PIX_FMT_NONE ;
constraints - > valid_sw_formats [ j ] = AV_PIX_FMT_NONE ;
}
}
} else {
// No configuration supplied.
// Return the full set of image formats known by the implementation.
constraints - > valid_sw_formats = av_malloc_array ( ctx - > nb_formats + 1 ,
sizeof ( pix_fmt ) ) ;
if ( ! constraints - > valid_sw_formats ) {
err = AVERROR ( ENOMEM ) ;
goto fail ;
}
for ( i = 0 ; i < ctx - > nb_formats ; i + + )
constraints - > valid_sw_formats [ i ] = ctx - > formats [ i ] . pix_fmt ;
constraints - > valid_sw_formats [ i ] = AV_PIX_FMT_NONE ;
}
constraints - > valid_hw_formats = av_malloc_array ( 2 , sizeof ( pix_fmt ) ) ;
constraints - > valid_hw_formats = av_malloc_array ( 2 , sizeof ( pix_fmt ) ) ;
if ( ! constraints - > valid_hw_formats ) {
if ( ! constraints - > valid_hw_formats ) {
@ -274,10 +260,6 @@ static int vaapi_frames_get_constraints(AVHWDeviceContext *hwdev,
err = 0 ;
err = 0 ;
fail :
fail :
av_freep ( & attr_list ) ;
av_freep ( & attr_list ) ;
if ( ! hwconfig ) {
vaDestroyConfig ( hwctx - > display , tmp_config - > config_id ) ;
av_freep ( & tmp_config ) ;
}
return err ;
return err ;
}
}
@ -285,21 +267,12 @@ static int vaapi_device_init(AVHWDeviceContext *hwdev)
{
{
VAAPIDeviceContext * ctx = hwdev - > internal - > priv ;
VAAPIDeviceContext * ctx = hwdev - > internal - > priv ;
AVVAAPIDeviceContext * hwctx = hwdev - > hwctx ;
AVVAAPIDeviceContext * hwctx = hwdev - > hwctx ;
AVHWFramesConstraints * constraints = NULL ;
VAImageFormat * image_list = NULL ;
VAImageFormat * image_list = NULL ;
VAStatus vas ;
VAStatus vas ;
int err , i , j , image_count ;
int err , i , image_count ;
enum AVPixelFormat pix_fmt ;
enum AVPixelFormat pix_fmt ;
unsigned int fourcc ;
unsigned int fourcc ;
constraints = av_mallocz ( sizeof ( * constraints ) ) ;
if ( ! constraints )
goto fail ;
err = vaapi_frames_get_constraints ( hwdev , NULL , constraints ) ;
if ( err < 0 )
goto fail ;
image_count = vaMaxNumImageFormats ( hwctx - > display ) ;
image_count = vaMaxNumImageFormats ( hwctx - > display ) ;
if ( image_count < = 0 ) {
if ( image_count < = 0 ) {
err = AVERROR ( EIO ) ;
err = AVERROR ( EIO ) ;
@ -325,28 +298,23 @@ static int vaapi_device_init(AVHWDeviceContext *hwdev)
for ( i = 0 ; i < image_count ; i + + ) {
for ( i = 0 ; i < image_count ; i + + ) {
fourcc = image_list [ i ] . fourcc ;
fourcc = image_list [ i ] . fourcc ;
pix_fmt = vaapi_pix_fmt_from_fourcc ( fourcc ) ;
pix_fmt = vaapi_pix_fmt_from_fourcc ( fourcc ) ;
for ( j = 0 ; constraints - > valid_sw_formats [ j ] ! = AV_PIX_FMT_NONE ; j + + ) {
if ( pix_fmt = = AV_PIX_FMT_NONE ) {
if ( pix_fmt = = constraints - > valid_sw_formats [ j ] )
av_log ( hwdev , AV_LOG_DEBUG , " Format %#x -> unknown. \n " ,
break ;
fourcc ) ;
}
} else {
if ( constraints - > valid_sw_formats [ j ] ! = AV_PIX_FMT_NONE ) {
av_log ( hwdev , AV_LOG_DEBUG , " Format %#x -> %s. \n " ,
av_log ( hwdev , AV_LOG_DEBUG , " Format %#x -> %s. \n " ,
fourcc , av_get_pix_fmt_name ( pix_fmt ) ) ;
fourcc , av_get_pix_fmt_name ( pix_fmt ) ) ;
ctx - > formats [ ctx - > nb_formats ] . pix_fmt = pix_fmt ;
ctx - > formats [ ctx - > nb_formats ] . pix_fmt = pix_fmt ;
ctx - > formats [ ctx - > nb_formats ] . image_format = image_list [ i ] ;
ctx - > formats [ ctx - > nb_formats ] . image_format = image_list [ i ] ;
+ + ctx - > nb_formats ;
+ + ctx - > nb_formats ;
} else {
av_log ( hwdev , AV_LOG_DEBUG , " Format %#x -> unknown. \n " , fourcc ) ;
}
}
}
}
av_free ( image_list ) ;
av_free ( image_list ) ;
av_hwframe_constraints_free ( & constraints ) ;
return 0 ;
return 0 ;
fail :
fail :
av_freep ( & ctx - > formats ) ;
av_freep ( & ctx - > formats ) ;
av_free ( image_list ) ;
av_free ( image_list ) ;
av_hwframe_constraints_free ( & constraints ) ;
return err ;
return err ;
}
}