Search code examples
cinheritancegstreamerrtspgnome

Process query string in gst-rtsp-server


I want to create rtsp server which works like certain ip camera.

RTSP query to camera looks:

DESCRIBE /axis-media/media.amp?videocodec=h264&camera=1&resolution=640x480&fps=15

The documentation of gst-rtsp-streamer says:

Usually the url will determine what kind of pipeline should be created. You can for example use query parameters to configure certain parts of the pipeline or select encoders and payloaders based on some url pattern.

But I can't find any examples to parse query string and creating different pipelines. I only see the way with different paths.

There was similar question, but I can't understand the answer.

Thank you in advance!


Solution

  • I found the solution!!!

    I create subclass of GstRTSPMediaFactory and override create_element method:

    typedef struct TestRTSPMediaFactoryClass TestRTSPMediaFactoryClass;
    typedef struct TestRTSPMediaFactory TestRTSPMediaFactory;
    
    struct TestRTSPMediaFactoryClass
    {
        GstRTSPMediaFactoryClass parent;
    };
    
    struct TestRTSPMediaFactory
    {
         GstRTSPMediaFactory parent;
    };
    
    
    static GstElement * custom_create_element(GstRTSPMediaFactory      *factory, const GstRTSPUrl *url);
    
    
    G_DEFINE_TYPE (TestRTSPMediaFactory, test_rtsp_media_factory, GST_TYPE_RTSP_MEDIA_FACTORY);
    
    static void
    test_rtsp_media_factory_class_init (TestRTSPMediaFactoryClass * test_klass)
    {
       GstRTSPMediaFactoryClass *klass = (GstRTSPMediaFactoryClass *) (test_klass);
       klass->create_element = custom_create_element;
    }
    
    static void
    test_rtsp_media_factory_init (TestRTSPMediaFactory * media)
    {
    }
    
    static GstElement *
    custom_create_element (GstRTSPMediaFactory * factory, const GstRTSPUrl  *url)
    {
         /* you can see at query string: */
         printf("query is: %s\n", url->query);
         /* according to query create GstElement, for example: */
         GstElement *element;
         GError *error = NULL;
    
         element = gst_parse_launch ("( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )",
                              &error);
         return element;
    }
    
    
    int main (int argc, char *argv[])
    {
       ...  
       GstRTSPMediaFactory *factory;
       factory = g_object_new(TEST_TYPE_RTSP_MEDIA_FACTORY, NULL);
    
       ...
       g_main_loop_run (loop);
    
       return 0;
    }
    

    I hope it'll help somebody to safe time! I use sources and examples/test-cgroups.c for it