GstMultifilesink post-消息回调
GstMultifilesink post-messages callback
我想知道如何使用 post-messages=TRUE 属性 从 gstreamer multifilesink 元素获取回调?在下面的代码中,my_bus_callback 函数从未被调用。
Multifilesink 文档说:如果 "post-messages" 属性 为真,它会在写入每个缓冲区后发送一条名为 "GstMultiFileSink" 的应用程序消息。
#include <gst/gst.h>
#include <stdio.h>
#include <unistd.h>
// Compilation:
// gcc gst_messages.c -g3 -o gst_messages `pkg-config --cflags --libs gstreamer-0.10`
static GMainLoop *loop;
static gboolean
my_bus_callback (GstBus *bus,
GstMessage *message,
gpointer data)
{
printf("Got %s message\n", GST_MESSAGE_TYPE_NAME (message));
/* we want to be notified again the next time there is a message
* on the bus, so returning TRUE (FALSE means we want to stop watching
* for messages on the bus and our callback should not be called again)
*/
return TRUE;
}
// http://pastebin.com/B3QixHCX
int main(int argc, char *argv[]) {
GstBus *bus;
guint bus_watch_id;
gst_init(&argc, &argv);
GstElement *pipeline = gst_pipeline_new("looper-pipeline");
GstElement *v4l2src = gst_element_factory_make("v4l2src", "src");
GstElement *x264enc = gst_element_factory_make("x264enc", "encoder");
GstElement *mpegtsmux = gst_element_factory_make("mpegtsmux", "mpegtsmux");
GstElement *multifilesink = gst_element_factory_make("multifilesink", "multifilesink");
g_object_set(multifilesink, "next-file", 2, NULL);
g_object_set(multifilesink, "location", "%05d.ts", NULL);
g_object_set(multifilesink, "post-messages", TRUE, NULL);
gst_bin_add(GST_BIN (pipeline), v4l2src);
gst_bin_add(GST_BIN (pipeline), x264enc);
gst_bin_add(GST_BIN (pipeline), mpegtsmux);
gst_bin_add(GST_BIN (pipeline), multifilesink);
gboolean success;
success = gst_element_link(v4l2src, x264enc);
if (!success) {
g_printerr("Elements could not be linked 1.\n");
}
success = gst_element_link(x264enc, mpegtsmux);
if (!success) {
g_printerr("Elements could not be linked 2.\n");
}
success = gst_element_link(mpegtsmux, multifilesink);
if (!success) {
g_printerr("Elements could not be linked 3.\n");
}
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_signal_watch (bus);
g_signal_connect (bus, "GstMultiFileSink", G_CALLBACK (my_bus_callback), NULL);
printf("Running\n");
gst_element_set_state (pipeline, GST_STATE_PLAYING);
sleep(35);
printf("STOPPING\n");
GstMessage *msg;
gst_element_send_event(v4l2src, gst_event_new_eos()); // shut down pipeline
/* Wait until error or EOS */
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);
printf("SETTING PIPELINE TO NULL\n");
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
}
好的,我收到了关于您的代码有两处更改的消息。在你的信号上使用这个:
g_signal_connect (bus, "message::element", G_CALLBACK (my_bus_callback), NULL);
文档没有说得很清楚,但显然有不同的信号名称,比如message::eos
。您正在查找元素消息。
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-bus.html
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/section-bus-message-types.html
接下来需要更改的是添加 GMainLoop
并调用 g_main_loop_run
。这显然是推动所有消息传递的原因。
gboolean end_my_pipeline_somehow(gpointer data) {
//end the pipeline
return TRUE;
}
g_timeout_add_seconds(35, end_my_pipeline_somehow, pipeline);
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(loop);
更新
message::element
是有效信号;它允许总线监听元素发布的消息。
我想知道如何使用 post-messages=TRUE 属性 从 gstreamer multifilesink 元素获取回调?在下面的代码中,my_bus_callback 函数从未被调用。
Multifilesink 文档说:如果 "post-messages" 属性 为真,它会在写入每个缓冲区后发送一条名为 "GstMultiFileSink" 的应用程序消息。
#include <gst/gst.h>
#include <stdio.h>
#include <unistd.h>
// Compilation:
// gcc gst_messages.c -g3 -o gst_messages `pkg-config --cflags --libs gstreamer-0.10`
static GMainLoop *loop;
static gboolean
my_bus_callback (GstBus *bus,
GstMessage *message,
gpointer data)
{
printf("Got %s message\n", GST_MESSAGE_TYPE_NAME (message));
/* we want to be notified again the next time there is a message
* on the bus, so returning TRUE (FALSE means we want to stop watching
* for messages on the bus and our callback should not be called again)
*/
return TRUE;
}
// http://pastebin.com/B3QixHCX
int main(int argc, char *argv[]) {
GstBus *bus;
guint bus_watch_id;
gst_init(&argc, &argv);
GstElement *pipeline = gst_pipeline_new("looper-pipeline");
GstElement *v4l2src = gst_element_factory_make("v4l2src", "src");
GstElement *x264enc = gst_element_factory_make("x264enc", "encoder");
GstElement *mpegtsmux = gst_element_factory_make("mpegtsmux", "mpegtsmux");
GstElement *multifilesink = gst_element_factory_make("multifilesink", "multifilesink");
g_object_set(multifilesink, "next-file", 2, NULL);
g_object_set(multifilesink, "location", "%05d.ts", NULL);
g_object_set(multifilesink, "post-messages", TRUE, NULL);
gst_bin_add(GST_BIN (pipeline), v4l2src);
gst_bin_add(GST_BIN (pipeline), x264enc);
gst_bin_add(GST_BIN (pipeline), mpegtsmux);
gst_bin_add(GST_BIN (pipeline), multifilesink);
gboolean success;
success = gst_element_link(v4l2src, x264enc);
if (!success) {
g_printerr("Elements could not be linked 1.\n");
}
success = gst_element_link(x264enc, mpegtsmux);
if (!success) {
g_printerr("Elements could not be linked 2.\n");
}
success = gst_element_link(mpegtsmux, multifilesink);
if (!success) {
g_printerr("Elements could not be linked 3.\n");
}
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_signal_watch (bus);
g_signal_connect (bus, "GstMultiFileSink", G_CALLBACK (my_bus_callback), NULL);
printf("Running\n");
gst_element_set_state (pipeline, GST_STATE_PLAYING);
sleep(35);
printf("STOPPING\n");
GstMessage *msg;
gst_element_send_event(v4l2src, gst_event_new_eos()); // shut down pipeline
/* Wait until error or EOS */
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);
printf("SETTING PIPELINE TO NULL\n");
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
}
好的,我收到了关于您的代码有两处更改的消息。在你的信号上使用这个:
g_signal_connect (bus, "message::element", G_CALLBACK (my_bus_callback), NULL);
文档没有说得很清楚,但显然有不同的信号名称,比如message::eos
。您正在查找元素消息。
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-bus.html
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/section-bus-message-types.html
接下来需要更改的是添加 GMainLoop
并调用 g_main_loop_run
。这显然是推动所有消息传递的原因。
gboolean end_my_pipeline_somehow(gpointer data) {
//end the pipeline
return TRUE;
}
g_timeout_add_seconds(35, end_my_pipeline_somehow, pipeline);
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(loop);
更新
message::element
是有效信号;它允许总线监听元素发布的消息。