tyr to add multiple users, but we fait to receive the second one's streams,
Wang Zhenzhong
wangzz at avonaco.com
Thu Apr 3 05:35:04 PDT 2014
the code like this:
srcpad = gst_element_get_static_pad (udprecv_video[i], "src");
sinkpad1 = gst_element_get_request_pad (rtpbin, "recv_rtp_sink_0");
lres = gst_pad_link (srcpad, sinkpad1);
g_assert (lres == GST_PAD_LINK_OK);
gst_object_unref (srcpad);
srcpad = gst_element_get_static_pad (udprecv_audio[i], "src");
sinkpad2 = gst_element_get_request_pad (rtpbin, "recv_rtp_sink_1");
lres = gst_pad_link (srcpad, sinkpad2);
g_assert (lres == GST_PAD_LINK_OK);
gst_object_unref (srcpad);
when I add first one's audio/video, it's OK
but when I add second one's audio/video, it's failed, we cant receive the second one's stream
thank you very much
PS:the full code
gint
main (int argc, char *argv[])
{
GstElement *pipeline;
GstElement *udprecv_video[MAX_NUM];
GstElement *udprecv_audio[MAX_NUM];
GstElement *rtpbin;
GstElement *multiudpsend_video[MAX_NUM];
GstElement *multiudpsend_audio[MAX_NUM];
GstElement *sinkpad1, *sinkpad2, *sinkpad3, *sinkpad4;
GstCaps *caps;
GstPad *srcpad ;
GstPadLinkReturn lres;
GMainLoop *loop;
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);
rtpbin = gst_element_factory_make ("rtpbin", "rtpbin0");
pipeline = gst_pipeline_new ("player0");
g_object_set (rtpbin, "do-retransmission", 1, NULL);
gst_bin_add(GST_BIN (pipeline), rtpbin);
int i = 0;
//two user
for(i=0; i<2; i++)
{
if(i==0)
{
//first user,two udpsrc,two output
//pipeline = gst_pipeline_new ("player0");
udprecv_video[i] = gst_element_factory_make ("udpsrc", "udprecv_video0");
udprecv_audio[i] = gst_element_factory_make ("udpsrc", "udprecv_audio0");
multiudpsend_video[i] = gst_element_factory_make ("multiudpsink", "multiudpsend_video0");
multiudpsend_audio[i] = gst_element_factory_make ("multiudpsink", "multiudpsend_audio0");
//rtpbin[i] = gst_element_factory_make ("rtpbin", "rtpbin0");
//g_object_set (rtpbin[i], "do-retransmission", 1, NULL);
}
else if(i==1)
{
//second,two udpsrc,two output
//pipeline[i] = gst_pipeline_new ("player1");
udprecv_video[i] = gst_element_factory_make ("udpsrc", "udprecv_video1");
udprecv_audio[i] = gst_element_factory_make ("udpsrc", "udprecv_audio1");
multiudpsend_video[i] = gst_element_factory_make ("multiudpsink", "multiudpsend_video1");
multiudpsend_audio[i] = gst_element_factory_make ("multiudpsink", "multiudpsend_audio1");
//rtpbin[i] = gst_element_factory_make ("rtpbin", "rtpbin1");
//g_object_set (rtpbin[i], "do-retransmission", 1, NULL);
}
if (!pipeline || !udprecv_video[i] || !udprecv_audio[i] || !multiudpsend_video[i] || !multiudpsend_audio[i]) {
g_print ("i[%d] One element could not be created. Exiting.\n", i);
return 1;
}
g_object_set (udprecv_video[i], "port", BASE_PORT+i*1000, NULL);
caps = gst_caps_from_string ("application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264");
g_object_set (udprecv_video[i], "caps", caps, NULL);
gst_caps_unref (caps);
g_object_set (udprecv_audio[i], "port", BASE_PORT+2+i*1000, NULL);
caps = gst_caps_from_string ("application/x-rtp,media=(string)audio,clock-rate=(int)44100,encoding-name=(string)aac");
g_object_set (udprecv_audio[i], "caps", caps, NULL);
gst_caps_unref (caps);
//gst_bin_add(GST_BIN (pipeline), rtpbin[i]);
gst_bin_add(GST_BIN (pipeline), udprecv_video[i]);
gst_bin_add(GST_BIN (pipeline), udprecv_audio[i]);
gst_bin_add(GST_BIN (pipeline), multiudpsend_video[i]);
gst_bin_add(GST_BIN (pipeline), multiudpsend_audio[i]);
if(i==0)
{
//link first one's src and sink
srcpad = gst_element_get_static_pad (udprecv_video[i], "src");
//sinkpad = gst_element_get_request_pad (rtpbin[i], "recv_rtp_sink_0");
sinkpad1 = gst_element_get_request_pad (rtpbin, "recv_rtp_sink_0");
lres = gst_pad_link (srcpad, sinkpad1);
g_assert (lres == GST_PAD_LINK_OK);
gst_object_unref (srcpad);
srcpad = gst_element_get_static_pad (udprecv_audio[i], "src");
//sinkpad = gst_element_get_request_pad (rtpbin[i], "recv_rtp_sink_1");
sinkpad2 = gst_element_get_request_pad (rtpbin, "recv_rtp_sink_1");
lres = gst_pad_link (srcpad, sinkpad2);
g_assert (lres == GST_PAD_LINK_OK);
gst_object_unref (srcpad);
//建立动态连接,有流来就收,然后分发
setup_dynamic_link1 (rtpbin, gst_element_get_static_pad (multiudpsend_video[i],
"sink"),0,12345,96);
setup_dynamic_link1 (rtpbin, gst_element_get_static_pad (multiudpsend_audio[i],
"sink"),1,54321,97);
}
else if(i==1)
{
//link second one's src and sink
g_print ("zx i[%d] 11.\n", i);
srcpad = gst_element_get_static_pad (udprecv_video[i], "src");
g_print ("zx srcpad = gst_element_get_static_pad (udprecv_video[i].\n", i);
//sinkpad = gst_element_get_request_pad (rtpbin[i], "recv_rtp_sink_2");
sinkpad3 = gst_element_get_request_pad (rtpbin, "recv_rtp_sink_2");
g_print ("zx i[%d] gst_pad_link.\n", i);
lres = gst_pad_link (srcpad, sinkpad3);
g_assert (lres == GST_PAD_LINK_OK);
gst_object_unref (srcpad);
g_print ("zx i[%d] 22.\n", i);
srcpad = gst_element_get_static_pad (udprecv_audio[i], "src");
//sinkpad = gst_element_get_request_pad (rtpbin[i], "recv_rtp_sink_3");
sinkpad4 = gst_element_get_request_pad (rtpbin, "recv_rtp_sink_3");
lres = gst_pad_link (srcpad, sinkpad4);
g_assert (lres == GST_PAD_LINK_OK);
gst_object_unref (srcpad);
setup_dynamic_link1 (rtpbin, gst_element_get_static_pad (multiudpsend_video[i],
"sink"),2,12345,96);
setup_dynamic_link1 (rtpbin, gst_element_get_static_pad (multiudpsend_audio[i],
"sink"),3,54321,97);
}
g_signal_connect(multiudpsend_video[i],"add",
G_CALLBACK(client_added_multiudpsink),NULL);
g_signal_connect(multiudpsend_audio[i],"add",
G_CALLBACK(client_added_multiudpsink),NULL);
//g_thread_create(test1_thread1,multiudpsend_video,TRUE,NULL);
g_signal_emit_by_name(multiudpsend_video[i],"add","192.168.6.209",SEND_BASE_PORT+i*1000,NULL);
//g_signal_emit_by_name(multiudpsend_video,"add","192.168.6.63",10002,NULL);
//g_signal_emit_by_name(multiudpsend_video,"add","192.168.6.63",10004,NULL);
g_signal_emit_by_name(multiudpsend_audio[i],"add","192.168.6.209",SEND_BASE_PORT+2+i*1000,NULL);
}
/* Set the pipeline to "playing" state*/
g_print ("Now playing: %s\n", argv[1]);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* Iterate */
g_print ("Running...\n");
g_main_loop_run (loop);
/* Out of the main loop, clean up nicely */
g_print ("Returned, stopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
g_main_loop_unref (loop);
return 0;
}
王振中
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20140403/66c965c8/attachment-0001.html>
More information about the gstreamer-devel
mailing list