使用rtspsrc创建Gstreamer pad

时间:2017-01-25 04:53:08

标签: c gstreamer gstreamer-1.0

我正在尝试使用打击垫链接音频和视频分档。但不知怎的,我得到了像

这样的错误

“内部数据流错误,原因未链接”。

我无法找到我的应用程序出现此错误的原因。 任何帮助表示赞赏。

请找到附带的代码段:

#include <gst/gst.h>
#include <glib.h>
#include <glib/gprintf.h>

GstElement *audioQueue, *videoQueue;
GstElement *source, *audio, *video, *convert, *pipeline, *audioDepay,*audioParse, *audioDecode, *audioConvert, *audioResample, *audioSink, *videoDepay, *videoParser, *videoDecode, *videoConvert, *videoScale, *videoSink;

在此处添加和链接音频和视频队列的打击垫:

static void onPadAdded(GstElement *element, GstPad *pad, gpointer data)
{
#if 1
    GstCaps *caps;
    const char *name;
    char *capsName;
    caps = gst_pad_get_current_caps(pad);
    GstStructure *str = gst_caps_get_structure(caps, 0);
    name = gst_structure_get_name(str);
    g_print("name of caps struct string: %s \n", name);
    capsName = gst_caps_to_string(caps);
    g_print("name of caps string: %s \n", capsName);
#endif
    if (g_strrstr(capsName,"audio"))
    {
            g_print("here .....1 \n");
            GstPad *dynamic_pad = gst_element_get_static_pad(audioQueue, "sink");
            gst_pad_link(pad, dynamic_pad);
    }

    else if (g_strrstr(capsName, "video"))
    {
            g_print("here .....2 \n");
            GstPad *video_dynamic_pad= gst_element_get_static_pad(videoQueue, "sink");
            gst_pad_link(pad, video_dynamic_pad);
    }
    g_free(capsName);

}

从这里开始主要功能:

int main(int argc, char *argv[]) {
    GstCaps *capsFilter;
    GstBus *bus;
    GstMessage *msg;
    GstPad *pad;
    gboolean link_ok;
    GstStateChangeReturn ret;

    /* Initialize GStreamer */
    gst_init (&argc, &argv);


    /* Create Elements */
    pipeline = gst_pipeline_new("rtsp-pipeline");
    source = gst_element_factory_make ("rtspsrc", "rtsp-source");
    g_object_set(source, "location", "rtsp://192.168.3.30:8554/rajvi", NULL);
    g_object_set(source, "latency", 0, NULL);
       audioQueue = gst_element_factory_make ("queue", "audio-queue");
    audioDepay = gst_element_factory_make ("rtpmp4gdepay", "audio-depayer");
    audioParse = gst_element_factory_make ("aacparse", "audio-parser");
    audioDecode = gst_element_factory_make ("avdec_aac", "audio-decoder");
    audioConvert = gst_element_factory_make ("audioconvert", "aconv");
    audioResample = gst_element_factory_make ("audioresample", "audio-resample");
    audioSink = gst_element_factory_make ("autoaudiosink", "audiosink");

    if (!audioQueue || !audioDepay || !audioParse || !audioConvert || !audioResample || !audioSink)
    {
            g_printerr("Cannot create audio elements \n");
            return 0;
    }
    videoQueue = gst_element_factory_make ("queue", "video-queue");
    videoDepay= gst_element_factory_make ("rtph264depay", "video-depay");
    videoParser = gst_element_factory_make ("h264parse", "video-parser");
    videoDecode = gst_element_factory_make ("omxh264dec", "video-decoder");
    videoConvert = gst_element_factory_make("videoconvert", "convert");
    videoScale = gst_element_factory_make("videoscale", "video-scale");
    videoSink = gst_element_factory_make("ximagesink", "video-sink");
    capsFilter = gst_caps_new_simple("video/x-raw",
                    "width", G_TYPE_INT, 176,
                    "height", G_TYPE_INT, 144,
                    NULL);

    if (!videoQueue || !videoDepay || !videoParser || !videoDecode || !videoConvert || !videoScale || !videoSink || !capsFilter)
    {
            g_printerr("Cannot create video elements \n");
            return 0;
    }
    gst_bin_add(GST_BIN(pipeline), source);
    gst_bin_add_many(GST_BIN(pipeline),
                    audioQueue, audioDepay, audioParse, audioDecode, audioConvert, audioResample, audioSink,
                    videoQueue, videoDepay, videoParser, videoDecode, videoConvert, videoScale, videoSink, NULL);

    if (!gst_element_link_many(audioQueue, audioDepay,  NULL ))
    {
            g_printerr("Cannot link audioqueue  and audioDepay \n");
            return 0;
    }
    if (!gst_element_link_many(audioParse, audioDecode, NULL ))
    {
            g_printerr("Cannot link audioParse and audiodecode \n");
            return 0;
    }
    if (!gst_element_link_many( audioConvert, audioResample, audioSink, NULL ))
    {
            g_printerr("Cannot link audioConvert, audioParse, audioSink \n");
            return 0;
    }

    /*Linking filter element to videoScale and videoSink */
    link_ok = gst_element_link_filtered(videoScale,videoSink, capsFilter);
    gst_caps_unref (capsFilter);
    if (!link_ok) {
            g_warning ("Failed to link element1 and element2!");
            return 0;
    }
    /* Linking video elements internally */
    if (!gst_element_link_many(videoQueue, videoDepay,  NULL))
    {
            g_printerr("Cannot link videoQueue and videoDepay \n");
            return 0;
    }
    if (!gst_element_link_many(videoParser, videoDecode, videoConvert, NULL))
    {
            g_printerr("Cannot link videoParser, videoDecode, videoConvert \n");
            return 0;
    }

信号连接rtspsrc有两个焊盘源和从这里下沉:

    g_signal_connect(source, "pad-added", G_CALLBACK(onPadAdded), NULL);

      /* Start playing */
    gst_element_set_state ( pipeline, GST_STATE_PLAYING);

    /* Wait until error or EOS */
    bus = gst_element_get_bus (pipeline);
    msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);

    /* Free resources */
    if (msg != NULL)
            gst_message_unref (msg);
    gst_object_unref (bus);
    gst_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (pipeline);
    return 0;
}

0 个答案:

没有答案