@ -62,7 +62,10 @@ void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
min_size = FFMAX ( 17 * min_size / 16 + 32 , min_size ) ;
ptr = av_realloc ( ptr , min_size ) ;
if ( ! ptr ) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now
/* we could set this to the unmodified min_size but this is safer
* if the user lost the ptr and uses NULL now
*/
if ( ! ptr )
min_size = 0 ;
* size = min_size ;
@ -78,7 +81,8 @@ static inline int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size,
min_size = FFMAX ( 17 * min_size / 16 + 32 , min_size ) ;
av_free ( * p ) ;
* p = zero_realloc ? av_mallocz ( min_size ) : av_malloc ( min_size ) ;
if ( ! * p ) min_size = 0 ;
if ( ! * p )
min_size = 0 ;
* size = min_size ;
return 1 ;
}
@ -117,8 +121,10 @@ static AVCodec *first_avcodec = NULL;
AVCodec * av_codec_next ( const AVCodec * c )
{
if ( c ) return c - > next ;
else return first_avcodec ;
if ( c )
return c - > next ;
else
return first_avcodec ;
}
static void avcodec_init ( void )
@ -147,7 +153,8 @@ void avcodec_register(AVCodec *codec)
AVCodec * * p ;
avcodec_init ( ) ;
p = & first_avcodec ;
while ( * p ! = NULL ) p = & ( * p ) - > next ;
while ( * p ! = NULL )
p = & ( * p ) - > next ;
* p = codec ;
codec - > next = NULL ;
@ -160,7 +167,8 @@ unsigned avcodec_get_edge_width(void)
return EDGE_WIDTH ;
}
void avcodec_set_dimensions ( AVCodecContext * s , int width , int height ) {
void avcodec_set_dimensions ( AVCodecContext * s , int width , int height )
{
s - > coded_width = width ;
s - > coded_height = height ;
s - > width = - ( ( - width ) > > s - > lowres ) ;
@ -253,7 +261,8 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
}
break ;
case PIX_FMT_BGR24 :
if ( ( s - > codec_id = = AV_CODEC_ID_MSZH ) | | ( s - > codec_id = = AV_CODEC_ID_ZLIB ) ) {
if ( ( s - > codec_id = = AV_CODEC_ID_MSZH ) | |
( s - > codec_id = = AV_CODEC_ID_ZLIB ) ) {
w_align = 4 ;
h_align = 4 ;
}
@ -271,17 +280,20 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
* width = FFALIGN ( * width , w_align ) ;
* height = FFALIGN ( * height , h_align ) ;
if ( s - > codec_id = = AV_CODEC_ID_H264 | | s - > lowres )
* height + = 2 ; // some of the optimized chroma MC reads one line too much
// some of the optimized chroma MC reads one line too much
// which is also done in mpeg decoders with lowres > 0
* height + = 2 ;
for ( i = 0 ; i < 4 ; i + + )
linesize_align [ i ] = STRIDE_ALIGN ;
}
void avcodec_align_dimensions ( AVCodecContext * s , int * width , int * height ) {
void avcodec_align_dimensions ( AVCodecContext * s , int * width , int * height )
{
int chroma_shift = av_pix_fmt_descriptors [ s - > pix_fmt ] . log2_chroma_w ;
int linesize_align [ AV_NUM_DATA_POINTERS ] ;
int align ;
avcodec_align_dimensions2 ( s , width , height , linesize_align ) ;
align = FFMAX ( linesize_align [ 0 ] , linesize_align [ 3 ] ) ;
linesize_align [ 1 ] < < = chroma_shift ;
@ -376,7 +388,7 @@ static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
buf = avci - > buffer ;
/* if there is a previously-used internal buffer, check its size and
channel count to see if we can reuse it */
* channel count to see if we can reuse it */
if ( buf - > extended_data ) {
/* if current buffer is too small, free it */
if ( buf - > extended_data [ 0 ] & & buf_size > buf - > audio_data_size ) {
@ -387,7 +399,7 @@ static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
buf - > data [ 0 ] = NULL ;
}
/* if number of channels has changed, reset and/or free extended data
pointers but leave data buffer in buf - > data [ 0 ] for reuse */
* pointers but leave data buffer in buf - > data [ 0 ] for reuse */
if ( buf - > nb_channels ! = avctx - > channels ) {
if ( buf - > extended_data ! = buf - > data )
av_free ( buf - > extended_data ) ;
@ -396,7 +408,7 @@ static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
}
/* if there is no previous buffer or the previous buffer cannot be used
as - is , allocate a new buffer and / or rearrange the channel pointers */
* as - is , allocate a new buffer and / or rearrange the channel pointers */
if ( ! buf - > extended_data ) {
if ( ! buf - > data [ 0 ] ) {
if ( ! ( buf - > data [ 0 ] = av_mallocz ( buf_size ) ) )
@ -494,9 +506,8 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
w + = w & ~ ( w - 1 ) ;
unaligned = 0 ;
for ( i = 0 ; i < 4 ; i + + ) {
for ( i = 0 ; i < 4 ; i + + )
unaligned | = picture . linesize [ i ] % stride_align [ i ] ;
}
} while ( unaligned ) ;
tmpsize = av_image_fill_pointers ( picture . data , s - > pix_fmt , h , NULL , picture . linesize ) ;
@ -571,7 +582,8 @@ int avcodec_default_get_buffer(AVCodecContext *avctx, AVFrame *frame)
}
}
void avcodec_default_release_buffer ( AVCodecContext * s , AVFrame * pic ) {
void avcodec_default_release_buffer ( AVCodecContext * s , AVFrame * pic )
{
int i ;
InternalBuffer * buf , * last ;
AVCodecInternal * avci = s - > internal ;
@ -596,10 +608,9 @@ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
FFSWAP ( InternalBuffer , * buf , * last ) ;
}
for ( i = 0 ; i < AV_NUM_DATA_POINTERS ; i + + ) {
for ( i = 0 ; i < AV_NUM_DATA_POINTERS ; i + + )
pic - > data [ i ] = NULL ;
// pic->base[i]=NULL;
}
//printf("R%X\n", pic->opaque);
if ( s - > debug & FF_DEBUG_BUFFERS )
@ -607,7 +618,8 @@ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
" buffers used \n " , pic , avci - > buffer_count ) ;
}
int avcodec_default_reget_buffer ( AVCodecContext * s , AVFrame * pic ) {
int avcodec_default_reget_buffer ( AVCodecContext * s , AVFrame * pic )
{
AVFrame temp_pic ;
int i ;
@ -652,36 +664,45 @@ int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
return 0 ;
}
int avcodec_default_execute ( AVCodecContext * c , int ( * func ) ( AVCodecContext * c2 , void * arg2 ) , void * arg , int * ret , int count , int size ) {
int avcodec_default_execute ( AVCodecContext * c , int ( * func ) ( AVCodecContext * c2 , void * arg2 ) , void * arg , int * ret , int count , int size )
{
int i ;
for ( i = 0 ; i < count ; i + + ) {
int r = func ( c , ( char * ) arg + i * size ) ;
if ( ret ) ret [ i ] = r ;
if ( ret )
ret [ i ] = r ;
}
return 0 ;
}
int avcodec_default_execute2 ( AVCodecContext * c , int ( * func ) ( AVCodecContext * c2 , void * arg2 , int jobnr , int threadnr ) , void * arg , int * ret , int count ) {
int avcodec_default_execute2 ( AVCodecContext * c , int ( * func ) ( AVCodecContext * c2 , void * arg2 , int jobnr , int threadnr ) , void * arg , int * ret , int count )
{
int i ;
for ( i = 0 ; i < count ; i + + ) {
int r = func ( c , arg , i , 0 ) ;
if ( ret ) ret [ i ] = r ;
if ( ret )
ret [ i ] = r ;
}
return 0 ;
}
enum PixelFormat avcodec_default_get_format ( struct AVCodecContext * s , const enum PixelFormat * fmt ) {
enum PixelFormat avcodec_default_get_format ( struct AVCodecContext * s , const enum PixelFormat * fmt )
{
while ( * fmt ! = PIX_FMT_NONE & & ff_is_hwaccel_pix_fmt ( * fmt ) )
+ + fmt ;
return fmt [ 0 ] ;
}
void avcodec_get_frame_defaults ( AVFrame * pic ) {
void avcodec_get_frame_defaults ( AVFrame * pic )
{
memset ( pic , 0 , sizeof ( AVFrame ) ) ;
pic - > pts = pic - > pkt_dts = pic - > pkt_pts = pic - > best_effort_timestamp = AV_NOPTS_VALUE ;
pic - > pts =
pic - > pkt_dts =
pic - > pkt_pts =
pic - > best_effort_timestamp = AV_NOPTS_VALUE ;
pic - > pkt_duration = 0 ;
pic - > pkt_pos = - 1 ;
pic - > key_frame = 1 ;
@ -689,10 +710,12 @@ void avcodec_get_frame_defaults(AVFrame *pic){
pic - > format = - 1 ; /* unknown */
}
AVFrame * avcodec_alloc_frame ( void ) {
AVFrame * avcodec_alloc_frame ( void )
{
AVFrame * pic = av_malloc ( sizeof ( AVFrame ) ) ;
if ( pic = = NULL ) return NULL ;
if ( pic = = NULL )
return NULL ;
avcodec_get_frame_defaults ( pic ) ;
@ -825,6 +848,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
//We only call avcodec_set_dimensions() for non h264 codecs so as not to overwrite previously setup dimensions
if ( ! ( avctx - > coded_width & & avctx - > coded_height & & avctx - > width & & avctx - > height & & avctx - > codec_id = = AV_CODEC_ID_H264 ) ) {
if ( avctx - > coded_width & & avctx - > coded_height )
avcodec_set_dimensions ( avctx , avctx - > coded_width , avctx - > coded_height ) ;
else if ( avctx - > width & & avctx - > height )
@ -839,7 +863,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
}
/* if the decoder init function was already called previously,
free the already allocated subtitle_header before overwriting it */
* free the already allocated subtitle_header before overwriting it */
if ( av_codec_is_decoder ( codec ) )
av_freep ( & avctx - > subtitle_header ) ;
@ -962,7 +986,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
avctx - > pts_correction_last_pts =
avctx - > pts_correction_last_dts = INT64_MIN ;
if ( avctx - > codec - > init & & ( ! ( avctx - > active_thread_type & FF_THREAD_FRAME ) | | avctx - > internal - > frame_thread_encoder ) ) {
if ( avctx - > codec - > init & & ( ! ( avctx - > active_thread_type & FF_THREAD_FRAME )
| | avctx - > internal - > frame_thread_encoder ) ) {
ret = avctx - > codec - > init ( avctx ) ;
if ( ret < 0 ) {
goto free_and_end ;
@ -1201,8 +1226,8 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
}
/* NOTE: if we add any audio encoders which output non-keyframe packets,
this needs to be moved to the encoders , but for now we can do it
here to simplify things */
* this needs to be moved to the encoders , but for now we can do it
* here to simplify things */
avpkt - > flags | = AV_PKT_FLAG_KEY ;
if ( padded_frame ) {
@ -1237,7 +1262,7 @@ int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx,
frame - > nb_samples = avctx - > frame_size ;
} else {
/* if frame_size is not set, the number of samples must be
calculated from the buffer size */
* calculated from the buffer size */
int64_t nb_samples ;
if ( ! av_get_bits_per_sample ( avctx - > codec_id ) ) {
av_log ( avctx , AV_LOG_ERROR , " avcodec_encode_audio() does not "
@ -1253,7 +1278,7 @@ int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx,
}
/* it is assumed that the samples buffer is large enough based on the
relevant parameters */
* relevant parameters */
samples_size = av_samples_get_buffer_size ( NULL , avctx - > channels ,
frame - > nb_samples ,
avctx - > sample_fmt , 1 ) ;
@ -1264,8 +1289,8 @@ int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx,
return ret ;
/* fabricate frame pts from sample count.
this is needed because the avcodec_encode_audio ( ) API does not have
a way for the user to provide pts */
* this is needed because the avcodec_encode_audio ( ) API does not have
* a way for the user to provide pts */
if ( avctx - > sample_rate & & avctx - > time_base . num )
frame - > pts = ff_samples_to_time_base ( avctx ,
avctx - > internal - > sample_count ) ;
@ -1290,6 +1315,7 @@ int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx,
return ret ? ret : pkt . size ;
}
# endif
# if FF_API_OLD_ENCODE_VIDEO
@ -1325,6 +1351,7 @@ int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf
return ret ? ret : pkt . size ;
}
# endif
int attribute_align_arg avcodec_encode_video2 ( AVCodecContext * avctx ,
@ -1519,14 +1546,10 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi
picture - > pkt_pos = avpkt - > pos ;
}
//FIXME these should be under if(!avctx->has_b_frames)
if ( ! picture - > sample_aspect_ratio . num )
picture - > sample_aspect_ratio = avctx - > sample_aspect_ratio ;
if ( ! picture - > width )
picture - > width = avctx - > width ;
if ( ! picture - > height )
picture - > height = avctx - > height ;
if ( picture - > format = = PIX_FMT_NONE )
picture - > format = avctx - > pix_fmt ;
if ( ! picture - > sample_aspect_ratio . num ) picture - > sample_aspect_ratio = avctx - > sample_aspect_ratio ;
if ( ! picture - > width ) picture - > width = avctx - > width ;
if ( ! picture - > height ) picture - > height = avctx - > height ;
if ( picture - > format = = PIX_FMT_NONE ) picture - > format = avctx - > pix_fmt ;
}
emms_c ( ) ; //needed to avoid an emms_c() call before every return;
@ -1596,6 +1619,7 @@ int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *sa
}
return ret ;
}
# endif
int attribute_align_arg avcodec_decode_audio4 ( AVCodecContext * avctx ,
@ -1714,8 +1738,7 @@ void avsubtitle_free(AVSubtitle *sub)
{
int i ;
for ( i = 0 ; i < sub - > num_rects ; i + + )
{
for ( i = 0 ; i < sub - > num_rects ; i + + ) {
av_freep ( & sub - > rects [ i ] - > pict . data [ 0 ] ) ;
av_freep ( & sub - > rects [ i ] - > pict . data [ 1 ] ) ;
av_freep ( & sub - > rects [ i ] - > pict . data [ 2 ] ) ;
@ -1925,6 +1948,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) ,
" (%s / 0x%04X) " , tag_buf , enc - > codec_tag ) ;
}
switch ( enc - > codec_type ) {
case AVMEDIA_TYPE_VIDEO :
if ( enc - > pix_fmt ! = PIX_FMT_NONE ) {
@ -2324,9 +2348,11 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
}
# if !HAVE_THREADS
int ff_thread_init ( AVCodecContext * s ) {
int ff_thread_init ( AVCodecContext * s )
{
return - 1 ;
}
# endif
unsigned int av_xiphlacing ( unsigned char * s , unsigned int v )
@ -2343,7 +2369,8 @@ unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
return n ;
}
int ff_match_2uint16 ( const uint16_t ( * tab ) [ 2 ] , int size , int a , int b ) {
int ff_match_2uint16 ( const uint16_t ( * tab ) [ 2 ] , int size , int a , int b )
{
int i ;
for ( i = 0 ; i < size & & ! ( tab [ i ] [ 0 ] = = a & & tab [ i ] [ 1 ] = = b ) ; i + + ) ;
return i ;
@ -2394,11 +2421,10 @@ AVHWAccel *ff_find_hwaccel(enum AVCodecID codec_id, enum PixelFormat pix_fmt)
{
AVHWAccel * hwaccel = NULL ;
while ( ( hwaccel = av_hwaccel_next ( hwaccel ) ) ) {
while ( ( hwaccel = av_hwaccel_next ( hwaccel ) ) )
if ( hwaccel - > id = = codec_id
& & hwaccel - > pix_fmt = = pix_fmt )
return hwaccel ;
}
return NULL ;
}