mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 11:40:22 +00:00
lavcd: use UltraGrid logger
This commit is contained in:
@@ -161,7 +161,7 @@ ADD_TO_PARAM("audioenc-frame-duration", "* audioenc-frame-duration=<ms>\n"
|
||||
static void *libavcodec_init(audio_codec_t audio_codec, audio_codec_direction_t direction, bool silent,
|
||||
int bitrate)
|
||||
{
|
||||
ug_set_av_log_level();
|
||||
ug_set_av_logging();
|
||||
|
||||
enum AVCodecID codec_id = AV_CODEC_ID_NONE;
|
||||
|
||||
|
||||
@@ -163,14 +163,53 @@ bool libav_codec_has_extradata(codec_t codec) {
|
||||
return codec == HFYU || codec == FFV1;
|
||||
}
|
||||
|
||||
static inline int av_to_uv_log(int level) {
|
||||
level /= 8;
|
||||
if (level <= 0) { // av_quiet + av_panic
|
||||
return level + 1;
|
||||
}
|
||||
if (level <= 3) {
|
||||
return level;
|
||||
}
|
||||
return level + 1;
|
||||
}
|
||||
|
||||
static inline int uv_to_av_log(int level) {
|
||||
level *= 8;
|
||||
if (level == 8 * LOG_LEVEL_QUIET) {
|
||||
return level - 8;
|
||||
}
|
||||
if (level <= 8 * LOG_LEVEL_NOTICE) { // LOG_LEVEL_NOTICE maps to AV_LOG_INFO
|
||||
return level;
|
||||
}
|
||||
return level - 8;
|
||||
}
|
||||
|
||||
static void av_log_ug_callback(void *avcl, int av_level, const char *fmt, va_list vl) {
|
||||
int level = av_to_uv_log(av_level);
|
||||
if (level > log_level) {
|
||||
return;
|
||||
}
|
||||
// avcl handling is taken from av_log_default_callback
|
||||
AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
|
||||
char new_fmt[1024];
|
||||
if (avc) {
|
||||
snprintf(new_fmt, sizeof new_fmt, "[lavc %s @ %p] %s", avc->item_name(avcl), avcl, fmt);
|
||||
} else {
|
||||
snprintf(new_fmt, sizeof new_fmt, "[lavc] %s", fmt);
|
||||
}
|
||||
log_vprintf(level, new_fmt, vl);
|
||||
}
|
||||
|
||||
ADD_TO_PARAM("lavcd-log-level",
|
||||
"* lavcd-log-level=<num>\n"
|
||||
" Set libavcodec log level (use UltraGrid range semantics)\n");
|
||||
/// Sets specified log level either given explicitly or from UG-wide log_level
|
||||
void ug_set_av_log_level() {
|
||||
void ug_set_av_logging() {
|
||||
const char *param = get_commandline_param("lavcd-log-level");
|
||||
int av_log_level = param != NULL ? atoi(param) : log_level;
|
||||
av_log_set_level((av_log_level - 1) * 8);
|
||||
av_log_set_level(uv_to_av_log(av_log_level));
|
||||
av_log_set_callback(av_log_ug_callback);
|
||||
}
|
||||
|
||||
/* vi: set expandtab sw=8: */
|
||||
|
||||
@@ -231,7 +231,7 @@ struct uv_to_av_pixfmt {
|
||||
codec_t get_av_to_ug_pixfmt(enum AVPixelFormat av_pixfmt) ATTRIBUTE(const);
|
||||
enum AVPixelFormat get_ug_to_av_pixfmt(codec_t ug_codec) ATTRIBUTE(const);
|
||||
const struct uv_to_av_pixfmt *get_av_to_ug_pixfmts(void) ATTRIBUTE(const);
|
||||
void ug_set_av_log_level(void);
|
||||
void ug_set_av_logging(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -598,7 +598,7 @@ static compress_module_info get_libavcodec_module_info(){
|
||||
|
||||
struct module * libavcodec_compress_init(struct module *parent, const char *opts)
|
||||
{
|
||||
ug_set_av_log_level();
|
||||
ug_set_av_logging();
|
||||
#if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(58, 9, 100)
|
||||
/* register all the codecs (you can also register only the codec
|
||||
* you wish to have smaller code */
|
||||
|
||||
@@ -390,7 +390,7 @@ static void * libavcodec_decompress_init(void)
|
||||
struct state_libavcodec_decompress *s =
|
||||
calloc(1, sizeof(struct state_libavcodec_decompress));
|
||||
|
||||
ug_set_av_log_level();
|
||||
ug_set_av_logging();
|
||||
|
||||
#if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(58, 9, 100)
|
||||
/* register all the codecs (you can also register only the codec
|
||||
|
||||
Reference in New Issue
Block a user