[xiph-commits] r14140 - branches/theora-thusnelda/lib/enc
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Wed Nov 14 19:31:56 PST 2007
Author: xiphmont
Date: 2007-11-14 19:31:56 -0800 (Wed, 14 Nov 2007)
New Revision: 14140
Modified:
branches/theora-thusnelda/lib/enc/codec_internal.h
branches/theora-thusnelda/lib/enc/dct_decode.c
branches/theora-thusnelda/lib/enc/dct_encode.c
branches/theora-thusnelda/lib/enc/encode.c
branches/theora-thusnelda/lib/enc/encoder_toplevel.c
Log:
First step toward elimination of multiple unnecessary intermediary
steps in frame reconstruction; do not generate reconstructed frames
from tokens, use the original quantized DCT values.
Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h 2007-11-15 02:08:32 UTC (rev 14139)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h 2007-11-15 03:31:56 UTC (rev 14140)
@@ -646,7 +646,7 @@
unsigned char *extra_fragments; /* extra updates not
recommended by pre-processor */
- ogg_int16_t *OriginalDC;
+ ogg_int16_t *PredictedDC;
ogg_uint32_t *FragmentLastQ; /* Array used to keep track of
quality at which each
@@ -670,7 +670,6 @@
/*********************************************************************/
ogg_uint32_t RunLength;
- ogg_uint32_t MaxBitTarget; /* Cut off target for rate capping */
double BitRateCapFactor; /* Factor relating delta frame target
to cut off target. */
Modified: branches/theora-thusnelda/lib/enc/dct_decode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_decode.c 2007-11-15 02:08:32 UTC (rev 14139)
+++ branches/theora-thusnelda/lib/enc/dct_decode.c 2007-11-15 03:31:56 UTC (rev 14140)
@@ -524,29 +524,14 @@
/* Step on by the zero run length */
*CoeffIndex += (unsigned char)((Token - DCT_RUN_CATEGORY1) + 1);
- /* The extra bit determines the sign. */
- if ( ExtraBits & 0x01 )
- ExpandedBlock[*CoeffIndex] = -1;
- else
- ExpandedBlock[*CoeffIndex] = 1;
} else if ( Token == DCT_RUN_CATEGORY1B ) {
/* Bits 0-1 determines the zero run length */
*CoeffIndex += (6 + (ExtraBits & 0x03));
- /* Bit 2 determines the sign */
- if ( ExtraBits & 0x04 )
- ExpandedBlock[*CoeffIndex] = -1;
- else
- ExpandedBlock[*CoeffIndex] = 1;
}else{
/* Bits 0-2 determines the zero run length */
*CoeffIndex += (10 + (ExtraBits & 0x07));
- /* Bit 3 determines the sign */
- if ( ExtraBits & 0x08 )
- ExpandedBlock[*CoeffIndex] = -1;
- else
- ExpandedBlock[*CoeffIndex] = 1;
}
}else{
/* If token == DCT_RUN_CATEGORY2 we have a single 0 followed by
@@ -555,106 +540,22 @@
/* Step on by the zero run length */
*CoeffIndex += 1;
- /* Bit 1 determines sign, bit 0 the value */
- if ( ExtraBits & 0x02 )
- ExpandedBlock[*CoeffIndex] = -(2 + (ExtraBits & 0x01));
- else
- ExpandedBlock[*CoeffIndex] = 2 + (ExtraBits & 0x01);
}else{
/* else we have 2->3 zeros followed by a value */
/* Bit 0 determines the zero run length */
*CoeffIndex += 2 + (ExtraBits & 0x01);
-
- /* Bit 2 determines the sign, bit 1 the value */
- if ( ExtraBits & 0x04 )
- ExpandedBlock[*CoeffIndex] = -(2 + ((ExtraBits & 0x02) >> 1));
- else
- ExpandedBlock[*CoeffIndex] = 2 + ((ExtraBits & 0x02) >> 1);
}
}
/* Step on over value */
*CoeffIndex += 1;
- } else if ( Token == DCT_SHORT_ZRL_TOKEN ) {
+ } else if ( Token == DCT_SHORT_ZRL_TOKEN || Token == DCT_ZRL_TOKEN ) {
/* Token is a ZRL token so step on by the appropriate number of zeros */
*CoeffIndex += ExtraBits + 1;
- } else if ( Token == DCT_ZRL_TOKEN ) {
- /* Token is a ZRL token so step on by the appropriate number of zeros */
- *CoeffIndex += ExtraBits + 1;
- } else if ( Token < LOW_VAL_TOKENS ) {
- /* Token is a small single value token. */
- switch ( Token ) {
- case ONE_TOKEN:
- ExpandedBlock[*CoeffIndex] = 1;
- break;
- case MINUS_ONE_TOKEN:
- ExpandedBlock[*CoeffIndex] = -1;
- break;
- case TWO_TOKEN:
- ExpandedBlock[*CoeffIndex] = 2;
- break;
- case MINUS_TWO_TOKEN:
- ExpandedBlock[*CoeffIndex] = -2;
- break;
- }
-
+ } else {
/* Step on the coefficient index. */
*CoeffIndex += 1;
- }else{
- /* Token is a larger single value token */
- /* Expand the token and additional bits to a data value. */
- if ( Token < DCT_VAL_CATEGORY3 ) {
- /* Offset from LOW_VAL_TOKENS determines value */
- Token = Token - LOW_VAL_TOKENS;
-
- /* Extra bit determines sign */
- if ( ExtraBits )
- ExpandedBlock[*CoeffIndex] =
- -((Q_LIST_ENTRY)(Token + DCT_VAL_CAT2_MIN));
- else
- ExpandedBlock[*CoeffIndex] =
- (Q_LIST_ENTRY)(Token + DCT_VAL_CAT2_MIN);
- } else if ( Token == DCT_VAL_CATEGORY3 ) {
- /* Bit 1 determines sign, Bit 0 the value */
- if ( ExtraBits & 0x02 )
- ExpandedBlock[*CoeffIndex] = -(DCT_VAL_CAT3_MIN + (ExtraBits & 0x01));
- else
- ExpandedBlock[*CoeffIndex] = DCT_VAL_CAT3_MIN + (ExtraBits & 0x01);
- } else if ( Token == DCT_VAL_CATEGORY4 ) {
- /* Bit 2 determines sign, Bit 0-1 the value */
- if ( ExtraBits & 0x04 )
- ExpandedBlock[*CoeffIndex] = -(DCT_VAL_CAT4_MIN + (ExtraBits & 0x03));
- else
- ExpandedBlock[*CoeffIndex] = DCT_VAL_CAT4_MIN + (ExtraBits & 0x03);
- } else if ( Token == DCT_VAL_CATEGORY5 ) {
- /* Bit 3 determines sign, Bit 0-2 the value */
- if ( ExtraBits & 0x08 )
- ExpandedBlock[*CoeffIndex] = -(DCT_VAL_CAT5_MIN + (ExtraBits & 0x07));
- else
- ExpandedBlock[*CoeffIndex] = DCT_VAL_CAT5_MIN + (ExtraBits & 0x07);
- } else if ( Token == DCT_VAL_CATEGORY6 ) {
- /* Bit 4 determines sign, Bit 0-3 the value */
- if ( ExtraBits & 0x10 )
- ExpandedBlock[*CoeffIndex] = -(DCT_VAL_CAT6_MIN + (ExtraBits & 0x0F));
- else
- ExpandedBlock[*CoeffIndex] = DCT_VAL_CAT6_MIN + (ExtraBits & 0x0F);
- } else if ( Token == DCT_VAL_CATEGORY7 ) {
- /* Bit 5 determines sign, Bit 0-4 the value */
- if ( ExtraBits & 0x20 )
- ExpandedBlock[*CoeffIndex] = -(DCT_VAL_CAT7_MIN + (ExtraBits & 0x1F));
- else
- ExpandedBlock[*CoeffIndex] = DCT_VAL_CAT7_MIN + (ExtraBits & 0x1F);
- } else if ( Token == DCT_VAL_CATEGORY8 ) {
- /* Bit 9 determines sign, Bit 0-8 the value */
- if ( ExtraBits & 0x200 )
- ExpandedBlock[*CoeffIndex] = -(DCT_VAL_CAT8_MIN + (ExtraBits & 0x1FF));
- else
- ExpandedBlock[*CoeffIndex] = DCT_VAL_CAT8_MIN + (ExtraBits & 0x1FF);
- }
-
- /* Step on the coefficient index. */
- *CoeffIndex += 1;
}
}
@@ -995,82 +896,12 @@
}
void ReconRefFrames (PB_INSTANCE *pbi){
- ogg_int32_t i;
+ ogg_int32_t i,j;
unsigned char *SwapReconBuffersTemp;
-
- /* predictor multiplier up-left, up, up-right,left, shift
- Entries are packed in the order L, UL, U, UR, with missing entries
- moved to the end (before the shift parameters). */
- static const ogg_int16_t pc[16][6]={
- {0,0,0,0,0,0},
- {1,0,0,0,0,0}, /* PL */
- {1,0,0,0,0,0}, /* PUL */
- {1,0,0,0,0,0}, /* PUL|PL */
- {1,0,0,0,0,0}, /* PU */
- {1,1,0,0,1,1}, /* PU|PL */
- {0,1,0,0,0,0}, /* PU|PUL */
- {29,-26,29,0,5,31}, /* PU|PUL|PL */
- {1,0,0,0,0,0}, /* PUR */
- {75,53,0,0,7,127}, /* PUR|PL */
- {1,1,0,0,1,1}, /* PUR|PUL */
- {75,0,53,0,7,127}, /* PUR|PUL|PL */
- {1,0,0,0,0,0}, /* PUR|PU */
- {75,0,53,0,7,127}, /* PUR|PU|PL */
- {3,10,3,0,4,15}, /* PUR|PU|PUL */
- {29,-26,29,0,5,31} /* PUR|PU|PUL|PL */
- };
-
- /* boundary case bit masks. */
- static const int bc_mask[8]={
- /* normal case no boundary condition */
- PUR|PU|PUL|PL,
- /* left column */
- PUR|PU,
- /* top row */
- PL,
- /* top row, left column */
- 0,
- /* right column */
- PU|PUL|PL,
- /* right and left column */
- PU,
- /* top row, right column */
- PL,
- /* top row, right and left column */
- 0
- };
-
- /* value left value up-left, value up, value up-right, missing
- values skipped. */
- int v[4];
-
- /* fragment number left, up-left, up, up-right */
- int fn[4];
-
- /* predictor count. */
- int pcount;
-
- short wpc;
- static const short Mode2Frame[] = {
- 1, /* CODE_INTER_NO_MV 0 => Encoded diff from same MB last frame */
- 0, /* CODE_INTRA 1 => DCT Encoded Block */
- 1, /* CODE_INTER_PLUS_MV 2 => Encoded diff from included MV MB last frame */
- 1, /* CODE_INTER_LAST_MV 3 => Encoded diff from MRU MV MB last frame */
- 1, /* CODE_INTER_PRIOR_MV 4 => Encoded diff from included 4 separate MV blocks */
- 2, /* CODE_USING_GOLDEN 5 => Encoded diff from same MB golden frame */
- 2, /* CODE_GOLDEN_MV 6 => Encoded diff from included MV MB golden frame */
- 1 /* CODE_INTER_FOUR_MV 7 => Encoded diff from included 4 separate MV blocks */
- };
- short Last[3];
- short PredictedDC;
int FragsAcross=pbi->HFragments;
int FromFragment,ToFragment;
int FragsDown = pbi->VFragments;
- int WhichFrame;
- int WhichCase;
- int j,k,m,n;
-
void (*ExpandBlockA) ( PB_INSTANCE *pbi, ogg_int32_t FragmentNumber );
if ( pbi->FrameType == KEY_FRAME )
@@ -1105,92 +936,11 @@
break;
}
- /* initialize our array of last used DC Components */
- for(k=0;k<3;k++)
- Last[k]=0;
-
- i=FromFragment;
-
- /* do prediction on all of Y, U or V */
- for ( m = 0 ; m < FragsDown ; m++) {
- for ( n = 0 ; n < FragsAcross ; n++, i++){
-
- /* only do 2 prediction if fragment coded and on non intra or
- if all fragments are intra */
- if( pbi->display_fragments[i] || (pbi->FrameType == KEY_FRAME) ){
- /* Type of Fragment */
- WhichFrame = Mode2Frame[pbi->FragCodingMethod[i]];
-
- /* Check Borderline Cases */
- WhichCase = (n==0) + ((m==0) << 1) + ((n+1 == FragsAcross) << 2);
-
- fn[0]=i-1;
- fn[1]=i-FragsAcross-1;
- fn[2]=i-FragsAcross;
- fn[3]=i-FragsAcross+1;
-
- /* fragment valid for prediction use if coded and it comes
- from same frame as the one we are predicting */
- for(k=pcount=wpc=0; k<4; k++) {
- int pflag;
- pflag=1<<k;
- if((bc_mask[WhichCase]&pflag) &&
- pbi->display_fragments[fn[k]] &&
- (Mode2Frame[pbi->FragCodingMethod[fn[k]]] == WhichFrame)){
- v[pcount]=pbi->QFragData[fn[k]][0];
- wpc|=pflag;
- pcount++;
- }
- }
-
- if(wpc==0){
- /* fall back to the last coded fragment */
- pbi->QFragData[i][0] += Last[WhichFrame];
-
- }else{
-
- /* don't do divide if divisor is 1 or 0 */
- PredictedDC = pc[wpc][0]*v[0];
- for(k=1; k<pcount; k++){
- PredictedDC += pc[wpc][k]*v[k];
- }
-
- /* if we need to do a shift */
- if(pc[wpc][4] != 0 ){
-
- /* If negative add in the negative correction factor */
- PredictedDC += (HIGHBITDUPPED(PredictedDC) & pc[wpc][5]);
-
- /* Shift in lieu of a divide */
- PredictedDC >>= pc[wpc][4];
- }
-
- /* check for outranging on the two predictors that can outrange */
- if((wpc&(PU|PUL|PL)) == (PU|PUL|PL)){
- if( abs(PredictedDC - v[2]) > 128) {
- PredictedDC = v[2];
- } else if( abs(PredictedDC - v[0]) > 128) {
- PredictedDC = v[0];
- } else if( abs(PredictedDC - v[1]) > 128) {
- PredictedDC = v[1];
- }
- }
-
- pbi->QFragData[i][0] += PredictedDC;
-
- }
-
- /* Save the last fragment coded for whatever frame we are
- predicting from */
- Last[WhichFrame] = pbi->QFragData[i][0];
-
- /* Inverse DCT and reconstitute buffer in thisframe */
- ExpandBlockA( pbi, i );
- }
- }
- }
+ /* Inverse DCT and reconstitute buffer in thisframe */
+ for(i=FromFragment;i<ToFragment;i++)
+ ExpandBlockA( pbi, i );
}
-
+
/* Copy the current reconstruction back to the last frame recon buffer. */
if(pbi->CodedBlockIndex > (ogg_int32_t) (pbi->UnitFragments >> 1)){
SwapReconBuffersTemp = pbi->ThisFrameRecon;
Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c 2007-11-15 02:08:32 UTC (rev 14139)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c 2007-11-15 03:31:56 UTC (rev 14140)
@@ -20,7 +20,7 @@
#include "dsp.h"
#include "quant_lookup.h"
-
+#include <stdio.h>
static int ModeUsesMC[MAX_MODES] = { 0, 0, 1, 1, 1, 0, 1, 1 };
static unsigned char TokenizeDctValue (ogg_int16_t DataValue,
@@ -102,10 +102,13 @@
tokens_added = 2;
} else {
TokenListPtr[0] = DCT_VAL_CATEGORY8;
- if ( DataValue > 0 )
+ if ( DataValue > 0 ){
TokenListPtr[1] = (511 - DCT_VAL_CAT8_MIN);
- else
+ fprintf(stderr,"OVERFLOW \n");
+ }else{
TokenListPtr[1] = (0x200) + (511 - DCT_VAL_CAT8_MIN);
+ fprintf(stderr,"OVERFLOW \n");
+ }
tokens_added = 2;
}
@@ -177,7 +180,8 @@
return tokens_added;
}
-static unsigned char TokenizeDctBlock (ogg_int16_t * RawData,
+static unsigned char TokenizeDctBlock (ogg_int16_t DC,
+ ogg_int16_t * RawData,
ogg_uint32_t * TokenListPtr ) {
ogg_uint32_t i;
unsigned char run_count;
@@ -187,15 +191,17 @@
/* Tokenize the block */
for( i = 0; i < BLOCK_SIZE; i++ ){
+ ogg_int16_t val = (i ? RawData[i] : DC);
run_count = 0;
/* Look for a zero run. */
/* NOTE the use of & instead of && which is faster (and
equivalent) in this instance. */
/* NO, NO IT ISN'T --Monty */
- while( (i < BLOCK_SIZE) && (!RawData[i]) ){
+ while( (i < BLOCK_SIZE) && (!val) ){
run_count++;
i++;
+ val = RawData[i];
}
/* If we have reached the end of the block then code EOB */
@@ -206,13 +212,12 @@
/* If we have a short zero run followed by a low data value code
the two as a composite token. */
if ( run_count ){
- AbsData = abs(RawData[i]);
+ AbsData = abs(val);
if ( ((AbsData == 1) && (run_count <= 17)) ||
((AbsData <= 3) && (run_count <= 3)) ) {
/* Tokenise the run and subsequent value combination value */
- token_count += TokenizeDctRunValue( run_count,
- RawData[i],
+ token_count += TokenizeDctRunValue( run_count, val,
&TokenListPtr[token_count] );
}else{
@@ -229,14 +234,12 @@
token_count++;
/* Now tokenize the value */
- token_count += TokenizeDctValue( RawData[i],
- &TokenListPtr[token_count] );
+ token_count += TokenizeDctValue( val, &TokenListPtr[token_count] );
}
}else{
/* Else there was NO zero run. */
/* Tokenise the value */
- token_count += TokenizeDctValue( RawData[i],
- &TokenListPtr[token_count] );
+ token_count += TokenizeDctValue( val, &TokenListPtr[token_count] );
}
}
}
@@ -259,7 +262,8 @@
}
/* Tokenise the dct data. */
- token_count = TokenizeDctBlock( cpi->pb.QFragData[FragIndex],
+ token_count = TokenizeDctBlock( cpi->PredictedDC[FragIndex],
+ cpi->pb.QFragData[FragIndex],
cpi->pb.TokenList[FragIndex] );
cpi->FragTokenCounts[FragIndex] = token_count;
@@ -275,7 +279,7 @@
for ( i = 0; i < 64; i ++ )
if ( QuantList[i] != 0 )
return 0;
-
+
return 1;
}
Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c 2007-11-15 02:08:32 UTC (rev 14139)
+++ branches/theora-thusnelda/lib/enc/encode.c 2007-11-15 03:31:56 UTC (rev 14140)
@@ -510,10 +510,11 @@
array. */
if ( Token == DCT_EOB_TOKEN )
cpi->pb.FragCoeffs[FragmentNumber] = BLOCK_SIZE;
- else
+ else{
ExpandToken( cpi->pb.QFragData[FragmentNumber],
&cpi->pb.FragCoeffs[FragmentNumber],
Token, ExtraBitsToken );
+ }
/* Update record of tokens coded and where we are in this fragment. */
/* Is there an extra bits token */
@@ -596,16 +597,12 @@
cpi->TokensToBeCoded = cpi->TotTokenCount;
cpi->TokensCoded = 0;
- /* Calculate the bit rate at which this frame should be capped. */
- cpi->MaxBitTarget = (ogg_uint32_t)((double)(cpi->ThisFrameTargetBytes * 8) *
- cpi->BitRateCapFactor);
-
/* Blank the various fragment data structures before we start. */
memset(cpi->pb.FragCoeffs, 0, cpi->pb.UnitFragments);
memset(cpi->FragTokens, 0, cpi->pb.UnitFragments);
/* Clear down the QFragData structure for all coded blocks. */
- ClearDownQFragData(&cpi->pb);
+ //ClearDownQFragData(&cpi->pb);
/* The tree is not needed (implicit) for key frames */
if ( cpi->pb.FrameType != KEY_FRAME ){
@@ -826,7 +823,7 @@
/* do prediction on all of Y, U or V */
for ( m = 0 ; m < FragsDown ; m++) {
for ( n = 0 ; n < FragsAcross ; n++, i++) {
- cpi->OriginalDC[i] = cpi->pb.QFragData[i][0];
+ cpi->PredictedDC[i] = cpi->pb.QFragData[i][0];
/* only do 2 prediction if fragment coded and on non intra or
if all fragments are intra */
@@ -852,7 +849,7 @@
if((bc_mask[WhichCase]&pflag) &&
cpi->pb.display_fragments[fn[k]] &&
(Mode2Frame[cpi->pb.FragCodingMethod[fn[k]]] == WhichFrame)){
- v[pcount]=cpi->OriginalDC[fn[k]];
+ v[pcount]=cpi->pb.QFragData[fn[k]][0];
wpc|=pflag;
pcount++;
}
@@ -861,7 +858,7 @@
if(wpc==0) {
/* fall back to the last coded fragment */
- cpi->pb.QFragData[i][0] -= Last[WhichFrame];
+ cpi->PredictedDC[i] -= Last[WhichFrame];
} else {
@@ -892,13 +889,13 @@
}
}
- cpi->pb.QFragData[i][0] -= PredictedDC;
+ cpi->PredictedDC[i] -= PredictedDC;
}
/* Save the last fragment coded for whatever frame we are
predicting from */
- Last[WhichFrame] = cpi->OriginalDC[i];
+ Last[WhichFrame] = cpi->pb.QFragData[i][0];
}
}
@@ -921,7 +918,6 @@
/* Get the linear index for the current coded fragment. */
FragIndex = cpi->pb.CodedBlockList[i];
coded_pixels += DPCMTokenizeBlock ( cpi, FragIndex);
-
}
/* Bit pack the video data data */
Modified: branches/theora-thusnelda/lib/enc/encoder_toplevel.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encoder_toplevel.c 2007-11-15 02:08:32 UTC (rev 14139)
+++ branches/theora-thusnelda/lib/enc/encoder_toplevel.c 2007-11-15 03:31:56 UTC (rev 14140)
@@ -176,8 +176,8 @@
_ogg_free( cpi->DCTDataBuffer);
if(cpi->quantized_list)
_ogg_free( cpi->quantized_list);
- if(cpi->OriginalDC)
- _ogg_free( cpi->OriginalDC);
+ if(cpi->PredictedDC)
+ _ogg_free( cpi->PredictedDC);
if(cpi->PartiallyCodedFlags)
_ogg_free(cpi->PartiallyCodedFlags);
if(cpi->PartiallyCodedMbPatterns)
@@ -199,7 +199,7 @@
cpi->DCT_codes = 0;
cpi->DCTDataBuffer = 0;
cpi->quantized_list = 0;
- cpi->OriginalDC = 0;
+ cpi->PredictedDC = 0;
cpi->BlockCodedFlags = 0;
}
@@ -239,9 +239,9 @@
cpi->FragTokens =
_ogg_malloc(cpi->pb.UnitFragments*
sizeof(*cpi->FragTokens));
- cpi->OriginalDC =
+ cpi->PredictedDC =
_ogg_malloc(cpi->pb.UnitFragments*
- sizeof(*cpi->OriginalDC));
+ sizeof(*cpi->PredictedDC));
cpi->FragTokenCounts =
_ogg_malloc(cpi->pb.UnitFragments*
sizeof(*cpi->FragTokenCounts));
More information about the commits
mailing list