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 551660 - gstreamer fails to handle variable number of channels in AC3 stream
gstreamer fails to handle variable number of channels in AC3 stream
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: dont know
0.10.x
Other All
: Normal normal
: 0.10.10
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2008-09-10 14:29 UTC by Andreas Moog
Modified: 2008-09-27 00:41 UTC
See Also:
GNOME target: ---
GNOME version: 2.23/2.24


Attachments
a52_flags.diff (2.54 KB, patch)
2008-09-10 23:36 UTC, Thijs Vermeir
none Details | Review
a52_flags.diff (2.82 KB, patch)
2008-09-15 22:51 UTC, Thijs Vermeir
none Details | Review

Description Andreas Moog 2008-09-10 14:29:30 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
Comment 1 Andreas Moog 2008-09-10 14:32:09 UTC
Testfile: http://launchpadlibrarian.net/17502489/mix.ac3
Comment 2 Moonshade 2008-09-10 14:49:39 UTC
Feel free to ask for additional information and test samples
Comment 3 Bastien Nocera 2008-09-10 14:53:19 UTC
Known problem in GStreamer.
Comment 4 Moonshade 2008-09-10 15:06:52 UTC
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.
Comment 5 Stefan Sauer (gstreamer, gtkdoc dev) 2008-09-10 20:21:08 UTC
number of channels and channel mappings are part of the caps and caps can change during playback. So in therory it is doable.
Comment 6 Thijs Vermeir 2008-09-10 23:36:44 UTC
Created attachment 118486 [details] [review]
a52_flags.diff

This patch rechecks the possible output channels when the channels in the stream change.
Comment 7 Moonshade 2008-09-12 11:14:11 UTC
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.
Comment 8 Thijs Vermeir 2008-09-12 17:05:53 UTC
(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?

Comment 9 Moonshade 2008-09-14 23:00:56 UTC
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
Comment 10 Thijs Vermeir 2008-09-15 22:51:24 UTC
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).
Comment 11 Moonshade 2008-09-17 21:28:26 UTC
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.
Comment 12 Jan Schmidt 2008-09-27 00:41:58 UTC
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