[xiph-commits] r15559 - branches/theora-thusnelda/lib/enc
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Fri Dec 5 15:18:51 PST 2008
Author: xiphmont
Date: 2008-12-05 15:18:50 -0800 (Fri, 05 Dec 2008)
New Revision: 15559
Modified:
branches/theora-thusnelda/lib/enc/codec_internal.h
branches/theora-thusnelda/lib/enc/dct_encode.c
branches/theora-thusnelda/lib/enc/encode.c
branches/theora-thusnelda/lib/enc/encoder_toplevel.c
branches/theora-thusnelda/lib/enc/mcenc.c
branches/theora-thusnelda/lib/enc/mode.c
Log:
Commit a few last minute valgrind catches in tokenization and mcenc startup
Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h 2008-12-05 05:42:46 UTC (rev 15558)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h 2008-12-05 23:18:50 UTC (rev 15559)
@@ -22,7 +22,7 @@
# include "config.h"
#endif
-//#define COLLECT_METRICS
+#define COLLECT_METRICS
#include "theora/theora.h"
#include "encoder_huffman.h"
@@ -143,6 +143,7 @@
mv_t analysis_mv[3][2]; /* [cur,prev,prev2][frame,golden] */
/*Minimum motion estimation error from the analysis stage.*/
int aerror;
+ int gerror;
char coded;
} macroblock_t;
Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c 2008-12-05 05:42:46 UTC (rev 15558)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c 2008-12-05 23:18:50 UTC (rev 15559)
@@ -496,7 +496,8 @@
/* demoting token will produce a zero. */
costB = 0;
if(j==BLOCK_SIZE){
- costD += tokenize_eobcost(cpi,chroma,i+1);
+ if(i+1<BLOCK_SIZE)
+ costD += tokenize_eobcost(cpi,chroma,i+1);
costD -= tokenize_eobcost(cpi,chroma,coeff);
}else{
costD += tokenize_dctcost(cpi,chroma,i+1,j,dct[j]);
@@ -533,7 +534,8 @@
i=j;
}
- return retcost+tokenize_mark_run(cpi,chroma,fi,coeff>1,coeff,stack);
+ if(coeff<BLOCK_SIZE) retcost+=tokenize_mark_run(cpi,chroma,fi,coeff>1,coeff,stack);
+ return retcost;
}
/* called after AC tokenization is complete, because DC coding has to
@@ -545,74 +547,69 @@
static void tokenize_DC(CP_INSTANCE *cpi, int fi, int chroma,
int *idx1, int *run1){
- unsigned char *cp=cpi->frag_coded;
+ int val = cpi->frag_dc[fi];
+ int token1 = cpi->dct_token[1][*idx1];
+ int eb1 = cpi->dct_token_eb[1][*idx1];
- if ( cp[fi] ) {
- int val = cpi->frag_dc[fi];
- int token1 = cpi->dct_token[1][*idx1];
- int eb1 = cpi->dct_token_eb[1][*idx1];
-
- if(!*run1) *run1 = decode_eob_token(token1, eb1);
+ if(!*run1) *run1 = decode_eob_token(token1, eb1);
+
+ if(val){
+ /* nonzero DC val, no coeff 1 stack 'fixup'. */
- if(val){
- /* nonzero DC val, no coeff 1 stack 'fixup'. */
+ tokenize_dctval(cpi,chroma,fi,0,0,val,NULL);
+
+ /* there was a nonzero DC value, so there's no alteration to the
+ track1 stack for this fragment; track/regenerate stack 1
+ state unchanged */
+ if(*run1){
+ /* in the midst of an EOB run in stack 1 */
+ tokenize_mark_run(cpi,chroma,fi,1,1,NULL);
+ (*run1)--;
- tokenize_dctval(cpi,chroma,fi,0,0,val,NULL);
-
- /* there was a nonzero DC value, so there's no alteration to the
- track1 stack for this fragment; track/regenerate stack 1
- state unchanged */
- if(*run1){
- /* in the midst of an EOB run in stack 1 */
- tokenize_mark_run(cpi,chroma,fi,1,1,NULL);
- (*run1)--;
-
- }else{
-
- /* non-EOB run token to emit for stack 1 */
- token_add_raw(cpi,chroma,fi,1,token1,eb1);
-
- }
-
}else{
+
+ /* non-EOB run token to emit for stack 1 */
+ token_add_raw(cpi,chroma,fi,1,token1,eb1);
+
+ }
+
+ }else{
- /* zero DC value; that means the entry in coeff position 1
- should have been coded from the DC coeff position. This
- requires a stack 1 fixup. */
+ /* zero DC value; that means the entry in coeff position 1
+ should have been coded from the DC coeff position. This
+ requires a stack 1 fixup. */
+
+ if(*run1){
- if(*run1){
-
- /* current stack 1 token an EOB run; conceptually move this fragment's EOBness to stack 0 */
- tokenize_mark_run(cpi,chroma,fi,0,0,NULL);
-
- /* decrement current EOB run for coeff 1 without adding to coded run */
- (*run1)--;
-
- }else{
- int run,val=0;
-
- /* stack 1 token is one of: zerorun, dctrun or dctval */
- /* A zero-run token is expanded and moved to token stack 0 (stack 1 entry dropped) */
- /* A dctval may be transformed into a single dctrun that is moved to stack 0,
- or if it does not fit in a dctrun, we leave the stack 1 entry alone and emit
- a single length-1 zerorun token for stack 0 */
- /* A dctrun is extended and moved to stack 0. During AC
- coding, we restrict the run lengths on dctruns for stack 1
- so we know there's no chance of overrunning the
- representable range */
-
- run = decode_token(token1,eb1,&val)+1;
-
- if(!tokenize_dctval(cpi,chroma,fi,0,run,val,NULL)){
- token_add_raw(cpi,chroma,fi,1,token1,eb1);
- }
+ /* current stack 1 token an EOB run; conceptually move this fragment's EOBness to stack 0 */
+ tokenize_mark_run(cpi,chroma,fi,0,0,NULL);
+
+ /* decrement current EOB run for coeff 1 without adding to coded run */
+ (*run1)--;
+
+ }else{
+ int run,val=0;
+
+ /* stack 1 token is one of: zerorun, dctrun or dctval */
+ /* A zero-run token is expanded and moved to token stack 0 (stack 1 entry dropped) */
+ /* A dctval may be transformed into a single dctrun that is moved to stack 0,
+ or if it does not fit in a dctrun, we leave the stack 1 entry alone and emit
+ a single length-1 zerorun token for stack 0 */
+ /* A dctrun is extended and moved to stack 0. During AC
+ coding, we restrict the run lengths on dctruns for stack 1
+ so we know there's no chance of overrunning the
+ representable range */
+
+ run = decode_token(token1,eb1,&val)+1;
+
+ if(!tokenize_dctval(cpi,chroma,fi,0,run,val,NULL)){
+ token_add_raw(cpi,chroma,fi,1,token1,eb1);
}
}
-
- /* update token counter if not in a run */
- if (!*run1) (*idx1)++;
-
}
+
+ /* update token counter if not in a run */
+ if (!*run1) (*idx1)++;
}
void dct_tokenize_init (CP_INSTANCE *cpi){
@@ -654,7 +651,8 @@
void dct_tokenize_finish (CP_INSTANCE *cpi){
int i,sbi;
int idx1=0,run1=0;
-
+ unsigned char *cp=cpi->frag_coded;
+
/* we parse the token stack for coeff1 to stay in sync, and re-use
the token stack counters to track */
/* emit an eob run for the end run of stack 1; this is used to
@@ -675,7 +673,8 @@
int bi;
for (bi=0; bi<16; bi++, i++ ) {
int fi = sb->f[bi];
- tokenize_DC(cpi, fi, 0, &idx1, &run1);
+ if(fi>=0 && cp[fi])
+ tokenize_DC(cpi, fi, 0, &idx1, &run1);
}
}
@@ -691,7 +690,8 @@
int bi;
for (bi=0; bi<16; bi++,i++ ) {
int fi = sb->f[bi];
- tokenize_DC(cpi, fi, 1, &idx1, &run1);
+ if(fi>=0 && cp[fi])
+ tokenize_DC(cpi, fi, 1, &idx1, &run1);
}
}
Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c 2008-12-05 05:42:46 UTC (rev 15558)
+++ branches/theora-thusnelda/lib/enc/encode.c 2008-12-05 23:18:50 UTC (rev 15559)
@@ -340,6 +340,8 @@
#ifdef COLLECT_METRICS
ModeMetrics(cpi);
+
+#if 0
{
int total = cpi->frag_total*64;
int fi=0,pi,x,y;
@@ -402,6 +404,7 @@
);
}
#endif
+#endif
dsp_restore_fpu (cpi->dsp);
}
Modified: branches/theora-thusnelda/lib/enc/encoder_toplevel.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encoder_toplevel.c 2008-12-05 05:42:46 UTC (rev 15558)
+++ branches/theora-thusnelda/lib/enc/encoder_toplevel.c 2008-12-05 23:18:50 UTC (rev 15559)
@@ -119,8 +119,8 @@
cpi->BaseQ = c->quality;
/* temporary while the RD code is only partially complete */
- cpi->skip_lambda=1000;
- cpi->token_lambda=2000;
+ cpi->skip_lambda=0;
+ cpi->token_lambda=0;
cpi->mv_lambda=0;
/* Set encoder flags. */
@@ -269,7 +269,7 @@
if(last_p){
cpi->doneflag=1;
#ifdef COLLECT_METRICS
- //DumpMetrics(cpi);
+ DumpMetrics(cpi);
#endif
}
return 1;
Modified: branches/theora-thusnelda/lib/enc/mcenc.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mcenc.c 2008-12-05 05:42:46 UTC (rev 15558)
+++ branches/theora-thusnelda/lib/enc/mcenc.c 2008-12-05 23:18:50 UTC (rev 15559)
@@ -562,6 +562,9 @@
if(!_goldenp)
mb->aerror = *best_err;
+ else
+ mb->gerror = *best_err;
+
mb->analysis_mv[0][_goldenp].x=best_vec.x<<1;;
mb->analysis_mv[0][_goldenp].y=best_vec.y<<1;;
@@ -588,6 +591,8 @@
mb->analysis_mv[0][_goldenp]=mv;
if(!_goldenp)
mb->aerror = err;
+ else
+ mb->gerror = err;
}
Modified: branches/theora-thusnelda/lib/enc/mode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mode.c 2008-12-05 05:42:46 UTC (rev 15558)
+++ branches/theora-thusnelda/lib/enc/mode.c 2008-12-05 23:18:50 UTC (rev 15559)
@@ -911,7 +911,6 @@
return coded;
}
-#include<stdio.h>
int PickModes(CP_INSTANCE *cpi, int recode){
unsigned char qi = cpi->BaseQ; // temporary
superblock_t *sb = cpi->super[0];
@@ -944,7 +943,7 @@
oc_mcenc_start(cpi, &mcenc);
dct_tokenize_init(cpi);
-
+
/* Choose mvs, modes; must be done in Hilbert order */
/* quantize and code Luma */
sb = cpi->super[0];
@@ -981,6 +980,9 @@
/* search golden frame */
oc_mcenc_search(cpi, &mcenc, mbi, 1, NULL, &gerror, NULL);
+ }else{
+ aerror = mb->aerror;
+ gerror = mb->gerror;
}
if(cpi->FrameType == KEY_FRAME){
More information about the commits
mailing list