pax*_*blo 9 c++ qt callback gstreamer-1.0
我有一个Qt应用程序,它在一个单独的线程中执行与GStreamer相关的东西.虽然我认为我已遵循设置信号回调的规则,但我指定的回调函数似乎没有被调用.
接下来是回调函数,它所做的只是将一些东西记录到控制台进行调试:
static gboolean Cb(GstBus *bus, GstMessage *msg, gpointer data)
{
std::cout << "g_sig, bus = " << (void*)bus
<< ", msg = " << (void*)msg
<< ", data = " << (void*)data
<< std::endl;
return TRUE;
}
Run Code Online (Sandbox Code Playgroud)
我用来启动和监控流的序列(来自IP摄像机的实时RTSP/H.264馈送)是:
GstElement *playBin = gst_parse_launch("<gstreamer pipeline>");
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(playBin));
gst_bus_add_signal_watch(bus);
g_signal_connect(bus, "message::state-changed", (GCallback)Cb, NULL);
gst_element_set_state(playBin, GST_STATE_PLAYING);
GMainLoop *mainLoop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(mainLoop);
Run Code Online (Sandbox Code Playgroud)
现在流正在播放(视频出现),所以我假设那里没有问题.但是,我希望在管道开始播放时应该发布状态更改消息.这似乎没有发生,因为我没有看到输出Cb().
我没有得到任何输出,即使我也搭上了message::eos,message::error并且message::element信号为好.
我不确定这会是一个问题但是,以防万一,上面的代码略有简化.实际上有两个流正在播放,因此上面的第一段代码发生了两次,每个playbin一次(序列对每个都是准确的,我只是看到没有必要不必要地使代码复杂化).
然后创建并运行主循环.
如上所述,我没有看到回调函数的输出,所以我的消息在哪里?
附录:对于它的价值,我也尝试过gst_bus_add_watch捕获所有消息而不是特定信号的方法,但仍然没有显示出来.我还应该提一下,作为一个Qt应用程序,我gtk_init在代码中没有- 我只是gst_init从主线程调用.
我对 gstreamer 的了解有限,我很久以前就弄乱了它。
我做了一个小测试,这似乎有效:
#include <stdio.h>
#include <gstreamer-1.0/gst/gst.h>
static gboolean Cb(GstBus *bus, GstMessage *msg, gpointer data)
{
printf("g_sig, bus = %x, msg = %s, data = %x\n",
bus,
gst_message_type_get_name(GST_MESSAGE_TYPE(msg)),
data);
return TRUE;
}
int main(int argc, char *argv[]) {
GstElement *pipeline;
GstBus *bus;
GstMessage *msg;
/* Initialize GStreamer */
gst_init (&argc, &argv);
/* Build the pipeline */
pipeline = gst_parse_launch ("playbin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm", NULL);
/* Wait until error or EOS */
bus = gst_element_get_bus (pipeline);
/* use the sync signal handler to link elements while the pipeline is still
* doing the state change */
gst_bus_set_sync_handler (bus, gst_bus_sync_signal_handler, pipeline, NULL);
g_object_connect (bus, "signal::sync-message::state-changed", G_CALLBACK (Cb), pipeline, NULL);
/* Start playing */
gst_element_set_state (pipeline, GST_STATE_PLAYING);
msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
/* Free resources */
if (msg != NULL)
gst_message_unref (msg);
gst_object_unref (bus);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是同时message::state-changed:
一条消息被张贴在公共汽车上。该信号是从添加到主循环的 GSource 发出的。只有在主循环运行时才会发出此信号。
signal::sync-message::state-changed 反而:
一条消息被张贴在公共汽车上。该信号是从发布消息的线程发出的,因此必须小心锁定。
所以同步消息也在主循环之外发出。
两个信号的文档。
| 归档时间: |
|
| 查看次数: |
1502 次 |
| 最近记录: |