爲10ms力的GStreamer appsink緩衝區我有個GStreamer的管道,其下降的所有數據到appsink:只保存數據
command = g_strdup_printf ("autoaudiosrc ! audio/x-raw-int, signed=true, endianness=1234, depth=%d, width=%d, channels=%d, rate=%d !"
" appsink name=soundSink max_buffers=2 drop=true ",
bitDepthIn, bitDepthIn, channelsIn, sampleRateIn);
通常看起來像,
autoaudiosrc ! audio/x-raw-int, signed=true, endianness=1234, depth=16, width=16, channels=1, rate=16000 ! appsink name=soundSink max_buffers=2 drop=true
在運行時。
它捕捉到的音頻很好,問題是它傾向於捕獲任何隨機數量的數據,而不是一個設定的大小或時間間隔。因此,對於實例,請求數據的rtp庫只需要960個字節(48khz/1個通道/ 16位深度10ms),但緩衝區的長度可以從10ms到26ms。這個流水線每個緩衝區只返回10ms是非常重要的。有沒有辦法做到這一點?這是抓取數據的代碼。
void GSTMediaStream::GetAudioInputData(void* data, int max_size, int& written)
{
if (soundAppSink != NULL)
{
GstBuffer* buffer = gst_app_sink_pull_buffer (GST_APP_SINK (soundAppSink));
if (buffer)
{
uint bufSize = MIN (GST_BUFFER_SIZE (buffer), max_size);
uint offset = 0;
std::cout << "buffer time length is " << GST_BUFFER_DURATION(buffer) << "ns buffer size is " << GST_BUFFER_SIZE (buffer)
<< " while max size is " << max_size << "\n";
//if max_size is smaller than the buffer, then only grab the last 10ms captured.
//I am assuming that the reason for the occasional difference is because the buffers are larger
//in the amount of audio frames than the rtp stream wants.
if(bufSize > 0)
uint offset = GST_BUFFER_SIZE (buffer)- bufSize;
memcpy (data, buffer->data + offset, bufSize);
written = bufSize;
gst_buffer_unref(buffer);
}
}
}
更新 好了,我已經縮小的問題降到了GStreamer的脈衝音頻插件。 autoaudiosrc使用pulsesrc插件進行捕獲,無論出於何種原因,脈衝服務器在幾次重新播放後都會變慢。我用alsasrc進行了測試,它似乎處理採樣率變化,同時保持10ms的緩衝區,但問題是它不會讓我捕捉單聲道的音頻:只能用立體聲。