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