changeset 32378:150df72e808f

Add a va_list version of mp_msg and use it to avoid yet another intermediate buffer when printing FFmpeg messages in vd_ffmpeg.c
author reimar
date Sat, 09 Oct 2010 12:12:14 +0000
parents 8b160dad46ab
children 5471c2bb7a2b
files libmpcodecs/vd_ffmpeg.c mp_msg.c mp_msg.h
diffstat 3 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/vd_ffmpeg.c	Sat Oct 09 12:08:50 2010 +0000
+++ b/libmpcodecs/vd_ffmpeg.c	Sat Oct 09 12:12:14 2010 +0000
@@ -185,7 +185,6 @@
     AVClass *avc= ptr ? *(AVClass **)ptr : NULL;
     int type= MSGT_FIXME;
     int mp_level;
-    char buf[256];
 
     switch(level){
     case AV_LOG_VERBOSE: mp_level = MSGL_V ; break;
@@ -226,8 +225,7 @@
     }
 
     print_prefix= strchr(fmt, '\n') != NULL;
-    vsnprintf(buf, sizeof(buf), fmt, vl);
-    mp_msg(type, mp_level, buf);
+    mp_msg_va(type, mp_level, fmt, vl);
 }
 
 static void set_format_params(struct AVCodecContext *avctx, enum PixelFormat fmt){
--- a/mp_msg.c	Sat Oct 09 12:08:50 2010 +0000
+++ b/mp_msg.c	Sat Oct 09 12:12:14 2010 +0000
@@ -178,6 +178,12 @@
 
 void mp_msg(int mod, int lev, const char *format, ... ){
     va_list va;
+    va_start(va, format);
+    mp_msg_va(mod, lev, format, va);
+    va_end(va);
+}
+
+void mp_msg_va(int mod, int lev, const char *format, va_list va){
     char tmp[MSGSIZE_MAX];
     FILE *stream = lev <= MSGL_WARN ? stderr : stdout;
     static int header = 1;
@@ -186,9 +192,7 @@
     size_t len;
 
     if (!mp_msg_test(mod, lev)) return; // do not display
-    va_start(va, format);
     vsnprintf(tmp, MSGSIZE_MAX, format, va);
-    va_end(va);
     tmp[MSGSIZE_MAX-2] = '\n';
     tmp[MSGSIZE_MAX-1] = 0;
 
--- a/mp_msg.h	Sat Oct 09 12:08:50 2010 +0000
+++ b/mp_msg.h	Sat Oct 09 12:12:14 2010 +0000
@@ -19,6 +19,8 @@
 #ifndef MPLAYER_MP_MSG_H
 #define MPLAYER_MP_MSG_H
 
+#include <stdarg.h>
+
 // defined in mplayer.c and mencoder.c
 extern int verbose;
 
@@ -140,6 +142,7 @@
 
 #include "config.h"
 
+void mp_msg_va(int mod, int lev, const char *format, va_list va);
 #ifdef __GNUC__
 void mp_msg(int mod, int lev, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
 #   ifdef MP_DEBUG