Guest User

gst_rtsp_stream_leave_bin

a guest
Feb 13th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.78 KB | None | 0 0
  1. #include <gst/gst.h>
  2.  
  3. #include <gst/rtsp-server/rtsp-server.h>
  4.  
  5. /* Video */
  6. static GstElement *pipeline;
  7.  
  8. /* signal callback when the media is prepared for streaming. */
  9. static void media_prepared_cb (GstRTSPMedia * media){
  10.  
  11.   pipeline = gst_rtsp_media_get_element (media);
  12.  
  13.   gst_debug_set_threshold_from_string ("*:5", TRUE);
  14.  
  15.   gst_rtsp_stream_leave_bin (gst_rtsp_media_get_stream (media, 1),
  16.                              GST_BIN(pipeline),
  17.                              gst_bin_get_by_name(GST_BIN (gst_element_get_parent(pipeline)),"rtpbin0"));
  18. }
  19.  
  20. static void new_stream_cb (){
  21.   g_print("New stream created!\n");
  22. }
  23.  
  24. static void media_configure_cb (GstRTSPMediaFactory * factory, GstRTSPMedia * media){
  25.   /* connect our prepared signal so that we can see when this media is
  26.    * prepared for streaming */
  27.  
  28.   // gst_debug_set_threshold_from_string ("*:5", TRUE);
  29.   g_signal_connect (media, "prepared", (GCallback) media_prepared_cb, factory);
  30.  
  31.   // Maybe this occurs before and therefore is never called.
  32.   g_signal_connect (media, "new-stream", (GCallback) new_stream_cb, factory);
  33. }
  34.  
  35.  
  36. int main (int argc, char *argv[]){
  37.   GMainLoop *loop;
  38.   GstRTSPServer *server;
  39.   GstRTSPMountPoints *mounts;
  40.   GstRTSPMediaFactory *factory;
  41.   gchar *str;
  42.  
  43.  
  44.   gst_init (&argc, &argv);
  45.  
  46.   loop = g_main_loop_new (NULL, FALSE);
  47.  
  48.   /* create a server instance */
  49.   server = gst_rtsp_server_new ();
  50.  
  51.   /* get the mount points for this server, every server has a default object
  52.    * that be used to map uri mount points to media factories */
  53.   mounts = gst_rtsp_server_get_mount_points (server);
  54.  
  55.   str = g_strdup_printf ("( videotestsrc name=videosrc ! videoconvert name=videoconvert ! vp8enc name=vp8enc ! rtpvp8pay name=pay0 "
  56.                          "  audiotestsrc name=audiotestsrc ! amrnbenc name=amrnbenc ! rtpamrpay name=pay1 )");
  57.  
  58.   g_print("str: %s\n", str);
  59.  
  60.   /* make a media factory for a test stream. The default media factory can use
  61.    * gst-launch syntax to create pipelines.
  62.    * any launch line works as long as it contains elements named pay%d. Each
  63.    * element with pay%d names will be a stream */
  64.   factory = gst_rtsp_media_factory_new ();
  65.   gst_rtsp_media_factory_set_launch (factory, str);
  66.  
  67.   g_signal_connect (factory, "media-configure", (GCallback) media_configure_cb, factory);
  68.  
  69.   g_free (str);
  70.  
  71.   /* attach the test factory to the /test url */
  72.   gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
  73.  
  74.   /* don't need the ref to the mapper anymore */
  75.   g_object_unref (mounts);
  76.  
  77.   /* attach the server to the default maincontext */
  78.   gst_rtsp_server_attach (server, NULL);
  79.  
  80.   /* start serving */
  81.   g_print ("stream ready at rtsp://127.0.0.1:8554/test\n");
  82.  
  83.   g_main_loop_run (loop);
  84.  
  85.   return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment