<div><br>hi all<br> 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 I re-write the code , but i get error as flows <br> 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> #include <gst/gsth><br>#include <glib.h><br>#include <unistd.h><br>#include <stdlib.h><br><br><br>GstElement *multiudpsink1, *multiudpsink2;<br><br>static gboolean<br>bus_call (GstBus *bus,<br> GstMessage *msg,<br> gpointer data)<br>{<br> GMainLoop *loop = (GMainLoop *) data;<br> switch (GST_MESSAGE_TYPE (msg)) {<br> case GST_MESSAGE_EOS:<br> g_print ("End of stream\n");<br> g_main_loop_quit (loop);<br> break;<br> case GST_MESSAGE_ERROR: {<br> gchar *debug;<br> GError *error;<br> gst_message_parse_error (msg, &error, &debug);<br> g_free (debug);<br> g_printerr ("Error: %s\n", error->message);<br> g_error_free (error);<br> g_main_loop_quit (loop);<br> break;<br> }<br> default:<br> break;<br> }<br> return TRUE;<br>}<br><br>// I have rewrite this function<br>static void on_pad_added(GstElement *element, GstPad *pad, gpointer data)<br>{<br> GstCaps *caps;<br> GstStructure *str;<br> GstPad *t_pad;<br> <br> caps=gst_pad_get_caps(pad);<br> str=gst_caps_get_structure(caps,0);<br> <br> //<br> if (g_strrstr (gst_structure_get_name (str), "audio")) <br> { <br> t_pad = gst_element_get_static_pad (multiudpsink1, "sink");<br> g_print("rtp catch audio\n");<br> }<br> else if(g_strrstr (gst_structure_get_name (str), "vedio"))<br> { <br> t_pad = gst_element_get_static_pad (multiudpsink2, "sink");<br> g_print("rtp catch vedio\n");<br> }<br> else<br> {<br> gst_caps_unref (caps);<br> return;<br> }<br> <br> if (GST_PAD_IS_LINKED (t_pad)) <br> {<br> gst_caps_unref (caps);<br> g_object_unref (t_pad);<br> return;<br> }<br> //<br> else<br> {<br> //<br> gst_pad_link (pad, t_pad);<br> g_print("Dynamic pad created, linking rtpbin/udp\n");<br> <br> gst_caps_unref (caps); <br> g_object_unref (t_pad);<br> return;<br> } <br>}<br><br>int main(int argc, char **argv)<br>{<br> GMainLoop *loop;<br> GstBus *bus;<br> GstPad *pad;<br> GstCaps *videocap, *audiocap;<br> GstElement *pipeline, *gstrtpbin, *udpsrc1, *udpsrc2;<br> <br> <br> gst_init(&argc, &argv);<br> loop = g_main_loop_new(NULL, FALSE);<br> <br> pipeline = gst_pipeline_new("server");<br> gstrtpbin = gst_element_factory_make("gstrtpbin", "gst_rtpbin");<br> udpsrc1 = gst_element_factory_make("udpsrc", "udpsrc1");<br> udpsrc2 = gst_element_factory_make("udpsrc", "udpsrc2");<br> multiudpsink1 = gst_element_factory_make("multiudpsink", "multiudpsink1");<br> multiudpsink2 = gst_element_factory_make("multiudpsink", "multiudpsink2"); <br> <br> <br> bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));<br> gst_bus_add_watch(bus, bus_call, loop);<br> gst_object_unref(bus);<br> <br> videocap = gst_caps_new_simple("application/x-rtp", <br> "media", G_TYPE_STRING, "video",<br> "clock-rate", G_TYPE_INT, 90000,<br> "encoding-name", G_TYPE_STRING, "H264", NULL);<br> <br> audiocap = gst_caps_new_simple("application/x-rtp",<br> "media", G_TYPE_STRING, "audio",<br> "clock-rate", G_TYPE_INT, 8000,<br> "encoding-name", G_TYPE_STRING, "PCMA", NULL);<br> <br> g_object_set(G_OBJECT(udpsrc1), "caps", videocap, NULL);<br> g_object_set(G_OBJECT(udpsrc2), "caps", audiocap, NULL);<br> g_object_set(G_OBJECT(udpsrc1), "port", 5000, NULL);<br> g_object_set(G_OBJECT(udpsrc2), "port", 5002, NULL);<br> g_object_set(G_OBJECT(multiudpsink1), "clients","172.21.29.169:5000,172.21.29.168:5000", NULL);<br> g_object_set(G_OBJECT(multiudpsink2), "clients","172.21.29.169:5002,172.21.29.168:5002", NULL);<br> g_object_set(G_OBJECT(multiudpsink1), "sync",FALSE, NULL);<br> g_object_set(G_OBJECT(multiudpsink2), "sync",FALSE, NULL);<br> <br> gst_caps_unref(videocap);<br> gst_caps_unref(audiocap);<br> <br> gst_bin_add_many(GST_BIN(pipeline), udpsrc1, udpsrc2, gstrtpbin, multiudpsink1, multiudpsink2, NULL);<br> <br> pad = gst_element_get_request_pad(gstrtpbin, "recv_rtp_sink_0");<br> gst_pad_link(gst_element_get_pad(udpsrc1, "src"), pad);<br> <br> pad = gst_element_get_request_pad(gstrtpbin, "recv_rtp_sink_1");<br> gst_pad_link(gst_element_get_pad(udpsrc2, "src"), pad);<br> <br> g_signal_connect(gstrtpbin, "pad-added", G_CALLBACK(on_pad_added),NULL); <br> <br> gst_element_set_state(pipeline, GST_STATE_PLAYING);<br> <br> g_print("Running...\n");<br> g_main_loop_run(loop);<br> <br> /* Out of the main loop, clean up nicely */<br> g_print("Returned, stopping playback\n");<br> gst_element_set_state(pipeline, GST_STATE_NULL);<br> <br> g_print("Deleting pipeline\n");<br> gst_object_unref(GST_OBJECT(pipeline));<br> <br> return 0;<br>}<br></div><br><!-- footer --><br><span title="neteasefooter"/><hr/>
<a href="http://qiye.163.com/?ft=2">网易全新推出企业邮箱</a>
</span>