首页 > 其他分享 >Gstreamer custom log

Gstreamer custom log

时间:2024-06-22 14:00:55浏览次数:10  
标签:function gstreamer gst Gstreamer GST custom debug log

Gstreamer log introduce


文章目录


一、gstreamer debug log介绍

  • gstreamer default log
    gstreamer 默认日志框架包含时间戳、进程ID、线程ID、日志等级、类型、文件名、源码行数、函数名、消息对象、消息等。示例如下:

0:00:00.868050000 1592 09F62420 WARN filesrc gstfilesrc.c:1044:gst_file_src_start: error: No such file “non-existing-file.webm”

  • gstreamer log level
    级别0:不输出任何日志信息。
    级别1:ERROR信息。
    级别2:WARNING信息。
    级别3:FIXME信息。
    级别4:INFO信息。
    级别5:DEBUG信息
    级别6:LOG信息。
    级别7:TRACE信息。
    级别8:MEMDUMP信息,最高级别日志
  • gstreamer log 设置
    使用时将GST_DEBUG设置相应级别,多模块以","隔开,支持“”通配符。
    ex: GST_DEBUG=2 或 GST_DEBUG=
    :2 打印ERRIR和WARNING级别log
    GST_DEBUG=2,audio*:6 以audio开始模块日志级别6,其他默认2.
    GST_DEBUG_FILE=/data/gst.log GST_DEBU_COLOR_MODE=off GST_DEBUG=3, v4l2*:6 日志写入文件输出,禁用色彩,v4l2开头的模块输出6等级日志,其他输出3等级日志。

二、Gstreamer debug log 初始化

1.gstreamer log初始化flow

gstreamer system log init flowGST_DEBUG_OBJECT() → GST_CAT_LEVEL_LOG() → gst_debug_log() → gst_debug_log_valist() → __log_functions
LogfuncEntry结构体中定义了log func,在执行GST_DEBUG_OBJECT()进行打印时,会指向初始化时链表中注册的debug log functions,进而执行对应functions,按照定义的格式打印log.
gstreamer 默认会注册gst_debug_log_default,即原生的log框架. 通过gst_debug_add_log_function来添加自定义log function,gst_debug_remove_log_function来移除默认的log function。

/* all registered debug handlers */
typedef struct
{
  GstLogFunction func;
  gpointer user_data;
  GDestroyNotify notify;
}
LogFuncEntry;

2.gstreamer default output log format

gstreamer_debug_log_default 位于…/gstreamer-1.0/gst/Gstinfo.c,定义日志输出格式。

#define PRINT_FMT " "PID_FMT" "PTR_FMT" %s "CAT_FMT" %s\n"
    fprintf (log_file, "%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
        pid, g_thread_self (), gst_debug_level_get_name (level),
        gst_debug_category_get_name (category), file, line, function, obj,
        gst_debug_message_get (message));
    fflush (log_file);

时间戳格式:"0:00:00.868050000"格式输出时,分,秒,纳秒。
日志等级:调用gst_debug_level_get_name(),默认输出0-9等级,可以在其中自定义等级。
类别:调用gst_debug_category_get_name(),获取日志类别,gstreamer预留了自定义类别接口。

三、Gstreamer custom log

  • using custom log category
    使用gstreamer 提供的日志系统,由gstreamer框架统一管理日志,但可以通过接口定义我们自己的类目,灵活debug。

    1. 首先需要自定义我们的log category
      GST_DEBUG_CATEGORY_STATIC (my_category);
      #define GST_CAT_DEFAULT my_category
      
    2. 在Gstreamer 初始化gst_init()之后,使用GST_DEBUG_CATEGORY_INIT(cat,name,color,description)注册一个新的类别。
      GST_DEBUG_CATEGORY_INIT (my_category, "my category", 0, "This is my very own");
      
  • add custom system log
    实际开发使用gstreamer时,有需要扩充log信息或者添加删除某些log category的需求。gstreamer 提供了接口,可以覆盖gstreamer 默认的系统log

    1. 如何自定义gstreamer system log
      在应用程序初始化前先使用该接口注册自定义log,func为自定义的log,初始化时会覆盖gstreamer_debug_log_default;user_data可指定输出到默认当前控制台或者FILE中。
      初始化之后需要移除系统默认的log func,即可按照我们自定义的log框架输出log。

      gst_debug_add_log_function ( GstLogFunction func,
                           gpointer user_data,
                           GDestroyNotify notify)
      
    2. 完整示例

      /* declare log function*/
      static void Mtk_Gst_log_func(GstDebugCategory * category,
                                             GstDebugLevel level,
                                             const gchar * file,
                                             const gchar * function,
                                             gint line,
                                             GObject * object,
                                             GstDebugMessage * message,
                                             gpointer user_data) {
         /* Add STC log Info, the print is in the same format as the kernel time */
         struct timespec time1={0,0};
         clock_gettime(CLOCK_MONOTONIC, &time1);
              
         printf("MTK_GST_LOG: [%ld.%ld][Level:%d] %s:%s:%d  %s\n",
         time1.tv_sec,time1_nsec,level, file, function, line,
         gst_debug_message_get(message));
      }
      
      int main()
      {
      ...
      /* set log function and remove the default one */
      gst_debug_add_log_function(Mtk_Gst_log_func, NULL, NULL);
      gst_debug_set_active(TRUE);
      gst_debug_set_default_threshold(GST_LEVEL_INFO);
      /* Initialize GStreamer */
      gst_init (&argc, &argv);
      /* default log function is added by gst_init, so we need remove it after that. */
      gst_debug_remove_log_function(gst_debug_log_default);
      ...
      }
      
    3. 执行结果
      MTK_GST_LOG: [STC] [log_level] File Func:line Msg


