]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/rv10.c
avformat/mxfdec: set toolkit version metadata
[ffmpeg] / libavcodec / rv10.c
index 4d4c2b0f2e8fb2b5bda85732b59574b45d2fdf1c..d5c7480611e0eed98d176802e09ef7f47f937c22 100644 (file)
@@ -47,7 +47,7 @@
 #define RV_GET_MICRO_VER(x) (((x) >> 12) & 0xFF)
 
 #define MAX_VLC_ENTRIES 1023 // Note: Does not include the skip entries.
-#define DC_VLC_BITS 14 // FIXME find a better solution
+#define DC_VLC_BITS        9
 
 typedef struct RVDecContext {
     MpegEncContext m;
@@ -84,22 +84,11 @@ int ff_rv_decode_dc(MpegEncContext *s, int n)
 
     if (n < 4) {
         code = get_vlc2(&s->gb, rv_dc_lum.table, DC_VLC_BITS, 2);
-        if (code < 0) {
-            /* Skip entry - no error. */
-            skip_bits(&s->gb, 18);
-            code = 255;
-        }
     } else {
         code = get_vlc2(&s->gb, rv_dc_chrom.table, DC_VLC_BITS, 2);
         if (code < 0) {
-            if (show_bits(&s->gb, 9) == 0x1FE) {
-                /* Skip entry - no error. */
-                skip_bits(&s->gb, 18);
-                code = 255;
-            } else {
-                av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n");
-                return -1;
-            }
+            av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n");
+            return -1;
         }
     }
     return code;
@@ -346,16 +335,27 @@ static av_cold void rv10_build_vlc(VLC *vlc, const uint16_t len_count[15],
 
 static av_cold void rv10_init_static(void)
 {
-    static VLC_TYPE table[16896 + 16640][2];
+    static VLC_TYPE table[1472 + 992][2];
 
     rv_dc_lum.table             = table;
-    rv_dc_lum.table_allocated   = 16896;
+    rv_dc_lum.table_allocated   = 1472;
     rv10_build_vlc(&rv_dc_lum, rv_lum_len_count,
                    rv_sym_run_len, FF_ARRAY_ELEMS(rv_sym_run_len));
-    rv_dc_chrom.table           = &table[16896];
-    rv_dc_chrom.table_allocated = 16640;
+    for (int i = 0; i < 1 << (DC_VLC_BITS - 7 /* Length of skip prefix */); i++) {
+        /* All codes beginning with 0x7F have the same length and value.
+         * Modifying the table directly saves us the useless subtables. */
+        rv_dc_lum.table[(0x7F << (DC_VLC_BITS - 7)) + i][0] = 255;
+        rv_dc_lum.table[(0x7F << (DC_VLC_BITS - 7)) + i][1] = 18;
+    }
+    rv_dc_chrom.table           = &table[1472];
+    rv_dc_chrom.table_allocated = 992;
     rv10_build_vlc(&rv_dc_chrom, rv_chrom_len_count,
                    rv_sym_run_len, FF_ARRAY_ELEMS(rv_sym_run_len) - 2);
+    for (int i = 0; i < 1 << (DC_VLC_BITS - 9 /* Length of skip prefix */); i++) {
+        /* Same as above. */
+        rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i][0] = 255;
+        rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i][1] = 18;
+    }
     ff_h263_decode_init_vlc();
 }
 
@@ -374,7 +374,6 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
                                    avctx->coded_height, 0, avctx)) < 0)
         return ret;
 
-    ff_mpv_decode_defaults(s);
     ff_mpv_decode_init(s, avctx);
 
     s->out_format  = FMT_H263;