[Ffmpeg-devel] [RFC] faad/rtsp/aac bug...

Michael Niedermayer michaelni
Wed Nov 1 17:50:45 CET 2006


Hi

On Wed, Nov 01, 2006 at 04:12:12PM +0100, bond wrote:
> > Date: Tue, 31 Oct 2006 02:03:35 +0100
> > From: Michael Niedermayer <michaelni at gmx.at>
> > Subject: Re: [Ffmpeg-devel] [RFC] faad/rtsp/aac bug...
> > To: FFmpeg development discussions and patches
> > <ffmpeg-devel at mplayerhq.hu>
> > Message-ID: <20061031010334.GG22553 at MichaelsNB>
> > Content-Type: text/plain; charset=us-ascii
> >
> > Hi
> >
> > On Mon, Oct 30, 2006 at 06:38:44PM -0600, Ryan Martell wrote:
> > > Hi--
> > >
> > > So there's a bug in rtsp.c/faad, that I could use a suggestion on
> > > fixing.
> > >
> > > 1) in rtsp.c:
> > >                     codec->sample_rate = i;
> > >                     get_word_sep(buf, sizeof(buf), "/", &p);
> > >                     i = atoi(buf);
> > >                     if (i > 0)
> > >                         codec->channels = i;
> > >                     // TODO: there is a bug here; if it is a mono
> > > stream, and less than 22000Hz, faad upconverts to stereo and twice the
> > >                     //  frequency.  No problem, but the sample rate
> > > is being set here by the sdp line.  Upcoming patch forthcoming. (rdm)
> > >
> > > 2) In faad.c:
> > >     if (avctx->extradata){
> > >         r = s->faacDecInit2(s->faac_handle, (uint8_t*) avctx-
> > > >extradata,
> > >                             avctx->extradata_size,
> > >                             &samplerate, &channels);
> > >         if (r < 0){
> > >             av_log(avctx, AV_LOG_ERROR,
> > >                    "faacDecInit2 failed r:%d   sr:%ld  ch:%ld  s:%d\n",
> > >                    r, samplerate, (long)channels, avctx-
> > > >extradata_size);
> > >         } else {
> > >             avctx->sample_rate = samplerate;
> > >             avctx->channels = channels;
> > >             s->init = 1;
> > >         }
> > >     }
> > >
> > > 3) The extradata specifies the channel count and the frequency.  In
> > > my case, it specifies it as a 22050/1, which is also what the SDP
> > > line says.
> > >
> > > 4) in the faad code, if the frequency is lower than a 22000Hz, it
> > > doubles the frequency, and if it is a mono channel, it doubles it to
> > > stereo.
> > >
> > > The hardware buffers are opened in ffplay, after the rtsp stuff is
> > > parsed but before the aac code is called that tells it to
> > > upconvert.   As a result, if it is a 22050 mono stream, it is really
> > > slow sounding.
> > >
> > > I could include the logic from aac that talks about how to do this
> > > (based on the extradata), but I believe that the upconversion/
> > > doubling of channels might just be a faad thing, and put that in the
> > > rtp code, but that seems potentially buggy.
> > >
> > > Any advice on where/how to fix this cleanly would be appreciated.
> >
> > the bug is clearly in faad, if the stream is 22khz mono faad should
> > output that and nothing else
> > id suggest to simply discard every second sample and the second chanel
> > in libavcodec/faad.c if faad messes with the samplingrate (but first
> > check that there is no parameter to faad which disables this silly
> > behavior and second confirm that the stream really is 22kz and not 44khz)
> 
> this is not a bug in faad2, but a feature ;)

i dont agree


> 
> according to menno, the faad2 dev, the mpeg aac standard does not define the
> necessity to explicitely signal the useage of sbr/he-aac (aka fake double
> frequency) in an aac stream. to still be able to play streams not signalling
> sbr with sbr, faad2 simply doubles the frequency for all low frequency
> streams (like 22khz) using sbr if its available

well if a stream doesnt signal sbr in any way then a aac decoder cannot decode
the high frequencies
what may be (i dunno the aac spec ... url for it would be welcome ...) is that
22khz packets could be mixed with 44khz packets (later with sbr would use
a different psychoacoustic lossy coding for the high 22khz) that of course
is very bad design ...

and if the you can figure out from n packets of an aac stream if any future
packets might contain 2x the sampling rate or not doesnt change the fact that
if the user sets sample_rate to 22khz then IMO the aac decoder should not 
second guess that unless it is abosolutely certain that the stream uses a 
higher sampling rate

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In the past you could go to a library and read, borrow or copy any book
Today you'd get arrested for mere telling someone where the library is




More information about the ffmpeg-devel mailing list