2 years ago

#63101

test-img

Charlie

Gstreamer RTSP-Server gst_rtsp_media_factory_set_launch() Example

I want to change the pipeline by using the gst_rtsp_media_factory_set_launch() function to receive an interrupt in the middle from RTSP-Server. I used the media_configure() callback function to get the GstElement for the pipeline. If an interrupt is received in the middle, it is changed to GST_STATE_NULL and then the command entered into the gst_rtsp_media_factory_set_launch() function has been changed. Specifically, when the user presses Ctrl+C while streaming V4L2 video0, V4L2 video1 will be streamed. The implementation was successful(i.e. change from video0 to video1), but there is a problem that the screen freezes for about 3 seconds after Ctrl+C and moves on to the next screen. This was not the case when using UDP, but this problem occurs when using RTSP. Please advise me, Thank You!

    #include <gst/rtsp-server/rtsp-server.h>
            
    GstRTSPServer *server;
    GstRTSPMountPoints *mounts;
    GstRTSPMediaFactory *factory;
    GMainLoop   *loop;
    GstElement *pipeline;
        
    void INThandler(int sig_no)
    {
        gst_element_set_state(pipeline, GST_STATE_NULL);
        gst_rtsp_media_factory_set_launch (factory, "( v4l2src device=/dev/video1 ! compositor ! vpuenc_h264  ! rtph264pay pt=96 name=pay0 )");
        //gst_rtsp_media_factory_set_launch (factory, "( filesrc location=test2.mp4 ! qtdemux ! decodebin ! compositor !  queue2  ! vpuenc_h264 ! rtph264pay pt=96 name=pay0 )");
    }
       
    static void media_configure (GstRTSPMediaFactory * factory, GstRTSPMedia * media,
                gpointer user_data)
    {
        pipeline =  gst_rtsp_media_get_element (media);
    }
        
    int main(int argc,char * argv[])
    {
        signal(SIGINT, INThandler);
        
        gst_init(&argc, &argv);
        
        loop = g_main_loop_new(NULL, FALSE);
        server = gst_rtsp_server_new ();
        gst_rtsp_server_set_service(server, "5002");
        mounts = gst_rtsp_server_get_mount_points (server);
        factory = gst_rtsp_media_factory_new ();
        
        gst_rtsp_media_factory_set_launch (factory, "( v4l2src device=/dev/video0 ! queue2 ! vpuenc_h264 ! rtph264pay pt=96 name=pay0 )");
        //gst_rtsp_media_factory_set_launch (factory, "( filesrc location=test1.mp4 ! qtdemux ! decodebin ! compositor !  queue2  ! vpuenc_h264 ! rtph264pay pt=96 name=pay0 )");
        g_signal_connect (factory, "media-configure", (GCallback) media_configure, NULL);
        gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
        g_object_unref (mounts);
        
        gst_rtsp_server_attach (server, NULL);
        g_main_loop_run(loop);
        
        return 0;
    }

udp

gstreamer

pipeline

rtsp

v4l2

0 Answers

Your Answer

Accepted video resources