Message ID | 1522249420-5373-2-git-send-email-t.rapp@noa-archive.com |
---|---|
State | New |
Headers | show |
On Wed, 28 Mar 2018 17:03:39 +0200 Tobias Rapp <t.rapp@noa-archive.com> wrote: > Allows to set log level and flag values from string. > > Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com> > --- > doc/APIchanges | 3 +++ > libavutil/log.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > libavutil/log.h | 16 +++++++++++ > libavutil/version.h | 2 +- > 4 files changed, 96 insertions(+), 1 deletion(-) > > diff --git a/doc/APIchanges b/doc/APIchanges > index 83c7a40..2d14452 100644 > --- a/doc/APIchanges > +++ b/doc/APIchanges > @@ -15,6 +15,9 @@ libavutil: 2017-10-21 > > API changes, most recent first: > > +2018-03-xx - xxxxxxx - lavu 56.13.100 - log.h > + Add av_log_set_opts(). > + > 2018-03-xx - xxxxxxx - lavc 58.16.100 - avcodec.h > Add FF_SUB_CHARENC_MODE_IGNORE. > > diff --git a/libavutil/log.c b/libavutil/log.c > index 0a99d01..af32cd6 100644 > --- a/libavutil/log.c > +++ b/libavutil/log.c > @@ -34,6 +34,7 @@ > #endif > #include <stdarg.h> > #include <stdlib.h> > +#include "avassert.h" > #include "avutil.h" > #include "bprint.h" > #include "common.h" > @@ -402,6 +403,81 @@ void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) > av_log_callback = callback; > } > > +int av_log_set_opts(const char *arg) > +{ > + const struct { const char *name; int level; } log_levels[] = { > + { "quiet" , AV_LOG_QUIET }, > + { "panic" , AV_LOG_PANIC }, > + { "fatal" , AV_LOG_FATAL }, > + { "error" , AV_LOG_ERROR }, > + { "warning", AV_LOG_WARNING }, > + { "info" , AV_LOG_INFO }, > + { "verbose", AV_LOG_VERBOSE }, > + { "debug" , AV_LOG_DEBUG }, > + { "trace" , AV_LOG_TRACE }, > + }; > + const char *token; > + char *tail; > + int flags = av_log_get_flags(); > + int level = av_log_get_level(); > + int cmd, i = 0; > + > + av_assert0(arg); > + while (*arg) { > + token = arg; > + if (*token == '+' || *token == '-') { > + cmd = *token++; > + } else { > + cmd = 0; > + } > + if (!i && !cmd) { > + flags = 0; /* missing relative prefix, build absolute value */ > + } > + if (!strncmp(token, "repeat", 6)) { > + if (cmd == '-') { > + flags |= AV_LOG_SKIP_REPEATED; > + } else { > + flags &= ~AV_LOG_SKIP_REPEATED; > + } > + arg = token + 6; > + } else if (!strncmp(token, "level", 5)) { > + if (cmd == '-') { > + flags &= ~AV_LOG_PRINT_LEVEL; > + } else { > + flags |= AV_LOG_PRINT_LEVEL; > + } > + arg = token + 5; > + } else { > + break; > + } > + i++; > + } > + if (!*arg) { > + goto end; > + } else if (*arg == '+') { > + arg++; > + } else if (!i) { > + flags = av_log_get_flags(); /* level value without prefix, reset flags */ > + } > + > + for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) { > + if (!strcmp(arg, log_levels[i].name)) { > + level = log_levels[i].level; > + goto end; > + } > + } > + > + level = strtol(arg, &tail, 10); > + if (*tail) { > + return -1; > + } > + > +end: > + av_log_set_flags(flags); > + av_log_set_level(level); > + return 0; > +} > + > static void missing_feature_sample(int sample, void *avc, const char *msg, > va_list argument_list) > { > diff --git a/libavutil/log.h b/libavutil/log.h > index d9554e6..97010f7 100644 > --- a/libavutil/log.h > +++ b/libavutil/log.h > @@ -356,6 +356,22 @@ void av_log_set_flags(int arg); > int av_log_get_flags(void); > > /** > + * Set log flags and level as an option string. Accepts "repeat" and "level" > + * flags mapped to AV_LOG_SKIP_REPEATED (inverted) and AV_LOG_PRINT_LEVEL, > + * followed by the log level specified either by name ("warning", "info", > + * "verbose", etc.) or by number. > + * > + * When flags are prefixed with "+" or "-" the change is relative to the > + * current flags value. When both flags and level are present a "+" separator > + * is expected between last flag and before level. > + * > + * @param arg log option string > + * @return Returns a negative value if parsing the option string failed, > + * otherwise returns 0. > + */ > +int av_log_set_opts(const char *arg); > + > +/** > * @} > */ > > diff --git a/libavutil/version.h b/libavutil/version.h > index d3dd2df..296c24b 100644 > --- a/libavutil/version.h > +++ b/libavutil/version.h > @@ -79,7 +79,7 @@ > */ > > #define LIBAVUTIL_VERSION_MAJOR 56 > -#define LIBAVUTIL_VERSION_MINOR 12 > +#define LIBAVUTIL_VERSION_MINOR 13 > #define LIBAVUTIL_VERSION_MICRO 100 > > #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ Seems like a step backwards. Why can't it stay in the fftools thing?
On 28.03.2018 17:11, wm4 wrote: > On Wed, 28 Mar 2018 17:03:39 +0200 > Tobias Rapp <t.rapp@noa-archive.com> wrote: > >> Allows to set log level and flag values from string. >> >> Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com> >> --- >> doc/APIchanges | 3 +++ >> libavutil/log.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ >> libavutil/log.h | 16 +++++++++++ >> libavutil/version.h | 2 +- >> 4 files changed, 96 insertions(+), 1 deletion(-) >> >> diff --git a/doc/APIchanges b/doc/APIchanges >> index 83c7a40..2d14452 100644 >> --- a/doc/APIchanges >> +++ b/doc/APIchanges >> @@ -15,6 +15,9 @@ libavutil: 2017-10-21 >> >> API changes, most recent first: >> >> +2018-03-xx - xxxxxxx - lavu 56.13.100 - log.h >> + Add av_log_set_opts(). >> + >> 2018-03-xx - xxxxxxx - lavc 58.16.100 - avcodec.h >> Add FF_SUB_CHARENC_MODE_IGNORE. >> >> diff --git a/libavutil/log.c b/libavutil/log.c >> index 0a99d01..af32cd6 100644 >> --- a/libavutil/log.c >> +++ b/libavutil/log.c >> @@ -34,6 +34,7 @@ >> #endif >> #include <stdarg.h> >> #include <stdlib.h> >> +#include "avassert.h" >> #include "avutil.h" >> #include "bprint.h" >> #include "common.h" >> @@ -402,6 +403,81 @@ void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) >> av_log_callback = callback; >> } >> >> +int av_log_set_opts(const char *arg) >> +{ >> + const struct { const char *name; int level; } log_levels[] = { >> + { "quiet" , AV_LOG_QUIET }, >> + { "panic" , AV_LOG_PANIC }, >> + { "fatal" , AV_LOG_FATAL }, >> + { "error" , AV_LOG_ERROR }, >> + { "warning", AV_LOG_WARNING }, >> + { "info" , AV_LOG_INFO }, >> + { "verbose", AV_LOG_VERBOSE }, >> + { "debug" , AV_LOG_DEBUG }, >> + { "trace" , AV_LOG_TRACE }, >> + }; >> + const char *token; >> + char *tail; >> + int flags = av_log_get_flags(); >> + int level = av_log_get_level(); >> + int cmd, i = 0; >> + >> + av_assert0(arg); >> + while (*arg) { >> + token = arg; >> + if (*token == '+' || *token == '-') { >> + cmd = *token++; >> + } else { >> + cmd = 0; >> + } >> + if (!i && !cmd) { >> + flags = 0; /* missing relative prefix, build absolute value */ >> + } >> + if (!strncmp(token, "repeat", 6)) { >> + if (cmd == '-') { >> + flags |= AV_LOG_SKIP_REPEATED; >> + } else { >> + flags &= ~AV_LOG_SKIP_REPEATED; >> + } >> + arg = token + 6; >> + } else if (!strncmp(token, "level", 5)) { >> + if (cmd == '-') { >> + flags &= ~AV_LOG_PRINT_LEVEL; >> + } else { >> + flags |= AV_LOG_PRINT_LEVEL; >> + } >> + arg = token + 5; >> + } else { >> + break; >> + } >> + i++; >> + } >> + if (!*arg) { >> + goto end; >> + } else if (*arg == '+') { >> + arg++; >> + } else if (!i) { >> + flags = av_log_get_flags(); /* level value without prefix, reset flags */ >> + } >> + >> + for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) { >> + if (!strcmp(arg, log_levels[i].name)) { >> + level = log_levels[i].level; >> + goto end; >> + } >> + } >> + >> + level = strtol(arg, &tail, 10); >> + if (*tail) { >> + return -1; >> + } >> + >> +end: >> + av_log_set_flags(flags); >> + av_log_set_level(level); >> + return 0; >> +} >> + >> static void missing_feature_sample(int sample, void *avc, const char *msg, >> va_list argument_list) >> { >> diff --git a/libavutil/log.h b/libavutil/log.h >> index d9554e6..97010f7 100644 >> --- a/libavutil/log.h >> +++ b/libavutil/log.h >> @@ -356,6 +356,22 @@ void av_log_set_flags(int arg); >> int av_log_get_flags(void); >> >> /** >> + * Set log flags and level as an option string. Accepts "repeat" and "level" >> + * flags mapped to AV_LOG_SKIP_REPEATED (inverted) and AV_LOG_PRINT_LEVEL, >> + * followed by the log level specified either by name ("warning", "info", >> + * "verbose", etc.) or by number. >> + * >> + * When flags are prefixed with "+" or "-" the change is relative to the >> + * current flags value. When both flags and level are present a "+" separator >> + * is expected between last flag and before level. >> + * >> + * @param arg log option string >> + * @return Returns a negative value if parsing the option string failed, >> + * otherwise returns 0. >> + */ >> +int av_log_set_opts(const char *arg); >> + >> +/** >> * @} >> */ >> >> diff --git a/libavutil/version.h b/libavutil/version.h >> index d3dd2df..296c24b 100644 >> --- a/libavutil/version.h >> +++ b/libavutil/version.h >> @@ -79,7 +79,7 @@ >> */ >> >> #define LIBAVUTIL_VERSION_MAJOR 56 >> -#define LIBAVUTIL_VERSION_MINOR 12 >> +#define LIBAVUTIL_VERSION_MINOR 13 >> #define LIBAVUTIL_VERSION_MICRO 100 >> >> #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ > > Seems like a step backwards. Why can't it stay in the fftools thing? When v2 of the patch was reviewed in http://ffmpeg.org/pipermail/ffmpeg-devel/2018-March/227077.html it was suggested to move the code into libavutil so that other applications can make use of it. I agree that it can be useful for command-line apps that interface with libav* to provide a loglevel option which accepts info/verbose/etc. name strings without the need to do an own string-to-level parsing. Regards, Tobias
On Thu, 29 Mar 2018 08:58:12 +0200 Tobias Rapp <t.rapp@noa-archive.com> wrote: > On 28.03.2018 17:11, wm4 wrote: > > On Wed, 28 Mar 2018 17:03:39 +0200 > > Tobias Rapp <t.rapp@noa-archive.com> wrote: > > > >> Allows to set log level and flag values from string. > >> > >> Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com> > >> --- > >> doc/APIchanges | 3 +++ > >> libavutil/log.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > >> libavutil/log.h | 16 +++++++++++ > >> libavutil/version.h | 2 +- > >> 4 files changed, 96 insertions(+), 1 deletion(-) > >> > >> diff --git a/doc/APIchanges b/doc/APIchanges > >> index 83c7a40..2d14452 100644 > >> --- a/doc/APIchanges > >> +++ b/doc/APIchanges > >> @@ -15,6 +15,9 @@ libavutil: 2017-10-21 > >> > >> API changes, most recent first: > >> > >> +2018-03-xx - xxxxxxx - lavu 56.13.100 - log.h > >> + Add av_log_set_opts(). > >> + > >> 2018-03-xx - xxxxxxx - lavc 58.16.100 - avcodec.h > >> Add FF_SUB_CHARENC_MODE_IGNORE. > >> > >> diff --git a/libavutil/log.c b/libavutil/log.c > >> index 0a99d01..af32cd6 100644 > >> --- a/libavutil/log.c > >> +++ b/libavutil/log.c > >> @@ -34,6 +34,7 @@ > >> #endif > >> #include <stdarg.h> > >> #include <stdlib.h> > >> +#include "avassert.h" > >> #include "avutil.h" > >> #include "bprint.h" > >> #include "common.h" > >> @@ -402,6 +403,81 @@ void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) > >> av_log_callback = callback; > >> } > >> > >> +int av_log_set_opts(const char *arg) > >> +{ > >> + const struct { const char *name; int level; } log_levels[] = { > >> + { "quiet" , AV_LOG_QUIET }, > >> + { "panic" , AV_LOG_PANIC }, > >> + { "fatal" , AV_LOG_FATAL }, > >> + { "error" , AV_LOG_ERROR }, > >> + { "warning", AV_LOG_WARNING }, > >> + { "info" , AV_LOG_INFO }, > >> + { "verbose", AV_LOG_VERBOSE }, > >> + { "debug" , AV_LOG_DEBUG }, > >> + { "trace" , AV_LOG_TRACE }, > >> + }; > >> + const char *token; > >> + char *tail; > >> + int flags = av_log_get_flags(); > >> + int level = av_log_get_level(); > >> + int cmd, i = 0; > >> + > >> + av_assert0(arg); > >> + while (*arg) { > >> + token = arg; > >> + if (*token == '+' || *token == '-') { > >> + cmd = *token++; > >> + } else { > >> + cmd = 0; > >> + } > >> + if (!i && !cmd) { > >> + flags = 0; /* missing relative prefix, build absolute value */ > >> + } > >> + if (!strncmp(token, "repeat", 6)) { > >> + if (cmd == '-') { > >> + flags |= AV_LOG_SKIP_REPEATED; > >> + } else { > >> + flags &= ~AV_LOG_SKIP_REPEATED; > >> + } > >> + arg = token + 6; > >> + } else if (!strncmp(token, "level", 5)) { > >> + if (cmd == '-') { > >> + flags &= ~AV_LOG_PRINT_LEVEL; > >> + } else { > >> + flags |= AV_LOG_PRINT_LEVEL; > >> + } > >> + arg = token + 5; > >> + } else { > >> + break; > >> + } > >> + i++; > >> + } > >> + if (!*arg) { > >> + goto end; > >> + } else if (*arg == '+') { > >> + arg++; > >> + } else if (!i) { > >> + flags = av_log_get_flags(); /* level value without prefix, reset flags */ > >> + } > >> + > >> + for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) { > >> + if (!strcmp(arg, log_levels[i].name)) { > >> + level = log_levels[i].level; > >> + goto end; > >> + } > >> + } > >> + > >> + level = strtol(arg, &tail, 10); > >> + if (*tail) { > >> + return -1; > >> + } > >> + > >> +end: > >> + av_log_set_flags(flags); > >> + av_log_set_level(level); > >> + return 0; > >> +} > >> + > >> static void missing_feature_sample(int sample, void *avc, const char *msg, > >> va_list argument_list) > >> { > >> diff --git a/libavutil/log.h b/libavutil/log.h > >> index d9554e6..97010f7 100644 > >> --- a/libavutil/log.h > >> +++ b/libavutil/log.h > >> @@ -356,6 +356,22 @@ void av_log_set_flags(int arg); > >> int av_log_get_flags(void); > >> > >> /** > >> + * Set log flags and level as an option string. Accepts "repeat" and "level" > >> + * flags mapped to AV_LOG_SKIP_REPEATED (inverted) and AV_LOG_PRINT_LEVEL, > >> + * followed by the log level specified either by name ("warning", "info", > >> + * "verbose", etc.) or by number. > >> + * > >> + * When flags are prefixed with "+" or "-" the change is relative to the > >> + * current flags value. When both flags and level are present a "+" separator > >> + * is expected between last flag and before level. > >> + * > >> + * @param arg log option string > >> + * @return Returns a negative value if parsing the option string failed, > >> + * otherwise returns 0. > >> + */ > >> +int av_log_set_opts(const char *arg); > >> + > >> +/** > >> * @} > >> */ > >> > >> diff --git a/libavutil/version.h b/libavutil/version.h > >> index d3dd2df..296c24b 100644 > >> --- a/libavutil/version.h > >> +++ b/libavutil/version.h > >> @@ -79,7 +79,7 @@ > >> */ > >> > >> #define LIBAVUTIL_VERSION_MAJOR 56 > >> -#define LIBAVUTIL_VERSION_MINOR 12 > >> +#define LIBAVUTIL_VERSION_MINOR 13 > >> #define LIBAVUTIL_VERSION_MICRO 100 > >> > >> #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ > > > > Seems like a step backwards. Why can't it stay in the fftools thing? > > When v2 of the patch was reviewed in > http://ffmpeg.org/pipermail/ffmpeg-devel/2018-March/227077.html it was > suggested to move the code into libavutil so that other applications can > make use of it. I agree that it can be useful for command-line apps that > interface with libav* to provide a loglevel option which accepts > info/verbose/etc. name strings without the need to do an own > string-to-level parsing. That seems completely unnecessary. Applications will have their own conventions and option parsers.
On 29.03.2018 12:58, wm4 wrote: > On Thu, 29 Mar 2018 08:58:12 +0200 > Tobias Rapp <t.rapp@noa-archive.com> wrote: > >> On 28.03.2018 17:11, wm4 wrote: >>> On Wed, 28 Mar 2018 17:03:39 +0200 >>> Tobias Rapp <t.rapp@noa-archive.com> wrote: >>> >>>> Allows to set log level and flag values from string. >>>> >>>> Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com> >>>> --- >>>> doc/APIchanges | 3 +++ >>>> libavutil/log.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ >>>> libavutil/log.h | 16 +++++++++++ >>>> libavutil/version.h | 2 +- >>>> 4 files changed, 96 insertions(+), 1 deletion(-) >>>> >>>> [...] >>> >>> Seems like a step backwards. Why can't it stay in the fftools thing? >> >> When v2 of the patch was reviewed in >> http://ffmpeg.org/pipermail/ffmpeg-devel/2018-March/227077.html it was >> suggested to move the code into libavutil so that other applications can >> make use of it. I agree that it can be useful for command-line apps that >> interface with libav* to provide a loglevel option which accepts >> info/verbose/etc. name strings without the need to do an own >> string-to-level parsing. > > That seems completely unnecessary. Applications will have their own > conventions and option parsers. In case the function is placed into fftools applications are forced to do their own thing, when it's available inside avutil applications can either use it _or_ implement an own parser. Thus I see no benefit in not having it inside avutil. Anyway: my goal still is to add support for setting AV_LOG_PRINT_LEVEL via some (ffmpeg) command-line option. If you're blocking addition to avutil and Michael accepts updating opt_loglevel() in fftools then that's also OK for me. Regards, Tobias
On Thu, 29 Mar 2018 13:47:55 +0200 Tobias Rapp <t.rapp@noa-archive.com> wrote: > On 29.03.2018 12:58, wm4 wrote: > > On Thu, 29 Mar 2018 08:58:12 +0200 > > Tobias Rapp <t.rapp@noa-archive.com> wrote: > > > >> On 28.03.2018 17:11, wm4 wrote: > >>> On Wed, 28 Mar 2018 17:03:39 +0200 > >>> Tobias Rapp <t.rapp@noa-archive.com> wrote: > >>> > >>>> Allows to set log level and flag values from string. > >>>> > >>>> Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com> > >>>> --- > >>>> doc/APIchanges | 3 +++ > >>>> libavutil/log.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > >>>> libavutil/log.h | 16 +++++++++++ > >>>> libavutil/version.h | 2 +- > >>>> 4 files changed, 96 insertions(+), 1 deletion(-) > >>>> > >>>> [...] > >>> > >>> Seems like a step backwards. Why can't it stay in the fftools thing? > >> > >> When v2 of the patch was reviewed in > >> http://ffmpeg.org/pipermail/ffmpeg-devel/2018-March/227077.html it was > >> suggested to move the code into libavutil so that other applications can > >> make use of it. I agree that it can be useful for command-line apps that > >> interface with libav* to provide a loglevel option which accepts > >> info/verbose/etc. name strings without the need to do an own > >> string-to-level parsing. > > > > That seems completely unnecessary. Applications will have their own > > conventions and option parsers. > > In case the function is placed into fftools applications are forced to > do their own thing, when it's available inside avutil applications can > either use it _or_ implement an own parser. Thus I see no benefit in not > having it inside avutil. > > Anyway: my goal still is to add support for setting AV_LOG_PRINT_LEVEL > via some (ffmpeg) command-line option. If you're blocking addition to > avutil and Michael accepts updating opt_loglevel() in fftools then > that's also OK for me. I'd like to block it, because I don't see it as a good thing that more fftools specific stuff is leaking into the generic libs. Sorry.
On Wed, Mar 28, 2018 at 05:03:39PM +0200, Tobias Rapp wrote: > Allows to set log level and flag values from string. > > Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com> > --- > doc/APIchanges | 3 +++ > libavutil/log.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > libavutil/log.h | 16 +++++++++++ > libavutil/version.h | 2 +- > 4 files changed, 96 insertions(+), 1 deletion(-) iam not intending to override anyone blocking this but as i looked at the code and it LGTM thx [...]
On 29.03.2018 20:38, Michael Niedermayer wrote: > On Wed, Mar 28, 2018 at 05:03:39PM +0200, Tobias Rapp wrote: >> Allows to set log level and flag values from string. >> >> Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com> >> --- >> doc/APIchanges | 3 +++ >> libavutil/log.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ >> libavutil/log.h | 16 +++++++++++ >> libavutil/version.h | 2 +- >> 4 files changed, 96 insertions(+), 1 deletion(-) > > iam not intending to override anyone blocking this but as i looked at the code > and it LGTM Thanks for review. Moved code into fftools/cmdutils.c and pushed to master. Will send a separate patch to ML for the missing documentation update. Regards, Tobias
On 4/3/18, Tobias Rapp <t.rapp@noa-archive.com> wrote: > On 29.03.2018 20:38, Michael Niedermayer wrote: >> On Wed, Mar 28, 2018 at 05:03:39PM +0200, Tobias Rapp wrote: >>> Allows to set log level and flag values from string. >>> >>> Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com> >>> --- >>> doc/APIchanges | 3 +++ >>> libavutil/log.c | 76 >>> +++++++++++++++++++++++++++++++++++++++++++++++++++++ >>> libavutil/log.h | 16 +++++++++++ >>> libavutil/version.h | 2 +- >>> 4 files changed, 96 insertions(+), 1 deletion(-) >> >> iam not intending to override anyone blocking this but as i looked at the >> code >> and it LGTM > > Thanks for review. Moved code into fftools/cmdutils.c and pushed to > master. Will send a separate patch to ML for the missing documentation > update. This was blocked, please revert ASAP!
On 03.04.2018 10:25, Paul B Mahol wrote: > On 4/3/18, Tobias Rapp <t.rapp@noa-archive.com> wrote: >> On 29.03.2018 20:38, Michael Niedermayer wrote: >>> On Wed, Mar 28, 2018 at 05:03:39PM +0200, Tobias Rapp wrote: >>>> Allows to set log level and flag values from string. >>>> >>>> Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com> >>>> --- >>>> doc/APIchanges | 3 +++ >>>> libavutil/log.c | 76 >>>> +++++++++++++++++++++++++++++++++++++++++++++++++++++ >>>> libavutil/log.h | 16 +++++++++++ >>>> libavutil/version.h | 2 +- >>>> 4 files changed, 96 insertions(+), 1 deletion(-) >>> >>> iam not intending to override anyone blocking this but as i looked at the >>> code >>> and it LGTM >> >> Thanks for review. Moved code into fftools/cmdutils.c and pushed to >> master. Will send a separate patch to ML for the missing documentation >> update. > > This was blocked, please revert ASAP! As far as I understood the responses from wm4 and Michael it was blocked to be added in libavutil/log.c but accepted to be added in fftools/cmdutils.c (as in version 2 of the patch it was only a suggestion to move the code to libavutil). Regards, Tobias
On Tue, 3 Apr 2018 10:25:56 +0200 Paul B Mahol <onemda@gmail.com> wrote: > On 4/3/18, Tobias Rapp <t.rapp@noa-archive.com> wrote: > > On 29.03.2018 20:38, Michael Niedermayer wrote: > >> On Wed, Mar 28, 2018 at 05:03:39PM +0200, Tobias Rapp wrote: > >>> Allows to set log level and flag values from string. > >>> > >>> Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com> > >>> --- > >>> doc/APIchanges | 3 +++ > >>> libavutil/log.c | 76 > >>> +++++++++++++++++++++++++++++++++++++++++++++++++++++ > >>> libavutil/log.h | 16 +++++++++++ > >>> libavutil/version.h | 2 +- > >>> 4 files changed, 96 insertions(+), 1 deletion(-) > >> > >> iam not intending to override anyone blocking this but as i looked at the > >> code > >> and it LGTM > > > > Thanks for review. Moved code into fftools/cmdutils.c and pushed to > > master. Will send a separate patch to ML for the missing documentation > > update. > > This was blocked, please revert ASAP! Looks fine to me. None of what was pushed was blocked.
diff --git a/doc/APIchanges b/doc/APIchanges index 83c7a40..2d14452 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2017-10-21 API changes, most recent first: +2018-03-xx - xxxxxxx - lavu 56.13.100 - log.h + Add av_log_set_opts(). + 2018-03-xx - xxxxxxx - lavc 58.16.100 - avcodec.h Add FF_SUB_CHARENC_MODE_IGNORE. diff --git a/libavutil/log.c b/libavutil/log.c index 0a99d01..af32cd6 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -34,6 +34,7 @@ #endif #include <stdarg.h> #include <stdlib.h> +#include "avassert.h" #include "avutil.h" #include "bprint.h" #include "common.h" @@ -402,6 +403,81 @@ void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) av_log_callback = callback; } +int av_log_set_opts(const char *arg) +{ + const struct { const char *name; int level; } log_levels[] = { + { "quiet" , AV_LOG_QUIET }, + { "panic" , AV_LOG_PANIC }, + { "fatal" , AV_LOG_FATAL }, + { "error" , AV_LOG_ERROR }, + { "warning", AV_LOG_WARNING }, + { "info" , AV_LOG_INFO }, + { "verbose", AV_LOG_VERBOSE }, + { "debug" , AV_LOG_DEBUG }, + { "trace" , AV_LOG_TRACE }, + }; + const char *token; + char *tail; + int flags = av_log_get_flags(); + int level = av_log_get_level(); + int cmd, i = 0; + + av_assert0(arg); + while (*arg) { + token = arg; + if (*token == '+' || *token == '-') { + cmd = *token++; + } else { + cmd = 0; + } + if (!i && !cmd) { + flags = 0; /* missing relative prefix, build absolute value */ + } + if (!strncmp(token, "repeat", 6)) { + if (cmd == '-') { + flags |= AV_LOG_SKIP_REPEATED; + } else { + flags &= ~AV_LOG_SKIP_REPEATED; + } + arg = token + 6; + } else if (!strncmp(token, "level", 5)) { + if (cmd == '-') { + flags &= ~AV_LOG_PRINT_LEVEL; + } else { + flags |= AV_LOG_PRINT_LEVEL; + } + arg = token + 5; + } else { + break; + } + i++; + } + if (!*arg) { + goto end; + } else if (*arg == '+') { + arg++; + } else if (!i) { + flags = av_log_get_flags(); /* level value without prefix, reset flags */ + } + + for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) { + if (!strcmp(arg, log_levels[i].name)) { + level = log_levels[i].level; + goto end; + } + } + + level = strtol(arg, &tail, 10); + if (*tail) { + return -1; + } + +end: + av_log_set_flags(flags); + av_log_set_level(level); + return 0; +} + static void missing_feature_sample(int sample, void *avc, const char *msg, va_list argument_list) { diff --git a/libavutil/log.h b/libavutil/log.h index d9554e6..97010f7 100644 --- a/libavutil/log.h +++ b/libavutil/log.h @@ -356,6 +356,22 @@ void av_log_set_flags(int arg); int av_log_get_flags(void); /** + * Set log flags and level as an option string. Accepts "repeat" and "level" + * flags mapped to AV_LOG_SKIP_REPEATED (inverted) and AV_LOG_PRINT_LEVEL, + * followed by the log level specified either by name ("warning", "info", + * "verbose", etc.) or by number. + * + * When flags are prefixed with "+" or "-" the change is relative to the + * current flags value. When both flags and level are present a "+" separator + * is expected between last flag and before level. + * + * @param arg log option string + * @return Returns a negative value if parsing the option string failed, + * otherwise returns 0. + */ +int av_log_set_opts(const char *arg); + +/** * @} */ diff --git a/libavutil/version.h b/libavutil/version.h index d3dd2df..296c24b 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 56 -#define LIBAVUTIL_VERSION_MINOR 12 +#define LIBAVUTIL_VERSION_MINOR 13 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
Allows to set log level and flag values from string. Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com> --- doc/APIchanges | 3 +++ libavutil/log.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ libavutil/log.h | 16 +++++++++++ libavutil/version.h | 2 +- 4 files changed, 96 insertions(+), 1 deletion(-)