[SCM] libav/experimental: Add initial_states array to ffv1.

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 17:18:11 UTC 2013


The following commit has been merged in the experimental branch:
commit 99a5e93526cc6394d347e3d2a8c86daf891ef9ac
Author: Michael Niedermayer <michaelni at gmx.at>
Date:   Tue Oct 26 23:01:11 2010 +0000

    Add initial_states array to ffv1.
    
    Originally committed as revision 25582 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 4985312..25006e8 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -247,6 +247,7 @@ typedef struct FFV1Context{
     int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256];
     int context_count[MAX_QUANT_TABLES];
     uint8_t state_transition[256];
+    uint8_t (*initial_states[MAX_QUANT_TABLES])[32];
     int run_index;
     int colorspace;
     int_fast16_t *sample_buffer;
@@ -754,6 +755,18 @@ static av_cold int init_slice_contexts(FFV1Context *f){
     return 0;
 }
 
+static int allocate_initial_states(FFV1Context *f){
+    int i;
+
+    for(i=0; i<f->quant_table_count; i++){
+        f->initial_states[i]= av_malloc(f->context_count[i]*sizeof(*f->initial_states[i]));
+        if(!f->initial_states[i])
+            return AVERROR(ENOMEM);
+        memset(f->initial_states[i], 128, f->context_count[i]*sizeof(*f->initial_states[i]));
+    }
+    return 0;
+}
+
 #if CONFIG_FFV1_ENCODER
 static int write_extra_header(FFV1Context *f){
     RangeCoder * const c= &f->c;
@@ -882,6 +895,9 @@ static av_cold int encode_init(AVCodecContext *avctx)
         p->context_count= s->context_count[p->quant_table_index];
     }
 
+    if(allocate_initial_states(s) < 0)
+        return AVERROR(ENOMEM);
+
     avctx->coded_frame= &s->picture;
     switch(avctx->pix_fmt){
     case PIX_FMT_YUV444P16:
@@ -977,6 +993,9 @@ static void clear_state(FFV1Context *f){
             p->interlace_bit_state[1]= 128;
 
             if(fs->ac){
+                if(f->initial_states[p->quant_table_index]){
+                    memcpy(p->state, f->initial_states[p->quant_table_index], CONTEXT_SIZE*p->context_count);
+                }else
                 memset(p->state, 128, CONTEXT_SIZE*p->context_count);
             }else{
             for(j=0; j<p->context_count; j++){
@@ -1137,6 +1156,7 @@ static av_cold int common_end(AVCodecContext *avctx){
 
     av_freep(&avctx->stats_out);
     for(j=0; j<s->quant_table_count; j++){
+        av_freep(&s->initial_states[j]);
         for(i=0; i<s->slice_count; i++){
             FFV1Context *sf= s->slice_context[i];
             av_freep(&sf->rc_stat2[j]);

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list