0
点赞
收藏
分享

微信扫一扫

[GStreamer] Bus && Message


Bus 里的 message 有两种被消费的方法:同步轮训返回,异步回调返回。

同步轮训返回:

使用 gst_bus_timed_pop_filtered 设置超时阻塞读取bus里的message,超时或者感兴趣的message被读到时函数返回。

异步回调返回:

使用gst_bus_add_signal_watch激活message信号上报机制,此函数调用后,每当有message进入bus,都会触发一个对应的 glib 信号,如果使用g_signal_connect设置了信号处理函数,那么此函数会被当做回掉函数被调用。

这种方法要求必须有glib mainloop存在,且回调函数的运行线程在mainloop的线程中

使用如下方法创建 glib mainloop:

  loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);

如果在loop创建和运行之前就有message被送入了bus,那么激活loop之后这些message也会被立刻处理,不会出现丢弃的情况。

Build-in Message Type:

  • Error, warning and information notifications: those are used by elements if a message should be shown to the user about the state of the pipeline. Error messages are fatal and terminate the data-passing. The error should be repaired to resume pipeline activity. Warnings are not fatal, but imply a problem nevertheless. Information messages are for non-problem notifications. All those messages contain a​​GError​​ with the main error type and message, and optionally a debug string. Both can be extracted using ​​gst_message_parse_error()​​, ​​_parse_warning ()​​ and ​​_parse_info ()​​. Both error and debug strings should be freed after use.
  • End-of-stream notification: this is emitted when the stream has ended. The state of the pipeline will not change, but further media handling will stall. Applications can use this to skip to the next song in their playlist. After end-of-stream, it is also possible to seek back in the stream. Playback will then continue automatically. This message has no specific arguments.
  • Tags: emitted when metadata was found in the stream. This can be emitted multiple times for a pipeline (e.g. once for descriptive metadata such as artist name or song title, and another one for stream-information, such as samplerate and bitrate). Applications should cache metadata internally.​​gst_message_parse_tag()​​ should be used to parse the taglist, which should be ​​gst_tag_list_unref ()​​'ed when no longer needed.
  • State-changes: emitted after a successful state change.​​gst_message_parse_state_changed ()​​ can be used to parse the old and new state of this transition.
  • Buffering: emitted during caching of network-streams. One can manually extract the progress (in percent) from the message by extracting the “buffer-percent” property from the structure returned by​​gst_message_get_structure()​​. See also ​​Buffering​​
  • Element messages: these are special messages that are unique to certain elements and usually represent additional features. The element's documentation should mention in detail which element messages a particular element may send. As an example, the 'qtdemux' QuickTime demuxer element may send a 'redirect' element message on certain occasions if the stream contains a redirect instruction.
  • Application-specific messages: any information on those can be extracted by getting the message structure (see above) and reading its fields. Usually these messages can safely be ignored.
    Application messages are primarily meant for internal use in applications in case the application needs to marshal information from some thread into the main thread. This is particularly useful when the application is making use of element signals (as those signals will be emitted in the context of the streaming thread).
举报

相关推荐

0 条评论