diff --git a/examples/demuxing_decoding/main.go b/examples/demuxing_decoding/main.go index e2f4c92..fdc8f0c 100644 --- a/examples/demuxing_decoding/main.go +++ b/examples/demuxing_decoding/main.go @@ -23,7 +23,7 @@ type stream struct { func main() { // Handle ffmpeg logs astiav.SetLogLevel(astiav.LogLevelDebug) - astiav.SetLogCallback(func(l astiav.LogLevel, msg, parent string) { + astiav.SetLogCallback(func(l astiav.LogLevel, fmt, msg, parent string) { log.Printf("ffmpeg log: %s (level: %d)\n", strings.TrimSpace(msg), l) }) diff --git a/examples/filtering/main.go b/examples/filtering/main.go index 418fba0..0028114 100644 --- a/examples/filtering/main.go +++ b/examples/filtering/main.go @@ -37,7 +37,7 @@ type stream struct { func main() { // Handle ffmpeg logs astiav.SetLogLevel(astiav.LogLevelDebug) - astiav.SetLogCallback(func(l astiav.LogLevel, msg, parent string) { + astiav.SetLogCallback(func(l astiav.LogLevel, fmt, msg, parent string) { log.Printf("ffmpeg log: %s (level: %d)\n", strings.TrimSpace(msg), l) }) diff --git a/examples/remuxing/main.go b/examples/remuxing/main.go index 61580c1..65c7c47 100644 --- a/examples/remuxing/main.go +++ b/examples/remuxing/main.go @@ -18,7 +18,7 @@ var ( func main() { // Handle ffmpeg logs astiav.SetLogLevel(astiav.LogLevelDebug) - astiav.SetLogCallback(func(l astiav.LogLevel, msg, parent string) { + astiav.SetLogCallback(func(l astiav.LogLevel, fmt, msg, parent string) { log.Printf("ffmpeg log: %s (level: %d)\n", strings.TrimSpace(msg), l) }) diff --git a/examples/transcoding/main.go b/examples/transcoding/main.go index c194fe7..4f2c361 100644 --- a/examples/transcoding/main.go +++ b/examples/transcoding/main.go @@ -42,7 +42,7 @@ type stream struct { func main() { // Handle ffmpeg logs astiav.SetLogLevel(astiav.LogLevelDebug) - astiav.SetLogCallback(func(l astiav.LogLevel, msg, parent string) { + astiav.SetLogCallback(func(l astiav.LogLevel, fmt, msg, parent string) { log.Printf("ffmpeg log: %s (level: %d)\n", strings.TrimSpace(msg), l) }) diff --git a/log.go b/log.go index 6f152cb..0e52734 100644 --- a/log.go +++ b/log.go @@ -3,7 +3,7 @@ package astiav //#cgo pkg-config: libavutil //#include /* -extern void goAstiavLogCallback(int level, char* msg, char* parent); +extern void goAstiavLogCallback(int level, char* fmt, char* msg, char* parent); static inline void astiavLogCallback(void *avcl, int level, const char *fmt, va_list vl) { @@ -15,7 +15,7 @@ static inline void astiavLogCallback(void *avcl, int level, const char *fmt, va_ } char msg[1024]; vsprintf(msg, fmt, vl); - goAstiavLogCallback(level, msg, parent); + goAstiavLogCallback(level, (char*)(fmt), msg, parent); } static inline void astiavSetLogCallback() { @@ -51,7 +51,7 @@ func SetLogLevel(l LogLevel) { C.av_log_set_level(C.int(l)) } -type LogCallback func(l LogLevel, msg, parent string) +type LogCallback func(l LogLevel, fmt, msg, parent string) var logCallback LogCallback @@ -61,11 +61,11 @@ func SetLogCallback(c LogCallback) { } //export goAstiavLogCallback -func goAstiavLogCallback(level C.int, msg, parent *C.char) { +func goAstiavLogCallback(level C.int, fmt, msg, parent *C.char) { if logCallback == nil { return } - logCallback(LogLevel(level), C.GoString(msg), C.GoString(parent)) + logCallback(LogLevel(level), C.GoString(fmt), C.GoString(msg), C.GoString(parent)) } func ResetLogCallback() { diff --git a/log_test.go b/log_test.go index a21846e..6651246 100644 --- a/log_test.go +++ b/log_test.go @@ -8,14 +8,16 @@ import ( ) type logItem struct { + fmt string l astiav.LogLevel msg string } func TestLog(t *testing.T) { var lis []logItem - astiav.SetLogCallback(func(l astiav.LogLevel, msg, parent string) { + astiav.SetLogCallback(func(l astiav.LogLevel, fmt, msg, parent string) { lis = append(lis, logItem{ + fmt: fmt, l: l, msg: msg, }) @@ -27,14 +29,17 @@ func TestLog(t *testing.T) { astiav.Log(astiav.LogLevelFatal, "fatal") require.Equal(t, []logItem{ { + fmt: "warning", l: astiav.LogLevelWarning, msg: "warning", }, { + fmt: "error", l: astiav.LogLevelError, msg: "error", }, { + fmt: "fatal", l: astiav.LogLevelFatal, msg: "fatal", },