gstreamer 1.0 rtspsrc到rtph264depay无法链接

gstreamer 1.0 rtspsrc到rtph264depay无法链接,gstreamer,rtsp,Gstreamer,Rtsp,我正在尝试连接到ubiquiti摄像头,并使用gstreamer成功地执行以下命令 gst-launch-1.0--gst debug=4 rtspsrc location=“rtsp://:554/live/ch00_0”!rtph264depay!h264parse!12月26日开放!d3dvideosink 我看了一下调试,它说无法将padsrtspsrc链接到rtph264depay。 但是它可以很好地获得流,并且可以看到视频。当我把它放到一个c项目中时,它说不能将源代码链接到rtph

我正在尝试连接到ubiquiti摄像头,并使用gstreamer成功地执行以下命令

gst-launch-1.0--gst debug=4 rtspsrc location=“rtsp://:554/live/ch00_0”!rtph264depay!h264parse!12月26日开放!d3dvideosink

我看了一下调试,它说无法将padsrtspsrc链接到rtph264depay。

但是它可以很好地获得流,并且可以看到视频。当我把它放到一个c项目中时,它说不能将源代码链接到rtph264parse。我环顾四周,它说使用一个动态键盘,代码如下

static void on_pad_added (GstElement *element, GstPad *pad, gpointer data)
{
    GstPad *sinkpad;
    GstElement *decoder = (GstElement *) data;
    /* We can now link this pad with the rtsp-decoder sink pad */
    g_print ("Dynamic pad created, linking source/demuxer\n");
    sinkpad = gst_element_get_static_pad (decoder, "sink");
    gst_pad_link (pad, sinkpad);
    gst_object_unref (sinkpad);
}

