简体   繁体   English

C++ 中的 GStreamer 管道

[英]GStreamer pipeline in C++

I have a working GStreamer-1.0 pipeline in terminal and I'm trying to replicate it in code using GStreamer 1.0 on Mac/Xcode.我在终端中有一个可用的 GStreamer-1.0 管道,我试图在 Mac/Xcode 上使用 GStreamer 1.0 在代码中复制它。

My sending pipeline:我的发送管道:

gst-launch-1.0 videotestsrc ! videoconvert ! x264enc ! rtph264pay config-interval=1 ! udpsink host=127.0.0.1 port=5000

My receiving pipeline:我的接收管道:

gst-launch-1.0 -vvv udpsrc port=5000 caps="application/x-rtp" ! rtph264depay ! avdec_h264 ! videoconvert ! xvimagesink

This can also by played back in VLC with the following SDP file:这也可以通过以下 SDP 文件在 VLC 中播放:

v=0
m=video 5000 RTP/AVP 96
c=IN IP4 127.0.0.1
a=rtpmap:96 H264/90000

I've created the following code to replicate the aforementioned but the problem is that the receiving pipeline doesn't display anything while running this code.我创建了以下代码来复制上述代码,但问题是接收管道在运行此代码时不显示任何内容。 The code does send packets to the network according to the Xcode debug console.该代码确实根据 Xcode 调试控制台将数据包发送到网络。

gint
main (gint   argc,
      gchar *argv[])
{
    GstElement *pipeline, *videosrc, *conv,*enc, *pay, *udp;

    // init GStreamer
    gst_init (&argc, &argv);
    loop = g_main_loop_new (NULL, FALSE);

    // setup pipeline
    pipeline = gst_pipeline_new ("pipeline");

    videosrc = gst_element_factory_make ("videotestsrc", "source");

    conv = gst_element_factory_make ("videoconvert", "conv");

    enc = gst_element_factory_make("x264enc", "enc");

    pay = gst_element_factory_make("rtph264pay", "pay");
    g_object_set(G_OBJECT(pay), "config-interval", 1, NULL);

    udp = gst_element_factory_make("udpsink", "udp");
    g_object_set(G_OBJECT(udp), "host", "127.0.0.1", NULL);
    g_object_set(G_OBJECT(udp), "port", "5000", NULL);

    gst_bin_add_many (GST_BIN (pipeline), videosrc, conv, enc, pay, udp, NULL);

    if (gst_element_link_many (videosrc, conv, enc, pay, udp, NULL) != TRUE)
    {
        return -1;
    }

    // play
    gst_element_set_state (pipeline, GST_STATE_PLAYING);

    g_main_loop_run (loop);

    // clean up
    gst_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (GST_OBJECT (pipeline));
    g_main_loop_unref (loop);

    return 0;
}

The problem was that the port parameter is supposed to be an int, so I had to change问题是端口参数应该是一个int,所以我不得不改变

g_object_set(G_OBJECT(udp), "port", "5000", NULL);

to

g_object_set(G_OBJECT(udp), "port", 5000, NULL);

Sometimes it's easy to miss one's own simple mistakes.有时很容易错过自己的简单错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM