Mercurial > libavcodec.hg
changeset 1302:c41f51b5d5d6 libavcodec
reducing memory consumption (reducing number of contexts and other stuff, no noticeable loss in compression rate)
author | michaelni |
---|---|
date | Mon, 09 Jun 2003 23:55:16 +0000 |
parents | 9d02a1859891 |
children | e1fae3528935 |
files | ffv1.c |
diffstat | 1 files changed, 33 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/ffv1.c Mon Jun 09 19:11:50 2003 +0000 +++ b/ffv1.c Mon Jun 09 23:55:16 2003 +0000 @@ -30,6 +30,8 @@ #include "cabac.h" #define MAX_PLANES 4 +#define CONTEXT_SIZE 32 + #if 0 #define DEFAULT_QDIFF_COUNT (9) @@ -76,18 +78,18 @@ }; #endif -static const int to8[16]={ -0,1,1,1, -1,2,2,3, -4,5,6,6, -7,7,7,7 +static const int to5[16]={ +0,0,0,0, +0,0,0,1, +2,3,4,4, +4,4,4,4, }; typedef struct PlaneContext{ uint8_t quant_table[256]; int qdiff_count; int context_count; - uint8_t (*state)[64]; //FIXME 64 + uint8_t (*state)[CONTEXT_SIZE]; uint8_t interlace_bit_state[2]; } PlaneContext; @@ -162,27 +164,13 @@ } } #else + /** * put */ static inline void put_symbol(CABACContext *c, uint8_t *state, int v, int is_signed){ int i; -#if 0 - const int a= ABS(v); - const int e= av_log2(a+1); - put_cabac_u(c, state+0, e, 7, 6, 1); //0..6 - if(e){ - put_cabac(c, state+6 + e, v < 0); //7..13 - - for(i=; i<e; i++){ - - } - } -#else -// 0 1 2 3 4 5 6 -// 0 1 2 3 4 5 6 -// 0 0 1 3 6 10 15 21 if(v){ const int a= ABS(v); const int e= av_log2(a); @@ -191,18 +179,15 @@ put_cabac_u(c, state+1, e, 7, 6, 1); //1..7 if(e<7){ for(i=e-1; i>=0; i--){ - static const int offset[7]= {14+0, 14+0, 14+1, 14+3, 14+6, 14+10, 14+15}; -// put_cabac(c, state+14+e-i, (a>>i)&1); //14..20 - put_cabac(c, state+offset[e]+i, (a>>i)&1); //14..34 + static const int offset[7]= {15+0, 15+0, 15+1, 15+3, 15+6, 15+10, 15+11}; + put_cabac(c, state+offset[e]+i, (a>>i)&1); //15..31 } - if(is_signed) put_cabac(c, state+8 + e, v < 0); //8..14 } }else{ put_cabac(c, state+0, 1); } -#endif } static inline int get_symbol(CABACContext *c, uint8_t *state, int is_signed){ @@ -217,8 +202,8 @@ int a= 1<<e; for(i=e-1; i>=0; i--){ - static const int offset[7]= {14+0, 14+0, 14+1, 14+3, 14+6, 14+10, 14+15}; - a += get_cabac(c, state+offset[e]+i)<<i; //14..34 + static const int offset[7]= {15+0, 15+0, 15+1, 15+3, 15+6, 15+10, 15+11}; + a += get_cabac(c, state+offset[e]+i)<<i; //14..31 } if(is_signed && get_cabac(c, state+8 + e)) //8..14 @@ -257,14 +242,14 @@ context= pred_diff[3+0][x-1] + 16*pred_diff[3-1][x+0]; else context= pred_diff[3+0][x-1] + 16*pred_diff[3-1][x+0] - + 16*16*to8[pred_diff[3-1][x+1]] + 16*16*8*to8[pred_diff[3-0][x-2]] + 16*16*8*8*to8[pred_diff[3-2][x+0]]; - + + 16*16*to5[pred_diff[3-1][x+1]] + 16*16*5*to5[pred_diff[3-0][x-2]] + 16*16*5*5*to5[pred_diff[3-2][x+0]]; + diff = (int8_t)(temp_src[0] - predict(s, temp_src, stride, x, y)); qdiff= p->quant_table[128+diff]; - + put_symbol(c, p->state[context], diff, 1); - + pred_diff[3][x]= qdiff; } } @@ -273,7 +258,7 @@ static void write_quant_table(CABACContext *c, uint8_t *quant_table){ int last=0; int i; - uint8_t state[64]={0}; + uint8_t state[CONTEXT_SIZE]={0}; for(i=1; i<256 ; i++){ if(quant_table[i] != quant_table[i-1]){ @@ -285,7 +270,7 @@ } static void write_header(FFV1Context *f){ - uint8_t state[64]={0}; + uint8_t state[CONTEXT_SIZE]={0}; int i; CABACContext * const c= &f->c; @@ -306,7 +291,7 @@ static int common_init(AVCodecContext *avctx){ FFV1Context *s = avctx->priv_data; - int i, j, width, height; + int width, height; s->avctx= avctx; s->flags= avctx->flags; @@ -318,10 +303,6 @@ assert(width && height); - for(i=0; i<s->plane_count; i++){ - PlaneContext *p= &s->plane[i]; - } - return 0; } @@ -343,10 +324,10 @@ #if 1 p->context_count= 256; - p->state= av_malloc(64*p->context_count*sizeof(uint8_t)); + p->state= av_malloc(CONTEXT_SIZE*p->context_count*sizeof(uint8_t)); #else - p->context_count= 16*16*8*8*8; //256*16; - p->state= av_malloc(64*p->context_count*sizeof(uint8_t)); + p->context_count= 16*16*128 /*5*5*5*/; + p->state= av_malloc(CONTEXT_SIZE*p->context_count*sizeof(uint8_t)); #endif } @@ -372,7 +353,7 @@ static void clear_state(FFV1Context *f){ - int i; + int i, j; for(i=0; i<f->plane_count; i++){ PlaneContext *p= &f->plane[i]; @@ -380,7 +361,10 @@ p->interlace_bit_state[0]= 0; p->interlace_bit_state[1]= 0; - memset(p->state, 0, p->context_count*sizeof(uint8_t)*64); + for(j=0; j<p->context_count; j++){ + memset(p->state[j], 0, sizeof(uint8_t)*CONTEXT_SIZE); + p->state[j][7] = 2*62; + } } } @@ -475,7 +459,7 @@ context= pred_diff[3+0][x-1] + 16*pred_diff[3-1][x+0]; else context= pred_diff[3+0][x-1] + 16*pred_diff[3-1][x+0] - + 16*16*to8[pred_diff[3-1][x+1]] + 16*16*8*to8[pred_diff[3-0][x-2]] + 16*16*8*8*to8[pred_diff[3-2][x+0]]; + + 16*16*to5[pred_diff[3-1][x+1]] + 16*16*5*to5[pred_diff[3-0][x-2]] + 16*16*5*5*to5[pred_diff[3-2][x+0]]; diff= get_symbol(c, p->state[context], 1); @@ -493,7 +477,7 @@ static int read_quant_table(CABACContext *c, uint8_t *quant_table){ int v; int i=0; - uint8_t state[64]={0}; + uint8_t state[CONTEXT_SIZE]={0}; for(v=0; i<256 ; v++){ int len= get_symbol(c, state, 0) + 1; @@ -511,7 +495,7 @@ } static int read_header(FFV1Context *f){ - uint8_t state[64]={0}; + uint8_t state[CONTEXT_SIZE]={0}; int i; CABACContext * const c= &f->c; @@ -531,7 +515,7 @@ if(p->qdiff_count < 0) return -1; if(!p->state) - p->state= av_malloc(64*p->context_count*sizeof(uint8_t)); + p->state= av_malloc(CONTEXT_SIZE*p->context_count*sizeof(uint8_t)); } return 0; @@ -654,7 +638,7 @@ NULL, decode_end, decode_frame, - /*CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND*/ 0, + CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/, NULL };