GSTREAMER回调不起作用GmainContext
我有此示例应用程序,其中创建gmainContext并在创建G_Main_loop时使用它。
GstElement *pipeline;
GstBus *bus;
guint bus_watch_id;
/* init */
gst_init(&argc, &argv);
/* create pipeline, add handler */
pipeline = gst_pipeline_new("my_pipeline");
/* adds a watch for new message on our pipeline's message bus to
* the default GLib main context, which is the main context that our
* GLib main loop is attached to below
*/
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
GstElement *filesrc = gst_element_factory_make("filesrc", "filesrc");
g_assert(filesrc);
g_object_set(filesrc, "location", "sample.wav", NULL);
GstElement *udpsink = gst_element_factory_make("udpsink", "udpsink");
g_assert(udpsink);
g_object_set(udpsink, "port", 6666, NULL);
gst_bin_add_many(GST_BIN(pipeline), filesrc, udpsink, NULL);
gst_element_link_many(filesrc, udpsink, NULL);
gst_bus_add_signal_watch(bus);
g_signal_connect(bus, "message::error", G_CALLBACK(my_bus_callback), NULL);
g_signal_connect(bus, "message::eos", G_CALLBACK(my_bus_callback), NULL);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
GMainContext *context = g_main_context_new();
loop = g_main_loop_new(context, FALSE);
g_main_loop_run(loop);
/* clean up */
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
// g_source_remove (bus_watch_id);
g_main_loop_unref(loop);
这样,我没有得到任何回调。因此,g_signal_connect
不起作用。但是,如果我在创建g_main_loop
时不通过上下文,则可以按预期工作。如何使其与gmaincontext
一起使用?
I have this sample application where i create GMainContext and uses it while creating g_main_loop.
GstElement *pipeline;
GstBus *bus;
guint bus_watch_id;
/* init */
gst_init(&argc, &argv);
/* create pipeline, add handler */
pipeline = gst_pipeline_new("my_pipeline");
/* adds a watch for new message on our pipeline's message bus to
* the default GLib main context, which is the main context that our
* GLib main loop is attached to below
*/
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
GstElement *filesrc = gst_element_factory_make("filesrc", "filesrc");
g_assert(filesrc);
g_object_set(filesrc, "location", "sample.wav", NULL);
GstElement *udpsink = gst_element_factory_make("udpsink", "udpsink");
g_assert(udpsink);
g_object_set(udpsink, "port", 6666, NULL);
gst_bin_add_many(GST_BIN(pipeline), filesrc, udpsink, NULL);
gst_element_link_many(filesrc, udpsink, NULL);
gst_bus_add_signal_watch(bus);
g_signal_connect(bus, "message::error", G_CALLBACK(my_bus_callback), NULL);
g_signal_connect(bus, "message::eos", G_CALLBACK(my_bus_callback), NULL);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
GMainContext *context = g_main_context_new();
loop = g_main_loop_new(context, FALSE);
g_main_loop_run(loop);
/* clean up */
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
// g_source_remove (bus_watch_id);
g_main_loop_unref(loop);
With this, I do not get any callback. So g_signal_connect
does not work. However, if I don't pass context while creating g_main_loop
, it works as expected. How do I make it work with GMainContext
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
gst_bus_add_signal_watch
在默认主上下文上工作。g_main_context_push_thread_default
需要调用以使用新创建的上下文。gst_bus_add_signal_watch
works on default main context.g_main_context_push_thread_default
needs to be called in order to use newly created context.