[xiph-commits] r14586 - branches/theora-thusnelda/lib/enc
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Thu Mar 13 20:44:27 PDT 2008
Author: xiphmont
Date: 2008-03-13 20:44:27 -0700 (Thu, 13 Mar 2008)
New Revision: 14586
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/mode.c
Log:
First step toward fully on-the-fly tokenization (such that mode select/transform/quantize/tokenize can be done in sequence per MB)
Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h 2008-03-14 02:09:51 UTC (rev 14585)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h 2008-03-14 03:44:27 UTC (rev 14586)
@@ -239,11 +239,10 @@
unsigned char *dct_token_storage;
ogg_uint16_t *dct_token_eb_storage;
- unsigned char *dct_token[64];
- ogg_uint16_t *dct_token_eb[64];
+ unsigned char *dct_token[3][64];
+ ogg_uint16_t *dct_token_eb[3][64];
- ogg_uint32_t dct_token_count[64];
- ogg_uint32_t dct_token_ycount[64];
+ ogg_uint32_t dct_token_count[3][64];
ogg_uint32_t dc_bits[2][DC_HUFF_CHOICES];
ogg_uint32_t ac_bits[2][AC_HUFF_CHOICES];
@@ -259,10 +258,10 @@
int *frag_mbi;
int *frag_sad;
int *dct_token_frag_storage;
- int *dct_token_frag[64];
+ int *dct_token_frag[3][64];
int *dct_eob_fi_storage;
- int *dct_eob_fi_stack[64];
- int dct_eob_fi_count[64];
+ int *dct_eob_fi_stack[3][64];
+ int dct_eob_fi_count[3][64];
#endif
/********************************************************************/
Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c 2008-03-14 02:09:51 UTC (rev 14585)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c 2008-03-14 03:44:27 UTC (rev 14586)
@@ -34,12 +34,12 @@
static void add_token(CP_INSTANCE *cpi, int plane, int coeff,
unsigned char token, ogg_uint16_t eb, int fi){
- cpi->dct_token[coeff][cpi->dct_token_count[coeff]] = token;
- cpi->dct_token_eb[coeff][cpi->dct_token_count[coeff]] = eb;
+ cpi->dct_token[plane][coeff][cpi->dct_token_count[plane][coeff]] = token;
+ cpi->dct_token_eb[plane][coeff][cpi->dct_token_count[plane][coeff]] = eb;
#ifdef COLLECT_METRICS
- cpi->dct_token_frag[coeff][cpi->dct_token_count[coeff]] = fi;
+ cpi->dct_token_frag[plane][coeff][cpi->dct_token_count[plane][coeff]] = fi;
#endif
- cpi->dct_token_count[coeff]++;
+ cpi->dct_token_count[plane][coeff]++;
if(coeff == 0){
/* DC */
@@ -52,22 +52,20 @@
for ( i = 0; i < AC_HUFF_CHOICES; i++)
cpi->ac_bits[plane][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
}
-
- if(!plane)cpi->dct_token_ycount[coeff]++;
}
static void prepend_token(CP_INSTANCE *cpi, int plane, int coeff,
unsigned char token, ogg_uint16_t eb, int fi){
- cpi->dct_token[coeff]--;
- cpi->dct_token_eb[coeff]--;
+ cpi->dct_token[plane][coeff]--;
+ cpi->dct_token_eb[plane][coeff]--;
#ifdef COLLECT_METRICS
- cpi->dct_token_frag[coeff]--;
- cpi->dct_token_frag[coeff][0] = fi;
+ cpi->dct_token_frag[plane][coeff]--;
+ cpi->dct_token_frag[plane][coeff][0] = fi;
#endif
- cpi->dct_token[coeff][0] = token;
- cpi->dct_token_eb[coeff][0] = eb;
- cpi->dct_token_count[coeff]++;
+ cpi->dct_token[plane][coeff][0] = token;
+ cpi->dct_token_eb[plane][coeff][0] = eb;
+ cpi->dct_token_count[plane][coeff]++;
if(coeff == 0){
/* DC */
@@ -80,8 +78,6 @@
for ( i = 0; i < AC_HUFF_CHOICES; i++)
cpi->ac_bits[plane][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
}
-
- if(!plane)cpi->dct_token_ycount[coeff]++;
}
static void emit_eob_run(CP_INSTANCE *cpi, int plane, int pos, int run){
@@ -213,19 +209,19 @@
}
}
-static void tokenize_groups(CP_INSTANCE *cpi,
- int *eob_run, int *eob_plane, int *eob_ypre, int *eob_uvpre){
+static void tokenize_groups(CP_INSTANCE *cpi, int plane,
+ int *eob_run, int *eob_plane,
+ int *eob_pre){
int SB,B;
unsigned char *cp=cpi->frag_coded;
- for ( SB=0; SB<cpi->super_total; SB++ ){
- superblock_t *sp = &cpi->super[0][SB];
+ for ( SB=0; SB<cpi->super_n[plane]; SB++ ){
+ superblock_t *sp = &cpi->super[plane][SB];
for ( B=0; B<16; B++ ) {
int fi = sp->f[B];
if ( cp[fi] ) {
int coeff = 0;
- int plane = (fi >= cpi->frag_n[0]);
dct_t *dct = &cpi->frag_dct[fi];
cpi->frag_nonzero[fi] = 0;
@@ -242,15 +238,12 @@
if ( i == BLOCK_SIZE ){
/* if there are no other tokens in this group yet, set up to be
- prepended later. Group 0 is the exception (can't be
+ prepended later. Group 0/Plane 0 is the exception (can't be
prepended) */
- if(cpi->dct_token_count[coeff] == 0 && coeff){
- if(!plane)
- eob_ypre[coeff]++;
- else
- eob_uvpre[coeff]++;
+ if(cpi->dct_token_count[plane][coeff] == 0 && (coeff||plane)){
+ eob_pre[coeff]++;
#ifdef COLLECT_METRICS
- cpi->dct_eob_fi_stack[coeff][cpi->dct_eob_fi_count[coeff]++]=fi;
+ cpi->dct_eob_fi_stack[plane][coeff][cpi->dct_eob_fi_count[plane][coeff]++]=fi;
#endif
}else{
if(eob_run[coeff] == 4095){
@@ -263,7 +256,7 @@
eob_run[coeff]++;
#ifdef COLLECT_METRICS
- cpi->dct_eob_fi_stack[coeff][cpi->dct_eob_fi_count[coeff]++]=fi;
+ cpi->dct_eob_fi_stack[plane][coeff][cpi->dct_eob_fi_count[plane][coeff]++]=fi;
#endif
}
coeff = BLOCK_SIZE;
@@ -300,131 +293,118 @@
}
void DPCMTokenize (CP_INSTANCE *cpi){
- int eob_run[64];
- int eob_plane[64];
+ int eob_run[3][64];
+ int eob_plane[3][64];
- int eob_ypre[64];
- int eob_uvpre[64];
+ int eob_pre[3][64];
- int i;
+ int i,j;
memset(eob_run, 0, sizeof(eob_run));
- memset(eob_ypre, 0, sizeof(eob_ypre));
- memset(eob_uvpre, 0, sizeof(eob_uvpre));
+ memset(eob_pre, 0, sizeof(eob_pre));
memset(cpi->dc_bits, 0, sizeof(cpi->dc_bits));
memset(cpi->ac_bits, 0, sizeof(cpi->ac_bits));
memset(cpi->dct_token_count, 0, sizeof(cpi->dct_token_count));
- memset(cpi->dct_token_ycount, 0, sizeof(cpi->dct_token_ycount));
#ifdef COLLECT_METRICS
memset(cpi->dct_eob_fi_count, 0, sizeof(cpi->dct_eob_fi_count));
#endif
for(i=0;i<BLOCK_SIZE;i++){
- cpi->dct_token[i] = cpi->dct_token_storage+cpi->frag_total*i;
- cpi->dct_token_eb[i] = cpi->dct_token_eb_storage+cpi->frag_total*i;
+ cpi->dct_token[0][i] = cpi->dct_token_storage+cpi->frag_total*i;
+ cpi->dct_token[1][i] = cpi->dct_token[0][i] + cpi->frag_n[0];
+ cpi->dct_token[2][i] = cpi->dct_token[1][i] + cpi->frag_n[1];
+
+ cpi->dct_token_eb[0][i] = cpi->dct_token_eb_storage+cpi->frag_total*i;
+ cpi->dct_token_eb[1][i] = cpi->dct_token_eb[0][i] + cpi->frag_n[0];
+ cpi->dct_token_eb[2][i] = cpi->dct_token_eb[1][i] + cpi->frag_n[1];
+
#ifdef COLLECT_METRICS
- cpi->dct_eob_fi_stack[i] = cpi->dct_eob_fi_storage+cpi->frag_total*i;
- cpi->dct_token_frag[i] = cpi->dct_token_frag_storage+cpi->frag_total*i;
+ cpi->dct_eob_fi_stack[0][i] = cpi->dct_eob_fi_storage+cpi->frag_total*i;
+ cpi->dct_eob_fi_stack[1][i] = cpi->dct_eob_fi_stack[0][i] + cpi->frag_n[0];
+ cpi->dct_eob_fi_stack[2][i] = cpi->dct_eob_fi_stack[1][i] + cpi->frag_n[1];
+ cpi->dct_token_frag[0][i] = cpi->dct_token_frag_storage+cpi->frag_total*i;
+ cpi->dct_token_frag[1][i] = cpi->dct_token_frag[0][i] + cpi->frag_n[0];
+ cpi->dct_token_frag[2][i] = cpi->dct_token_frag[1][i] + cpi->frag_n[1];
#endif
}
/* Tokenize the dct data. */
- tokenize_groups (cpi, eob_run, eob_plane, eob_ypre, eob_uvpre);
+ for(i=0;i<3;i++)
+ tokenize_groups (cpi, i, eob_run[i], eob_plane[i], eob_pre[i]);
/* tie together eob runs at the beginnings/ends of coeff groups */
{
int coeff = 0;
int run = 0;
- int plane = 0;
+ int plane = 0; /* not the current plane; plane of next token to
+ emit, used to track start of eob runs */
for(i=0;i<BLOCK_SIZE;i++){
-
- if(eob_ypre[i] || eob_uvpre[i]){
- /* group begins with an EOB run */
-
- if(run && run + eob_ypre[i] >= 4095){
- emit_eob_run(cpi,plane,coeff,4095);
- eob_ypre[i] -= 4095-run;
- run = 0;
- coeff = i;
- plane = (eob_ypre[i] ? 0 : 1);
- }
-
- if(run && run + eob_ypre[i] + eob_uvpre[i] >= 4095){
- emit_eob_run(cpi,plane,coeff,4095);
- eob_uvpre[i] -= 4095 - eob_ypre[i] - run;
- eob_ypre[i] = 0;
- run = 0;
- coeff = i;
- plane = 1;
- }
-
- if(run){
- if(cpi->dct_token_count[i]){
- /* group is not only an EOB run; emit the run token */
- emit_eob_run(cpi,plane,coeff,run + eob_ypre[i] + eob_uvpre[i]);
- eob_ypre[i] = 0;
- eob_uvpre[i] = 0;
- run = eob_run[i];
+ for(j=0;j<3;j++){
+ if(eob_pre[j][i]){
+ /* group begins with an EOB run */
+
+ if(run && run + eob_pre[j][i] >= 4095){
+ emit_eob_run(cpi,plane,coeff,4095);
+ eob_pre[j][i] -= 4095-run;
+ run = 0;
coeff = i;
- plane = eob_plane[i];
+ plane = (eob_pre[j][i] ? 0 : 1);
+ }
+
+ if(run){
+ if(cpi->dct_token_count[j][i]){
+ /* group is not only an EOB run; emit the run token */
+ emit_eob_run(cpi,plane,coeff,run + eob_pre[j][i]);
+ eob_pre[j][i] = 0;
+ run = eob_run[j][i];
+ coeff = i;
+ plane = eob_plane[j][i];
+ }else{
+ /* group consists entirely of EOB run. Add, iterate */
+ run += eob_pre[j][i];
+ eob_pre[j][i] = 0;
+ }
}else{
- /* group consists entirely of EOB run. Add, iterate */
- run += eob_ypre[i];
- run += eob_uvpre[i];
- eob_ypre[i] = 0;
- eob_uvpre[i] = 0;
+
+ if(cpi->dct_token_count[j][i]){
+ /* there are other tokens in this group; work backwards as we need to prepend */
+ while(eob_pre[j][i] >= 4095){
+ prepend_eob_run(cpi,j,i,4095);
+ eob_pre[j][i] -= 4095;
+ }
+ if(eob_pre[j][i]){
+ prepend_eob_run(cpi,j, i, eob_pre[j][i]);
+ eob_pre[j][i] = 0;
+ }
+ run = eob_run[j][i];
+ coeff = i;
+ plane = eob_plane[j][i];
+ }else{
+ /* group consists entirely of EOB run. Add, flush overs, iterate */
+ while(eob_pre[j][i] >= 4095){
+ emit_eob_run(cpi,j,i,4095);
+ eob_pre[j][i] -= 4095;
+ }
+ run = eob_pre[j][i];
+ coeff = i;
+ plane = j;
+ }
}
}else{
+ /* no eob run to begin group */
+ if(cpi->dct_token_count[j][i]){
+ if(run)
+ emit_eob_run(cpi,plane,coeff,run);
- if(cpi->dct_token_count[i]){
- /* there are other tokens in this group; work backwards as we need to prepend */
- while(eob_uvpre[i] >= 4095){
- prepend_eob_run(cpi,1,i,4095);
- eob_uvpre[i] -= 4095;
- }
- while(eob_uvpre[i] + eob_ypre[i] >= 4095){
- prepend_eob_run(cpi,0,i,4095);
- eob_ypre[i] -= 4095 - eob_uvpre[i];
- eob_uvpre[i] = 0;
- }
- if(eob_uvpre[i] + eob_ypre[i]){
- prepend_eob_run(cpi, (eob_ypre[i] ? 0 : 1), i, eob_ypre[i] + eob_uvpre[i]);
- eob_ypre[i] = 0;
- eob_uvpre[i] = 0;
- }
- run = eob_run[i];
+ run = eob_run[j][i];
coeff = i;
- plane = eob_plane[i];
- }else{
- /* group consists entirely of EOB run. Add, flush overs, iterate */
- while(eob_ypre[i] >= 4095){
- emit_eob_run(cpi,0,i,4095);
- eob_ypre[i] -= 4095;
- }
- while(eob_uvpre[i] + eob_ypre[i] >= 4095){
- emit_eob_run(cpi,(eob_ypre[i] ? 0 : 1), i, 4095);
- eob_uvpre[i] -= 4095 - eob_ypre[i];
- eob_ypre[i] = 0;
- }
- run = eob_uvpre[i]+eob_ypre[i];
- coeff = i;
- plane = (eob_ypre[i] ? 0 : 1);
+ plane = eob_plane[j][i];
}
}
- }else{
- /* no eob run to begin group */
- if(cpi->dct_token_count[i]){
- if(run)
- emit_eob_run(cpi,plane,coeff,run);
-
- run = eob_run[i];
- coeff = i;
- plane = eob_plane[i];
- }
}
}
-
+
if(run)
emit_eob_run(cpi,plane,coeff,run);
Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c 2008-03-14 02:09:51 UTC (rev 14585)
+++ branches/theora-thusnelda/lib/enc/encode.c 2008-03-14 03:44:27 UTC (rev 14586)
@@ -238,9 +238,9 @@
int i;
oggpack_buffer *opb=cpi->oggbuffer;
- int y = cpi->dct_token_ycount[group];
- unsigned char *token = cpi->dct_token[group];
- ogg_uint16_t *eb = cpi->dct_token_eb[group];
+ int y = cpi->dct_token_count[0][group];
+ unsigned char *token = cpi->dct_token[0][group];
+ ogg_uint16_t *eb = cpi->dct_token_eb[0][group];
for(i=0; i<y; i++){
oggpackB_write( opb, cpi->HuffCodeArray_VP3x[huffY][token[i]],
@@ -249,12 +249,23 @@
oggpackB_write( opb, eb[i], cpi->ExtraBitLengths_VP3x[token[i]] );
}
- for(; i<cpi->dct_token_count[group]; i++){
+ token = cpi->dct_token[1][group];
+ eb = cpi->dct_token_eb[1][group];
+ for(i=0; i<cpi->dct_token_count[1][group]; i++){
oggpackB_write( opb, cpi->HuffCodeArray_VP3x[huffC][token[i]],
cpi->HuffCodeLengthArray_VP3x[huffC][token[i]] );
if (cpi->ExtraBitLengths_VP3x[token[i]] > 0)
oggpackB_write( opb, eb[i], cpi->ExtraBitLengths_VP3x[token[i]] );
}
+
+ token = cpi->dct_token[2][group];
+ eb = cpi->dct_token_eb[2][group];
+ for(i=0; i<cpi->dct_token_count[2][group]; i++){
+ oggpackB_write( opb, cpi->HuffCodeArray_VP3x[huffC][token[i]],
+ cpi->HuffCodeLengthArray_VP3x[huffC][token[i]] );
+ if (cpi->ExtraBitLengths_VP3x[token[i]] > 0)
+ oggpackB_write( opb, eb[i], cpi->ExtraBitLengths_VP3x[token[i]] );
+ }
}
static void EncodeTokenList (CP_INSTANCE *cpi, int huff[4]) {
Modified: branches/theora-thusnelda/lib/enc/mode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mode.c 2008-03-14 02:09:51 UTC (rev 14585)
+++ branches/theora-thusnelda/lib/enc/mode.c 2008-03-14 03:44:27 UTC (rev 14586)
@@ -426,6 +426,55 @@
return cost;
}
+void mb_get_dct_input(CP_INSTANCE *cpi,
+ coding_mode_t mode,
+ int fi,
+ mv_t mv,
+ ogg_int16_t *block){
+
+ int plane = fi>=cpi->frag_n[0]; /* sets plane to 'Y' or 'Chroma' */
+ int qp = (plane?1:0);
+ int bi = cpi->frag_buffer_index[fi];
+ unsigned char *frame_ptr = &cpi->frame[bi];
+ unsigned char *recon = ((mode == CODE_USING_GOLDEN ||
+ mode == CODE_GOLDEN_MV) ?
+ cpi->golden : cpi->lastrecon);
+ int stride = cpi->stride[plane];
+
+ switch(mode){
+ case CODE_INTER_PLUS_MV:
+ case CODE_INTER_LAST_MV:
+ case CODE_INTER_PRIOR_LAST:
+ case CODE_GOLDEN_MV:
+ case CODE_INTER_FOURMV:
+
+ {
+ int mx = mvmap[qp][mv.x+31];
+ int my = mvmap[qp][mv.y+31];
+ int mx2 = mvmap2[qp][mv.x+31];
+ int my2 = mvmap2[qp][mv.y+31];
+
+ unsigned char *r1 = recon + bi+ my * stride + mx;
+
+ if(mx2 || my2){
+ unsigned char *r2 = r1 + my2 * stride + mx2;
+ dsp_sub8x8avg2(cpi->dsp, frame_ptr, r1, r2, block, stride);
+ }else{
+ dsp_sub8x8(cpi->dsp, frame_ptr, r1, block, stride);
+ }
+ }
+ break;
+
+ case CODE_USING_GOLDEN:
+ case CODE_INTER_NO_MV:
+ dsp_sub8x8(cpi->dsp, frame_ptr, recon+bi, block, stride);
+ break;
+ case CODE_INTRA:
+ dsp_sub8x8_128(cpi->dsp, frame_ptr, block, stride);
+ break;
+ }
+}
+
int PickModes(CP_INSTANCE *cpi){
unsigned char qi = cpi->BaseQ; // temporary
superblock_t *sb = cpi->super[0];
More information about the commits
mailing list