GNOME Bugzilla – Bug 636599
matroskademux: wrongly set caps rate with AAC audio
Last modified: 2018-11-03 14:43:02 UTC
Created attachment 175923 [details] A sample file audio is AAC 48Khz caps is created with rate=96Khz Using the attached file, or any other for that matter, the audio caps is build with the wrong sample rate value. GST_DEBUG="matr*:5" gst-launch-0.10 playbin2 uri="file:///samplerate_48_reported_96.mkv" 0:00:00.066778665 3153 0x27f10a0 DEBUG matroskademux matroska-demux.c:1555:gst_matroska_demux_add_stream:<matroskademux0> TrackAudioSamplingFrequency: 48000.000000 0:00:00.066796811 3153 0x27f10a0 DEBUG matroskademux matroska-demux.c:1591:gst_matroska_demux_add_stream:<matroskademux0> TrackAudioChannels: 2 0:00:00.066810746 3153 0x27f10a0 DEBUG matroskademux matroska-demux.c:1607:gst_matroska_demux_add_stream:<matroskademux0> Parsing TrackAudio element finished with 'ok' 0:00:00.066824620 3153 0x27f10a0 DEBUG matroskademux matroska-demux.c:1815:gst_matroska_demux_add_stream:<matroskademux0> Parsing TrackEntry element finished with 'ok' 0:00:00.066845196 3153 0x27f10a0 DEBUG matroskademux matroska-demux.c:6740:gst_matroska_demux_audio_caps: obj_type = 2, freq_index = 3 0:00:00.066906340 3153 0x27f10a0 INFO matroskademux matroska-demux.c:1954:gst_matroska_demux_add_stream:<matroskademux0> Adding pad 'audio_00' with caps audio/mpeg, mpegversion=(int)4, framed=(boolean)true, codec_data=( buffer)119056e500, channels=(int)2, rate=(int)96000 As we can see audio is detected as 48000 (TrackAudioSamplingFrequency) but the caps has rate=(int)96000 The error is in matroska-demux.c::gst_matroska_demux_audio_caps (line 6776) where context->codec_priv_size == (5 + explicit_freq_bytes)is evaluated to true if (obj_type == 5 || (freq_index >= 6 && freq_index != 15) || (context->codec_priv_size == (5 + explicit_freq_bytes))) { audiocontext->samplerate *= 2; audiocontext->samplerate gets doubled up because of explicit_freq_bytes. I would have provided a path but I am not sure what explicit_freq_bytes should be ?
I would say the above lines are not really an error (though maybe not optimal); 5 bytes of codec-data probably indicates HE-AAC (e.g. SBR), which is why the samplerate is doubled. Problem is that it is hard to know whether some other field (e.g. matroska samplerate field) has already taken this into account or not. Definitive solution may require codec-utils in -base to also support parsing of HE-AAC codec-data (which may need some more specs in that area).
Created attachment 189851 [details] [review] matroskademux: improve the AAC codec data parsing logic
Created attachment 189869 [details] [review] matroskademux: use GstBitReader instead of masks to read AAC codec data
Created attachment 189870 [details] [review] matroskademux: improve the AAC codec data parsing logic
Split the initial patch in two parts: first one replaces the masks by GstBitReader, the second one changes the logic.
Created attachment 189884 [details] [review] matroskademux: use GstBitReader instead of masks to read AAC codec data Create the GstBitReader on the stack.
Created attachment 189885 [details] [review] matroskademux: improve the AAC codec data parsing logic Create the GstBitReader on the stack.
This should be integrated into gst-plugins-base/gst-libs/gst/pbutils/codec-utils. And then used in matroskademux, but also aacparse.
Still applies to git master (note: sample file is only the header, parser/demuxer errors are expected)
-- GitLab Migration Automatic Message -- This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/issues/37.