gstreamer播放rtsp碼流C語言

在gstreamer框架下使用C語言編寫播放rtsp碼流,
以下就是用到的元件,其中解碼元件(vaapih264de可以換成decodebin使用軟解碼),並且cb_new_rtspsrc_pad()爲source是接收元件的回調函數,用於連接解封裝元件
完整的代碼下載連接在我的資源站中,可以去我的博客下載資源上查找
source = gst_element_factory_make ( “rtspsrc”, “source”);
g_object_set (G_OBJECT (source), “latency”, 2000, NULL);
rtppay = gst_element_factory_make ( “rtph264depay”, “depayl”);
parse = gst_element_factory_make ( “h264parse”, “parse”);
decodebin = gst_element_factory_make ( “vaapih264dec”, “decode”);
sink = gst_element_factory_make ( “xvimagesink”, “sink”);

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);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章