Mercurial > libavcodec.hg
comparison utils.c @ 1855:bafde44145f9 libavcodec
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
author | michael |
---|---|
date | Wed, 03 Mar 2004 15:41:21 +0000 |
parents | 73ee15c391bf |
children | ed6eb3e304cc |
comparison
equal
deleted
inserted
replaced
1854:73ee15c391bf | 1855:bafde44145f9 |
---|---|
384 | 384 |
385 /** | 385 /** |
386 * allocates a AVCodecContext and set it to defaults. | 386 * allocates a AVCodecContext and set it to defaults. |
387 * this can be deallocated by simply calling free() | 387 * this can be deallocated by simply calling free() |
388 */ | 388 */ |
389 static const char* context_to_name(void* class_ptr) { return ((AVCodecContext*) class_ptr)->codec->name; } | |
390 | |
391 static AVClass av_codec_context_class = { "AVCodecContext", context_to_name }; | |
392 | |
389 AVCodecContext *avcodec_alloc_context(void){ | 393 AVCodecContext *avcodec_alloc_context(void){ |
390 AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext)); | 394 AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext)); |
391 | 395 |
392 if(avctx==NULL) return NULL; | 396 if(avctx==NULL) return NULL; |
393 | 397 |
398 avctx->class = av_codec_context_class; | |
394 avcodec_get_context_defaults(avctx); | 399 avcodec_get_context_defaults(avctx); |
395 | 400 |
396 return avctx; | 401 return avctx; |
397 } | 402 } |
398 | 403 |
833 return ((h/c)<<32) + l/c; | 838 return ((h/c)<<32) + l/c; |
834 } | 839 } |
835 | 840 |
836 /* av_log API */ | 841 /* av_log API */ |
837 | 842 |
838 #ifdef AV_LOG_TRAP_PRINTF | 843 static const char* null_to_name(void* class_ptr) { return "NULL"; } |
839 #undef stderr | 844 |
845 static AVClass av_null_class = { "NULL", null_to_name }; | |
846 | |
847 static int av_log_level = AV_LOG_DEBUG; | |
848 | |
849 static void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) | |
850 { | |
851 static int print_prefix=1; | |
852 AVClass* avcl = ptr; | |
853 if(!avcl || !avcl->class_name) | |
854 avcl = &av_null_class; | |
855 if(level>av_log_level) | |
856 return; | |
840 #undef fprintf | 857 #undef fprintf |
841 #endif | 858 if(print_prefix) { |
842 | 859 fprintf(stderr, "[%s:%s @ %p]", avcl->class_name, avcl->item_name(avcl), avcl); |
843 static int av_log_level = AV_LOG_DEBUG; | 860 } |
844 | |
845 static void av_log_default_callback(AVCodecContext* avctx, int level, const char* fmt, va_list vl) | |
846 { | |
847 static int print_prefix=1; | |
848 | |
849 if(level>av_log_level) | |
850 return; | |
851 #undef fprintf | |
852 if(avctx && print_prefix) | |
853 fprintf(stderr, "[%s @ %p]", avctx->codec ? avctx->codec->name : "?", avctx); | |
854 #define fprintf please_use_av_log | 861 #define fprintf please_use_av_log |
855 | 862 |
856 print_prefix= strstr(fmt, "\n") != NULL; | 863 print_prefix= strstr(fmt, "\n") != NULL; |
857 | 864 |
858 vfprintf(stderr, fmt, vl); | 865 vfprintf(stderr, fmt, vl); |
859 } | 866 } |
860 | 867 |
861 static void (*av_log_callback)(AVCodecContext*, int, const char*, va_list) = av_log_default_callback; | 868 static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback; |
862 | 869 |
863 void av_log(AVCodecContext* avctx, int level, const char *fmt, ...) | 870 void av_log(void* avcl, int level, const char *fmt, ...) |
864 { | 871 { |
865 va_list vl; | 872 va_list vl; |
866 va_start(vl, fmt); | 873 va_start(vl, fmt); |
867 av_vlog(avctx, level, fmt, vl); | 874 av_vlog(avcl, level, fmt, vl); |
868 va_end(vl); | 875 va_end(vl); |
869 } | 876 } |
870 | 877 |
871 void av_vlog(AVCodecContext* avctx, int level, const char *fmt, va_list vl) | 878 void av_vlog(void* avcl, int level, const char *fmt, va_list vl) |
872 { | 879 { |
873 av_log_callback(avctx, level, fmt, vl); | 880 av_log_callback(avcl, level, fmt, vl); |
874 } | 881 } |
875 | 882 |
876 int av_log_get_level(void) | 883 int av_log_get_level(void) |
877 { | 884 { |
878 return av_log_level; | 885 return av_log_level; |
881 void av_log_set_level(int level) | 888 void av_log_set_level(int level) |
882 { | 889 { |
883 av_log_level = level; | 890 av_log_level = level; |
884 } | 891 } |
885 | 892 |
886 void av_log_set_callback(void (*callback)(AVCodecContext*, int, const char*, va_list)) | 893 void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) |
887 { | 894 { |
888 av_log_callback = callback; | 895 av_log_callback = callback; |
889 } | 896 } |
890 | 897 |