[Ffmpeg-devel] [RFC] faad/rtsp/aac bug...
Ryan Martell
rdm4
Tue Oct 31 03:08:55 CET 2006
Hey...
On Oct 30, 2006, at 7:03 PM, Michael Niedermayer wrote:
> 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)
It really is 22050. It's my stream, and if I replace the TODO above
with
codec->sample_rate = 44100
codec->channels = 2;
which it upconverts it to, it works just fine. I also checked the
faad source to verify I wasn't nuts. I'm not sure if this is
something that it is supposed to do (ie from some specification) or
not. I'm like you- if it says 22050/1, it should output 22050/1.
There may have been some reason relating to non-compatible sound
hardware.
I don't think there's a flag, but I will definitely check.
Other than that though, you think I should hack on faad.c to fix it.
I'll have to verify that that won't break the non-rtsp case.
Thanks,
-R
More information about the ffmpeg-devel
mailing list