需要复习的:FFmpeg源代码简单分析:日志输出系统(av_log()等)

来源:互联网 发布:厂牌制作软件 编辑:程序博客网 时间:2024/06/04 18:17

http://blog.csdn.net/leixiaohua1020/article/details/44243155

征文 | 从高考,到程序员      CSDN日报20170620——《找一个好工作,谈一份好薪水》      6 月书讯 | 最受欢迎的 SQL 入门书重磅升级
 

FFmpeg源代码简单分析:日志输出系统(av_log()等)

标签: FFmpeg源代码日志logav_log
 18324人阅读 评论(2) 收藏 举报
本文章已收录于: 
 直播技术知识库
 分类:

目录(?)[+]

=====================================================

FFmpeg的库函数源代码分析文章列表:

【架构图】

FFmpeg源代码结构图 - 解码

FFmpeg源代码结构图 - 编码

【通用】

FFmpeg 源代码简单分析:av_register_all()

FFmpeg 源代码简单分析:avcodec_register_all()

FFmpeg 源代码简单分析:内存的分配和释放(av_malloc()av_free()等)

FFmpeg 源代码简单分析:常见结构体的初始化和销毁(AVFormatContextAVFrame等)

FFmpeg 源代码简单分析:avio_open2()

FFmpeg 源代码简单分析:av_find_decoder()av_find_encoder()

FFmpeg 源代码简单分析:avcodec_open2()

FFmpeg 源代码简单分析:avcodec_close()

【解码】

图解FFMPEG打开媒体的函数avformat_open_input

FFmpeg 源代码简单分析:avformat_open_input()

FFmpeg 源代码简单分析:avformat_find_stream_info()

FFmpeg 源代码简单分析:av_read_frame()

FFmpeg 源代码简单分析:avcodec_decode_video2()

FFmpeg 源代码简单分析:avformat_close_input()

【编码】

FFmpeg 源代码简单分析:avformat_alloc_output_context2()

FFmpeg 源代码简单分析:avformat_write_header()

FFmpeg 源代码简单分析:avcodec_encode_video()

FFmpeg 源代码简单分析:av_write_frame()

FFmpeg 源代码简单分析:av_write_trailer()

【其它】

FFmpeg源代码简单分析:日志输出系统(av_log()等)

FFmpeg源代码简单分析:结构体成员管理系统-AVClass

FFmpeg源代码简单分析:结构体成员管理系统-AVOption

FFmpeg源代码简单分析:libswscalesws_getContext()

FFmpeg源代码简单分析:libswscalesws_scale()

FFmpeg源代码简单分析:libavdeviceavdevice_register_all()

FFmpeg源代码简单分析:libavdevicegdigrab

【脚本】

FFmpeg源代码简单分析:makefile

FFmpeg源代码简单分析:configure

【H.264】

FFmpegH.264解码器源代码简单分析:概述

=====================================================


本文分析一下FFmpeg的日志(Log)输出系统的源代码。日志输出部分的核心函数只有一个:av_log()。使用av_log()在控制台输出日志的效果如下图所示。


函数调用结构图

FFmpeg日志输出系统的函数调用结构图如图所示。


av_log()

av_log()是FFmpeg中输出日志的函数。随便打开一个FFmpeg的源代码文件,就会发现其中遍布着av_log()函数。一般情况下FFmpeg类库的源代码中是不允许使用printf()这种的函数的,所有的输出一律使用av_log()。
av_log()的声明位于libavutil\log.h,如下所示。
[cpp] view plain copy
  1. /** 
  2.  * Send the specified message to the log if the level is less than or equal 
  3.  * to the current av_log_level. By default, all logging messages are sent to 
  4.  * stderr. This behavior can be altered by setting a different logging callback 
  5.  * function. 
  6.  * @see av_log_set_callback 
  7.  * 
  8.  * @param avcl A pointer to an arbitrary struct of which the first field is a 
  9.  *        pointer to an AVClass struct. 
  10.  * @param level The importance level of the message expressed using a @ref 
  11.  *        lavu_log_constants "Logging Constant". 
  12.  * @param fmt The format string (printf-compatible) that specifies how 
  13.  *        subsequent arguments are converted to output. 
  14.  */  
  15. void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);  

这个函数的声明有两个地方比较特殊:

(1)函数最后一个参数是“…”。
在C语言中,在函数参数数量不确定的情况下使用“…”来代表参数。例如printf()的原型定义如下
[cpp] view plain copy
  1. int printf (const char*, ...);  

后文中对此再作详细分析。

(2)它的声明后面有一个av_printf_format(3, 4)。有关这个地方的左右还没有深入研究,网上资料中说它的作用是按照printf()的格式检查av_log()的格式。
av_log()每个字段的含义如下:
avcl:指定一个包含AVClass的结构体。
level:log的级别
fmt:和printf()一样。
由此可见,av_log()和printf()的不同主要在于前面多了两个参数。其中第一个参数指定该log所属的结构体,例如AVFormatContext、AVCodecContext等等。第二个参数指定log的级别,源代码中定义了如下几个级别。
[cpp] view plain copy
  1. /** 
  2.  * Print no output. 
  3.  */  
  4. #define AV_LOG_QUIET    -8  
  5.   
  6. /** 
  7.  * Something went really wrong and we will crash now. 
  8.  */  
  9. #define AV_LOG_PANIC     0  
  10.   
  11. /** 
  12.  * Something went wrong and recovery is not possible. 
  13.  * For example, no header was found for a format which depends 
  14.  * on headers or an illegal combination of parameters is used. 
  15.  */  
  16. #define AV_LOG_FATAL     8  
  17.   
  18. /** 
  19.  * Something went wrong and cannot losslessly be recovered. 
  20.  * However, not all future data is affected. 
  21.  */  
  22. #define AV_LOG_ERROR    16  
  23.   
  24. /** 
  25.  * Something somehow does not look correct. This may or may not 
  26.  * lead to problems. An example would be the use of '-vstrict -2'. 
  27.  */  
  28. #define AV_LOG_WARNING  24  
  29.   
  30. /** 
  31.  * Standard information. 
  32.  */  
  33. #define AV_LOG_INFO     32  
  34.   
  35. /** 
  36.  * Detailed information. 
  37.  */  
  38. #define AV_LOG_VERBOSE  40  
  39.   
  40. /** 
  41.  * Stuff which is only useful for libav* developers. 
  42.  */  
  43. #define AV_LOG_DEBUG    48  

从定义中可以看出来,随着严重程度逐渐下降,一共包含如下级别:AV_LOG_PANIC,AV_LOG_FATAL,AV_LOG_ERROR,AV_LOG_WARNING,AV_LOG_INFO,AV_LOG_VERBOSE,AV_LOG_DEBUG。每个级别定义的数值代表了严重程度,数值越小代表越严重。默认的级别是AV_LOG_INFO。此外,还有一个级别不输出任何信息,即AV_LOG_QUIET。

当前系统存在着一个“Log级别”。所有严重程度高于该级别的Log信息都会输出出来。例如当前的Log级别是AV_LOG_WARNING,则会输出AV_LOG_PANIC,AV_LOG_FATAL,AV_LOG_ERROR,AV_LOG_WARNING级别的信息,而不会输出AV_LOG_INFO级别的信息。可以通过av_log_get_level()获得当前Log的级别,通过另一个函数av_log_set_level()设置当前的Log级别。


av_log_get_level(), av_log_set_level()<

阅读全文
0 0
原创粉丝点击