aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichel Bardiaux <mbardiaux@peaktime.be>2004-03-03 15:41:21 +0000
committerMichael Niedermayer <michaelni@gmx.at>2004-03-03 15:41:21 +0000
commitbc874daea8273e2471f5a6f914cdc9cf97371a1c (patch)
tree967f82d529194e1dcc9865caedc0378950ec6f2f /libavcodec
parent81c5f887485a3d46ec5948832acc7da8167b5248 (diff)
downloadffmpeg-bc874daea8273e2471f5a6f914cdc9cf97371a1c.tar.gz
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
Originally committed as revision 2840 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/avcodec.h31
-rw-r--r--libavcodec/utils.c37
2 files changed, 42 insertions, 26 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 956a2ef74a..772fbd7ae8 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -570,10 +570,27 @@ typedef struct AVFrame {
#define DEFAULT_FRAME_RATE_BASE 1001000
/**
+ * Used by av_log
+ */
+typedef struct AVCLASS AVClass;
+struct AVCLASS {
+ const char* class_name;
+ const char* (*item_name)(void*); /* actually passing a pointer to an AVCodecContext
+ or AVFormatContext, which begin with an AVClass.
+ Needed because av_log is in libavcodec and has no visibility
+ of AVIn/OutputFormat */
+};
+
+/**
* main external api structure.
*/
typedef struct AVCodecContext {
/**
+ * Info on struct for av_log
+ * - set by avcodec_alloc_context
+ */
+ AVClass class;
+ /**
* the average bitrate.
* - encoding: set by user. unused for constant quantizer encoding
* - decoding: set by lavc. 0 or some bitrate if this info is available in the stream
@@ -2095,19 +2112,11 @@ void img_copy(AVPicture *dst, const AVPicture *src,
#define AV_LOG_INFO 1
#define AV_LOG_DEBUG 2
-extern void av_log(AVCodecContext*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
-extern void av_vlog(AVCodecContext*, int level, const char *fmt, va_list);
+extern void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
+extern void av_vlog(void*, int level, const char *fmt, va_list);
extern int av_log_get_level(void);
extern void av_log_set_level(int);
-extern void av_log_set_callback(void (*)(AVCodecContext*, int, const char*, va_list));
-
-#undef AV_LOG_TRAP_PRINTF
-#ifdef AV_LOG_TRAP_PRINTF
-#define printf DO NOT USE
-#define fprintf DO NOT USE
-#undef stderr
-#define stderr DO NOT USE
-#endif
+extern void av_log_set_callback(void (*)(void*, int, const char*, va_list));
#ifdef __cplusplus
}
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 9fadfcd969..7f20d03c37 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -386,11 +386,16 @@ void avcodec_get_context_defaults(AVCodecContext *s){
* allocates a AVCodecContext and set it to defaults.
* this can be deallocated by simply calling free()
*/
+static const char* context_to_name(void* class_ptr) { return ((AVCodecContext*) class_ptr)->codec->name; }
+
+static AVClass av_codec_context_class = { "AVCodecContext", context_to_name };
+
AVCodecContext *avcodec_alloc_context(void){
AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
if(avctx==NULL) return NULL;
+ avctx->class = av_codec_context_class;
avcodec_get_context_defaults(avctx);
return avctx;
@@ -835,22 +840,24 @@ 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 const char* null_to_name(void* class_ptr) { return "NULL"; }
+
+static AVClass av_null_class = { "NULL", null_to_name };
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* avcl = ptr;
+ if(!avcl || !avcl->class_name)
+ avcl = &av_null_class;
if(level>av_log_level)
- return;
+ return;
#undef fprintf
- if(avctx && print_prefix)
- fprintf(stderr, "[%s @ %p]", avctx->codec ? avctx->codec->name : "?", avctx);
+ if(print_prefix) {
+ fprintf(stderr, "[%s:%s @ %p]", avcl->class_name, avcl->item_name(avcl), avcl);
+ }
#define fprintf please_use_av_log
print_prefix= strstr(fmt, "\n") != NULL;
@@ -858,19 +865,19 @@ static void av_log_default_callback(AVCodecContext* avctx, int level, const char
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)
@@ -883,7 +890,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;
}