0
votes

I want to use the RTP function of GStreamer to realize a real-time intercom program。 The following commands can play voice normally:

gst-launch-1.0 udpsrc port=5699 address="127.0.0.1" do-timestamp=true caps= "application/x-rtp-stream,media=audio,clock-rate=44100,encoding-name=VORBIS" ! rtpstreamdepay ! rtpvorbisdepay ! decodebin ! audioconvert ! audioresample ! autoaudiosink

When I translate this cmd into code,I found no sound. The code is as follows:

gst_init(NULL, NULL);
GMainLoop *loop;
loop = g_main_loop_new(NULL, FALSE);

GstElement *pipeline, *udpsrc, *rtpstreamdepay, *rtpvorbisdepay, *decodebin, *audioconvert, *audioresample, *autoaudiosink;

pipeline = gst_pipeline_new("pipeline");
udpsrc = gst_element_factory_make("udpsrc", "udpsrc");
rtpstreamdepay = gst_element_factory_make("rtpstreamdepay", "rtpstreamdepay");
rtpvorbisdepay = gst_element_factory_make("rtpvorbisdepay", "rtpvorbisdepay");
decodebin = gst_element_factory_make("decodebin", "decodebin");
audioconvert = gst_element_factory_make("audioconvert", "audioconvert");
audioresample = gst_element_factory_make("audioresample", "audioresample");
autoaudiosink = gst_element_factory_make("autoaudiosink", "autoaudiosink");

g_object_set(G_OBJECT(udpsrc),
             "port", 5699,
            "address", "127.0.0.1",
            "do-timestamp", true,
             "caps", gst_caps_new_simple("application/x-rtp-stream", "media", G_TYPE_STRING, "audio", 
             "clock-rate", G_TYPE_INT, 44100, 
            //  "width",G_TYPE_INT,16,
            //  "height",G_TYPE_INT,16,
             "encoding-name", G_TYPE_STRING, "VORBIS", 
            //  "channels",G_TYPE_INT,2,
            //  "channel-positions",G_TYPE_INT,1,
            //  "payload",G_TYPE_INT,1,
             NULL),
             NULL);

gst_bin_add_many(GST_BIN(pipeline), udpsrc, rtpstreamdepay, rtpvorbisdepay, decodebin, audioconvert, audioresample, autoaudiosink, NULL);
gst_element_link_many(udpsrc, rtpstreamdepay, rtpvorbisdepay, decodebin, audioconvert, audioresample, autoaudiosink, NULL);
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);
printf("data depletion");
}

Can anyone help me to see what's wrong?Tks.

1
is it C or C++?IrAM
it is a C + + program on Linuxkalelu

1 Answers

0
votes

I found the cause of the problem. The cmd can connect pad automatically, but the code can't.