总结

本文介绍了gstreamer log的等级,如何设置不同的log level,以及自定义gstreamer log如何实现。

标签:function,gstreamer,gst,Gstreamer,GST,custom,debug,log
From: https://blog.csdn.net/Dzp1994/article/details/139748076

相关文章

  • HKCU\Environment\UserInitMprLogonScript;HKLM\Software\Microsoft\Windows NT
    HKCU\Environment\UserInitMprLogonScript: 这个键位于HKEY_CURRENT_USER(HKCU)的Environment分支下,它用于存储与当前用户环境相关的设置。UserInitMprLogonScript 键可能被设置为在用户登录时运行一个脚本或程序。这个脚本通常用于配置用户特定的环境设置或执行一些登录......
  • 【仿真建模-anylogic】Network代码解析
    Author:赵志乾Date:2024-06-22Declaration:AllRightReserved!!!1.类图2.代码解析//************************核心字段*************************//Network所属的levelprivatetransientLevellevel;//Network的绘制模式privateShapeDrawModedrawMode;//Network......
  • 【仿真建模-anylogic】INetwork相关接口说明
    Author:赵志乾Date:2024-06-22Declaration:AllRightReserved!!!1.类图2.说明    INetwork为辊道网络、路线网路的顶层接口,其组成元素有节点和路径两种,对应的接口为INode、IPath;2.1INetworkMarkupElement核心方法如下://获取标记元素所在的网络INetworkgetNetwo......
  • [转] MySQL binlog 日志自动清理及手动删除
    参考转载自mysqlbinlog日志自动清理及手动删除-景岳-博客园说明当开启mysql数据库主从时,会产生大量如mysql-bin.00000*log的文件,这会大量耗费您的硬盘空间。mysql-bin.000001mysql-bin.000002mysql-bin.000003mysql-bin.000004mysql-bin.000005…有三种解......
  • Syslog日志外发
    Syslog是一种广泛应用于网络设备、操作系统和应用程序的日志通信协议,通过收集、监控和分析Syslog日志,企业可以有效维护网络安全、故障排除和运营管理。除了内部监控,有时企业也需要将Syslog日志外发以实现更多的管理和合规需求。在实现Syslog日志外发的过程中,合适的工具如EventLog......
  • 【QCustomPlot实战系列】QCPGraph堆叠图
    将一个QCPGraph叠加到另一个QCPGraph上显示,就得到了折线堆叠图staticQCPScatterStyleGetScatterStyle(constQColor&color){QPenpen(color,2);returnQCPScatterStyle(QCPScatterStyle::ssCircle,pen,Qt::white,......
  • 【仿真建模-anylogic】ConveyorCustomStation原理解析
    Author:赵志乾Date:2024-06-19Declaration:AllRightReserved!!!1.类图2.原理解析2.1核心函数函数功能ConveyorCustomStation()无参构造函数;该类另有两个有参构造函数,但已标注为废弃;voidaddVertex(doublex,doubley)为2D多边形添加坐标点;voidonEnter(Tagent)物料进入......
  • PTA题目集7~8总结性Blog
    (1)前言题目集7,8主要涉及以下知识点,Java是一种面向对象的编程语言,需要理解类和对象的概念,如何设计和实现各种设备的类。设计控制设备类和受控设备类,理解如何通过类和对象来模拟真实世界中的设备和其行为。通过继承和多态实现设备之间的关系和行为的多样化。例如,可以将不同类型的......
  • 【Emacs Verilog mode保姆级的使用指南】
    ......
  • PS去除logo背景
    一、打开图片二、点击通道选择色差最明显的通道三、复制通道四、点击载入 五、反选ctrl+shift+i(鼠标右键亦可,然后调整下范围) 六、点击图层,复制图层(ctrl+J) (先确保图层是解锁的,右边有个小锁)七、把有背景的图层可视取消即可......