From 0d90aec0fd7428a77b5c4c536ab65635669bc42d Mon Sep 17 00:00:00 2001 From: Mike Melanson Date: Sun, 14 Mar 2004 21:14:07 +0000 Subject: sync to ffmpeg build 4707 CVS patchset: 6253 CVS date: 2004/03/14 21:14:07 --- src/libffmpeg/libavcodec/utils.c | 85 +++++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 23 deletions(-) (limited to 'src/libffmpeg/libavcodec/utils.c') diff --git a/src/libffmpeg/libavcodec/utils.c b/src/libffmpeg/libavcodec/utils.c index 2fb82c347..b6b6059e9 100644 --- a/src/libffmpeg/libavcodec/utils.c +++ b/src/libffmpeg/libavcodec/utils.c @@ -103,9 +103,13 @@ void av_free_static(void) last_static = 0; } -/* cannot call it directly because of 'void **' casting is not automatic */ -void __av_freep(void **ptr) +/** + * Frees memory and sets the pointer to NULL. + * @param arg pointer to the pointer which should be freed + */ +void av_freep(void *arg) { + void **ptr= (void**)arg; av_free(*ptr); *ptr = NULL; } @@ -238,7 +242,8 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ const int h_shift= i==0 ? 0 : h_chroma_shift; const int v_shift= i==0 ? 0 : v_chroma_shift; - buf->linesize[i]= ALIGN(pixel_size*w>>h_shift, s_align); + //FIXME next ensures that linesize= 2^x uvlinesize, thats needed because some MC code assumes it + buf->linesize[i]= ALIGN(pixel_size*w>>h_shift, s_align<<(h_chroma_shift-h_shift)); buf->base[i]= av_mallocz((buf->linesize[i]*h>>v_shift)+16); //FIXME 16 if(buf->base[i]==NULL) return -1; @@ -323,11 +328,35 @@ int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){ return 0; } -enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, enum PixelFormat * fmt){ +int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){ + int i; + + for(i=0; icodec && avc->codec->name) + return avc->codec->name; + else + return "NULL"; +} + +static AVClass av_codec_context_class = { "AVCodecContext", context_to_name }; + void avcodec_get_context_defaults(AVCodecContext *s){ + memset(s, 0, sizeof(AVCodecContext)); + + s->av_class= &av_codec_context_class; s->bit_rate= 800*1000; s->bit_rate_tolerance= s->bit_rate*10; s->qmin= 2; @@ -351,6 +380,8 @@ void avcodec_get_context_defaults(AVCodecContext *s){ s->get_buffer= avcodec_default_get_buffer; s->release_buffer= avcodec_default_release_buffer; s->get_format= avcodec_default_get_format; + s->execute= avcodec_default_execute; + s->thread_count=1; s->me_subpel_quality=8; s->lmin= FF_QP2LAMBDA * s->qmin; s->lmax= FF_QP2LAMBDA * s->qmax; @@ -368,7 +399,7 @@ void avcodec_get_context_defaults(AVCodecContext *s){ * this can be deallocated by simply calling free() */ AVCodecContext *avcodec_alloc_context(void){ - AVCodecContext *avctx= av_mallocz(sizeof(AVCodecContext)); + AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext)); if(avctx==NULL) return NULL; @@ -377,12 +408,22 @@ AVCodecContext *avcodec_alloc_context(void){ return avctx; } +void avcodec_get_frame_defaults(AVFrame *pic){ + memset(pic, 0, sizeof(AVFrame)); + + pic->pts= AV_NOPTS_VALUE; +} + /** * allocates a AVPFrame and set it to defaults. * this can be deallocated by simply calling free() */ AVFrame *avcodec_alloc_frame(void){ - AVFrame *pic= av_mallocz(sizeof(AVFrame)); + AVFrame *pic= av_malloc(sizeof(AVFrame)); + + if(pic==NULL) return NULL; + + avcodec_get_frame_defaults(pic); return pic; } @@ -806,40 +847,38 @@ int64_t av_rescale(int64_t a, int b, int c){ /* av_log API */ -#ifdef AV_LOG_TRAP_PRINTF -#undef stderr -#undef fprintf -#endif - static int av_log_level = AV_LOG_DEBUG; -static void av_log_default_callback(AVCodecContext* avctx, int level, const char* fmt, va_list vl) +static void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) { static int print_prefix=1; - + AVClass* avc= ptr ? *(AVClass**)ptr : NULL; if(level>av_log_level) - return; - if(avctx && print_prefix) - fprintf(stderr, "[%s @ %p]", avctx->codec ? avctx->codec->name : "?", avctx); + return; +#undef fprintf + if(print_prefix && avc) { + fprintf(stderr, "[%s @ %p]", avc->item_name(ptr), avc); + } +#define fprintf please_use_av_log - print_prefix= (int)strstr(fmt, "\n"); + print_prefix= strstr(fmt, "\n") != NULL; vfprintf(stderr, fmt, vl); } -static void (*av_log_callback)(AVCodecContext*, int, const char*, va_list) = av_log_default_callback; +static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback; -void av_log(AVCodecContext* avctx, int level, const char *fmt, ...) +void av_log(void* avcl, int level, const char *fmt, ...) { va_list vl; va_start(vl, fmt); - av_vlog(avctx, level, fmt, vl); + av_vlog(avcl, level, fmt, vl); va_end(vl); } -void av_vlog(AVCodecContext* avctx, int level, const char *fmt, va_list vl) +void av_vlog(void* avcl, int level, const char *fmt, va_list vl) { - av_log_callback(avctx, level, fmt, vl); + av_log_callback(avcl, level, fmt, vl); } int av_log_get_level(void) @@ -852,7 +891,7 @@ void av_log_set_level(int level) av_log_level = level; } -void av_log_set_callback(void (*callback)(AVCodecContext*, int, const char*, va_list)) +void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) { av_log_callback = callback; } -- cgit v1.2.3