Re: [FFmpeg-devel] [PATCH 1/1] avcodec/dolby_e: Add error recovery when parse_mantissas run out of bits

2024-03-26 Thread Nicolas Gaullier
>De : Nicolas Gaullier  
>Envoyé : lundi 11 mars 2024 15:01
>
>Mantissas are the last data in the channel subsegment and it appears it is 
>sometimes missing a very few bits for the parsing to complete.
>This must not be confused with data corruption.
>In standard conditions with certified products, it has been observed that the 
>occurence of this issue is pretty steady and about once every 2 hours. The 
>truncation is at about 950 out of the 1024 values (923 is the minimum I have 
>seen so far).
>The current code raises a severe 'Read past end' error and all data is lost 
>resulting in 20ms(@25fps) of silence for the affected channel.
>This patch introduces a tolerance: if 800 out of the 1024 mantissas have been 
>parsed, a simple warning is raised and the data is preserved.

Ping ?
still applies
last posted here: https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=11090
Samples (source/before patch/after patch) here: https://0x0.st/oOvv.zip

Nicolas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/1] avcodec/dolby_e: Add error recovery when parse_mantissas run out of bits

2024-03-11 Thread Nicolas Gaullier
Mantissas are the last data in the channel subsegment and it appears it
is sometimes missing a very few bits for the parsing to complete.
This must not be confused with data corruption.
In standard conditions with certified products, it has been observed
that the occurence of this issue is pretty steady and about once every 2
hours. The truncation is at about 950 out of the 1024 values (923 is the
minimum I have seen so far).
The current code raises a severe 'Read past end' error and all data is
lost resulting in 20ms(@25fps) of silence for the affected channel.
This patch introduces a tolerance: if 800 out of the 1024 mantissas have
been parsed, a simple warning is raised and the data is preserved.

Signed-off-by: Nicolas Gaullier 
---
 libavcodec/dolby_e.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c
index 9c3f6006c2..1f8442e2e9 100644
--- a/libavcodec/dolby_e.c
+++ b/libavcodec/dolby_e.c
@@ -845,6 +845,7 @@ static int parse_indices(DBEContext *s, DBEChannel *c)
 return 0;
 }
 
+#define MIN_MANTISSAS 800
 static int parse_mantissas(DBEContext *s, DBEChannel *c)
 {
 DBEGroup *g;
@@ -885,6 +886,13 @@ static int parse_mantissas(DBEContext *s, DBEChannel *c)
 }
 }
 } else {
+if (i == c->nb_groups - 1
+&& count * size1 > get_bits_left(>gb)
+&& get_bits_left(>gb) >= 0
+&& (int)(mnt - c->mantissas) >= MIN_MANTISSAS) {
+av_log(s->avctx, AV_LOG_WARNING, "Truncated mantissas @%d, 
highest frequencies not recoverable\n", (int)(mnt - c->mantissas));
+break;
+}
 for (k = 0; k < count; k++)
 mnt[k] = get_sbits(>gb, size1) * scale;
 }
-- 
2.30.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/1] avcodec/dolby_e: Add error recovery when parse_mantissas run out of bits

2023-03-13 Thread Nicolas Gaullier
>fre 2023-03-10 klockan 10:17 +0100 skrev Nicolas Gaullier:
>> +    if (i == c->nb_groups - 1
>> +    && count * size1 > get_bits_left(>gb)
>> +    && get_bits_left(>gb) >= 0
>> +    && (int)(mnt - c->mantissas) >= MIN_MANTISSAS) {
>> +    av_log(s->avctx, AV_LOG_WARNING, "Truncated
>> mantissas @%d, "
>> +    "highest frequencies not recoverable\n",
>> (int)(mnt - c->mantissas));
>> +    break;
>> +    }
>
>Surely there's a proper way to fix this rather than having an arbitrary 
>threshold. At the very least the get_bits_left() check could be moved to 
>before parse_mantissas(). If get_bits_left() is < 0 after
>parse_mantissas() then a warning could be issued instead of erroring out, 
>which should have an effect similar to this.
>
>Is there a spec saying what to do with truncated packets? Since this is 
>Dolby-E I suspect the answer is "no".
>
>/Tomas

