+// Convert ffmpeg log level to equivalent libopenh264 log level. Given the
+// conversions below, you must set the ffmpeg log level to something greater
+// than AV_LOG_DEBUG if you want to see WELS_LOG_DETAIL messages.
+static int ffmpeg_to_libopenh264_log_level (
+ int ffmpeg_log_level
+ )
+{
+ if (ffmpeg_log_level > AV_LOG_DEBUG) return WELS_LOG_DETAIL;
+ else if (ffmpeg_log_level >= AV_LOG_DEBUG) return WELS_LOG_DEBUG;
+ else if (ffmpeg_log_level >= AV_LOG_INFO) return WELS_LOG_INFO;
+ else if (ffmpeg_log_level >= AV_LOG_WARNING) return WELS_LOG_WARNING;
+ else if (ffmpeg_log_level >= AV_LOG_ERROR) return WELS_LOG_ERROR;
+ else return WELS_LOG_QUIET;
+}
+
+// Convert libopenh264 log level to equivalent ffmpeg log level.
+static int libopenh264_to_ffmpeg_log_level (
+ int libopenh264_log_level
+ )
+{
+ if (libopenh264_log_level >= WELS_LOG_DETAIL) return AV_LOG_TRACE;
+ else if (libopenh264_log_level >= WELS_LOG_DEBUG) return AV_LOG_DEBUG;
+ else if (libopenh264_log_level >= WELS_LOG_INFO) return AV_LOG_INFO;
+ else if (libopenh264_log_level >= WELS_LOG_WARNING) return AV_LOG_WARNING;
+ else if (libopenh264_log_level >= WELS_LOG_ERROR) return AV_LOG_ERROR;
+ else return AV_LOG_QUIET;
+}
+
+// This function will be provided to the libopenh264 library. The function will be called
+// when libopenh264 wants to log a message (error, warning, info, etc.). The signature for
+// this function (defined in .../codec/api/svc/codec_api.h) is:
+//
+// typedef void (*WelsTraceCallback) (void* ctx, int level, const char* string);
+
+static void libopenh264_trace_callback (
+ void * ctx,
+ int level,
+ char const * msg
+ )
+{
+ // The message will be logged only if the requested EQUIVALENT ffmpeg log level is
+ // less than or equal to the current ffmpeg log level. Note, however, that before
+ // this function is called, welsCodecTrace::CodecTrace() will have already discarded
+ // the message (and this function will not be called) if the requested libopenh264
+ // log level "level" is greater than the current libopenh264 log level.
+ int equiv_ffmpeg_log_level = libopenh264_to_ffmpeg_log_level(level);
+ if (equiv_ffmpeg_log_level <= av_log_get_level())
+ av_log(ctx, equiv_ffmpeg_log_level, "%s\n", msg);
+}
+