feat(ffmpeg): logging callback handler

This commit is contained in:
Adrian Shum 2022-09-11 11:04:08 +08:00 committed by GitHub
parent f11d2b351c
commit 57541418b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 71 additions and 1 deletions

View file

@ -1,7 +1,9 @@
package ffmpeg
// #include "ffmpeg.h"
// #include "logging.h"
import "C"
import "sync"
// AVLogLevel defines the ffmpeg threshold for dumping information to stderr.
type AVLogLevel int
@ -19,6 +21,12 @@ const (
AVLogTrace
)
var (
currentLoggingHandlerFunction = noopLoggingHandler
currentLoggingVerbosity AVLogLevel
onceLogging sync.Once
)
func logLevel() AVLogLevel {
return AVLogLevel(C.av_log_get_level())
}
@ -26,4 +34,25 @@ func logLevel() AVLogLevel {
// SetFFmpegLogLevel allows you to change the log level from the default (AVLogInfo).
func SetFFmpegLogLevel(logLevel AVLogLevel) {
C.av_log_set_level(C.int(logLevel))
currentLoggingVerbosity = logLevel
}
type LoggingHandlerFunction func(messageLevel AVLogLevel, message string)
func SetLogging(handler LoggingHandlerFunction) {
onceLogging.Do(func() {
C.goavLogSetup()
})
if handler != nil {
currentLoggingHandlerFunction = handler
}
}
func noopLoggingHandler(_ AVLogLevel, _ string) {
}
func log(level AVLogLevel, message string) {
if level <= currentLoggingVerbosity {
currentLoggingHandlerFunction(level, message)
}
}