使用 gstreamer api 播放 .wav 文件时出错
error while playing .wav file using gstreamer apis
我知道这个问题已经发布了好几次了。但是 none 的解决方案对我有用。
我正在尝试使用 gstreamer api 播放 .wav 文件。
下面的命令播放 .wav 文件(有或没有 audioconvert):
gst-launch-1.0 filesrc location=sound.wav ! wavparse ! audioconvert ! alsasink
我已经为上述命令编写了一个简单的 C++ 代码,参考 the GStreamer Hello world example。但它以 "Internal data flow error" 结尾。这是我的代码:
{
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; replaced "oggdemux" with "wavparse" and "vorbisdec" with "identity" from the Gstreamer Hello World example as suggested in this 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.
我在代码中遗漏了什么?
您收到未linked 错误,某些元素未linked。
元素是wavparse。您的代码试图等待它向 link 添加一个 pad,但是 wavparse 有一个 'always' 源 pad,这意味着它自元素创建以来就存在,因此您可以 link 它直接就像你对你的 filesrc 所做的那样。
我知道这个问题已经发布了好几次了。但是 none 的解决方案对我有用。
我正在尝试使用 gstreamer api 播放 .wav 文件。 下面的命令播放 .wav 文件(有或没有 audioconvert):
gst-launch-1.0 filesrc location=sound.wav ! wavparse ! audioconvert ! alsasink
我已经为上述命令编写了一个简单的 C++ 代码,参考 the GStreamer Hello world example。但它以 "Internal data flow error" 结尾。这是我的代码:
{
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; replaced "oggdemux" with "wavparse" and "vorbisdec" with "identity" from the Gstreamer Hello World example as suggested in this 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.
我在代码中遗漏了什么?
您收到未linked 错误,某些元素未linked。
元素是wavparse。您的代码试图等待它向 link 添加一个 pad,但是 wavparse 有一个 'always' 源 pad,这意味着它自元素创建以来就存在,因此您可以 link 它直接就像你对你的 filesrc 所做的那样。