From 70d9fda7589b4d437d9bc305f5890b72895adde1 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 14 Nov 2018 17:02:52 -0500 Subject: [PATCH] Implement a logging callback for avcodec to use our logging functions --- src/zm_ffmpeg.cpp | 39 ++++++++++++++++++++++++++++++++++++--- src/zm_logger.cpp | 1 + 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index 79a1d8b26..00aee7961 100644 --- a/src/zm_ffmpeg.cpp +++ b/src/zm_ffmpeg.cpp @@ -24,14 +24,47 @@ #if HAVE_LIBAVCODEC || HAVE_LIBAVUTIL || HAVE_LIBSWSCALE +void log_libav_callback( void *ptr, int level, const char *fmt, va_list vargs ) { + Logger *log = Logger::fetch(); + int log_level = 0; + if ( level == AV_LOG_QUIET ) { // -8 + log_level = Logger::NOLOG; + } else if ( level == AV_LOG_PANIC ) { //0 + log_level = Logger::PANIC; + } else if ( level == AV_LOG_FATAL ) { // 8 + log_level = Logger::FATAL; + } else if ( level == AV_LOG_ERROR ) { // 16 + log_level = Logger::ERROR; + } else if ( level == AV_LOG_WARNING ) { //24 + log_level = Logger::WARNING; + } else if ( level == AV_LOG_INFO ) { //32 + log_level = Logger::INFO; + } else if ( level == AV_LOG_VERBOSE ) { //40 + log_level = Logger::DEBUG1; + } else if ( level == AV_LOG_DEBUG ) { //48 + log_level = Logger::DEBUG2; + } else if ( level == AV_LOG_TRACE ) { + log_level = Logger::DEBUG8; + } else if ( level == AV_LOG_MAX_OFFSET ) { + log_level = Logger::DEBUG9; + } else { + Error("Unknown log level %d", level); + } + + if ( log ) { + log->logPrint(false, __FILE__, __LINE__, log_level, fmt, vargs); + } +} + void FFMPEGInit() { static bool bInit = false; if ( !bInit ) { - //if ( logDebugging() ) - //av_log_set_level( AV_LOG_DEBUG ); - //else + if ( logDebugging() ) + av_log_set_level( AV_LOG_DEBUG ); + else av_log_set_level( AV_LOG_QUIET ); + av_log_set_callback(log_libav_callback); av_register_all(); avformat_network_init(); bInit = true; diff --git a/src/zm_logger.cpp b/src/zm_logger.cpp index 736d36377..9740a100f 100644 --- a/src/zm_logger.cpp +++ b/src/zm_logger.cpp @@ -581,6 +581,7 @@ void Logger::logPrint( bool hex, const char * const filepath, const int line, co } } + void logInit(const char *name, const Logger::Options &options) { if ( !Logger::smInstance ) Logger::smInstance = new Logger();