[FFmpeg-devel] [PATCH 2/3] avcodec/tests/rangecoder: Test coder more completely

Michael Niedermayer michael at niedermayer.cc
Wed Dec 19 03:40:19 EET 2018


Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
 libavcodec/tests/rangecoder.c | 43 +++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/libavcodec/tests/rangecoder.c b/libavcodec/tests/rangecoder.c
index 76a13e7091..3fd07ed9a9 100644
--- a/libavcodec/tests/rangecoder.c
+++ b/libavcodec/tests/rangecoder.c
@@ -24,41 +24,50 @@
 
 #include "libavcodec/rangecoder.h"
 
-#define SIZE 10240
+#define SIZE 1240
 
 int main(void)
 {
     RangeCoder c;
     uint8_t b[9 * SIZE];
     uint8_t r[9 * SIZE];
-    int i;
+    int i, p, actual_length, version;
     uint8_t state[10];
     AVLFG prng;
 
     av_lfg_init(&prng, 1);
+    for (version = 0; version < 2; version++) {
+        for (p = 0; p< 1024; p++) {
+            ff_init_range_encoder(&c, b, SIZE);
+            ff_build_rac_states(&c, (1LL << 32) / 20, 128 + 64 + 32 + 16);
 
-    ff_init_range_encoder(&c, b, SIZE);
-    ff_build_rac_states(&c, (1LL << 32) / 20, 128 + 64 + 32 + 16);
+            memset(state, 128, sizeof(state));
 
-    memset(state, 128, sizeof(state));
+            for (i = 0; i < SIZE; i++)
+                r[i] = av_lfg_get(&prng) % 7;
 
-    for (i = 0; i < SIZE; i++)
-        r[i] = av_lfg_get(&prng) % 7;
+            for (i = 0; i < SIZE; i++)
+                put_rac(&c, state, r[i] & 1);
 
-    for (i = 0; i < SIZE; i++)
-        put_rac(&c, state, r[i] & 1);
+            actual_length = ff_rac_terminate(&c, version);
 
-    ff_rac_terminate(&c, 0);
+            ff_init_range_decoder(&c, b, version ? SIZE : actual_length);
 
-    ff_init_range_decoder(&c, b, SIZE);
+            memset(state, 128, sizeof(state));
 
-    memset(state, 128, sizeof(state));
-
-    for (i = 0; i < SIZE; i++)
-        if ((r[i] & 1) != get_rac(&c, state)) {
-            av_log(NULL, AV_LOG_ERROR, "rac failure at %d\n", i);
-            return 1;
+            for (i = 0; i < SIZE; i++)
+                if ((r[i] & 1) != get_rac(&c, state)) {
+                    av_log(NULL, AV_LOG_ERROR, "rac failure at %d pass %d version %d\n", i, p, version);
+                    return 1;
+                }
+            if(version)
+                get_rac(&c, (uint8_t[]) { 129 });
+            if (c.bytestream - c.bytestream_start - actual_length != version) {
+                av_log(NULL, AV_LOG_ERROR, "rac failure at pass %d version %d\n", p, version);
+                return 1;
+            }
         }
+    }
 
     return 0;
 }
-- 
2.19.2



More information about the ffmpeg-devel mailing list