After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 574408 - audiomixer: Need an element to do synchronized audio mixing
audiomixer: Need an element to do synchronized audio mixing
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
0.10.22
Other All
: Normal enhancement
: 1.3.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2009-03-06 18:37 UTC by Balachandran. C
Modified: 2014-12-26 18:34 UTC
See Also:
GNOME target: ---
GNOME version: 2.25/2.26



Description Balachandran. C 2009-03-06 18:37:25 UTC
Please describe the problem:
Adder resets the timestamp of buffers to zero on state change from ready to pause. It disregards the timestamp of the incoming buffers. This causes synchronisation problems when downstream elements (eg. alsasink) sync on the clock. It results in having no audio.

Steps to reproduce:
1. Place an adder in a sink bin:=  queue2 ! adder ! alsasink.
2. Add this sink bin to a playing pipeline.
3. Link a playing source to this sink bin.

Actual results:
There is no audio written out to the soundcard, unless the "sync" property of alsasink is set to false. If false, audio is output with a substantial latency.


Expected results:
Adder should be able to produce a stream that is playable by syncing elements downstream. Audio is output when the adder is removed from the sink bin, the same behavior is expected when the adder element is a part of the bin.

Does this happen every time?
Yes.

Other information:
This is because the timestamp of the input buffers are not considered in computing the timestamp of the output buffer. Timestamp is set to zero everytime the element changes state from READY to PAUSED.
Comment 1 Stefan Sauer (gstreamer, gtkdoc dev) 2009-07-06 19:08:28 UTC
Having a test in adders unit-test suite would be great (gst-plugins-base/tests/check/elements/adder.c). Balachandran, could you try writing one and attach it here?
Comment 2 Stefan Sauer (gstreamer, gtkdoc dev) 2009-07-28 11:42:39 UTC
Now thinking more about it, I think the problem is the one in bug #474016. tee is not sending a newsegment to the new pad and thus adder starts from scratch.
Comment 3 Wim Taymans 2009-12-24 18:06:51 UTC
Almost all elements reset their timestamps to zero when going to READY so this is not so much different from, say, audiotestsrc.

If adder is supposed to preserve incomming timestamps it needs to be configured in sync mode (not implemented yet) where it would only mix incomming samples with the same timestamps to produce an  
outgoing stream with those timestamps.

If streams that don't need sync need to be mixed with streams that need sync, then 2 adders should be used, one configured with sync and the other without.

I think that would make most sense.
Comment 4 Olivier Crête 2011-05-20 14:55:38 UTC
liveadder does that... but I guess the real fix should be in GstCollectPads2 or something about which there is an open bug somewhere
Comment 5 Sebastian Dröge (slomo) 2013-08-16 11:55:42 UTC
I started working on this and have a somewhat working element called audiomixer in a local branch. Hope I have some time to finish it :)
Comment 6 oly 2013-08-23 18:33:47 UTC
I would love to know the status of this ?

I have built a pipeline with 6 samples added with addr, when i set the pipeline playing they all play perfectly in sync.

If i stop 3 of them setting there state to ready then trigger the pipeline back to playing they all start but not in sync i can hear them starting slightly one after the other sounds like it the same issue that others have experienced here.
Comment 7 oly 2013-08-23 19:28:42 UTC
I would love to know the status of this ?

I have built a pipeline with 6 samples added with addr, when i set the pipeline playing they all play perfectly in sync.

If i stop 3 of them setting there state to ready then trigger the pipeline back to playing they all start but not in sync i can hear them starting slightly one after the other sounds like it the same issue that others have experienced here.
Comment 8 Sebastian Dröge (slomo) 2013-08-24 08:29:03 UTC
I'm on it, I hope to be able to finish it in the next 1-2 weeks and put it in gst-plugins-bad then. If there's something to test I'll write it on the bug here :)
Comment 9 oly 2013-08-25 10:44:02 UTC
sounds great keep us posted :)
Comment 10 Sebastian Dröge (slomo) 2013-11-06 14:41:25 UTC
Took longer than expected, but here it is. New "audiomixer" element in gst-plugins-bad:

commit 69525a147771bcd95d1e24df3e501dad009bb126
Author: Sebastian Dröge <sebastian@centricular.com>
Date:   Wed Nov 6 15:31:31 2013 +0100

    audiomixer: Add test to the .gitignore file

commit e2e4e8e7414b0a92922fb2f6e08aecaa8b11ea95
Author: Sebastian Dröge <sebastian@centricular.com>
Date:   Wed Nov 6 15:18:58 2013 +0100

    audiomixer: Add simply synchronization test

commit caeaade7008b9716e4801afeb8a37d9ed240ccaf
Author: Sebastian Dröge <sebastian@centricular.com>
Date:   Wed Nov 6 15:18:50 2013 +0100

    audiomixer: Add new element based on adder that does synchronized audio mixing
Comment 11 Michael Olbrich 2013-11-08 10:50:37 UTC
Nice. Some comments about this:
I had to remove the special channel-mask handling. Otherwise negotiation failed because alsa sets it for channels=2. Note: I had to backport your patches to 1.0.x so this might have changed.

I mix a alsasrc with something unreliable (e.g. some kind of network source). I'd like to  always get the audio from alsa, even when the other source stops providing new buffers. Right now audiomixer just stalls. What's the correct way to handle this?
Comment 12 Sebastian Dröge (slomo) 2013-11-08 11:27:00 UTC
(In reply to comment #11)
> Nice. Some comments about this:
> I had to remove the special channel-mask handling. Otherwise negotiation failed
> because alsa sets it for channels=2. Note: I had to backport your patches to
> 1.0.x so this might have changed.

That should be fixed already, I fixed that soon after pushing the initial version

> I mix a alsasrc with something unreliable (e.g. some kind of network source).
> I'd like to  always get the audio from alsa, even when the other source stops
> providing new buffers. Right now audiomixer just stalls. What's the correct way
> to handle this?

Proper live support in collectpads and the mixers/muxers (i.e. not wait forever until buffers arrive but time out to properly continue mixing). I'm currently working on that whenever I have some time.