Thank you for inspecting the patch.
Concerning the arbitrary threshold: it may be understood as a very high level 
safeguard, but my intend was mostly to make the code more easily understandable.
Actually, the fix is restricted to the last audio band (see "i == c->nb_groups 
- 1") and, at the end, the MIN_MANTISSAS condition could be simply removed with 
no audible risk, I guess.
But to get this precision, the fix cannot be moved elsewhere. The idea here is 
to still be able to detect harsh packet truncation with full errors and keep 
current code behaviour in that case.

Of course, this patch looks as a work-around, but a work-around that make it 
possible to decode the official reference bitstream implementation (dp600 at 
least, but maybe they are no different ones).
So, this is a somewhat special scenario. Sadly, I don't see any another way to 
handle this.

To conclude, I don't have any other idea than the complete removal of the 
arbitrary threshold. Would it make the patch more acceptable ?

Nicolas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/1] avcodec/dolby_e: Add error recovery when parse_mantissas run out of bits

2023-03-13 Thread Tomas Härdin
fre 2023-03-10 klockan 10:17 +0100 skrev Nicolas Gaullier:
> +    if (i == c->nb_groups - 1
> +    && count * size1 > get_bits_left(>gb)
> +    && get_bits_left(>gb) >= 0
> +    && (int)(mnt - c->mantissas) >= MIN_MANTISSAS) {
> +    av_log(s->avctx, AV_LOG_WARNING, "Truncated
> mantissas @%d, "
> +    "highest frequencies not recoverable\n",
> (int)(mnt - c->mantissas));
> +    break;
> +    }

Surely there's a proper way to fix this rather than having an arbitrary
threshold. At the very least the get_bits_left() check could be moved
to before parse_mantissas(). If get_bits_left() is < 0 after
parse_mantissas() then a warning could be issued instead of erroring
out, which should have an effect similar to this.

Is there a spec saying what to do with truncated packets? Since this is
Dolby-E I suspect the answer is "no".

/Tomas

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/1] avcodec/dolby_e: Add error recovery when parse_mantissas run out of bits

2023-03-10 Thread Nicolas Gaullier
Mantissas are the last data in the channel subsegment and it appears it is
sometimes missing a very few bits for the parsing to complete.
This should not be confused with data corruption.
For 5.1+2@25fps, the occurence of this issue is pretty steady and about once 
every 2 hours.
The truncation is at about 950 out of the 1024 values (never seen below 923 so 
far).
The current code raises a severe 'Read past end' error and all data is lost 
resulting in
20ms(@25fps) of silence for the affected channel.
This patch introduces a tolerance: if 800 out of the 1024 mantissas have been 
parsed,
a simple warning is raised and the data is preserved.

Signed-off-by: Nicolas Gaullier 
---
 libavcodec/dolby_e.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c
index 921c33f3ba..a24edfcc93 100644
--- a/libavcodec/dolby_e.c
+++ b/libavcodec/dolby_e.c
@@ -845,6 +845,7 @@ static int parse_indices(DBEContext *s, DBEChannel *c)
 return 0;
 }
 
+#define MIN_MANTISSAS 800
 static int parse_mantissas(DBEContext *s, DBEChannel *c)
 {
 DBEGroup *g;
@@ -885,6 +886,14 @@ static int parse_mantissas(DBEContext *s, DBEChannel *c)
 }
 }
 } else {
+if (i == c->nb_groups - 1
+&& count * size1 > get_bits_left(>gb)
+&& get_bits_left(>gb) >= 0
+&& (int)(mnt - c->mantissas) >= MIN_MANTISSAS) {
+av_log(s->avctx, AV_LOG_WARNING, "Truncated mantissas @%d, 
"
+"highest frequencies not recoverable\n", (int)(mnt - 
c->mantissas));
+break;
+}
 for (k = 0; k < count; k++)
 mnt[k] = get_sbits(>gb, size1) * scale;
 }
-- 
2.30.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".