当前位置:  开发笔记 > 编程语言 > 正文

GstMultifilesink消息后回调

如何解决《GstMultifilesink消息后回调》经验,为你挑选了1个好方法。

我想知道如何使用post-messages = TRUE属性从gstreamer multifilesink元素获取回调?在下面的代码中,永不调用my_bus_callback函数。

Multifilesink文档说:如果“ post-messages”属性为TRUE,则在写入每个缓冲区后会发送名为“ GstMultiFileSink”的应用程序消息。

http://www.freedesktop.org/software/gstreamer-sdk/data/docs/2012.5/gst-plugins-good-plugins-0.10/gst-plugins-good-plugins-multifilesink.html#GstMultiFileSink--帖子后消息

#include 
#include 
#include 

// 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);
}

mpr.. 5

好的,我收到消息,但对您的代码进行了两次更改。在您的信号上使用此:

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是有效信号;它允许总线监听元素发布的消息。



1> mpr..:

好的,我收到消息,但对您的代码进行了两次更改。在您的信号上使用此:

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是有效信号;它允许总线监听元素发布的消息。

推荐阅读
殉情放开那只小兔子
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有