@ -125,15 +125,6 @@ void avcodec_set_dimensions(AVCodecContext *s, int width, int height){
s - > height = - ( ( - height ) > > s - > lowres ) ;
}
typedef struct InternalBuffer {
int last_pic_num ;
uint8_t * base [ 4 ] ;
uint8_t * data [ 4 ] ;
int linesize [ 4 ] ;
int width , height ;
enum PixelFormat pix_fmt ;
} InternalBuffer ;
# define INTERNAL_BUFFER_SIZE (32+1)
void avcodec_align_dimensions2 ( AVCodecContext * s , int * width , int * height , int linesize_align [ 4 ] ) {
@ -250,32 +241,27 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
int h = s - > height ;
InternalBuffer * buf ;
int * picture_number ;
AVCodecInternal * avci = s - > internal ;
if ( pic - > data [ 0 ] ! = NULL ) {
av_log ( s , AV_LOG_ERROR , " pic->data[0]!=NULL in avcodec_default_get_buffer \n " ) ;
return - 1 ;
}
if ( s - > internal_ buffer_count > = INTERNAL_BUFFER_SIZE ) {
av_log ( s , AV_LOG_ERROR , " internal_ buffer_count overflow (missing release_buffer?)\n " ) ;
if ( avci - > buffer_count > = INTERNAL_BUFFER_SIZE ) {
av_log ( s , AV_LOG_ERROR , " buffer_count overflow (missing release_buffer?) \n " ) ;
return - 1 ;
}
if ( av_image_check_size ( w , h , 0 , s ) )
return - 1 ;
if ( s - > internal_buffer = = NULL ) {
s - > internal_buffer = av_mallocz ( ( INTERNAL_BUFFER_SIZE + 1 ) * sizeof ( InternalBuffer ) ) ;
if ( ! avci - > buffer ) {
avci - > buffer = av_mallocz ( ( INTERNAL_BUFFER_SIZE + 1 ) *
sizeof ( InternalBuffer ) ) ;
}
#if 0
s - > internal_buffer = av_fast_realloc (
s - > internal_buffer ,
& s - > internal_buffer_size ,
sizeof ( InternalBuffer ) * FFMAX ( 99 , s - > internal_buffer_count + 1 ) /*FIXME*/
) ;
# endif
buf = & ( ( InternalBuffer * ) s - > internal_buffer ) [ s - > internal_ buffer_count] ;
picture_number = & ( ( ( InternalBuffer * ) s - > internal_ buffer) [ INTERNAL_BUFFER_SIZE ] ) . last_pic_num ; //FIXME ugly hack
buf = & avci - > buffer [ avci - > buffer_count ] ;
picture_number = & ( avci - > buffer [ INTERNAL_BUFFER_SIZE ] ) . last_pic_num ; //FIXME ugly hack
( * picture_number ) + + ;
if ( buf - > base [ 0 ] & & ( buf - > width ! = w | | buf - > height ! = h | | buf - > pix_fmt ! = s - > pix_fmt ) ) {
@ -366,14 +352,15 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
pic - > data [ i ] = buf - > data [ i ] ;
pic - > linesize [ i ] = buf - > linesize [ i ] ;
}
s - > internal_ buffer_count+ + ;
avci - > buffer_count + + ;
if ( s - > pkt ) pic - > pkt_pts = s - > pkt - > pts ;
else pic - > pkt_pts = AV_NOPTS_VALUE ;
pic - > reordered_opaque = s - > reordered_opaque ;
if ( s - > debug & FF_DEBUG_BUFFERS )
av_log ( s , AV_LOG_DEBUG , " default_get_buffer called on pic %p, %d buffers used \n " , pic , s - > internal_buffer_count ) ;
av_log ( s , AV_LOG_DEBUG , " default_get_buffer called on pic %p, %d "
" buffers used \n " , pic , avci - > buffer_count ) ;
return 0 ;
}
@ -381,22 +368,23 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
void avcodec_default_release_buffer ( AVCodecContext * s , AVFrame * pic ) {
int i ;
InternalBuffer * buf , * last ;
AVCodecInternal * avci = s - > internal ;
assert ( pic - > type = = FF_BUFFER_TYPE_INTERNAL ) ;
assert ( s - > internal_ buffer_count) ;
if ( s - > internal_ buffer) {
buf = NULL ; /* avoids warning */
for ( i = 0 ; i < s - > internal_ buffer_count; i + + ) { //just 3-5 checks so is not worth to optimize
buf = & ( ( InternalBuffer * ) s - > internal_ buffer) [ i ] ;
if ( buf - > data [ 0 ] = = pic - > data [ 0 ] )
break ;
}
assert ( i < s - > internal_ buffer_count) ;
s - > internal_ buffer_count- - ;
last = & ( ( InternalBuffer * ) s - > internal_buffer ) [ s - > internal_ buffer_count] ;
assert ( avci - > buffer_count ) ;
if ( avci - > buffer ) {
buf = NULL ; /* avoids warning */
for ( i = 0 ; i < avci - > buffer_count ; i + + ) { //just 3-5 checks so is not worth to optimize
buf = & avci - > buffer [ i ] ;
if ( buf - > data [ 0 ] = = pic - > data [ 0 ] )
break ;
}
assert ( i < avci - > buffer_count ) ;
avci - > buffer_count - - ;
last = & avci - > buffer [ avci - > buffer_count ] ;
FFSWAP ( InternalBuffer , * buf , * last ) ;
FFSWAP ( InternalBuffer , * buf , * last ) ;
}
for ( i = 0 ; i < 4 ; i + + ) {
@ -406,7 +394,8 @@ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
//printf("R%X\n", pic->opaque);
if ( s - > debug & FF_DEBUG_BUFFERS )
av_log ( s , AV_LOG_DEBUG , " default_release_buffer called on pic %p, %d buffers used \n " , pic , s - > internal_buffer_count ) ;
av_log ( s , AV_LOG_DEBUG , " default_release_buffer called on pic %p, %d "
" buffers used \n " , pic , avci - > buffer_count ) ;
}
int avcodec_default_reget_buffer ( AVCodecContext * s , AVFrame * pic ) {
@ -521,6 +510,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD
goto end ;
}
avctx - > internal = av_mallocz ( sizeof ( AVCodecInternal ) ) ;
if ( ! avctx - > internal ) {
ret = AVERROR ( ENOMEM ) ;
goto end ;
}
if ( codec - > priv_data_size > 0 ) {
if ( ! avctx - > priv_data ) {
avctx - > priv_data = av_mallocz ( codec - > priv_data_size ) ;
@ -670,6 +665,7 @@ end:
free_and_end :
av_dict_free ( & tmp ) ;
av_freep ( & avctx - > priv_data ) ;
av_freep ( & avctx - > internal ) ;
avctx - > codec = NULL ;
goto end ;
}
@ -844,6 +840,7 @@ av_cold int avcodec_close(AVCodecContext *avctx)
avctx - > codec - > close ( avctx ) ;
avcodec_default_free_buffers ( avctx ) ;
avctx - > coded_frame = NULL ;
av_freep ( & avctx - > internal ) ;
if ( avctx - > codec & & avctx - > codec - > priv_class )
av_opt_free ( avctx - > priv_data ) ;
av_opt_free ( avctx ) ;
@ -1109,22 +1106,25 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
}
void avcodec_default_free_buffers ( AVCodecContext * s ) {
AVCodecInternal * avci = s - > internal ;
int i , j ;
if ( s - > internal_buffer = = NULL ) return ;
if ( ! avci - > buffer )
return ;
if ( s - > internal_buffer_count )
av_log ( s , AV_LOG_WARNING , " Found %i unreleased buffers! \n " , s - > internal_buffer_count ) ;
if ( avci - > buffer_count )
av_log ( s , AV_LOG_WARNING , " Found %i unreleased buffers! \n " ,
avci - > buffer_count ) ;
for ( i = 0 ; i < INTERNAL_BUFFER_SIZE ; i + + ) {
InternalBuffer * buf = & ( ( InternalBuffer * ) s - > internal_ buffer) [ i ] ;
InternalBuffer * buf = & avci - > buffer [ i ] ;
for ( j = 0 ; j < 4 ; j + + ) {
av_freep ( & buf - > base [ j ] ) ;
buf - > data [ j ] = NULL ;
}
}
av_freep ( & s - > internal_ buffer) ;
av_freep ( & avci - > buffer ) ;
s - > internal_ buffer_count= 0 ;
avci - > buffer_count = 0 ;
}
# if FF_API_OLD_FF_PICT_TYPES