[Ffmpeg-devel] MP3 decoding from RTP stream. Getting "invalid new backstep"

Martin marthi
Tue Oct 31 13:24:46 CET 2006


M?ns Rullg?rd wrote:
> Martin Thielen said:
>>>>I'm using ffmpeg to encode MP3 data transmit it over RTP and decode it.
>>>>If I start the RTP sender before the receiver I get warnings on the
>>>>decoder side from the ffmpeg library (only at the very beginning):
>>>>backstep:452, lastbuf:0
>>>>invalid new backstep 381
>>>>overread, skip -5 enddists: -4 -4
>>>>overread, skip -9 enddists: -1 -1
>>>>invalid new backstep 382
>>>>The sound is distorted as well (just for 1 second or so). Is it somehow
>>>>possible to tell the AVParser or the decoder to discard the frames that
>>>>leads to the distortion?
>>>yes if you implement it and send a patch, and yes i fully agree that the
>>>mp3 decoder should discard such packets instead of annoying the user
>>>with the noise
>>>just look at the code which outputs the error messages and silence the
>>>output somehowm shouldnt be too hard
>>I'm trying to silence the distorted output now. What would you consider
> Didn't Michael already do something?
>>the best way:
>>1) Return a value that indicates a problem
>>2) Set a flag (which one?) in AVCodecContext that indicates a problem
>>3) Changing the buffer values to 0? Is 0 the right value for silence?
> Zero is not a good value as it will cause pops or clicks if the previous
> sample has a large value.

ok, I had a look at the new source again and I think -1 is returned now
in the mp_decode_layer3 function of the file mpegaudiodec.c:

if(main_data_begin > s->last_buf_size){
  av_log(NULL, AV_LOG_ERROR, "backstep:%d, lastbuf:%d\n",
main_data_begin, s->last_buf_size);
//        s->last_buf_size= main_data_begin;
        return -1;

My problems result from 2 points in the mp_decode_frame function:

if(i >= 0 && i <= BACKSTEP_SIZE) {
   memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb)>>3), i);
   } else
      av_log(NULL, AV_LOG_ERROR, "invalid old backstep %d\n", i);


if(i<0 || i > BACKSTEP_SIZE || nb_frames<0){
            av_log(NULL, AV_LOG_ERROR, "invalid new backstep %d\n", i);
            i= FFMIN(BACKSTEP_SIZE, buf_size - HEADER_SIZE);

Is it a solution to return -1 at these two points, as well or would it
break something? Is the return value propagated to the api functions
avcodec_decode_audio or av_parser_parse then?


More information about the ffmpeg-devel mailing list