简体   繁体   中英

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.

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:

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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