Query duration of many sound files in a loop

Tim-Philipp Müller t.i.m at zen.co.uk
Sat Aug 17 10:40:49 PDT 2013


On Sat, 2013-08-17 at 04:52 +0300, Jiergir Ogoerg wrote:

Hi,

> I wanna query a lot of sound files duration in a loop efficiently, so
> instead of waiting in a sub-loop with a sleep method until the query
> succeeds for each given file - I wanna go for the second approach by
> processing the GST_MESSAGE_ASYNC_DONE message on the bus, thus
> bypassing the potential need to do (several) sleep(s) for each sound
> file.
> 
> 
> How do I do it properly?
> 
> The only thing I can think about is launching the files query loop in
> a different thread, from there for each file block on a condition
> variable until I get the async event on the bus on the main thread
> which would fire pthread_cond_signal() to unblock the querying thread
> to query the corresponding file and move on to the next sound file in
> the loop.
> 
> 
> Is there a better way to implement this non-sleep approach?

If you're happy to block, you could simply do:

 msg = gst_bus_timed_pop_filtered (bus, -1,
     GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR);

which will block until you get an error message or async_done.


> How do I know that GST_MESSAGE_ASYNC_DONE isn't fired by some other
> source since gstreamer is multi-threaded and can work with many sound
> sources in parallel so the events on the bus might be rather random,
> right?

Not sure if I understand this question right. What's your setup exactly?
Do you have multiple pipelines? Or are you trying to process multiple
files in parallel within the same pipeline?

ASYNC_DONE is part of the preroll mechanism in GStreamer. It is usually
posted by sinks, and aggregated by bins/the pipeline to only be
forwarded once all sinks/children are finished prerolling.

Cheers
 -Tim




More information about the gstreamer-devel mailing list