[GStreamer] GStreamer日志控制

The debug log

GStreamer and its plugins are full of debug traces, this is, places in the code where a particularly interesting piece of information is printed to the console, along with time stamping, process, category, source code file, function and element information.

The debug output is controlled with the GST_DEBUG environment variable. Here’s an example with 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"

As you can see, this is quite a bit of information. In fact, the GStreamer debug log is so verbose, that when fully enabled it can render applications unresponsive (due to the console scrolling) or fill up megabytes of text files (when redirected to a file). For this reason, the logs are categorized, and you seldom need to enable all categories at once.

The first category is the Debug Level, which is a number specifying the amount of desired output:

| # | 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.           |
+------------------------------------------------------------------------------+

To enable debug output, set the GST_DEBUG environment variable to the desired debug level. All levels below that will also be shown (i.e., if you set GST_DEBUG=2, you will get both ERROR and WARNING messages).

Furthermore, each plugin or part of the GStreamer defines its own category, so you can specify a debug level for each individual category. For example, GST_DEBUG=2,audiotestsrc:6, will use Debug Level 6 for the audiotestsrc element, and 2 for all the others.

The GST_DEBUG environment variable, then, is a comma-separated list of category:level pairs, with an optional level at the beginning, representing the default debug level for all categories.

The '*' wildcard is also available. For example GST_DEBUG=2,audio*:6 will use Debug Level 5 for all categories starting with the word audioGST_DEBUG=*:2 is equivalent to GST_DEBUG=2.

Use gst-launch-1.0 --gst-debug-help to obtain the list of all registered categories. Bear in mind that each plugin registers its own categories, so, when installing or removing plugins, this list can change.

Use GST_DEBUG when the error information posted on the GStreamer bus does not help you nail down a problem. It is common practice to redirect the output log to a file, and then examine it later, searching for specific messages.

GStreamer allows for custom debugging information handlers but when using the default one, the content of each line in the debug output looks like:

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

And this is how the information formatted:

| 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.                                       |
+------------------------------------------------------------------------------+

Adding your own debug information

In the parts of your code that interact with GStreamer, it is interesting to use GStreamer’s debugging facilities. In this way, you have all debug output in the same file and the temporal relationship between different messages is preserved.

To do so, use the GST_ERROR()GST_WARNING()GST_INFO()GST_LOG() and GST_DEBUG() macros. They accept the same parameters as printf, and they use the default category (default will be shown as the Debug category in the output log).

To change the category to something more meaningful, add these two lines at the top of your code:

GST_DEBUG_CATEGORY_STATIC (my_category);
#define GST_CAT_DEFAULT my_category

And then this one after you have initialized GStreamer with gst_init():

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

This registers a new category (this is, for the duration of your application: it is not stored in any file), and sets it as the default category for your code. See the documentation for GST_DEBUG_CATEGORY_INIT().

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
gstreamer是一个用于处理多媒体数据的框架,它提供了一系列的插件来实现音视频数据的采集、转换、编解码、过滤、显示等功能。如果需要实现特定的功能,我们可以使用gstreamer插件开发扩展gstreamer的功能。 首先,我们需要了解gstreamer插件的类型。gstreamer插件主要分为元件插件(element plug-in)和扩展插件(extension plug-in)两种。 元件插件主要用于实现音视频数据的处理,如采集、解码、过滤、转换等。而扩展插件则用于提供其他不属于元件插件的功能,如sink、source、codec、protocol等。 其次,我们需要了解gstreamer插件的开发步骤。在开发过程中,我们需要先基于gstreamer提供的开发库进行开发。开发的过程中需要实现插件的指定功能,可以通过编写C/C++代码的方式实现。对于元件插件,需要实现对应的gst_element_class结构体; 对于扩展插件,需要实现对应的GstPlugin结构体。完成插件的开发后,通过编译、安装等步骤将插件集成到gstreamer中。 最后,我们需要注意一些开发细节。在开发插件时,需要考虑插件的性能、稳定性、易用性等方面。需要注意内存泄漏等问题,以及错误处理和日志输出等,方便调试和排查问题。 总之,gstreamer插件开发是一项有挑战的工作,需要我们对gstreamer的内部原理和机制有较深的了解。如果能够熟练掌握gstreamer的开发技巧和方法,可以大大扩展其功能和适用范围。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值