GStreamer——教程——基础教程11:Debugging tools

基础教程11:调试工具

目标

有时候事情不会像预期的那样发展,从总线(如果有)检索到的错误消息并没有提供足够的信息。幸运的是,GStreamer附带了大量的调试信息,通常可以提示问题可能是什么。本教程展示了:

  • 如何从GStreamer获取更多调试信息。

  • 如何将您自己的调试信息打印到GStreamer日志中。

  • 如何获取管道图

打印调试信息

调试日志

GStreamer和它的插件充满了调试痕迹,也就是说,在代码中有一条特别有趣的信息被打印到控制台,以及时间戳、进程、类别、源代码文件、函数和元素信息。

调试输出由GST_DEBUG环境控制变量。这是一个GST_DEBUG=2的例子:

0:00:00.868050000  1592   09F62420 WARN                 filesrc gstfilesrc.c:1044:gst_file_src_start:<filesrc0> error: No such file "non-existing-file.webm"

如您所见,这是相当多的信息。实际上,GStreamer调试日志非常冗长,当完全启用时,它可能会导致应用程序无响应(由于控制台滚动)或填满数兆字节的文本文件(当重定向到文件时)。出于这个原因,日志被分类,您很少需要同时启用所有类别。
第一个类别是调试级别,它是一个数字,指定所需输出的数量:

| # | Name    | Description                                                    |
|---|---------|----------------------------------------------------------------|
| 0 | none    | No debug information is output.                                |
| 1 | ERROR   | Logs all fatal errors. These are errors that do not allow the  |
|   |         | core or elements to perform the requested action. The          |
|   |         | application can still recover if programmed to handle the      |
|   |         | conditions that triggered the error.                           |
| 2 | WARNING | Logs all warnings. Typically these are non-fatal, but          |
|   |         | user-visible problems are expected to happen.                  |
| 3 | FIXME   | Logs all "fixme" messages. Those typically that a codepath that|
|   |         | is known to be incomplete has been triggered. It may work in   |
|   |         | most cases, but may cause problems in specific instances.      |
| 4 | INFO    | Logs all informational messages. These are typically used for  |
|   |         | events in the system that only happen once, or are important   |
|   |         | and rare enough to be logged at this level.                    |
| 5 | DEBUG   | Logs all debug messages. These are general debug messages for  |
|   |         | events that happen only a limited number of times during an    |
|   |         | object's lifetime; these include setup, teardown, change of    |
|   |         | parameters, etc.                                               |
| 6 | LOG     | Logs all log messages. These are messages for events that      |
|   |         | happen repeatedly during an object's lifetime; these include   |
|   |         | streaming and steady-state conditions. This is used for log    |
|   |         | messages that happen on every buffer in an element for example.|
| 7 | TRACE   | Logs all trace messages. Those are message that happen very    |
|   |         | very often. This is for example is each time the reference     |
|   |         | count of a GstMiniObject, such as a GstBuffer or GstEvent, is  |
|   |         | modified.                                                      |
| 9 | MEMDUMP | Logs all memory dump messages. This is the heaviest logging and|
|   |         | may include dumping the content of blocks of memory.           |
+------------------------------------------------------------------------------+

要启用调试输出,将GST_DEBUG环境变量设置为所需的调试级别。低于该级别的所有级别也将显示(即,如果您将GST_DEBUG设置为2,您将同时获得ERROR和WARNING消息)。
此外,每个插件或GStreamer的一部分都定义了自己的类别,因此您可以为每个单独的类别指定一个调试级别。例如,GST_DEBUG=2,audiotestsrc:6,将为audiotestsrc元素使用调试级别6,其他所有元素使用2。
然后,GST_DEBUG环境变量是一个逗号分隔的类别:级别对列表,可选级别位于开头,表示所有类别的默认调试级别。
'*'通配符也是可用的。例如,GST_DEBUG=2,audio*:6将对所有以单词audio开头的类别使用调试级别6。GST_DEBUG=*:2等同于GST_DEBUG=2。
使用gst-launch-1.0 --gst-debug-help获取所有已注册类别的列表。请记住,每个插件都会注册自己的类别,因此,在安装或删除插件时,此列表可能会发生变化。
当GStreamer总线上发布的错误信息无法帮助您确定问题时,请使用GST_DEBUG。通常的做法是将输出日志重定向到文件,然后在以后检查它,搜索特定的消息。
GStreamer允许自定义调试信息处理程序,但在使用默认处理程序时,调试输出中每行的内容如下所示:

