[FFmpeg-devel] [PATCH 2/3] avcodec/siren: don't reduce getbitcontext size by checksum_bits at initialisation

Peter Ross pross at xvid.org
Sat Sep 18 13:02:54 EEST 2021


this allows the checksum calculation routine to also use getbitcontext
---
at the expense of having to offset get_bits_left(gb) everywhere

 libavcodec/siren.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/siren.c b/libavcodec/siren.c
index 3b0ad7b642..92fd3632f5 100644
--- a/libavcodec/siren.c
+++ b/libavcodec/siren.c
@@ -594,7 +594,7 @@ static int decode_vector(SirenContext *s, int number_of_regions,
             for (i = 0; i < number_of_vectors[category]; i++) {
                 index = 0;
                 do {
-                    if (get_bits_left(gb) <= 0) {
+                    if (get_bits_left(gb) - s->checksum_bits <= 0) {
                         error = 1;
                         break;
                     }
@@ -614,7 +614,7 @@ static int decode_vector(SirenContext *s, int number_of_regions,
                         index >>= index_table[category];
 
                         if (decoded_value) {
-                            if (get_bits_left(gb) <= 0) {
+                            if (get_bits_left(gb) - s->checksum_bits <= 0) {
                                 error = 1;
                                 break;
                             }
@@ -693,7 +693,7 @@ static int decode_vector(SirenContext *s, int number_of_regions,
         }
     }
 
-    return error == 1 ? AVERROR_INVALIDDATA : get_bits_left(gb);
+    return error == 1 ? AVERROR_INVALIDDATA : (get_bits_left(gb) - s->checksum_bits);
 }
 
 static int siren_decode(AVCodecContext *avctx, void *data,
@@ -712,7 +712,7 @@ static int siren_decode(AVCodecContext *avctx, void *data,
         if (avpkt->size < bits_per_frame / 8)
             return AVERROR_INVALIDDATA;
 
-        if ((ret = init_get_bits(gb, avpkt->data, bits_per_frame - s->checksum_bits)) < 0)
+        if ((ret = init_get_bits(gb, avpkt->data, bits_per_frame)) < 0)
             return ret;
     } else
     if ((ret = init_get_bits8(gb, avpkt->data, avpkt->size)) < 0)
@@ -726,7 +726,7 @@ static int siren_decode(AVCodecContext *avctx, void *data,
 
     rate_control = get_bits(gb, 4);
 
-    ret = categorize_regions(s->number_of_regions, get_bits_left(gb),
+    ret = categorize_regions(s->number_of_regions, get_bits_left(gb) - s->checksum_bits,
                              s->absolute_region_power_index, s->power_categories,
                              s->category_balance);
     if (ret < 0)
@@ -741,11 +741,11 @@ static int siren_decode(AVCodecContext *avctx, void *data,
     if (ret < 0 && !s->microsoft)
         return ret;
 
-    if (get_bits_left(gb) > 0) {
+    if (get_bits_left(gb) - s->checksum_bits > 0) {
         do {
             frame_error |= !get_bits1(gb);
-        } while (get_bits_left(gb) > 0);
-    } else if (get_bits_left(gb) < 0 &&
+        } while (get_bits_left(gb) - s->checksum_bits > 0);
+    } else if (get_bits_left(gb) - s->checksum_bits < 0 &&
                rate_control + 1 < s->rate_control_possibilities) {
         frame_error = 1;
     }
-- 
2.33.0

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20210918/46f89c38/attachment.sig>


More information about the ffmpeg-devel mailing list