[vlc-devel] [PATCH 2/2] libavutil: set verbosity based on VLC own verbosity

Jean-Baptiste Kempf jb at videolan.org
Wed Dec 18 20:18:01 CET 2013


I like the idea, but didn't we have some thread-safety issues for logs
from libav/FFmpeg ?

Else, LGTM.

On 18 Dec, Rafaël Carré wrote :
> ---
>  modules/access/avio.c            |  4 ++--
>  modules/codec/avcodec/avcodec.c  |  2 +-
>  modules/codec/avcodec/avcommon.h | 32 ++++++++++++++++++++++++++++++--
>  modules/codec/avcodec/encoder.c  |  2 +-
>  modules/demux/avformat/demux.c   |  2 +-
>  modules/demux/avformat/mux.c     |  2 +-
>  6 files changed, 36 insertions(+), 8 deletions(-)
> 
> diff --git a/modules/access/avio.c b/modules/access/avio.c
> index 47dc34a..6b2276d 100644
> --- a/modules/access/avio.c
> +++ b/modules/access/avio.c
> @@ -140,7 +140,7 @@ int OpenAvio(vlc_object_t *object)
>      }
>  
>      /* */
> -    vlc_init_avformat();
> +    vlc_init_avformat(object);
>  
>      int ret;
>  #if LIBAVFORMAT_VERSION_MAJOR < 54
> @@ -224,7 +224,7 @@ int OutOpenAvio(vlc_object_t *object)
>      sys->context = NULL;
>  
>      /* */
> -    vlc_init_avformat();
> +    vlc_init_avformat(object);
>  
>      if (!access->psz_path)
>          goto error;
> diff --git a/modules/codec/avcodec/avcodec.c b/modules/codec/avcodec/avcodec.c
> index d403202..9ce9221 100644
> --- a/modules/codec/avcodec/avcodec.c
> +++ b/modules/codec/avcodec/avcodec.c
> @@ -269,7 +269,7 @@ static int OpenDecoder( vlc_object_t *p_this )
>      }
>  
>      /* Initialization must be done before avcodec_find_decoder() */
> -    vlc_init_avcodec();
> +    vlc_init_avcodec(p_this);
>  
>      /* *** ask ffmpeg for a decoder *** */
>      char *psz_decoder = var_CreateGetString( p_this, "avcodec-codec" );
> diff --git a/modules/codec/avcodec/avcommon.h b/modules/codec/avcodec/avcommon.h
> index 293755b..e03bc41 100644
> --- a/modules/codec/avcodec/avcommon.h
> +++ b/modules/codec/avcodec/avcommon.h
> @@ -40,6 +40,7 @@
>  #ifdef HAVE_LIBAVUTIL_AVUTIL_H
>  # include <libavutil/avutil.h>
>  # include <libavutil/dict.h>
> +# include <libavutil/log.h>
>  
>  #define AV_OPTIONS_TEXT     "Advanced options"
>  #define AV_OPTIONS_LONGTEXT "Advanced options, in the form {opt=val,opt2=val2}."
> @@ -58,16 +59,41 @@ static inline AVDictionary *vlc_av_get_options(const char *psz_opts)
>      }
>      return options;
>  }
> +
> +static inline void vlc_init_avutil(vlc_object_t *obj)
> +{
> +    int level = AV_LOG_QUIET;
> +
> +    if (!var_InheritBool(obj, "quiet")) {
> +        int64_t verbose = var_InheritInteger(obj, "verbose");
> +        if (verbose >= 0) switch(verbose + VLC_MSG_ERR) {
> +        case VLC_MSG_ERR:
> +            level = AV_LOG_ERROR;
> +            break;
> +        case VLC_MSG_WARN:
> +            level = AV_LOG_WARNING;
> +            break;
> +        case VLC_MSG_DBG:
> +            level = AV_LOG_DEBUG;
> +        default:
> +            break;
> +        }
> +    }
> +
> +    av_log_set_level(level);
> +}
>  #endif
>  
>  unsigned GetVlcDspMask( void );
>  
>  #ifdef HAVE_LIBAVFORMAT_AVFORMAT_H
>  # include <libavformat/avformat.h>
> -static inline void vlc_init_avformat(void)
> +static inline void vlc_init_avformat(vlc_object_t *obj)
>  {
>      vlc_avcodec_lock();
>  
> +    vlc_init_avutil(obj);
> +
>  #if LIBAVUTIL_VERSION_CHECK(51, 25, 0, 42, 100)
>      av_set_cpu_flags_mask( INT_MAX & ~GetVlcDspMask() );
>  #endif
> @@ -80,10 +106,12 @@ static inline void vlc_init_avformat(void)
>  
>  #ifdef HAVE_LIBAVCODEC_AVCODEC_H
>  # include <libavcodec/avcodec.h>
> -static inline void vlc_init_avcodec(void)
> +static inline void vlc_init_avcodec(vlc_object_t *obj)
>  {
>      vlc_avcodec_lock();
>  
> +    vlc_init_avutil(obj);
> +
>  #if LIBAVCODEC_VERSION_MAJOR < 54
>      avcodec_init();
>  #endif
> diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
> index 5bc9d15..8203fe6 100644
> --- a/modules/codec/avcodec/encoder.c
> +++ b/modules/codec/avcodec/encoder.c
> @@ -216,7 +216,7 @@ int OpenEncoder( vlc_object_t *p_this )
>      char *psz_val;
>  
>      /* Initialization must be done before avcodec_find_encoder() */
> -    vlc_init_avcodec();
> +    vlc_init_avcodec(p_this);
>  
>      config_ChainParse( p_enc, ENC_CFG_PREFIX, ppsz_enc_options, p_enc->p_cfg );
>  
> diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
> index e340281..501003d 100644
> --- a/modules/demux/avformat/demux.c
> +++ b/modules/demux/avformat/demux.c
> @@ -129,7 +129,7 @@ int OpenDemux( vlc_object_t *p_this )
>      }
>      stream_Control( p_demux->s, STREAM_CAN_SEEK, &b_can_seek );
>  
> -    vlc_init_avformat();
> +    vlc_init_avformat(p_this);
>  
>      char *psz_format = var_InheritString( p_this, "avformat-format" );
>      if( psz_format )
> diff --git a/modules/demux/avformat/mux.c b/modules/demux/avformat/mux.c
> index c3361ee..c422492 100644
> --- a/modules/demux/avformat/mux.c
> +++ b/modules/demux/avformat/mux.c
> @@ -83,7 +83,7 @@ int OpenMux( vlc_object_t *p_this )
>      sout_mux_sys_t *p_sys;
>      char *psz_mux;
>  
> -    vlc_init_avformat();
> +    vlc_init_avformat(p_this);
>  
>      config_ChainParse( p_mux, "sout-avformat-", ppsz_mux_options, p_mux->p_cfg );
>  
> -- 
> 1.8.5.2
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel

-- 
With my kindest regards,

-- 
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device



More information about the vlc-devel mailing list