[Live-devel] Arithmetic exception in MP3Internals

Eric Peters epeters at graphics.cs.uni-sb.de
Thu Oct 27 15:59:53 PDT 2005


Hallo all,

following problem: Sometimes, I got an arithmetic exception in
MP3Internals::ComputeFrameSize. I'm streaming from a live source a demuxed MPEG
audio and video stream. So sometimes when a new client connects via RTSP to my
server there occurs the exception.

I made a core dump and looked in ddd to the values:

In MP3FrameParams::setParamsFromHeader() the samplingFrequency is derived by
parsing a index value out of the mpeg header:

  if (isMPEG2_5) {
    samplingFreqIndex = ((hdr>>10)&0x3) + 6;
  } else {
    samplingFreqIndex = ((hdr>>10)&0x3) + (isMPEG2*3);
  }

Because of isMPEG2_5 the first case is used and the resulting value
samplingFreqIndex = 9 . Some lines later the sampling frequency is set out of
the array live_freqs[] which is defined in the head using the samplingFreqIndex.

If I look into the array I see that the corresponding value for the index 9 is 0. So

samplingFreq = 0

If all values are calculated, MP3Internals::ComputeFrameSize is called with the
values

ComputeFrameSize(144, 0, 0, 1, 1)

In ComputeFrameSize the frame size is calculated by

  unsigned const bitrateMultiplier = (layer == 1) ? 12000*4 : 144000;
  unsigned framesize;

  framesize = bitrate*bitrateMultiplier;
  framesize /= samplingFreq<<isMPEG2;
  framesize = framesize + usePadding - 4;

Now to the arithmetic exception. My sampling frequency is 0 shifted by 1 is 0.
So if you try to divide the framesize by 0 the exception occurs.

Sorry for this long explanation. But I can't give you an example to reproduce
this bug because it is a live stream. So I think if you have as many information
as you can get, you have an idea where the problem is. I used the actual release
from today.

Perhaps this problem can be fixed by a test wether this value equals 0 or not.
If it is 0 can you return 0 as framesize??

Thanks in advance
Eric


More information about the live-devel mailing list