在gst-rtsp-server中处理查询字符串

时间:2016-06-06 16:58:49

标签: c inheritance gstreamer rtsp gnome

我想创建像某些ip camera一样工作的rtsp服务器。

对相机的RTSP查询:

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

gst-rtsp-streamer的文档说:

  

通常,url将确定应该使用哪种管道   创建。例如,您可以使用查询参数来配置某些参数   管道的一部分或根据一些选择编码器和付费加载器   网址模式。

但我找不到任何解析查询字符串和创建不同管道的示例。我只看到不同路径的方式。

有类似的question,但我无法理解答案。

提前谢谢!

1 个答案:

答案 0 :(得分:3)

我找到了解决方案!!!

我创建GstRTSPMediaFactory的子类并覆盖create_element方法:

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;
}

我希望它可以帮助别人安全!我使用了源代码和examples / test-cgroups.c