MP3 decoding from RTP stream. Getting "invalid new backstep"
Hi,
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
[...]
Hi, I'm trying to silence the distorted output now. What would you consider 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? Thanks, Martin
Martin Thielen said:
Hi,
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
[...]
Hi,
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. -- M?ns Rullg?rd mru at inprovide.com
Hi, M?ns Rullg?rd wrote:
Martin Thielen said:
Hi,
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
[...]
Hi,
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); s->last_buf_size=i; } else av_log(NULL, AV_LOG_ERROR, "invalid old backstep %d\n", i); and 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? Thanks, Martin
Hi On Tue, Oct 31, 2006 at 09:52:51AM -0000, M?ns Rullg?rd wrote:
Martin Thielen said:
Hi,
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
[...]
Hi,
I'm trying to silence the distorted output now. What would you consider
Didn't Michael already do something?
yes and no, my change was just fixing the random trash for some mencoder generated files which had random trash at the start of the mp3 stream it was not a general error concealment thing ...
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.
hmm zeroing a block before the MDCT shouldnt introduce any big discontinuities i think though iam not that good at MDCT related stuff ... one alternative might be to simply use the coeffs fromm the previous block, if that fails too google/citeseer would be the right place to look for audio error concealment [...] -- 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
Hi,
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.
hmm zeroing a block before the MDCT shouldnt introduce any big discontinuities i think though iam not that good at MDCT related stuff ... one alternative might be to simply use the coeffs fromm the previous block, if that fails too google/citeseer would be the right place to look for audio error concealment
[...]
I'm still not able to solve the problem with writing zero to the buffer I tried like this in the function mp_decode_frame : right before returning: if (discard_frame) { //dicard frame is set if an backstep or overread occurs. for(i=0;i<nb_frames;i++) { for(ch=0;ch<s->nb_channels;ch++) { int j; for(j=0;j<SBLIMIT;j++) { s->sb_samples[ch][i][j] = 0; } } } } This didn't worked as expected. Also I found another problem caused by this point in the huffman_decode() function: if (pos > end_pos2 && last_pos){ /* some encoders generate an incorrect size for this part. We must go back into the data */ s_index -= 4; skip_bits_long(&s->gb, last_pos - pos); av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos); s->frame_distorted = 1; break; } My idea was now to introduce a new flag into the MPADecodeContext: int frame_distorted; Now I set this flag to 0 at the start of decode_frame() and set it to 1 when backstep or overread occurs. At the end of decode_frame() I check the flag and return -1 if it is set. This is working for me. If I send a patch with the new flag, would you include it? Martin
Hi On Fri, Nov 03, 2006 at 10:24:19AM +0100, Martin wrote:
Hi,
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.
hmm zeroing a block before the MDCT shouldnt introduce any big discontinuities i think though iam not that good at MDCT related stuff ... one alternative might be to simply use the coeffs fromm the previous block, if that fails too google/citeseer would be the right place to look for audio error concealment
[...]
I'm still not able to solve the problem with writing zero to the buffer I tried like this in the function mp_decode_frame :
right before returning:
if (discard_frame) { //dicard frame is set if an backstep or overread occurs. for(i=0;i<nb_frames;i++) { for(ch=0;ch<s->nb_channels;ch++) { int j; for(j=0;j<SBLIMIT;j++) { s->sb_samples[ch][i][j] = 0; } } } }
This didn't worked as expected. Also I found another problem caused by this point in the huffman_decode() function:
if (pos > end_pos2 && last_pos){ /* some encoders generate an incorrect size for this part. We must go back into the data */ s_index -= 4; skip_bits_long(&s->gb, last_pos - pos); av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos); s->frame_distorted = 1;
break; }
My idea was now to introduce a new flag into the MPADecodeContext: int frame_distorted;
Now I set this flag to 0 at the start of decode_frame() and set it to 1 when backstep or overread occurs. At the end of decode_frame() I check the flag and return -1 if it is set. This is working for me. If I send a patch with the new flag, would you include it?
not without understanding why setting sb_samples to 0 doesnt work [...] -- 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
Hi,
right before returning:
if (discard_frame) { //dicard frame is set if an backstep or overread occurs. for(i=0;i<nb_frames;i++) { for(ch=0;ch<s->nb_channels;ch++) { int j; for(j=0;j<SBLIMIT;j++) { s->sb_samples[ch][i][j] = 0; } } } }
This didn't worked as expected. Also I found another problem caused by this point in the huffman_decode() function:
if (pos > end_pos2 && last_pos){ /* some encoders generate an incorrect size for this part. We must go back into the data */ s_index -= 4; skip_bits_long(&s->gb, last_pos - pos); av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos); s->frame_distorted = 1;
break; }
My idea was now to introduce a new flag into the MPADecodeContext: int frame_distorted;
Now I set this flag to 0 at the start of decode_frame() and set it to 1 when backstep or overread occurs. At the end of decode_frame() I check the flag and return -1 if it is set. This is working for me. If I send a patch with the new flag, would you include it?
not without understanding why setting sb_samples to 0 doesnt work
[...]
It seems to work now, with setting sb_frames to 0. I did it after the synthesis filter which didn't work. How should I transmit the fact that a distortion occured in huffmann_decode() to the function mp_decode_frame()? Can I use the flag for this purpose? I'm not sure whether I break something if I set sb_samples to 0 directly at the point where the distortion occurs in huffmann_decode(). Thanks, Martin
Hi On Fri, Nov 03, 2006 at 12:25:30PM +0100, Martin wrote:
Hi,
right before returning:
if (discard_frame) { //dicard frame is set if an backstep or overread occurs. for(i=0;i<nb_frames;i++) { for(ch=0;ch<s->nb_channels;ch++) { int j; for(j=0;j<SBLIMIT;j++) { s->sb_samples[ch][i][j] = 0; } } } }
This didn't worked as expected. Also I found another problem caused by this point in the huffman_decode() function:
if (pos > end_pos2 && last_pos){ /* some encoders generate an incorrect size for this part. We must go back into the data */ s_index -= 4; skip_bits_long(&s->gb, last_pos - pos); av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos); s->frame_distorted = 1;
break; }
My idea was now to introduce a new flag into the MPADecodeContext: int frame_distorted;
Now I set this flag to 0 at the start of decode_frame() and set it to 1 when backstep or overread occurs. At the end of decode_frame() I check the flag and return -1 if it is set. This is working for me. If I send a patch with the new flag, would you include it?
not without understanding why setting sb_samples to 0 doesnt work
[...]
It seems to work now, with setting sb_frames to 0. I did it after the synthesis filter which didn't work. How should I transmit the fact that a distortion occured in huffmann_decode() to the function mp_decode_frame()? Can I use the flag for this purpose? I'm not sure whether I break something if I set sb_samples to 0 directly at the point where the distortion occurs in huffmann_decode().
huffmann_decode() should return -1 if theres an error [...] -- 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
Michael Niedermayer wrote:
Hi
On Fri, Nov 03, 2006 at 12:25:30PM +0100, Martin wrote:
Hi,
right before returning:
if (discard_frame) { //dicard frame is set if an backstep or overread occurs. for(i=0;i<nb_frames;i++) { for(ch=0;ch<s->nb_channels;ch++) { int j; for(j=0;j<SBLIMIT;j++) { s->sb_samples[ch][i][j] = 0; } } } }
This didn't worked as expected. Also I found another problem caused by this point in the huffman_decode() function:
if (pos > end_pos2 && last_pos){ /* some encoders generate an incorrect size for this part. We must go back into the data */ s_index -= 4; skip_bits_long(&s->gb, last_pos - pos); av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos); s->frame_distorted = 1;
break; }
My idea was now to introduce a new flag into the MPADecodeContext: int frame_distorted;
Now I set this flag to 0 at the start of decode_frame() and set it to 1 when backstep or overread occurs. At the end of decode_frame() I check the flag and return -1 if it is set. This is working for me. If I send a patch with the new flag, would you include it?
not without understanding why setting sb_samples to 0 doesnt work
[...]
It seems to work now, with setting sb_frames to 0. I did it after the synthesis filter which didn't work. How should I transmit the fact that a distortion occured in huffmann_decode() to the function mp_decode_frame()? Can I use the flag for this purpose? I'm not sure whether I break something if I set sb_samples to 0 directly at the point where the distortion occurs in huffmann_decode().
huffmann_decode() should return -1 if theres an error
[...]
Thanks for the help! So here is a patch which sets buffers to 0 if 'overread' or 'backstep' occurs which prior resulted in distorted sound. Martin
Hi On Fri, Nov 03, 2006 at 03:20:04PM +0100, Martin wrote:
Michael Niedermayer wrote:
Hi
On Fri, Nov 03, 2006 at 12:25:30PM +0100, Martin wrote:
Hi,
right before returning:
if (discard_frame) { //dicard frame is set if an backstep or overread occurs. for(i=0;i<nb_frames;i++) { for(ch=0;ch<s->nb_channels;ch++) { int j; for(j=0;j<SBLIMIT;j++) { s->sb_samples[ch][i][j] = 0; } } } }
This didn't worked as expected. Also I found another problem caused by this point in the huffman_decode() function:
if (pos > end_pos2 && last_pos){ /* some encoders generate an incorrect size for this part. We must go back into the data */ s_index -= 4; skip_bits_long(&s->gb, last_pos - pos); av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos); s->frame_distorted = 1;
break; }
My idea was now to introduce a new flag into the MPADecodeContext: int frame_distorted;
Now I set this flag to 0 at the start of decode_frame() and set it to 1 when backstep or overread occurs. At the end of decode_frame() I check the flag and return -1 if it is set. This is working for me. If I send a patch with the new flag, would you include it?
not without understanding why setting sb_samples to 0 doesnt work
[...]
It seems to work now, with setting sb_frames to 0. I did it after the synthesis filter which didn't work. How should I transmit the fact that a distortion occured in huffmann_decode() to the function mp_decode_frame()? Can I use the flag for this purpose? I'm not sure whether I break something if I set sb_samples to 0 directly at the point where the distortion occurs in huffmann_decode().
huffmann_decode() should return -1 if theres an error
[...]
Thanks for the help! So here is a patch which sets buffers to 0 if 'overread' or 'backstep' occurs which prior resulted in distorted sound.
Martin
--- mpegaudiodec.c_bak 2006-11-03 14:38:48.263103729 +0100 +++ mpegaudiodec.c 2006-11-03 14:43:02.153241601 +0100 @@ -1705,7 +1705,8 @@ static int huffman_decode(MPADecodeConte s_index -= 4; skip_bits_long(&s->gb, last_pos - pos); av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos); - break; + //break; + return -1; }
this one will break decoding of some mp3 files (from broken encoders ...) [...]
assert(i <= buf_size - HEADER_SIZE && i>= 0); memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i); @@ -2503,6 +2508,19 @@ static int mp_decode_frame(MPADecodeCont } } #endif + + // zero samples if frame is distorted by overread or backstep + if (discard_frame) { + for(i=0;i<nb_frames;i++) { + for(ch=0;ch<s->nb_channels;ch++) { + int j; + for(j=0;j<SBLIMIT;j++) { + s->sb_samples[ch][i][j] = 0; + } + } + } + }
memset(0); [...] -- 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
Hi Michael Niedermayer wrote:
Hi
On Fri, Nov 03, 2006 at 03:20:04PM +0100, Martin wrote:
Michael Niedermayer wrote:
Hi
On Fri, Nov 03, 2006 at 12:25:30PM +0100, Martin wrote:
Hi,
right before returning:
if (discard_frame) { //dicard frame is set if an backstep or overread occurs. for(i=0;i<nb_frames;i++) { for(ch=0;ch<s->nb_channels;ch++) { int j; for(j=0;j<SBLIMIT;j++) { s->sb_samples[ch][i][j] = 0; } } } }
This didn't worked as expected. Also I found another problem caused by this point in the huffman_decode() function:
if (pos > end_pos2 && last_pos){ /* some encoders generate an incorrect size for this part. We must go back into the data */ s_index -= 4; skip_bits_long(&s->gb, last_pos - pos); av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos); s->frame_distorted = 1;
break; }
My idea was now to introduce a new flag into the MPADecodeContext: int frame_distorted;
Now I set this flag to 0 at the start of decode_frame() and set it to 1 when backstep or overread occurs. At the end of decode_frame() I check the flag and return -1 if it is set. This is working for me. If I send a patch with the new flag, would you include it?
not without understanding why setting sb_samples to 0 doesnt work
[...]
It seems to work now, with setting sb_frames to 0. I did it after the synthesis filter which didn't work. How should I transmit the fact that a distortion occured in huffmann_decode() to the function mp_decode_frame()? Can I use the flag for this purpose? I'm not sure whether I break something if I set sb_samples to 0 directly at the point where the distortion occurs in huffmann_decode().
huffmann_decode() should return -1 if theres an error
[...]
Thanks for the help! So here is a patch which sets buffers to 0 if 'overread' or 'backstep' occurs which prior resulted in distorted sound.
Martin
--- mpegaudiodec.c_bak 2006-11-03 14:38:48.263103729 +0100 +++ mpegaudiodec.c 2006-11-03 14:43:02.153241601 +0100 @@ -1705,7 +1705,8 @@ static int huffman_decode(MPADecodeConte s_index -= 4; skip_bits_long(&s->gb, last_pos - pos); av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos); - break; + //break; + return -1; }
this one will break decoding of some mp3 files (from broken encoders ...)
So ahould I set the samples to 0 here as well instead of return -1?
[...]
assert(i <= buf_size - HEADER_SIZE && i>= 0); memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i); @@ -2503,6 +2508,19 @@ static int mp_decode_frame(MPADecodeCont } } #endif + + // zero samples if frame is distorted by overread or backstep + if (discard_frame) { + for(i=0;i<nb_frames;i++) { + for(ch=0;ch<s->nb_channels;ch++) { + int j; + for(j=0;j<SBLIMIT;j++) { + s->sb_samples[ch][i][j] = 0; + } + } + } + }
memset(0);
[...]
Is the rest of the patch ok? Martin
Hi On Mon, Nov 06, 2006 at 09:19:17AM +0100, Martin Thielen wrote:
Hi
Michael Niedermayer wrote:
Hi
On Fri, Nov 03, 2006 at 03:20:04PM +0100, Martin wrote:
Michael Niedermayer wrote:
Hi
On Fri, Nov 03, 2006 at 12:25:30PM +0100, Martin wrote:
Hi,
>right before returning: > >if (discard_frame) { > //dicard frame is set if an backstep or overread occurs. > for(i=0;i<nb_frames;i++) { > for(ch=0;ch<s->nb_channels;ch++) { > int j; > for(j=0;j<SBLIMIT;j++) { > s->sb_samples[ch][i][j] = 0; > } > } > } >} > > > >This didn't worked as expected. Also I found another problem caused by >this point in the huffman_decode() function: > >if (pos > end_pos2 && last_pos){ > /* some encoders generate an incorrect size for this > part. We must go back into the data */ > s_index -= 4; > skip_bits_long(&s->gb, last_pos - pos); > av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: >%d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos); > s->frame_distorted = 1; > > break; > } > > >My idea was now to introduce a new flag into the MPADecodeContext: >int frame_distorted; > >Now I set this flag to 0 at the start of decode_frame() >and set it to 1 when backstep or overread occurs. At the end of >decode_frame() I check the flag and return -1 if it is set. This is >working for me. If I send a patch with the new flag, would you include it?
not without understanding why setting sb_samples to 0 doesnt work
[...]
It seems to work now, with setting sb_frames to 0. I did it after the synthesis filter which didn't work. How should I transmit the fact that a distortion occured in huffmann_decode() to the function mp_decode_frame()? Can I use the flag for this purpose? I'm not sure whether I break something if I set sb_samples to 0 directly at the point where the distortion occurs in huffmann_decode().
huffmann_decode() should return -1 if theres an error
[...]
Thanks for the help! So here is a patch which sets buffers to 0 if 'overread' or 'backstep' occurs which prior resulted in distorted sound.
Martin
--- mpegaudiodec.c_bak 2006-11-03 14:38:48.263103729 +0100 +++ mpegaudiodec.c 2006-11-03 14:43:02.153241601 +0100 @@ -1705,7 +1705,8 @@ static int huffman_decode(MPADecodeConte s_index -= 4; skip_bits_long(&s->gb, last_pos - pos); av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos); - break; + //break; + return -1; }
this one will break decoding of some mp3 files (from broken encoders ...)
So ahould I set the samples to 0 here as well instead of return -1?
no this case is not an error
[...]
assert(i <= buf_size - HEADER_SIZE && i>= 0); memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i); @@ -2503,6 +2508,19 @@ static int mp_decode_frame(MPADecodeCont } } #endif + + // zero samples if frame is distorted by overread or backstep + if (discard_frame) { + for(i=0;i<nb_frames;i++) { + for(ch=0;ch<s->nb_channels;ch++) { + int j; + for(j=0;j<SBLIMIT;j++) { + s->sb_samples[ch][i][j] = 0; + } + } + } + }
memset(0);
[...]
Is the rest of the patch ok?
i think so, but thats just from memory ... [...] -- 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
Hi Michael Niedermayer wrote:
Hi
On Mon, Nov 06, 2006 at 09:19:17AM +0100, Martin Thielen wrote:
Hi
Michael Niedermayer wrote:
Hi
On Fri, Nov 03, 2006 at 03:20:04PM +0100, Martin wrote:
Michael Niedermayer wrote:
Hi
On Fri, Nov 03, 2006 at 12:25:30PM +0100, Martin wrote:
Hi,
>>right before returning: >> >>if (discard_frame) { >> //dicard frame is set if an backstep or overread occurs. >> for(i=0;i<nb_frames;i++) { >> for(ch=0;ch<s->nb_channels;ch++) { >> int j; >> for(j=0;j<SBLIMIT;j++) { >> s->sb_samples[ch][i][j] = 0; >> } >> } >> } >>} >> >> >> >>This didn't worked as expected. Also I found another problem caused by >>this point in the huffman_decode() function: >> >>if (pos > end_pos2 && last_pos){ >> /* some encoders generate an incorrect size for this >> part. We must go back into the data */ >> s_index -= 4; >> skip_bits_long(&s->gb, last_pos - pos); >> av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: >>%d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos); >> s->frame_distorted = 1; >> >> break; >> } >> >> >>My idea was now to introduce a new flag into the MPADecodeContext: >>int frame_distorted; >> >>Now I set this flag to 0 at the start of decode_frame() >>and set it to 1 when backstep or overread occurs. At the end of >>decode_frame() I check the flag and return -1 if it is set. This is >>working for me. If I send a patch with the new flag, would you include it? > > >not without understanding why setting sb_samples to 0 doesnt work > >[...]
It seems to work now, with setting sb_frames to 0. I did it after the synthesis filter which didn't work. How should I transmit the fact that a distortion occured in huffmann_decode() to the function mp_decode_frame()? Can I use the flag for this purpose? I'm not sure whether I break something if I set sb_samples to 0 directly at the point where the distortion occurs in huffmann_decode().
huffmann_decode() should return -1 if theres an error
[...]
Thanks for the help! So here is a patch which sets buffers to 0 if 'overread' or 'backstep' occurs which prior resulted in distorted sound.
Martin
--- mpegaudiodec.c_bak 2006-11-03 14:38:48.263103729 +0100 +++ mpegaudiodec.c 2006-11-03 14:43:02.153241601 +0100 @@ -1705,7 +1705,8 @@ static int huffman_decode(MPADecodeConte s_index -= 4; skip_bits_long(&s->gb, last_pos - pos); av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos); - break; + //break; + return -1; }
this one will break decoding of some mp3 files (from broken encoders ...)
So ahould I set the samples to 0 here as well instead of return -1?
no this case is not an error
Ok, so I removed this return -1 from the patch.
[...]
assert(i <= buf_size - HEADER_SIZE && i>= 0); memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i); @@ -2503,6 +2508,19 @@ static int mp_decode_frame(MPADecodeCont } } #endif + + // zero samples if frame is distorted by overread or backstep + if (discard_frame) { + for(i=0;i<nb_frames;i++) { + for(ch=0;ch<s->nb_channels;ch++) { + int j; + for(j=0;j<SBLIMIT;j++) { + s->sb_samples[ch][i][j] = 0; + } + } + } + }
memset(0);
[...]
Is the rest of the patch ok?
i think so, but thats just from memory ...
[...]
The new patch which sets buffers to 0 if 'backstep'occurs which prior resulted in distorted sound is attached. Martin
Hi On Mon, Nov 06, 2006 at 03:19:10PM +0100, Martin wrote: [...]
assert(i <= buf_size - HEADER_SIZE && i>= 0); memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i); @@ -2503,6 +2508,19 @@ static int mp_decode_frame(MPADecodeCont } } #endif + + // zero samples if frame is distorted by overread or backstep + if (discard_frame) { + for(i=0;i<nb_frames;i++) { + for(ch=0;ch<s->nb_channels;ch++) { + int j; + for(j=0;j<SBLIMIT;j++) { + s->sb_samples[ch][i][j] = 0; + } + } + } + }
memset(0);
[...]
Is the rest of the patch ok?
i think so, but thats just from memory ...
[...]
The new patch which sets buffers to 0 if 'backstep'occurs which prior resulted in distorted sound is attached. [...]
+ // zero samples if frame is distorted by overread or backstep + if (discard_frame) { + for(i=0;i<nb_frames;i++) { + for(ch=0;ch<s->nb_channels;ch++) { + int j; + for(j=0;j<SBLIMIT;j++) { + s->sb_samples[ch][i][j] = 0; + } + } + } + }
the whole above should be replaced by a if (discard_frame) \n memset(..., 0, ...) as already said [...] -- 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
Hi Michael Niedermayer wrote:
Hi
On Mon, Nov 06, 2006 at 03:19:10PM +0100, Martin wrote: [...]
assert(i <= buf_size - HEADER_SIZE && i>= 0); memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i); @@ -2503,6 +2508,19 @@ static int mp_decode_frame(MPADecodeCont } } #endif + + // zero samples if frame is distorted by overread or backstep + if (discard_frame) { + for(i=0;i<nb_frames;i++) { + for(ch=0;ch<s->nb_channels;ch++) { + int j; + for(j=0;j<SBLIMIT;j++) { + s->sb_samples[ch][i][j] = 0; + } + } + } + }
memset(0);
[...]
Is the rest of the patch ok?
i think so, but thats just from memory ...
[...]
The new patch which sets buffers to 0 if 'backstep'occurs which prior resulted in distorted sound is attached.
[...]
+ // zero samples if frame is distorted by overread or backstep + if (discard_frame) { + for(i=0;i<nb_frames;i++) { + for(ch=0;ch<s->nb_channels;ch++) { + int j; + for(j=0;j<SBLIMIT;j++) { + s->sb_samples[ch][i][j] = 0; + } + } + } + }
the whole above should be replaced by a if (discard_frame) \n memset(..., 0, ...) as already said
[...]
Ok, I didn't see that. Obviously its much better that way... :) Attached the updated patch. Hope everything is finally ok now... ;)
Hi On Mon, Nov 06, 2006 at 05:44:07PM +0100, Martin wrote:
Hi
Michael Niedermayer wrote:
Hi
On Mon, Nov 06, 2006 at 03:19:10PM +0100, Martin wrote: [...]
> assert(i <= buf_size - HEADER_SIZE && i>= 0); > memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i); >@@ -2503,6 +2508,19 @@ static int mp_decode_frame(MPADecodeCont > } > } >#endif >+ >+ // zero samples if frame is distorted by overread or backstep >+ if (discard_frame) { >+ for(i=0;i<nb_frames;i++) { >+ for(ch=0;ch<s->nb_channels;ch++) { >+ int j; >+ for(j=0;j<SBLIMIT;j++) { >+ s->sb_samples[ch][i][j] = 0; >+ } >+ } >+ } >+ }
memset(0);
[...]
Is the rest of the patch ok?
i think so, but thats just from memory ...
[...]
The new patch which sets buffers to 0 if 'backstep'occurs which prior resulted in distorted sound is attached.
[...]
+ // zero samples if frame is distorted by overread or backstep + if (discard_frame) { + for(i=0;i<nb_frames;i++) { + for(ch=0;ch<s->nb_channels;ch++) { + int j; + for(j=0;j<SBLIMIT;j++) { + s->sb_samples[ch][i][j] = 0; + } + } + } + }
the whole above should be replaced by a if (discard_frame) \n memset(..., 0, ...) as already said
[...]
Ok, I didn't see that. Obviously its much better that way... :) Attached the updated patch. Hope everything is finally ok now... ;)
looks ok whoever applies this should test it with a damaged mp3 though [...] -- 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
Hi, On 11/6/06, Michael Niedermayer <michaelni at gmx.at> wrote:
Hi On Mon, Nov 06, 2006 at 05:44:07PM +0100, Martin wrote:
Hi
Michael Niedermayer wrote:
[..]
the whole above should be replaced by a if (discard_frame) \n memset(..., 0, ...) as already said
[...]
Ok, I didn't see that. Obviously its much better that way... :) Attached the updated patch. Hope everything is finally ok now... ;)
looks ok
whoever applies this should test it with a damaged mp3 though
I don't have one on hand. Martin, please provide the damaged mp3 that your patch is supposed to improve support for. Guillaume -- With DADVSI (http://en.wikipedia.org/wiki/DADVSI), France finally has a lead on USA on selling out individuals right to corporations! Vive la France!
Hi Guillaume Guillaume POIRIER wrote:
Hi,
On 11/6/06, Michael Niedermayer <michaelni at gmx.at> wrote:
Hi On Mon, Nov 06, 2006 at 05:44:07PM +0100, Martin wrote:
Hi
Michael Niedermayer wrote:
[..]
the whole above should be replaced by a if (discard_frame) \n memset(..., 0, ...) as already said
[...]
Ok, I didn't see that. Obviously its much better that way... :) Attached the updated patch. Hope everything is finally ok now... ;)
looks ok
whoever applies this should test it with a damaged mp3 though
I don't have one on hand. Martin, please provide the damaged mp3 that your patch is supposed to improve support for.
Guillaume
I only realized the distorted sound while encoding MP3, streaming it via RTP using the liblive and decoding it again. If the sender starts before the receiver these backsteps occur. I'm sorry, I don't have a damaged file which shows these errors. Martin
Hi On Mon, Nov 06, 2006 at 06:10:28PM +0100, Guillaume POIRIER wrote:
Hi,
On 11/6/06, Michael Niedermayer <michaelni at gmx.at> wrote:
Hi On Mon, Nov 06, 2006 at 05:44:07PM +0100, Martin wrote:
Hi
Michael Niedermayer wrote:
[..]
the whole above should be replaced by a if (discard_frame) \n memset(..., 0, ...) as already said
[...]
Ok, I didn't see that. Obviously its much better that way... :) Attached the updated patch. Hope everything is finally ok now... ;)
looks ok
whoever applies this should test it with a damaged mp3 though
I don't have one on hand. Martin, please provide the damaged mp3 that your patch is supposed to improve support for.
try the attached program (but make a backup first ;) ) [...] -- 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
Hi, Michael Niedermayer wrote:
Hi
On Mon, Nov 06, 2006 at 06:10:28PM +0100, Guillaume POIRIER wrote:
Hi,
On 11/6/06, Michael Niedermayer <michaelni at gmx.at> wrote:
Hi On Mon, Nov 06, 2006 at 05:44:07PM +0100, Martin wrote:
Hi
Michael Niedermayer wrote:
[..]
the whole above should be replaced by a if (discard_frame) \n
memset(..., 0, ...)
as already said
[...]
Ok, I didn't see that. Obviously its much better that way... :) Attached the updated patch. Hope everything is finally ok now... ;)
looks ok
whoever applies this should test it with a damaged mp3 though
I don't have one on hand. Martin, please provide the damaged mp3 that your patch is supposed to improve support for.
try the attached program (but make a backup first ;) )
[...]
is the patch for avoiding distorted sound when backsteps occur tested already? I would like to know if it gets applied... Thanks, Martin
Hi, On 11/22/06, Martin <marthi at graphics.cs.uni-sb.de> wrote:
Michael Niedermayer wrote:
On Mon, Nov 06, 2006 at 06:10:28PM +0100, Guillaume POIRIER wrote:
On 11/6/06, Michael Niedermayer <michaelni at gmx.at> wrote:
[..]
looks ok
whoever applies this should test it with a damaged mp3 though
I don't have one on hand. Martin, please provide the damaged mp3 that your patch is supposed to improve support for.
try the attached program (but make a backup first ;) )
[...]
is the patch for avoiding distorted sound when backsteps occur tested already? I would like to know if it gets applied...
Thanks, Martin
No, I haven't had time to test it. If you could put together a test case that features a broken sample and a test commandline, that would jump-start me into testing and applying this fix. Guillaume -- With DADVSI (http://en.wikipedia.org/wiki/DADVSI), France finally has a lead on USA on selling out individuals right to corporations! Vive la France!
Hi, Guillaume POIRIER wrote:
Hi,
On 11/22/06, Martin <marthi at graphics.cs.uni-sb.de> wrote:
Michael Niedermayer wrote:
On Mon, Nov 06, 2006 at 06:10:28PM +0100, Guillaume POIRIER wrote:
On 11/6/06, Michael Niedermayer <michaelni at gmx.at> wrote:
[..]
looks ok
whoever applies this should test it with a damaged mp3 though
I don't have one on hand. Martin, please provide the damaged mp3 that your patch is supposed to improve support for.
try the attached program (but make a backup first ;) )
[...]
is the patch for avoiding distorted sound when backsteps occur tested already? I would like to know if it gets applied...
Thanks, Martin
No, I haven't had time to test it. If you could put together a test case that features a broken sample and a test commandline, that would jump-start me into testing and applying this fix.
Guillaume
didn't Michael already provide an application for testing? Martin
Hi, Martin wrote:
Hi,
Guillaume POIRIER wrote:
Hi,
On 11/22/06, Martin <marthi at graphics.cs.uni-sb.de> wrote:
Michael Niedermayer wrote:
On Mon, Nov 06, 2006 at 06:10:28PM +0100, Guillaume POIRIER wrote:
On 11/6/06, Michael Niedermayer <michaelni at gmx.at> wrote:
[..]
looks ok
whoever applies this should test it with a damaged mp3 though
I don't have one on hand. Martin, please provide the damaged mp3 that your patch is supposed to improve support for.
try the attached program (but make a backup first ;) )
[...]
is the patch for avoiding distorted sound when backsteps occur tested already? I would like to know if it gets applied...
Thanks, Martin
No, I haven't had time to test it. If you could put together a test case that features a broken sample and a test commandline, that would jump-start me into testing and applying this fix.
Guillaume
didn't Michael already provide an application for testing?
Martin
any news from this? I attached the program from Michael again. Martin
Hi, On 11/6/06, Michael Niedermayer <michaelni at gmx.at> wrote:
On Mon, Nov 06, 2006 at 06:10:28PM +0100, Guillaume POIRIER wrote:
On 11/6/06, Michael Niedermayer <michaelni at gmx.at> wrote:
On Mon, Nov 06, 2006 at 05:44:07PM +0100, Martin wrote:
Michael Niedermayer wrote:
[..]
the whole above should be replaced by a if (discard_frame) \n memset(..., 0, ...) as already said
[...]
Ok, I didn't see that. Obviously its much better that way... :) Attached the updated patch. Hope everything is finally ok now... ;)
looks ok
whoever applies this should test it with a damaged mp3 though
I don't have one on hand. Martin, please provide the damaged mp3 that your patch is supposed to improve support for.
try the attached program (but make a backup first ;) )
Ok, I finaly found some time to test this patch with the trasher. I'm really sorry for the delay. I'm sorry to say that your patch doesn't seem to work for me, at least with an mp3 sample trashed by Michael's trasher. Actually, I think that Michael's trasher doesn't trash files in a way that make lavc display the message "invalid new backstep". All I'm getting is this: DISPLAY=:0 ./ffplay_g /tmp/01-ya_pas_darrangement.mp3 bits_left=-6 overread, skip -10 enddists: -4 -4 mdb:127, lastbuf:95 skiping granule 0 bits_left=-1 bits_left=-3 mdb:145, lastbuf:49 skiping granule 0 bits_left=-5 overread, skip -5 enddists: -3 -3 overread, skip -7 enddists: -2 -2 overread, skip -7 enddists: -1 -1 mdb:129, lastbuf:25 skiping granule 0 bits_left=-2 overread, skip -7 enddists: -1 -1 overread, skip -8 enddists: -6 -6 mdb:105, lastbuf:19 skiping granule 0 bits_left=-7 overread, skip -8 enddists: -4 -4 overread, skip -6 enddists: -3 -3 overread, skip -6 enddists: -4 -4 overread, skip -7 enddists: -6 -6 mdb:19, lastbuf:16 skiping granule 0 overread, skip -9 enddists: -8 -8 overread, skip -5 enddists: -3 -3 mdb:75, lastbuf:25 skiping granule 0 overread, skip -6 enddists: -2 -2 overread, skip -7 enddists: -2 -2 overread, skip -5 enddists: -2 -2 overread, skip -7 enddists: -2 -2 overread, skip -7 enddists: -2 -2 [..] I can clearly hear corruptions that indicate that the mp3 file was corrupted, but that's about it! :-( Sorry, but it looks like I'd need a sample that exhibits the very problem that your patch is supposed to fix :-( Guillaume -- An association of men who will not quarrel with one another is a thing which has never yet existed, from the greatest confederacy of nations down to a town meeting or a vestry. -- Thomas Jefferson (when interviewed about MPlayer ML flamewars) http://www.brainyquote.com/quotes/quotes/t/thomasjeff157207.html
participants (4)
-
marthi@graphics.cs.uni-sb.de -
michaelni@gmx.at -
mru@inprovide.com -
poirierg@gmail.com