int main(int argc, char *argv[])
{
   /* Initialize GStreamer */
   gst_init(&argc,&argv);

   /* Build Pipeline */ 
   pipel.pipeline = gst_pipeline_new("My pipeline");
   pipel.source = gst_element_factory_make ("rtspsrc","source");
   g_object_set (G_OBJECT (pipel.source), "latency",2000,NULL);
   pipel.rtppay = gst_element_factory_make( "rtph264depay", "depayl");
   pipel.parse = gst_element_factory_make("h264parse","parse");
   pipel.filter1 = gst_element_factory_make("capsfilter","filter");
   pipel.decodebin = gst_element_factory_make ("openh264dec","decode");
   pipel.sink = gst_element_factory_make("d3dvideosink","sink");

   g_object_set (G_OBJECT (pipel.sink), "sync",FALSE,NULL);

   //create_uri(url,url_size,ip_address,port);
   g_object_set(GST_OBJECT(pipel.source),"location","rtsp://<IP>:554/live/ch00_0",NULL);

   filtercaps = gst_caps_from_string("application/x-rtp");
   g_object_set (G_OBJECT (pipel.filter1), "caps",filtercaps,NULL);

   gst_caps_unref(filtercaps);

   gst_bin_add_many (GST_BIN (pipel.pipeline),pipel.source
                                          ,pipel.rtppay
                                          ,pipel.parse
                                          ,pipel.decodebin
                                          ,pipel.sink
                                          ,NULL);
   if(!gst_element_link(pipel.source,pipel.rtppay))
        printf("\nFailed source to rtppay\n");
   if(!gst_element_link_many(pipel.parse,pipel.decodebin,pipel.sink,NULL))
        printf("\nFailed to link parse to sink");

    g_signal_connect(pipel.rtppay, "pad-added", G_CALLBACK(on_pad_added), pipel.parse);
}
添加了键盘上的静态空白(GstElement*元素、GstPad*键盘、gpointer数据) { GstPad*下沉板; GstElement*解码器=(GstElement*)数据; /*现在,我们可以将此焊盘与rtsp解码器接收器焊盘链接*/ g_print(“创建动态焊盘,链接源/解复用器”); sinkpad=gst_元素_get_静态_pad(译码器,“接收器”); gst_垫_链接(垫、下沉垫); gst_object_unref(下沉板); } int main(int argc,char*argv[]) { /*初始化GStreamer*/ gst_init(&argc,&argv); /*构建管道*/ pipel.pipeline=gst_pipeline_new(“我的管道”); pipel.source=gst元素工厂制造(“rtspsrc”,“source”); g_对象集(g_对象(管道源),“延迟”,2000,空); pipel.rtppay=gst元素工厂制造(“RTPH264代支付”、“代支付”); pipel.parse=gst_元素_工厂_制造(“h264parse”,“parse”); pipel.filter1=gst元件工厂制造(“capsfilter”、“过滤器”); pipel.DECOBIN=gst元素工厂制造(“openh264dec”,“解码”); pipel.sink=gst元素工厂制造(“d3dvideosink”、“sink”); g_对象集(g_对象(管道接收器),“同步”,假,空); //创建uri(url、url大小、ip地址、端口); g_对象集(GST_对象(管道源),“位置”,“rtsp://:554/live/ch00_0”,空); filtercaps=gst_caps_from_string(“应用程序/x-rtp”); g_对象集(g_对象(pipel.filter1),“caps”,filtercaps,NULL); gst_caps_unref(过滤盖); gst_bin_add_many(gst_bin(管道),管道来源 ,pipel.rtppay ,pipel.parse ,pipel.decodebin 管道水槽 ,空); if(!gst_元素_链接(管道源,管道rtppay)) printf(“\n源到rtppay失败\n”); if(!gst\u元素\u链接\u多(pipel.parse、pipel.decodebin、pipel.sink、NULL)) printf(“\n链接解析到接收器失败”); g_信号连接(pipel.rtppay,“pad added”,g_回调(on_pad_added),pipel.parse); }
静态无效cb\u新\u rtspsrc\u焊盘(GstElement*元件、GstPad*焊盘、gpointer数据)
{
gchar*名称;
GSTCAP*p_上限;
gchar*说明;
GstElement*p_rtph264 depay;
名称=gst\u pad\u get\u名称(pad);
g_print(“创建了一个新的焊盘%s,\n”,名称);
//在这里,您将为新创建的焊盘设置一个新的焊盘链接
//sooo,现在发现需要rtph264depay并链接它们?
p_caps=gst_pad_get_pad_模板_caps(pad);
description=gst_caps_to_string(p_caps);
printf(“%s\n”,p_caps,”,“,description,”\n”);
g_free(描述);
p_RTPH264; dePay=GST_元素(数据);
//试着把垫子连接起来然后。。。
如果(!gst\u元素\u链接\u焊盘(元素、名称、p\u rtph264depay,“接收器”))
{
printf(“未能链接元素3\n”);
}
g_free(姓名);
}
/*------------主要------------------*/
int main(int argc,char*argv[])
{
/*初始化GStreamer*/
gst_init(&argc,&argv);
/*构建管道*/
pipel.pipeline=gst_pipeline_new(“我的管道”);
创建_管道(ip_地址、端口);
pipel.source=gst元素工厂制造(“rtspsrc”,“source”);
g_对象集(g_对象(管道源),“延迟”,2000,空);
pipel.rtppay=gst元素工厂制造(“RTPH264代支付”、“代支付”);
pipel.parse=gst_元素_工厂_制造(“h264parse”,“parse”);
pipel.filter1=gst元件工厂制造(“capsfilter”、“过滤器”);
pipel.DECOBIN=gst元素工厂制造(“openh264dec”,“解码”);
pipel.sink=gst元素工厂制造(“d3dvideosink”、“sink”);
g_对象集(g_对象(管道接收器),“同步”,假,空);
//创建uri(url、url大小、ip地址、端口);
g_对象集(GST_对象(管道源),“位置”,“rtsp://:554/live/ch00_0”,空);
filtercaps=gst_caps_from_string(“应用程序/x-rtp”);
g_对象集(g_对象(pipel.filter1),“caps”,filtercaps,NULL);
gst_caps_unref(过滤盖);
gst_bin_add_many(gst_bin(管道),管道来源
,pipel.rtppay
,空);
//收听新创建的pad
g_信号连接(pipel.source,“pad added”,g_回调(cb_new_rtspsrc_pad),pipel.rtppay);
gst_bin_add_many(gst_bin(pipel.pipeline)、pipel.parse、NULL);
if(!gst_元素_链接(pipe.rtppay,pipe.parse))
printf(“\n操作\n”);
gst_bin_add_many(gst_bin(管道)、管道
管道水槽
,空);
if(!gst\u元素\u链接\u多(pipel.parse、pipel.decodebin、pipel.sink、NULL))
printf(“\n链接解析到接收器失败”);
g_信号连接(pipel.rtppay,“pad added”,g_回调(on_pad_added),pipel.parse);
}
现在工作

  • 使用cb_new_rtspsrc_pad动态添加pad
  • 将解析添加到bin
  • rtppay和parse之间的链接
  • 在字符串的其余部分添加必要的元素以使其正常工作
static void cb_new_rtspsrc_pad(GstElement *element,GstPad*pad,gpointer  data)
{
    gchar *name;
    GstCaps * p_caps;
    gchar * description;
    GstElement *p_rtph264depay;

    name = gst_pad_get_name(pad);
    g_print("A new pad %s was created\n", name);

    // here, you would setup a new pad link for the newly created pad
    // sooo, now find that rtph264depay is needed and link them?
    p_caps = gst_pad_get_pad_template_caps (pad);

    description = gst_caps_to_string(p_caps);
    printf("%s\n",p_caps,", ",description,"\n");
    g_free(description);

    p_rtph264depay = GST_ELEMENT(data);

    // try to link the pads then ...
    if(!gst_element_link_pads(element, name, p_rtph264depay, "sink"))
    {
        printf("Failed to link elements 3\n");
    }

    g_free(name);
}

/* ---------- Main --------------- */
int main(int argc, char *argv[])
{
    /* Initialize GStreamer */
    gst_init(&argc,&argv);

    /* Build Pipeline */ 
    pipel.pipeline = gst_pipeline_new("My pipeline");

    creating_pipeline(ip_address,port);

    pipel.source = gst_element_factory_make ("rtspsrc","source");
    g_object_set (G_OBJECT (pipel.source), "latency",2000,NULL);
    pipel.rtppay = gst_element_factory_make( "rtph264depay", "depayl");
    pipel.parse = gst_element_factory_make("h264parse","parse");
    pipel.filter1 = gst_element_factory_make("capsfilter","filter");
    pipel.decodebin = gst_element_factory_make ("openh264dec","decode");
    pipel.sink = gst_element_factory_make("d3dvideosink","sink");

    g_object_set (G_OBJECT (pipel.sink), "sync",FALSE,NULL);

    //create_uri(url,url_size,ip_address,port);
    g_object_set(GST_OBJECT(pipel.source),"location","rtsp://<ip>:554/live/ch00_0",NULL);

    filtercaps = gst_caps_from_string("application/x-rtp");
    g_object_set (G_OBJECT (pipel.filter1), "caps",filtercaps,NULL);

    gst_caps_unref(filtercaps);

    gst_bin_add_many (GST_BIN (pipel.pipeline),pipel.source
            ,pipel.rtppay
            ,NULL);
    // listen for newly created pads
    g_signal_connect(pipel.source, "pad-added", G_CALLBACK(cb_new_rtspsrc_pad),pipel.rtppay);
    gst_bin_add_many (GST_BIN (pipel.pipeline),pipel.parse,NULL);
    if(!gst_element_link(pipel.rtppay,pipel.parse))
        printf("\nNOPE\n");

    gst_bin_add_many (GST_BIN (pipel.pipeline),pipel.decodebin
            ,pipel.sink
            ,NULL);

    if(!gst_element_link_many(pipel.parse,pipel.decodebin,pipel.sink,NULL))
        printf("\nFailed to link parse to sink");

    g_signal_connect(pipel.rtppay, "pad-added", G_CALLBACK(on_pad_added), pipel.parse);
}