[FFmpeg-cvslog] ffv1: Explicitly name the coder type

Vittorio Giovara git at videolan.org
Sun Nov 22 18:09:05 CET 2015


ffmpeg | branch: master | Vittorio Giovara <vittorio.giovara at gmail.com> | Sun Nov 15 23:26:07 2015 +0100| [4bb1070c154e49d35805fbcdac9c9e92f702ef96] | committer: Vittorio Giovara

ffv1: Explicitly name the coder type

FFv1 uses two types of coders, golomb and range with two different
tables. This is exposed this in a rather convoluted way, for example
mentioning to set coder type 1 while initializing the variable 'ac' to 2,
because encoder does not use range coder with default table.

Appropriate internal coder type values have been added and used in any
check rather than using raw numbers.

Initialization of avctx.coder_type in ffv1dec is removed because this
field is encoder only. An unneeded validation check in the encoder
is dropped too.

Signed-off-by: Vittorio Giovara <vittorio.giovara at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4bb1070c154e49d35805fbcdac9c9e92f702ef96
---

 libavcodec/ffv1.c    |    6 +++---
 libavcodec/ffv1.h    |    4 ++++
 libavcodec/ffv1dec.c |   16 ++++++++--------
 libavcodec/ffv1enc.c |   30 ++++++++++++------------------
 4 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 0836d42..3a6c7fa 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -160,7 +160,7 @@ int ffv1_init_slice_state(FFV1Context *f, FFV1Context *fs)
     for (j = 0; j < f->plane_count; j++) {
         PlaneContext *const p = &fs->plane[j];
 
-        if (fs->ac) {
+        if (fs->ac != AC_GOLOMB_RICE) {
             if (!p->state)
                 p->state = av_malloc(CONTEXT_SIZE * p->context_count *
                                      sizeof(uint8_t));
@@ -174,7 +174,7 @@ int ffv1_init_slice_state(FFV1Context *f, FFV1Context *fs)
         }
     }
 
-    if (fs->ac > 1) {
+    if (fs->ac == AC_RANGE_CUSTOM_TAB) {
         //FIXME only redo if state_transition changed
         for (j = 1; j < 256; j++) {
             fs->c.one_state[j]        = f->state_transition[j];
@@ -257,7 +257,7 @@ void ffv1_clear_slice_state(FFV1Context *f, FFV1Context *fs)
         p->interlace_bit_state[0] = 128;
         p->interlace_bit_state[1] = 128;
 
-        if (fs->ac) {
+        if (fs->ac != AC_GOLOMB_RICE) {
             if (f->initial_states[p->quant_table_index]) {
                 memcpy(p->state, f->initial_states[p->quant_table_index],
                        CONTEXT_SIZE * p->context_count);
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 6e8c798..b44253e 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -36,6 +36,10 @@
 #define MAX_QUANT_TABLES 8
 #define MAX_CONTEXT_INPUTS 5
 
+#define AC_GOLOMB_RICE          0
+#define AC_RANGE_DEFAULT_TAB    1
+#define AC_RANGE_CUSTOM_TAB     2
+
 extern const uint8_t ff_log2_run[41];
 
 extern const int8_t ffv1_quant5_10bit[256];
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 01c58a1..d32da60 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -120,7 +120,7 @@ static av_always_inline void decode_line(FFV1Context *s, int w,
 
         av_assert2(context < p->context_count);
 
-        if (s->ac) {
+        if (s->ac != AC_GOLOMB_RICE) {
             diff = get_symbol_inline(c, p->state[context], 1);
         } else {
             if (context == 0 && run_mode == 0)
@@ -274,7 +274,7 @@ static int decode_slice_header(FFV1Context *f, FFV1Context *fs)
     unsigned ps, i, context_count;
     memset(state, 128, sizeof(state));
 
-    if (fs->ac > 1) {
+    if (fs->ac == AC_RANGE_CUSTOM_TAB) {
         for (i = 1; i < 256; i++) {
             fs->c.one_state[i]        = f->state_transition[i];
             fs->c.zero_state[256 - i] = 256 - fs->c.one_state[i];
@@ -364,7 +364,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
     x      = fs->slice_x;
     y      = fs->slice_y;
 
-    if (!fs->ac) {
+    if (fs->ac == AC_GOLOMB_RICE) {
         if (f->version == 3 && f->minor_version > 1 || f->version > 3)
             get_rac(&fs->c, (uint8_t[]) { 129 });
         fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - fs->c.bytestream_start - 1 : 0;
@@ -401,7 +401,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
                                p->data[2] + ps * x + y * p->linesize[2] };
         decode_rgb_frame(fs, planes, width, height, p->linesize);
     }
-    if (fs->ac && f->version > 2) {
+    if (fs->ac != AC_GOLOMB_RICE && f->version > 2) {
         int v;
         get_rac(&fs->c, (uint8_t[]) { 129 });
         v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5 * f->ec;
@@ -477,9 +477,9 @@ static int read_extra_header(FFV1Context *f)
         c->bytestream_end -= 4;
         f->minor_version   = get_symbol(c, state, 0);
     }
-    f->ac = f->avctx->coder_type = get_symbol(c, state, 0);
+    f->ac = get_symbol(c, state, 0);
 
-    if (f->ac > 1) {
+    if (f->ac == AC_RANGE_CUSTOM_TAB) {
         for (i = 1; i < 256; i++)
             f->state_transition[i] = get_symbol(c, state, 1) + c->one_state[i];
     }
@@ -559,9 +559,9 @@ static int read_header(FFV1Context *f)
         }
         f->version = v;
 
-        f->ac = f->avctx->coder_type = get_symbol(c, state, 0);
+        f->ac = get_symbol(c, state, 0);
 
-        if (f->ac > 1) {
+        if (f->ac == AC_RANGE_CUSTOM_TAB) {
             for (i = 1; i < 256; i++)
                 f->state_transition[i] =
                     get_symbol(c, state, 1) + c->one_state[i];
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 32b3711..fe144b8 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -178,7 +178,7 @@ static av_always_inline int encode_line(FFV1Context *s, int w,
     int run_count = 0;
     int run_mode  = 0;
 
-    if (s->ac) {
+    if (s->ac != AC_GOLOMB_RICE) {
         if (c->bytestream_end - c->bytestream < w * 20) {
             av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
             return AVERROR_INVALIDDATA;
@@ -203,7 +203,7 @@ static av_always_inline int encode_line(FFV1Context *s, int w,
 
         diff = fold(diff, bits);
 
-        if (s->ac) {
+        if (s->ac != AC_GOLOMB_RICE) {
             if (s->flags & AV_CODEC_FLAG_PASS1) {
                 put_symbol_inline(c, p->state[context], diff, 1, s->rc_stat,
                                   s->rc_stat2[p->quant_table_index][context]);
@@ -388,7 +388,7 @@ static void write_header(FFV1Context *f)
     if (f->version < 2) {
         put_symbol(c, state, f->version, 0);
         put_symbol(c, state, f->ac, 0);
-        if (f->ac > 1) {
+        if (f->ac == AC_RANGE_CUSTOM_TAB) {
             for (i = 1; i < 256; i++)
                 put_symbol(c, state,
                            f->state_transition[i] - c->one_state[i], 1);
@@ -449,7 +449,7 @@ static int write_extradata(FFV1Context *f)
     }
 
     put_symbol(c, state, f->ac, 0);
-    if (f->ac > 1)
+    if (f->ac == AC_RANGE_CUSTOM_TAB)
         for (i = 1; i < 256; i++)
             put_symbol(c, state, f->state_transition[i] - c->one_state[i], 1);
 
@@ -587,7 +587,7 @@ static av_cold int ffv1_encode_init(AVCodecContext *avctx)
         return AVERROR(ENOSYS);
     }
 
-    s->ac = avctx->coder_type > 0 ? 2 : 0;
+    s->ac = avctx->coder_type > 0 ? AC_RANGE_CUSTOM_TAB : AC_GOLOMB_RICE;
 
     s->plane_count = 3;
     switch (avctx->pix_fmt) {
@@ -615,16 +615,10 @@ static av_cold int ffv1_encode_init(AVCodecContext *avctx)
             av_log(avctx, AV_LOG_ERROR, "bits_per_raw_sample invalid\n");
             return AVERROR_INVALIDDATA;
         }
-        if (!s->ac && avctx->coder_type == -1) {
+        if (s->ac == AC_GOLOMB_RICE) {
             av_log(avctx, AV_LOG_INFO,
-                   "bits_per_raw_sample > 8, forcing coder 1\n");
-            s->ac = 2;
-        }
-        if (!s->ac) {
-            av_log(
-                avctx, AV_LOG_ERROR,
-                "bits_per_raw_sample of more than 8 needs -coder 1 currently\n");
-            return AVERROR_INVALIDDATA;
+                   "bits_per_raw_sample > 8, forcing range coder\n");
+            s->ac = AC_RANGE_CUSTOM_TAB;
         }
         s->version = FFMAX(s->version, 1);
     case AV_PIX_FMT_GRAY8:
@@ -679,7 +673,7 @@ static av_cold int ffv1_encode_init(AVCodecContext *avctx)
         return AVERROR(EINVAL);
     }
 
-    if (s->ac > 1)
+    if (s->ac == AC_RANGE_CUSTOM_TAB)
         for (i = 1; i < 256; i++)
             s->state_transition[i] = ffv1_ver2_state[i];
 
@@ -889,7 +883,7 @@ static int encode_slice(AVCodecContext *c, void *arg)
     if (f->version > 2) {
         encode_slice_header(f, fs);
     }
-    if (!fs->ac) {
+    if (fs->ac == AC_GOLOMB_RICE) {
         if (f->version > 2)
             put_rac(&fs->c, (uint8_t[]) { 129 }, 0);
         fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate( &fs->c) : 0;
@@ -958,7 +952,7 @@ static int ffv1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         f->key_frame = 0;
     }
 
-    if (f->ac > 1) {
+    if (f->ac == AC_RANGE_CUSTOM_TAB) {
         int i;
         for (i = 1; i < 256; i++) {
             c->one_state[i]        = f->state_transition[i];
@@ -981,7 +975,7 @@ static int ffv1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         FFV1Context *fs = f->slice_context[i];
         int bytes;
 
-        if (fs->ac) {
+        if (fs->ac != AC_GOLOMB_RICE) {
             uint8_t state = 129;
             put_rac(&fs->c, &state, 0);
             bytes = ff_rac_terminate(&fs->c);



More information about the ffmpeg-cvslog mailing list