实际的gst版本是1.8.1。使用gstreamer 1.0解码流音频并访问波形数据?
目前我有接收gstreamer编码流并通过我的声卡播放它的代码。我想修改它,让我的应用程序访问原始未压缩的音频数据。这应该会产生一个整数声音样本数组,如果我要绘制它们,我会看到音频波形(例如完美的音调将是一个很好的正弦波),如果我要将最新的数组添加到最后一个回调收到我不会看到任何不连续。
这是当前播放代码: https://github.com/lucasw/audio_common/blob/master/audio_play/src/audio_play.cpp
我想我需要的alsasink更改为appsink,并设置一个回调已经通过解码器通过后,将获得音频的最新块。这是改编自https://github.com/jojva/gst-plugins-base/blob/master/tests/examples/app/appsink-src.c:
_sink = gst_element_factory_make("appsink", "sink");
g_object_set (G_OBJECT (_sink), "emit-signals", TRUE,
"sync", FALSE, NULL);
g_signal_connect (_sink, "new-sample",
G_CALLBACK (on_new_sample_from_sink), this);
再有就是回调:
static GstFlowReturn
on_new_sample_from_sink (GstElement * elt, gpointer data)
{
RosGstProcess *client = reinterpret_cast<RosGstProcess*>(data);
GstSample *sample;
GstBuffer *app_buffer, *buffer;
GstElement *source;
/* get the sample from appsink */
sample = gst_app_sink_pull_sample (GST_APP_SINK (elt));
buffer = gst_sample_get_buffer (sample);
/* make a copy */
app_buffer = gst_buffer_copy (buffer);
/* we don't need the appsink sample anymore */
gst_sample_unref (sample);
/* get source and push new buffer */
source = gst_bin_get_by_name (GST_BIN (client->_sink), "app_source");
return gst_app_src_push_buffer (GST_APP_SRC (source), app_buffer);
}
我可以在该回调的数据?我该怎么处理GstFlowReturn?如果这是将数据传递给另一个管道元素,我不想这样做,我宁愿在那里完成并完成。
https://github.com/lucasw/audio_common/blob/appsink/audio_process/src/audio_process.cpp
传递给回调gpointer数据正是我想要的(强制转换为gint16阵列?),否则我怎么转换和访问它?
谢谢!我目前正在手动转换为Float32,但如果我可以设置它来为我完成它,那么这将变得更加脆弱。 –