[MPlayer-dev-eng] [PATCH] add and use vararg mp_msg
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Thu Oct 7 22:13:05 CEST 2010
This allows vd_ffmpeg to avoid a useless intermediate buffer that can only
cause trouble and the required changes are rather minimal.
Index: mp_msg.c
===================================================================
--- mp_msg.c (revision 32437)
+++ mp_msg.c (working copy)
@@ -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;
Index: mp_msg.h
===================================================================
--- mp_msg.h (revision 32437)
+++ mp_msg.h (working copy)
@@ -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
Index: libmpcodecs/vd_ffmpeg.c
===================================================================
--- libmpcodecs/vd_ffmpeg.c (revision 32437)
+++ libmpcodecs/vd_ffmpeg.c (working copy)
@@ -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){
More information about the MPlayer-dev-eng
mailing list