使用gstreamer apis

时间:2015-09-11 15:51:23

标签: gstreamer

我知道这个问题已多次发布。但这些解决方案都不适合我。

我正在尝试使用gstreamer apis播放.wav文件。 以下命令播放.wav文件(带或不带audioconvert):

gst-launch-1.0 filesrc location=sound.wav ! wavparse ! audioconvert ! alsasink

我为上面的命令the GStreamer Hello world example编写了一个简单的c ++代码。但它以“内部数据流错误”结束。这是我的代码:

{
    gst_init(NULL, NULL);
    m_pipeline  = gst_pipeline_new("audio-player");
    m_fileSource = gst_element_factory_make("filesrc", "file-source");
    m_parser = gst_element_factory_make("wavparse", "wav-parser");
    m_sink = gst_element_factory_make("alsasink", "audio-output");
    if (!m_pipeline || !m_fileSource || !m_parser || !m_sink) {
        g_printerr ("One or more elements could not be created !! \n");
        return false;
    }
    /* Set up the pipeline */
    else {
        /* set the input filename to the source element */
        g_object_set (G_OBJECT (m_fileSource), "location", path.toLatin1().data(), NULL);

        /* set a message handler on a bus */
        GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_pipeline));
        gst_bus_add_watch(bus, bus_call, this);
        gst_object_unref(bus);

        /* add all elements into the pipeline */
        gst_bin_add_many (GST_BIN (m_pipeline), m_fileSource, m_parser, m_sink, NULL);

        /* link the elements together */
        gst_element_link (m_fileSource, m_parser);

        g_signal_connect(m_parser, "pad-added", G_CALLBACK(on_pad_added), m_sink);
    }
    gst_element_set_state(m_pipeline, GST_STATE_READY);
    gst_element_set_state(m_pipeline, GST_STATE_PAUSED);
}

on_pad_added(GstElement *src_element, GstPad *src_pad, gpointer data)
{
    GstElement *sink_element = (GstElement *)data;

    GstPad *sink_pad = gst_element_get_static_pad(sink_element, "sink");
gst_pad_link(src_pad, sink_pad);

    gst_object_unref(sink_pad);
    src_element = NULL;
}

我甚至尝试了link中建议的解决方案;将“oggdemux”替换为“wavparse”,将“vorbisdec”替换为Gstreamer Hello World示例中的“identity”,如link所述。我收到错误:

    0:00:00.289443936  1624  0x1234e00 WARN                 basesrc gstbasesrc.c:3470:gst_base_src_start_complete:<file-source> pad not activated yet
0:00:00.290993573  1624  0x1740030 FIXME                default gstutils.c:3643:gst_pad_create_stream_id_internal:<wav-parser:src> Creating random stream-id, consider implementing a deterministic way of creating a stream-id
0:00:00.291883886  1624  0x1740030 WARN                wavparse gstwavparse.c:1564:gst_wavparse_stream_headers:<wav-parser> Ignoring chunk bext
0:00:00.292198262  1624  0x1740030 WARN                wavparse gstwavparse.c:1564:gst_wavparse_stream_headers:<wav-parser> Ignoring chunk junk
0:00:00.305086920  1624  0x1234e00 WARN                 basesrc gstbasesrc.c:3470:gst_base_src_start_complete:<file-source> pad not activated yet
0:00:00.306444838  1624  0x17400c0 FIXME                default gstutils.c:3643:gst_pad_create_stream_id_internal:<wav-parser:src> Creating random stream-id, consider implementing a deterministic way of creating a stream-id
0:00:00.307224214  1624  0x17400c0 WARN                wavparse gstwavparse.c:1564:gst_wavparse_stream_headers:<wav-parser> Ignoring chunk bext
0:00:00.307636819  1624  0x17400c0 WARN                wavparse gstwavparse.c:1564:gst_wavparse_stream_headers:<wav-parser> Ignoring chunk junk
0:00:00.526277506  1624  0x17400c0 WARN                wavparse gstwavparse.c:2186:gst_wavparse_loop:<wav-parser> error: Internal data flow error.
0:00:00.526495475  1624  0x17400c0 WARN                wavparse gstwavparse.c:2186:gst_wavparse_loop:<wav-parser> error: streaming task paused, reason not-linked (-1)
0:00:00.527296570  1624  0x1740030 WARN                wavparse gstwavparse.c:2186:gst_wavparse_loop:<wav-parser> error: Internal data flow error.
0:00:00.527439278  1624  0x1740030 WARN                wavparse gstwavparse.c:2186:gst_wavparse_loop:<wav-parser> error: streaming task paused, reason not-linked (-1)
ERROR: Internal data flow error.
ERROR: Internal data flow error.

我在代码中缺少什么?

1 个答案:

答案 0 :(得分:1)

你得到一个没有链接的错误,一些元素被取消链接。

元素是wavparse。你的代码试图等待它添加一个pad来链接它,但是wavparse总是有一个&#39;总是&#39;源代码填充,意味着它自元素创建以来就存在,因此您可以直接链接它,就像使用filesrc一样。