以下总结三种监听Bus总线消息的方式。
1 Gst阻塞监听
[..]
bus = gst_element_get_bus (pipeline);
/*阻塞,一直等到出现error和eos消息*/
GstMessage * gst_bus_timed_pop_filtered (GstBus * bus,
GstClockTime timeout, /*超时时间*/
GstMessageType types);/*消息类型*/
[..]
2 事件
我认为这类似于Glib主循环中添加Source事件源。
[..]
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
guint gst_bus_add_watch (GstBus * bus,
GstBusFunc func, /*回调函数*/
gpointer user_data);
[..]
/*回调函数定义*/
typedef gboolean (*GstBusFunc) (GstBus * bus,
GstMessage * message,
gpointer user_data);
3 信号
连接到所需要的信号格式为"message::< type >",如
- message::error
- message::eos
- message::state-changed
- message::application
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
gst_bus_add_signal_watch(bus);
g_signal_connect(G_OBJECT(bus),
"message::state-changed",
G_CALLBACK(eos_cb), pipeline);
/*回调函数*/
static void eos_cb
(GstBus *bus, GstMessage *msg, gpointer pipeline);