python - Looping playback of a list of Gst.Sample with GstApp.AppSrc -


i'm trying write simple music player using gstreamer. want play arbitrary music file abs_file_path, store samples other purposes , later loop on these indefinitely, once original end of stream reached.

now playing music works fine until short after last sample of track played. of time there's silence, there 1 or 2 audible samples indicating, track started playing again. same holds terminal output. shows, few samples after looping started, need-data signal sent more before.

i've used fakesink dumping data, seemed work fine. data looped, intended.

so happens here? why don't samples play second (third, fourth, ...) time? i've run out of ideas.

following added minimal example of i'm doing without ui, same problem:

import itertools, signal signal.signal(signal.sigint, signal.sig_dfl) gi.repository import gst, gstapp, gtk gst.init(none)  # read samples gst.appsink playbin playbin = gst.elementfactory.make("playbin") playbin.props.uri = "file://" + abs_file_path # works absolute paths playbin.props.audio_sink = gstapp.appsink(sync=false, emit_signals=true) playbin.set_state(gst.state.playing)  # loop on samples def samples(app_sink):     samples = []     sample = app_sink.pull_sample()     while sample:         yield sample         samples.append(sample)         sample = app_sink.pull_sample()     print('looping')     sample in itertools.cycle(samples):         yield sample  # write samples gst.appsrc def need_data(appsrc, length, samples):     print('sample')     sample = next(samples)     appsrc.set_caps(sample.get_caps())     appsrc.push_buffer(sample.get_buffer()) src = gstapp.appsrc(format=gst.format.time, emit_signals=true) src.connect('need-data', need_data, samples(playbin.props.audio_sink))  # autoaudiosink or fakesink sink = gst.elementfactory.make("autoaudiosink") #sink = gst.elementfactory.make("fakesink") #sink.props.dump = true # dump contents of fakesink  # playback play = gst.pipeline() play.add(src) play.add(sink) src.link(sink) play.set_state(gst.state.playing)  gtk.main() 

gst-plugins-base: 1.4.4

i've found working solution of comment of thiagoss.

the gstbuffer struct documentation lists fields relevant timestamp

struct gstbuffer {   [...]   /* timestamp */   gstclocktime           pts;   gstclocktime           dts;   gstclocktime           duration;   [...] }; 

where presentation timestamp pts relevant value. setting gst.clock_time_none before using sample second time solve issue:

# loop on samples def samples(app_sink):     samples = []     sample = app_sink.pull_sample()     while sample:         yield sample         sample.get_buffer().pts = gst.clock_time_none #unset pts         samples.append(sample)         sample = app_sink.pull_sample()     print('looping')     sample in itertools.cycle(samples):         yield sample 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -