Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gst/gst.h>
- #include <gst/rtsp-server/rtsp-server.h>
- /* Video */
- static GstElement *pipeline;
- /* signal callback when the media is prepared for streaming. */
- static void media_prepared_cb (GstRTSPMedia * media){
- pipeline = gst_rtsp_media_get_element (media);
- gst_debug_set_threshold_from_string ("*:5", TRUE);
- gst_rtsp_stream_leave_bin (gst_rtsp_media_get_stream (media, 1),
- GST_BIN(pipeline),
- gst_bin_get_by_name(GST_BIN (gst_element_get_parent(pipeline)),"rtpbin0"));
- }
- static void new_stream_cb (){
- g_print("New stream created!\n");
- }
- static void media_configure_cb (GstRTSPMediaFactory * factory, GstRTSPMedia * media){
- /* connect our prepared signal so that we can see when this media is
- * prepared for streaming */
- // gst_debug_set_threshold_from_string ("*:5", TRUE);
- g_signal_connect (media, "prepared", (GCallback) media_prepared_cb, factory);
- // Maybe this occurs before and therefore is never called.
- g_signal_connect (media, "new-stream", (GCallback) new_stream_cb, factory);
- }
- int main (int argc, char *argv[]){
- GMainLoop *loop;
- GstRTSPServer *server;
- GstRTSPMountPoints *mounts;
- GstRTSPMediaFactory *factory;
- gchar *str;
- gst_init (&argc, &argv);
- loop = g_main_loop_new (NULL, FALSE);
- /* create a server instance */
- server = gst_rtsp_server_new ();
- /* get the mount points for this server, every server has a default object
- * that be used to map uri mount points to media factories */
- mounts = gst_rtsp_server_get_mount_points (server);
- str = g_strdup_printf ("( videotestsrc name=videosrc ! videoconvert name=videoconvert ! vp8enc name=vp8enc ! rtpvp8pay name=pay0 "
- " audiotestsrc name=audiotestsrc ! amrnbenc name=amrnbenc ! rtpamrpay name=pay1 )");
- g_print("str: %s\n", str);
- /* make a media factory for a test stream. The default media factory can use
- * gst-launch syntax to create pipelines.
- * any launch line works as long as it contains elements named pay%d. Each
- * element with pay%d names will be a stream */
- factory = gst_rtsp_media_factory_new ();
- gst_rtsp_media_factory_set_launch (factory, str);
- g_signal_connect (factory, "media-configure", (GCallback) media_configure_cb, factory);
- g_free (str);
- /* attach the test factory to the /test url */
- gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
- /* don't need the ref to the mapper anymore */
- g_object_unref (mounts);
- /* attach the server to the default maincontext */
- gst_rtsp_server_attach (server, NULL);
- /* start serving */
- g_print ("stream ready at rtsp://127.0.0.1:8554/test\n");
- g_main_loop_run (loop);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment