<div><br>hi all<br>&nbsp;&nbsp; I come across a problem when sending out vedio through rtp protocol.Last time i ask the same question here and Wim Taymans told me that i had connected to the pad-added signal twice.I should thank him first .Later&nbsp; I re-write the code , but i get error as flows <br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Error: internal data flow error.<br>I am new to gstreamer , can anyone help me to check my code and give me some suggestions . Thank you very much. the following is my code<br><br>/******************************************************<br>&nbsp;#include &lt;gst/gsth&gt;<br>#include &lt;glib.h&gt;<br>#include &lt;unistd.h&gt;<br>#include &lt;stdlib.h&gt;<br><br><br>GstElement *multiudpsink1, *multiudpsink2;<br><br>static gboolean<br>bus_call (GstBus&nbsp;&nbsp;&nbsp;&nbsp; *bus,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GstMessage *msg,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpointer&nbsp;&nbsp;&nbsp; data)<br>{<br>&nbsp; GMainLoop *loop = (GMainLoop *) data;<br>&nbsp; switch (GST_MESSAGE_TYPE (msg)) {<br>&nbsp;&nbsp;&nbsp; case GST_MESSAGE_EOS:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_print ("End of stream\n");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_main_loop_quit (loop);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp; case GST_MESSAGE_ERROR: {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gchar *debug;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GError *error;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gst_message_parse_error (msg, &amp;error, &amp;debug);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_free (debug);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_printerr ("Error: %s\n", error-&gt;message);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_error_free (error);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_main_loop_quit (loop);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; default:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp; }<br>&nbsp; return TRUE;<br>}<br><br>// I have rewrite this function<br>static void on_pad_added(GstElement *element, GstPad *pad, gpointer data)<br>{<br>&nbsp;&nbsp;&nbsp; GstCaps *caps;<br>&nbsp;&nbsp;&nbsp; GstStructure *str;<br>&nbsp;&nbsp;&nbsp; GstPad *t_pad;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; caps=gst_pad_get_caps(pad);<br>&nbsp;&nbsp;&nbsp; str=gst_caps_get_structure(caps,0);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (g_strrstr (gst_structure_get_name (str), "audio")) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;t_pad = gst_element_get_static_pad (multiudpsink1, "sink");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;g_print("rtp catch audio\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(g_strrstr (gst_structure_get_name (str), "vedio"))<br>&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;t_pad = gst_element_get_static_pad (multiudpsink2, "sink");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;g_print("rtp catch vedio\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gst_caps_unref (caps);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (GST_PAD_IS_LINKED (t_pad)) <br>&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gst_caps_unref (caps);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_object_unref (t_pad);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return;<br>&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp; &nbsp;&nbsp;&nbsp; //<br>&nbsp; &nbsp;&nbsp;&nbsp; else<br>&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gst_pad_link (pad, t_pad);<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_print("Dynamic pad created, linking rtpbin/udp\n");<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gst_caps_unref (caps);&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_object_unref (t_pad);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return;<br>&nbsp; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; <br>}<br><br>int main(int argc, char **argv)<br>{<br>&nbsp;&nbsp;&nbsp; GMainLoop *loop;<br>&nbsp;&nbsp;&nbsp; GstBus *bus;<br>&nbsp;&nbsp;&nbsp; GstPad *pad;<br>&nbsp;&nbsp;&nbsp; GstCaps *videocap, *audiocap;<br>&nbsp;&nbsp;&nbsp; GstElement *pipeline, *gstrtpbin, *udpsrc1, *udpsrc2;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; gst_init(&amp;argc, &amp;argv);<br>&nbsp;&nbsp;&nbsp; loop = g_main_loop_new(NULL, FALSE);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; pipeline = gst_pipeline_new("server");<br>&nbsp;&nbsp;&nbsp; gstrtpbin = gst_element_factory_make("gstrtpbin", "gst_rtpbin");<br>&nbsp;&nbsp;&nbsp; udpsrc1 = gst_element_factory_make("udpsrc", "udpsrc1");<br>&nbsp;&nbsp;&nbsp; udpsrc2 = gst_element_factory_make("udpsrc", "udpsrc2");<br>&nbsp;&nbsp;&nbsp; multiudpsink1 = gst_element_factory_make("multiudpsink", "multiudpsink1");<br>&nbsp;&nbsp;&nbsp; multiudpsink2 = gst_element_factory_make("multiudpsink", "multiudpsink2");&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));<br>&nbsp;&nbsp;&nbsp; gst_bus_add_watch(bus, bus_call, loop);<br>&nbsp;&nbsp;&nbsp; gst_object_unref(bus);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; videocap = gst_caps_new_simple("application/x-rtp", <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "media", G_TYPE_STRING, "video",<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "clock-rate", G_TYPE_INT, 90000,<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "encoding-name", G_TYPE_STRING, "H264", NULL);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; audiocap = gst_caps_new_simple("application/x-rtp",<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "media", G_TYPE_STRING, "audio",<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "clock-rate", G_TYPE_INT, 8000,<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "encoding-name", G_TYPE_STRING, "PCMA", NULL);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; g_object_set(G_OBJECT(udpsrc1), "caps", videocap, NULL);<br>&nbsp;&nbsp;&nbsp; g_object_set(G_OBJECT(udpsrc2), "caps", audiocap, NULL);<br>&nbsp;&nbsp;&nbsp; g_object_set(G_OBJECT(udpsrc1), "port", 5000, NULL);<br>&nbsp;&nbsp;&nbsp; g_object_set(G_OBJECT(udpsrc2), "port", 5002, NULL);<br>&nbsp;&nbsp;&nbsp; g_object_set(G_OBJECT(multiudpsink1), "clients","172.21.29.169:5000,172.21.29.168:5000", NULL);<br>&nbsp;&nbsp;&nbsp; g_object_set(G_OBJECT(multiudpsink2), "clients","172.21.29.169:5002,172.21.29.168:5002", NULL);<br>&nbsp;&nbsp;&nbsp; g_object_set(G_OBJECT(multiudpsink1), "sync",FALSE, NULL);<br>&nbsp;&nbsp;&nbsp; g_object_set(G_OBJECT(multiudpsink2), "sync",FALSE, NULL);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; gst_caps_unref(videocap);<br>&nbsp;&nbsp;&nbsp; gst_caps_unref(audiocap);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; gst_bin_add_many(GST_BIN(pipeline), udpsrc1, udpsrc2, gstrtpbin, multiudpsink1, multiudpsink2, NULL);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; pad = gst_element_get_request_pad(gstrtpbin, "recv_rtp_sink_0");<br>&nbsp;&nbsp;&nbsp; gst_pad_link(gst_element_get_pad(udpsrc1, "src"), pad);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; pad = gst_element_get_request_pad(gstrtpbin, "recv_rtp_sink_1");<br>&nbsp;&nbsp;&nbsp; gst_pad_link(gst_element_get_pad(udpsrc2, "src"), pad);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; g_signal_connect(gstrtpbin, "pad-added", G_CALLBACK(on_pad_added),NULL);&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; gst_element_set_state(pipeline, GST_STATE_PLAYING);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; g_print("Running...\n");<br>&nbsp;&nbsp;&nbsp; g_main_loop_run(loop);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; /* Out of the main loop, clean up nicely */<br>&nbsp;&nbsp;&nbsp; g_print("Returned, stopping playback\n");<br>&nbsp;&nbsp;&nbsp; gst_element_set_state(pipeline, GST_STATE_NULL);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; g_print("Deleting pipeline\n");<br>&nbsp;&nbsp;&nbsp; gst_object_unref(GST_OBJECT(pipeline));<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br></div><br><!-- footer --><br><span title="neteasefooter"/><hr/>
<a href="http://qiye.163.com/?ft=2">网易全新推出企业邮箱</a>
</span>