實際的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,但如果我可以設置它來爲我完成它,那麼這將變得更加脆弱。 –