Use decodebin with adder

I am trying to create an audio stream with a constant source of sound (in this case, audiotestsrc), to which I can sometimes add sounds from files (of various formats, which is why I use decodebin) via play_file (). For this purpose I use an adder. However, for some reason, I cannot correctly add a second sound. Not only does the program play the sound incorrectly, but it also completely stops the original audiotestsrc. Here is my code:

import gst; import gobject; gobject.threads_init() pipe = gst.Pipeline() adder = gst.element_factory_make("adder", "adder") first_sink = adder.get_request_pad('sink%d') pipe.add(adder) test = gst.element_factory_make("audiotestsrc", "test") test.set_property('freq', 100) pipe.add(test) testsrc = test.get_pad("src") testsrc.link(first_sink) output = gst.element_factory_make("alsasink", "output") pipe.add(output) adder.link(output) pipe.set_state(gst.STATE_PLAYING) raw_input('Press key to play sound') def play_file(filename): adder_sink = adder.get_request_pad('sink%d') audiofile = gst.element_factory_make('filesrc', 'audiofile') audiofile.set_property('location', filename) decoder = gst.element_factory_make('decodebin', 'decoder') def on_new_decoded_pad(element, pad, last): pad.link(adder_sink) decoder.connect('new-decoded-pad', on_new_decoded_pad) pipe.add(audiofile) pipe.add(decoder) audiofile.link(decoder) pipe.set_state(gst.STATE_PAUSED) pipe.set_state(gst.STATE_PLAYING) play_file('sample.wav') while True: pass 
+4
source share
1 answer

Thanks to moch on #gstreamer, I realized that all adder sources should have the same format. I modified the above script so that the caps are "audio/x-raw-int, endianness=(int)1234, channels=(int)1, width=(int)16, depth=(int)16, signed=(boolean)true, rate=(int)11025" (example) passed before each input in the adder.

+4
source

Source: https://habr.com/ru/post/1336345/


All Articles