0:00:00.868050000  1592   09F62420 WARN                 filesrc gstfilesrc.c:1044:gst_file_src_start:<filesrc0> error: No such file "non-existing-file.webm"

这是信息的格式:

| Example          | Explained                                                 |
|------------------|-----------------------------------------------------------|
|0:00:00.868050000 | Time stamp in HH:MM:SS.sssssssss format since the start of|
|                  | the program.                                              |
|1592              | Process ID from which the message was issued. Useful when |
|                  | your problem involves multiple processes.                 |
|09F62420          | Thread ID from which the message was issued. Useful when  |
|                  | your problem involves multiple threads.                   |
|WARN              | Debug level of the message.                               |
|filesrc           | Debug Category of the message.                            |
|gstfilesrc.c:1044 | Source file and line in the GStreamer source code where   |
|                  | this message was issued.                                  |
|gst_file_src_start| Function that issued the message.                         |
|<filesrc0>        | Name of the object that issued the message. It can be an  |
|                  | element, a pad, or something else. Useful when you have   |
|                  | multiple elements of the same kind and need to distinguish|
|                  | among them. Naming your elements with the name property   |
|                  | makes this debug output more readable but GStreamer       |
|                  | assigns each new element a unique name by default.        |
| error: No such   |                                                           |
| file ....        | The actual message.                                       |
+------------------------------------------------------------------------------+

添加您自己的调试信息

在与GStreamer交互的代码部分中,使用GStreamer的调试工具很有趣。这样,您可以在同一个文件中获得所有调试输出,并且保留不同消息之间的时间关系。

为此,请使用GST_ERROR()GST_WARNING()GST_INFO()、 GST_LOG()GST_DEBUG()宏。它们接受与 printf,它们使用default类别(default将显示 作为输出日志中的调试类别)。

要将类别更改为更有意义的类别,请在代码顶部添加以下两行:

GST_DEBUG_CATEGORY_STATIC (my_category);
#define GST_CAT_DEFAULT my_category

然后这个在你初始化GStreamer之后 gst_init()

GST_DEBUG_CATEGORY_INIT (my_category, "my category", 0, "This is my very own");

这注册了一个新的类别(在您的应用程序期间:它不会存储在任何文件中),并将其设置为代码的默认类别。请参阅GST_DEBUG_CATEGORY_INIT()的文档。

获取管道图

对于管道开始变得过大而您失去对连接情况的跟踪的情况,GStreamer具有输出图形文件的功能。这些是.dot文件,可以使用GraphViz等免费程序读取,描述了您的管道的拓扑结构以及每个链接中协商的caps。
当使用all-in-one元素(如playbin或uridecodebin)时,这也非常方便,它们会在其中实例化多个元素。使用.dot文件了解它们在内部创建了什么管道(并在此过程中学习一些GStreamer知识)。
要获取.dot文件,只需将GST_DEBUG_DUMP_DOT_DIR环境变量设置为指向您希望放置文件的文件夹。gst-launch-1.0将在每个状态更改时创建一个.dot文件,因此您可以查看caps协商的演变。取消设置该变量将禁用此功能。在您的应用程序中,您可以使用GST_DEBUG_BIN_TO_DOT_FILE()和GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS()宏根据您的需要生成.dot文件。
这里有一个playbin生成的管道示例。它非常复杂,因为playbin可以处理许多不同的情况:您的手动管道通常不需要这么长。如果您的手动管道开始变得非常大,请考虑使用playbin

要下载完整尺寸的图片,请使用此页面顶部的附件链接(https://gstreamer.freedesktop.org/documentation/tutorials/basic/images/playbin.png 它是paperclip icon)。

结论

本教程显示:

  • 如何使用GST_DEBUG环境变量从GStreamer获取更多调试信息。
  • 如何使用GST_ERROR()宏及其相关函数将您自己的调试信息打印到GStreamer日志中。
  • 如何使用GST_DEBUG_DUMP_DOT_DIR环境变量获取管道图。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值