2017-07-16 20 views
0

我在gstreamer管道中使用交錯元素時遇到問題。當使用帶有兩個接收器的交錯元素時,Gst管道未運行

我正在從輸入(autoaudiosrc)中讀取音頻到一個tee中,所以我可以將它寫入磁盤並實時獲取音頻電平(將其添加到硬件vu計量器中,級別到標準輸出)。我希望能夠使用任何1或2個通道並將它們寫入單獨的文件,這樣我就可以將6個輸入通道分成5個文件(1個立體聲,4個單聲道)。 現在把一切寫到一個文件中工作正常,然後我添加了一個deinterleave元素來將所有文件拆分成單聲道文件,這些文件也可以正常工作,但是將兩個通道合併到一個立體聲通道中會破壞整個管道。

def new_recorder_bin(path, sinks=1): 
    bin = Gst.Bin() 
    interleave = Gst.ElementFactory.make('interleave', None) 
    queue = Gst.ElementFactory.make('queue', None) 
    encoder = Gst.ElementFactory.make('wavenc', None) 
    output = Gst.ElementFactory.make('filesink', None) 
    output.set_property('location', path) 
    bin.add(interleave) 
    bin.add(queue) 
    bin.add(encoder) 
    bin.add(output) 
    interleave.link(queue) 
    queue.link(encoder) 
    encoder.link(output) 
    if sinks == 1: 
     interleave.set_property('channel_positions', [GstAudio.AudioChannelPosition.MONO]) 
     sink = interleave.get_request_pad('sink_0') 
     ghostpad = Gst.GhostPad.new('sink_0', sink) 
     bin.add_pad(ghostpad) 
    elif sinks == 2: 
     interleave.set_property('channel_positions', [ 
      GstAudio.AudioChannelPosition.FRONT_LEFT, 
      GstAudio.AudioChannelPosition.FRONT_RIGHT 
     ]) 
     sink0 = interleave.get_request_pad('sink_0') 
     ghostpad0 = Gst.GhostPad.new('sink_0', sink0) 
     sink1 = interleave.get_request_pad('sink_1') 
     ghostpad1 = Gst.GhostPad.new('sink_1', sink1) 
     bin.add_pad(ghostpad0) 
     bin.add_pad(ghostpad1) 
    return bin 

這是創建一個新的bin來將一個或兩個通道寫入磁盤的代碼。當我只連接到一個水槽墊(並將水槽設置爲1)時,一切仍然正常,但是當我連接兩個水槽墊(並將水槽設置爲2)時,文件被創建,但管道似乎卡住了。級別不會打印出來,也不會將數據寫入文件。

我已經附上完整的文件的要點,這是原型代碼,但在我重構此之前,我希望一切工作,因爲它應該。

https://gist.github.com/maxjoehnk/16785499db6e864bf120cf85a81b1ecf

+0

不確定完整流水線的樣子。但是因爲所有音頻都來自一個線程(相同的音頻源)。我希望交錯元素能夠阻止自己。嘗試在交織匯點之前添加隊列元素。 –

+0

現在我有一個將信號「分裂」成兩個隊列的三通,一個用於level元素,另一個用於解交錯元素。完整管道的源代碼可以在我已鏈接的要點中找到。我真的需要爲每個pad或每個元素添加一個隊列嗎?因爲我在交錯元素後面有一個隊列,所以我不太確定如何在之前添加它 –

回答

0

好了,所以通過Florian Zwoch的意見是線索。我爲每個頻道添加了一個隊列,現在一切正常。所以我new_recorder_bin函數現在看起來是這樣的:

def new_recorder_bin(path, sinks=1): 
    bin = Gst.Bin() 
    interleave = Gst.ElementFactory.make('interleave', None) 
    encoder = Gst.ElementFactory.make('wavenc', None) 
    output = Gst.ElementFactory.make('filesink', None) 
    output.set_property('location', path) 
    bin.add(interleave) 
    bin.add(encoder) 
    bin.add(output) 
    interleave.link(encoder) 
    encoder.link(output) 
    if sinks == 1: 
     queue = Gst.ElementFactory.make('queue', None) 
     bin.add(queue) 
     interleave.set_property('channel_positions', [GstAudio.AudioChannelPosition.MONO]) 
     sink = interleave.get_request_pad('sink_0') 
     queueSink = queue.get_static_pad('sink') 
     queueSrc = queue.get_static_pad('src') 
     queueSrc.link(sink) 
     ghostpad = Gst.GhostPad.new('sink_0', queueSink) 
     bin.add_pad(ghostpad) 
    elif sinks == 2: 
     queue0 = Gst.ElementFactory.make('queue', 'Queue L') 
     queue1 = Gst.ElementFactory.make('queue', 'Queue R') 
     bin.add(queue0) 
     bin.add(queue1) 
     interleave.set_property('channel_positions', [ 
      GstAudio.AudioChannelPosition.FRONT_LEFT, 
      GstAudio.AudioChannelPosition.FRONT_RIGHT 
     ]) 
     sink0 = interleave.get_request_pad('sink_0') 
     queueSink0 = queue0.get_static_pad('sink') 
     queueSrc0 = queue0.get_static_pad('src') 
     queueSrc0.link(sink0) 
     ghostpad0 = Gst.GhostPad.new('sink_0', queueSink0) 
     sink1 = interleave.get_request_pad('sink_1') 
     queueSink1 = queue1.get_static_pad('sink') 
     queueSrc1 = queue1.get_static_pad('src') 
     queueSrc1.link(sink1) 
     ghostpad1 = Gst.GhostPad.new('sink_1', queueSink1) 
     bin.add_pad(ghostpad0) 
     bin.add_pad(ghostpad1) 
    return bin 

這是不是特別乾淨,但它似乎做工精細所以現在我會堅持下去。

相關問題