GNOME Bugzilla – Bug 551660
gstreamer fails to handle variable number of channels in AC3 stream
Last modified: 2008-09-27 00:41:58 UTC
Please describe the problem: Got a few movies recorded as MPEG-TS stream from satellite, one of audio streams is AC3. At the beginning this stream contains 2 channels and then switches to 6 channels. totem-gstreamer fails to make a correct switch to 6 channels, it continues to decode stream as it is stereo. FYI test results in other frameworks/players: 1) totem-xine and xine - switches correctly 2) mplayer - failure, keeps playing stereo 3) vlc - fails to switch Everything tested in Ubuntu 8.04, all players output to pulseaudio. MPC/ffdshow under windows also decodes stream correctly. Attaching sample AC3 file, demuxed and cut from original TS container. Switch from 2 to 6 channels occurs on 17th second. Steps to reproduce: Actual results: Expected results: Does this happen every time? Yes Other information: This bug was reported on Launchpad: https://bugs.edge.launchpad.net/ubuntu/+source/totem/+bug/268552
Testfile: http://launchpadlibrarian.net/17502489/mix.ac3
Feel free to ask for additional information and test samples
Known problem in GStreamer.
Is it a design problem in GStreamer or just a problem in particular module? GStream correctly handles changes in stream attributes in other places, for example aspect rate of video changes from 4:3 to 16:9 in the very same place of my MPEG-TS file, Gstreamer deals with it just fine.
number of channels and channel mappings are part of the caps and caps can change during playback. So in therory it is doable.
Created attachment 118486 [details] [review] a52_flags.diff This patch rechecks the possible output channels when the channels in the stream change.
Thanks for patch, Thijs! Had to recall my C skills and did some digging, GStreamer source looks very clean! Patch almost works, but I had to replace gst_structure_fixate_field_nearest_int() call with gst_structure_set() as first invocation fixates number of channel to 2 and never changes it later, as as a result renegotiation never occurs. No idea if it can break something else, could use some guidance here. Following the chain... pulsesink only handles change in like 30% of cases, failing in other 70% in gst_pulsesink_prepare(), some kind of timing/threading issue.. But thats another story, for now got around it by disabling check for stream state after connect. So for now, after applying patch and two more hacks sample AC3 file switches correctly! Full .ts container still fails to switch, probably demuxer or something else in a chain is forcing number of channels, will investigate later.
(In reply to comment #7) > Patch almost works, but I had to replace > gst_structure_fixate_field_nearest_int() call with gst_structure_set() as first > invocation fixates number of channel to 2 and never changes it later, as as a > result renegotiation never occurs. No idea if it can break something else, > could use some guidance here. That does not sound correct,... the gst_structure_fixate_field_nearest_int tries to get the amount of channels allowed in the caps. Using the *_set function does not look at the caps and forces this amount of channels (which can be a not allowed channel number in some cases). However we pick the first caps from a list of allowed caps, the caps are sorted in preferred order of the sink. However I see that alsasink is not prefering more channels over stereo... alsa gstalsasink.c:321:gst_alsasink_getcaps:<alsasink0> returning caps ...channels=(int)[ 1, 2 ]; ... channels=(int)4 ... So, on my system a52dec will always try to downmix to 2 channels because alsasink prefers this over multiple channels...but I assume that this is a bug in alsasink and it should prefer as much channels as possible. > Following the chain... pulsesink only handles change in like 30% of cases, > failing in other 70% in gst_pulsesink_prepare(), some kind of timing/threading > issue.. But thats another story, for now got around it by disabling check for > stream state after connect. Can you check what pulsesink is returning as preferred caps?
Some debugging output from GST_DEBUG="5" gst-launch filesrc location=mix.ac3 ! a52dec ! pulsesink 2>&1 | grep channels. Patch applied, no other hacks. Beginning of stream: http://pastebin.com/m6c0d945 18th second, switch to 6 channels: http://pastebin.com/m344cb04e
Created attachment 118801 [details] [review] a52_flags.diff The element was setting the caps to fixes caps on the src pad. Now it should switch to 6 channels,... (tested with pulsesink and fakesink).
Latest patch works for me, a52dec seems to switch channels just fine, in both directions :) Some other issues still left... sporadic pulsesink connection problems on switch already mentioned above, totem-gstreamer correctly switches sample ac3 only when visualisations are toggled off, properties pane in totem not updating, etc.. Will fill more bugreports when I get more time to investigate.
Awesome, this fixes my problems with at least one DVD. Committed: 2008-09-27 Jan Schmidt <jan.schmidt@sun.com> * ext/a52dec/gsta52dec.c: * ext/a52dec/gsta52dec.h: Fix channel re-negotiation on a change of the incoming stream. Patch By: Thijs Vermeir <thijsvermeir@gmail.com> Fixes: #551660