@ -38,8 +38,8 @@
# include "itut35.h"
# include "itut35.h"
# include "hwconfig.h"
# include "hwconfig.h"
# include "profiles.h"
# include "profiles.h"
# include "progressframe.h"
# include "refstruct.h"
# include "refstruct.h"
# include "thread.h"
/**< same with Div_Lut defined in spec 7.11.3.7 */
/**< same with Div_Lut defined in spec 7.11.3.7 */
static const uint16_t div_lut [ AV1_DIV_LUT_NUM ] = {
static const uint16_t div_lut [ AV1_DIV_LUT_NUM ] = {
@ -672,7 +672,7 @@ static int get_pixel_format(AVCodecContext *avctx)
static void av1_frame_unref ( AV1Frame * f )
static void av1_frame_unref ( AV1Frame * f )
{
{
av_frame_unref ( f - > f ) ;
ff_progress_frame_unref ( & f - > p f) ;
ff_refstruct_unref ( & f - > hwaccel_picture_private ) ;
ff_refstruct_unref ( & f - > hwaccel_picture_private ) ;
ff_refstruct_unref ( & f - > header_ref ) ;
ff_refstruct_unref ( & f - > header_ref ) ;
f - > raw_frame_header = NULL ;
f - > raw_frame_header = NULL ;
@ -683,20 +683,16 @@ static void av1_frame_unref(AV1Frame *f)
f - > coded_lossless = 0 ;
f - > coded_lossless = 0 ;
}
}
static int av1_frame_ref ( AVCodecContext * avctx , AV1Frame * dst , const AV1Frame * src )
static void av1_frame_ref ( AVCodecContext * avctx , AV1Frame * dst , const AV1Frame * src )
{
{
int ret ;
ff_refstruct_replace ( & dst - > header_ref , src - > header_ref ) ;
ff_refstruct_replace ( & dst - > header_ref , src - > header_ref ) ;
dst - > raw_frame_header = src - > raw_frame_header ;
dst - > raw_frame_header = src - > raw_frame_header ;
if ( ! src - > f - > buf [ 0 ] )
if ( ! src - > f )
return 0 ;
return ;
ret = av_frame_ref ( dst - > f , src - > f ) ;
ff_progress_frame_ref ( & dst - > pf , & src - > pf ) ;
if ( ret < 0 )
goto fail ;
ff_refstruct_replace ( & dst - > hwaccel_picture_private ,
ff_refstruct_replace ( & dst - > hwaccel_picture_private ,
src - > hwaccel_picture_private ) ;
src - > hwaccel_picture_private ) ;
@ -725,12 +721,6 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *s
sizeof ( dst - > ref_frame_sign_bias ) ) ;
sizeof ( dst - > ref_frame_sign_bias ) ) ;
memcpy ( dst - > order_hints , src - > order_hints ,
memcpy ( dst - > order_hints , src - > order_hints ,
sizeof ( dst - > order_hints ) ) ;
sizeof ( dst - > order_hints ) ) ;
return 0 ;
fail :
av1_frame_unref ( dst ) ;
return AVERROR ( ENOMEM ) ;
}
}
static av_cold int av1_decode_free ( AVCodecContext * avctx )
static av_cold int av1_decode_free ( AVCodecContext * avctx )
@ -738,16 +728,9 @@ static av_cold int av1_decode_free(AVCodecContext *avctx)
AV1DecContext * s = avctx - > priv_data ;
AV1DecContext * s = avctx - > priv_data ;
AV1RawMetadataITUTT35 itut_t35 ;
AV1RawMetadataITUTT35 itut_t35 ;
for ( int i = 0 ; i < FF_ARRAY_ELEMS ( s - > ref ) ; i + + ) {
for ( int i = 0 ; i < FF_ARRAY_ELEMS ( s - > ref ) ; i + + )
if ( s - > ref [ i ] . f ) {
av1_frame_unref ( & s - > ref [ i ] ) ;
av1_frame_unref ( & s - > ref [ i ] ) ;
av1_frame_unref ( & s - > cur_frame ) ;
av_frame_free ( & s - > ref [ i ] . f ) ;
}
}
if ( s - > cur_frame . f ) {
av1_frame_unref ( & s - > cur_frame ) ;
av_frame_free ( & s - > cur_frame . f ) ;
}
av_buffer_unref ( & s - > seq_data_ref ) ;
av_buffer_unref ( & s - > seq_data_ref ) ;
ff_refstruct_unref ( & s - > seq_ref ) ;
ff_refstruct_unref ( & s - > seq_ref ) ;
ff_refstruct_unref ( & s - > header_ref ) ;
ff_refstruct_unref ( & s - > header_ref ) ;
@ -863,16 +846,6 @@ static av_cold int av1_decode_init(AVCodecContext *avctx)
s - > pkt = avctx - > internal - > in_pkt ;
s - > pkt = avctx - > internal - > in_pkt ;
s - > pix_fmt = AV_PIX_FMT_NONE ;
s - > pix_fmt = AV_PIX_FMT_NONE ;
for ( int i = 0 ; i < FF_ARRAY_ELEMS ( s - > ref ) ; i + + ) {
s - > ref [ i ] . f = av_frame_alloc ( ) ;
if ( ! s - > ref [ i ] . f )
return AVERROR ( ENOMEM ) ;
}
s - > cur_frame . f = av_frame_alloc ( ) ;
if ( ! s - > cur_frame . f )
return AVERROR ( ENOMEM ) ;
ret = ff_cbs_init ( & s - > cbc , AV_CODEC_ID_AV1 , avctx ) ;
ret = ff_cbs_init ( & s - > cbc , AV_CODEC_ID_AV1 , avctx ) ;
if ( ret < 0 )
if ( ret < 0 )
return ret ;
return ret ;
@ -934,7 +907,8 @@ static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f)
return ret ;
return ret ;
}
}
if ( ( ret = ff_thread_get_buffer ( avctx , f - > f , AV_GET_BUFFER_FLAG_REF ) ) < 0 )
ret = ff_progress_frame_get_buffer ( avctx , & f - > pf , AV_GET_BUFFER_FLAG_REF ) ;
if ( ret < 0 )
goto fail ;
goto fail ;
frame = f - > f ;
frame = f - > f ;
@ -1211,23 +1185,17 @@ FF_ENABLE_DEPRECATION_WARNINGS
return 0 ;
return 0 ;
}
}
static int update_reference_list ( AVCodecContext * avctx )
static void update_reference_list ( AVCodecContext * avctx )
{
{
AV1DecContext * s = avctx - > priv_data ;
AV1DecContext * s = avctx - > priv_data ;
const AV1RawFrameHeader * header = s - > raw_frame_header ;
const AV1RawFrameHeader * header = s - > raw_frame_header ;
int ret ;
for ( int i = 0 ; i < AV1_NUM_REF_FRAMES ; i + + ) {
for ( int i = 0 ; i < AV1_NUM_REF_FRAMES ; i + + ) {
if ( header - > refresh_frame_flags & ( 1 < < i ) ) {
if ( header - > refresh_frame_flags & ( 1 < < i ) ) {
av1_frame_unref ( & s - > ref [ i ] ) ;
av1_frame_unref ( & s - > ref [ i ] ) ;
if ( ( ret = av1_frame_ref ( avctx , & s - > ref [ i ] , & s - > cur_frame ) ) < 0 ) {
av1_frame_ref ( avctx , & s - > ref [ i ] , & s - > cur_frame ) ;
av_log ( avctx , AV_LOG_ERROR ,
" Failed to update frame %d in reference list \n " , i ) ;
return ret ;
}
}
}
}
}
return 0 ;
}
}
static int get_current_frame ( AVCodecContext * avctx )
static int get_current_frame ( AVCodecContext * avctx )
@ -1358,20 +1326,12 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
if ( s - > raw_frame_header - > show_existing_frame ) {
if ( s - > raw_frame_header - > show_existing_frame ) {
av1_frame_unref ( & s - > cur_frame ) ;
av1_frame_unref ( & s - > cur_frame ) ;
ret = av1_frame_ref ( avctx , & s - > cur_frame ,
av1_frame_ref ( avctx , & s - > cur_frame ,
& s - > ref [ s - > raw_frame_header - > frame_to_show_map_idx ] ) ;
& s - > ref [ s - > raw_frame_header - > frame_to_show_map_idx ] ) ;
if ( ret < 0 ) {
av_log ( avctx , AV_LOG_ERROR , " Failed to get reference frame. \n " ) ;
goto end ;
}
ret = update_reference_list ( avctx ) ;
update_reference_list ( avctx ) ;
if ( ret < 0 ) {
av_log ( avctx , AV_LOG_ERROR , " Failed to update reference list. \n " ) ;
goto end ;
}
if ( s - > cur_frame . f - > buf [ 0 ] ) {
if ( s - > cur_frame . f ) {
ret = set_output_frame ( avctx , frame ) ;
ret = set_output_frame ( avctx , frame ) ;
if ( ret < 0 )
if ( ret < 0 )
av_log ( avctx , AV_LOG_ERROR , " Set output frame error. \n " ) ;
av_log ( avctx , AV_LOG_ERROR , " Set output frame error. \n " ) ;
@ -1392,7 +1352,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
s - > cur_frame . spatial_id = header - > spatial_id ;
s - > cur_frame . spatial_id = header - > spatial_id ;
s - > cur_frame . temporal_id = header - > temporal_id ;
s - > cur_frame . temporal_id = header - > temporal_id ;
if ( avctx - > hwaccel & & s - > cur_frame . f - > buf [ 0 ] ) {
if ( avctx - > hwaccel & & s - > cur_frame . f ) {
ret = FF_HW_CALL ( avctx , start_frame , unit - > data , unit - > data_size ) ;
ret = FF_HW_CALL ( avctx , start_frame , unit - > data , unit - > data_size ) ;
if ( ret < 0 ) {
if ( ret < 0 ) {
av_log ( avctx , AV_LOG_ERROR , " HW accel start frame fail. \n " ) ;
av_log ( avctx , AV_LOG_ERROR , " HW accel start frame fail. \n " ) ;
@ -1418,7 +1378,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
if ( ret < 0 )
if ( ret < 0 )
goto end ;
goto end ;
if ( avctx - > hwaccel & & s - > cur_frame . f - > buf [ 0 ] ) {
if ( avctx - > hwaccel & & s - > cur_frame . f ) {
ret = FF_HW_CALL ( avctx , decode_slice , raw_tile_group - > tile_data . data ,
ret = FF_HW_CALL ( avctx , decode_slice , raw_tile_group - > tile_data . data ,
raw_tile_group - > tile_data . data_size ) ;
raw_tile_group - > tile_data . data_size ) ;
if ( ret < 0 ) {
if ( ret < 0 ) {
@ -1469,7 +1429,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
if ( raw_tile_group & & ( s - > tile_num = = raw_tile_group - > tg_end + 1 ) ) {
if ( raw_tile_group & & ( s - > tile_num = = raw_tile_group - > tg_end + 1 ) ) {
int show_frame = s - > raw_frame_header - > show_frame ;
int show_frame = s - > raw_frame_header - > show_frame ;
if ( avctx - > hwaccel & & s - > cur_frame . f - > buf [ 0 ] ) {
if ( avctx - > hwaccel & & s - > cur_frame . f ) {
ret = FF_HW_SIMPLE_CALL ( avctx , end_frame ) ;
ret = FF_HW_SIMPLE_CALL ( avctx , end_frame ) ;
if ( ret < 0 ) {
if ( ret < 0 ) {
av_log ( avctx , AV_LOG_ERROR , " HW accel end frame fail. \n " ) ;
av_log ( avctx , AV_LOG_ERROR , " HW accel end frame fail. \n " ) ;
@ -1477,13 +1437,9 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
}
}
}
}
ret = update_reference_list ( avctx ) ;
update_reference_list ( avctx ) ;
if ( ret < 0 ) {
av_log ( avctx , AV_LOG_ERROR , " Failed to update reference list. \n " ) ;
goto end ;
}
if ( s - > raw_frame_header - > show_frame & & s - > cur_frame . f - > buf [ 0 ] ) {
if ( s - > raw_frame_header - > show_frame & & s - > cur_frame . f ) {
ret = set_output_frame ( avctx , frame ) ;
ret = set_output_frame ( avctx , frame ) ;
if ( ret < 0 ) {
if ( ret < 0 ) {
av_log ( avctx , AV_LOG_ERROR , " Set output frame error \n " ) ;
av_log ( avctx , AV_LOG_ERROR , " Set output frame error \n " ) ;
@ -1597,7 +1553,9 @@ const FFCodec ff_av1_decoder = {
. close = av1_decode_free ,
. close = av1_decode_free ,
FF_CODEC_RECEIVE_FRAME_CB ( av1_receive_frame ) ,
FF_CODEC_RECEIVE_FRAME_CB ( av1_receive_frame ) ,
. p . capabilities = AV_CODEC_CAP_DR1 ,
. p . capabilities = AV_CODEC_CAP_DR1 ,
. caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM ,
. caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
FF_CODEC_CAP_USES_PROGRESSFRAMES ,
. flush = av1_decode_flush ,
. flush = av1_decode_flush ,
. p . profiles = NULL_IF_CONFIG_SMALL ( ff_av1_profiles ) ,
. p . profiles = NULL_IF_CONFIG_SMALL ( ff_av1_profiles ) ,
. p . priv_class = & av1_class ,
. p . priv_class = & av1_class ,