]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/rv34: Simplify getting right VLC
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 22 Oct 2020 10:02:11 +0000 (12:02 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Mon, 26 Oct 2020 06:16:10 +0000 (07:16 +0100)
For both RealVideo 3.0 as well as RealVideo 4.0 the VLC table to use
depends upon the slice's quantization parameter; these are coded on five
bits in the bitstream and are therefore in the range of 0..31; yet the
last element here is not valid and therefore the quantizer is clipped to
the range 0..30 to get the index. But this is unnecessary: One can just
add one element more to the relevant array to avoid the clipping.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/rv34.c
libavcodec/rv34data.h

index d251c6817cd1541848c8bce207f837d263e5992b..09fa962b2f59e16b38f75e6b7065f0edbc50b939 100644 (file)
@@ -24,6 +24,7 @@
  * RV30/40 decoder common data
  */
 
+#include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
 
@@ -339,8 +340,9 @@ static inline RV34VLC* choose_vlc_set(int quant, int mod, int type)
 {
     if(mod == 2 && quant < 19) quant += 10;
     else if(mod && quant < 26) quant += 5;
-    return type ? &inter_vlcs[rv34_quant_to_vlc_set[1][av_clip(quant, 0, 30)]]
-                : &intra_vlcs[rv34_quant_to_vlc_set[0][av_clip(quant, 0, 30)]];
+    av_assert2(quant >= 0 && quant < 32);
+    return type ? &inter_vlcs[rv34_quant_to_vlc_set[1][quant]]
+                : &intra_vlcs[rv34_quant_to_vlc_set[0][quant]];
 }
 
 /**
index 4b2701fee60857e74a1d8395d5e2a94f696c3b07..32ecc395a88f268414978c5a958a6bd87c30675a 100644 (file)
@@ -90,13 +90,13 @@ static const uint16_t rv34_qscale_tab[32] = {
 
 /**
  * tables used to translate a quantizer value into a VLC set for decoding
- * The first table is used for intraframes.
+ * The first table is used for intraframes. The two last entries are invalid.
  */
-static const uint8_t rv34_quant_to_vlc_set[2][31] = {
+static const uint8_t rv34_quant_to_vlc_set[2][32] = {
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
-   2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 0 },
+   2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3,
-   3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6 },
+   3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6 },
 };
 
 /**