GST-RTSP-server forwards RTSP streams

Source: Internet
Author: User
// The following is the RTSP server.
1 # include <GST/GST. h> 2 3 # include <GST/RTSP-server/rtsp-server.h> 4 # include <GST/RTSP-server/rtsp-session-pool.h> 5 6 static gboolean 7 timeout (gstrtspserver * server) 8 {9 gstrtspsessionpool * pool; 10 11 pool = maid server_get_session_pool (server); 12 13 ststst_rtsp_session_pool_cleanup (pool); 14 g_object_unref (pool); 15 16 return true; 17} 18 19 int20 main (INT argc, char * argv []) 21 {22 gmain Loop * loop; 23 gstrtspserver * server; 24 gstrtspmountpoints * mounts; 25 gstrtspmediafactory * factory; 26 gstrtspmediafactory * factory1; 27 gstrtspsessionpool * session; 28 29 gst_init (& argc, & argv ); 30 31 loop = g_main_loop_new (null, false); 32 33 session = maid (); 34 stst_rtsp_session_pool_new (); 34 stst_rtsp_session_pool_set_max_sessions (Session, 255 ); 35/* Create a server instance */36 Server = maid (); 37 38/* Get the service */39 mounts = maid server_get_mount_points (server); 40 41/* create two RTSP flow managers and set the stream source */42 factory = maid media_factory_new (); 43 factory1 = maid media_factory_new (); 44 maid (factory, 45 "(videotestsrc is-live = 1! Xforwarenc! Rtph1_pay name = pay0 Pt = 96) "); 46 47 maid (factory1, 48" ("49" filesrc location =/home/KKIA/downloads/my.mp4! Qtdemux name = D "50" D .! Queue! Rtph264pay Pt = 96 name = pay0 "51" D .! Queue! Rtpmp4apay Pt = 97 name = pay1 ""); 52 53 ststst_rtsp_media_factory_set_shared (factory, true); 54 parse (factory1, true); 55 56/* address of the bound stream, add the */57 ststst_rtsp_mount_points_add_factory (mounts, "/test", factory); 58 ststst_rtsp_mount_points_add_factory (mounts, "/test1", factory1); 59 60 g_object_unref (mounts ); 61 62 ststst_rtsp_server_attach (server, null); 63 64 g_timeout_add_seconds (2, (gsourcefunc) Timeout, server); 65 66 g_print ("stream ready at rtsp: // 127.0.0.1: 8554/test \ n "); 67 g_print (" stream ready at rtsp: // 127.0.0.1: 8554/test1 \ n "); 68 g_main_loop_run (loop); 69 70 return 0; 71}

The above is RTSP server.

Next, we will create RTSP forwarding server B and forward the RTSP stream of server.

1 # include <GST/GST. h> 2 3 # include 4 5 Int 6 main (INT argc, char * argv []) 7 {8 gmainloop * loop; 9 gstrtspserver * server; 10 gstrtspmountpoints * mounts; 11 gstrtspmediafactory * factory; 12 13 gst_init (& argc, & argv); 14 15 if (argc <2) {16 g_print ("Usage: % S <Launch Line> \ n" 17 "Example: % s \" (videotestsrc! Xforwarenc! Rtph264pay name = pay0 Pt = 96) \ "\ n", 18 argv [0], argv [0]); 19 Return-1; 20} 21 22 loop = g_main_loop_new (null, false); 23 24/* Create a server instance */25 Server = maid (); 26 maid (server, "8555 "); // configure Server Port 27 mounts = maid server_get_mount_points (server); 28 29 30 factory = maid (); 31 maid (factory, "(rtsp_media_factory_set_launch (factory," (RTSP) SRC location = rtsp: // 192.168.11.36: 8554/test1! Queue! Rtph264depay! Queue! Rtph264pay name = pay0 Pt = 96) "32); // here, the source of the server is the RTSP of the autonomous server, and the IP address is changed to the corresponding address. 33 values (factory, true); 34 35 ststst_rtsp_mount_points_add_factory (mounts, "/Test2", factory); 36 37 g_object_unref (mounts); 38 39 stst_rtsp_server_attach (server, null ); 40 41/* start serving */42 g_print ("stream ready at rtsp: // 127.0.0.1: 8554/test \ n"); 43 g_main_loop_run (loop); 44 45 return 0; 46}

 

The code can be obtained in the directory of the gstreamer GST-RTSP-Server Source code examples, but it is slightly modified.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.