[xiph-commits] r7718 - experimental/derf/theora-exp/lib
tterribe at motherfish-iii.xiph.org
tterribe at motherfish-iii.xiph.org
Wed Sep 8 17:34:53 PDT 2004
Author: tterribe
Date: 2004-09-08 17:34:52 -0700 (Wed, 08 Sep 2004)
New Revision: 7718
Modified:
experimental/derf/theora-exp/lib/bitrate.c
experimental/derf/theora-exp/lib/encint.h
experimental/derf/theora-exp/lib/encode.c
Log:
Some bug fixes and some bitrate stats updates.
Block-level qi selection now allows the qi to be set greater than the DC qi,
like it was meant to.
Macro-block mode coding method 7 now doesn't apply the "old VP3 numbering" ->
"new numbering" mapping twice, so the correct modes actually get encoded.
Bit-rate stats now only use 7 fractional bits of precision, since they weren't
fitting into 16-bit numbers with 8 in the high qi levels.
Also, code to read/write statistics from a file was added.
Modified: experimental/derf/theora-exp/lib/bitrate.c
===================================================================
--- experimental/derf/theora-exp/lib/bitrate.c 2004-09-09 00:30:59 UTC (rev 7717)
+++ experimental/derf/theora-exp/lib/bitrate.c 2004-09-09 00:34:52 UTC (rev 7718)
@@ -5,9 +5,46 @@
ogg_uint16_t OC_RES_BITRATES[64][3][OC_NMODES][16];
#if defined(OC_BITRATE_STATS)
-static ogg_uint32_t OC_RES_BITRATE_ACCUM[64][3][OC_NMODES][16];
-static int OC_RES_BITRATE_SAMPLES[64][3][OC_NMODES][16];
+static ogg_int64_t OC_RES_BITRATE_ACCUM[64][3][OC_NMODES][16];
+static int OC_RES_BITRATE_SAMPLES[64][3][OC_NMODES][16];
+#include <stdio.h>
+
+void oc_bitrate_stats_read(void){
+ FILE *in;
+ in=fopen("modedec.stats","rb");
+ if(in==NULL)return;
+ fread(OC_RES_BITRATE_ACCUM,sizeof(OC_RES_BITRATE_ACCUM),1,in);
+ fread(OC_RES_BITRATE_SAMPLES,sizeof(OC_RES_BITRATE_SAMPLES),1,in);
+ /*Update the current bitrate statistics in use.*/
+ {
+ int qi;
+ for(qi=0;qi<64;qi++){
+ int pli;
+ for(pli=0;pli<3;pli++){
+ int modei;
+ for(modei=0;modei<OC_NMODES;modei++){
+ int erri;
+ for(erri=0;erri<16;erri++){
+ int n;
+ n=OC_RES_BITRATE_SAMPLES[qi][pli][modei][erri];
+ if(!n)continue;
+ OC_RES_BITRATES[qi][pli][modei][erri]=(ogg_uint16_t)OC_MINI(65535,
+ ((OC_RES_BITRATE_ACCUM[qi][pli][modei][erri]<<1)+n)/(n<<1));
+ }
+ }
+ }
+ }
+ }
+}
+
+void oc_bitrate_stats_write(void){
+ FILE *out;
+ out=fopen("modedec.stats","wb");
+ fwrite(OC_RES_BITRATE_ACCUM,sizeof(OC_RES_BITRATE_ACCUM),1,out);
+ fwrite(OC_RES_BITRATE_SAMPLES,sizeof(OC_RES_BITRATE_SAMPLES),1,out);
+}
+
void oc_bitrate_update_stats(oc_enc_ctx *_enc,int _huff_idxs[5][3]){
static OC_HUFF_GROUP_IDXS[64]={
0,1,1,1,1,1,2,2,
@@ -68,7 +105,7 @@
if(_enc->dct_token_offs[pli+1][zzj]>=_enc->ndct_tokens[zzj])break;
}
eob_bits[zzk]=OC_DCT_TOKEN_EXTRA_BITS[token]+
- _enc->huff_codes[_huff_idxs[hgi][pli]][token].nbits<<8;
+ _enc->huff_codes[_huff_idxs[hgi][pli]][token].nbits<<OC_BIT_SCALE;
/*Compute the bits that will be left to be distributed when we start
each non-trivial coefficient spanned by the run after the one the run
is started in.*/
@@ -135,11 +172,11 @@
if(skip<0){
eob_runs[zzi]=-skip;
eob_bits[zzi]=OC_DCT_TOKEN_EXTRA_BITS[token]+
- _enc->huff_codes[_huff_idxs[hgi][pli]][token].nbits<<8;
+ _enc->huff_codes[_huff_idxs[hgi][pli]][token].nbits<<OC_BIT_SCALE;
}
else{
frag_bits+=OC_DCT_TOKEN_EXTRA_BITS[token]+
- _enc->huff_codes[_huff_idxs[hgi][pli]][token].nbits<<8;
+ _enc->huff_codes[_huff_idxs[hgi][pli]][token].nbits<<OC_BIT_SCALE;
zzi+=skip;
}
}
Modified: experimental/derf/theora-exp/lib/encint.h
===================================================================
--- experimental/derf/theora-exp/lib/encint.h 2004-09-09 00:30:59 UTC (rev 7717)
+++ experimental/derf/theora-exp/lib/encint.h 2004-09-09 00:34:52 UTC (rev 7718)
@@ -214,6 +214,9 @@
void oc_psych_free(oc_psych_ctx *_psych);
void oc_psych_scan(oc_psych_ctx *_psych,float _contrast);
+/*The number of fractional bits in bitrate statistics.*/
+#define OC_BIT_SCALE (7)
+
/*Estimated bits needed to code a residual given the: quality index, color
plane, macro-block mode, and a SAD bin.
SAD values for a block are divided by 256 for INTRA mode and 64 for INTER
Modified: experimental/derf/theora-exp/lib/encode.c
===================================================================
--- experimental/derf/theora-exp/lib/encode.c 2004-09-09 00:30:59 UTC (rev 7717)
+++ experimental/derf/theora-exp/lib/encode.c 2004-09-09 00:34:52 UTC (rev 7718)
@@ -76,7 +76,7 @@
};
static const theora_huff_code OC_MODE_CODESB[OC_NMODES]={
- {0x01,3},{0x00,3},{0x02,3},{0x03,3},{0x04,3},{0x07,3},{0x06,3},{0x05,3}
+ {0x00,3},{0x01,3},{0x02,3},{0x03,3},{0x04,3},{0x05,3},{0x06,3},{0x07,3}
};
@@ -727,8 +727,9 @@
efrag=_enc->frinfo+fragi;
best_qii=0;
for(qii=1;qii<_enc->state.nqis;qii++){
- if(_enc->state.qis[qii]<_enc->state.qis[best_qii]&&
- efrag->qi_min[0]<=_enc->state.qis[qii]){
+ if(efrag->qi_min[0]<=_enc->state.qis[qii]&&
+ (_enc->state.qis[best_qii]<efrag->qi_min[0]||
+ _enc->state.qis[qii]<_enc->state.qis[best_qii])){
best_qii=qii;
}
}
@@ -1986,8 +1987,9 @@
for(fti=0;fti<2;fti++)for(qti=0;qti<=fti;qti++){
best_qii=0;
for(qii=1;qii<_enc->nqis[fti];qii++){
- if(_enc->qis[fti][qii]<_enc->qis[fti][best_qii]&&
- efrag->qi_min[qti]<=_enc->qis[fti][qii]){
+ if(efrag->qi_min[qti]<=_enc->qis[fti][qii]&&
+ (_enc->qis[fti][qii]<_enc->qis[fti][best_qii]||
+ _enc->qis[fti][best_qii]<efrag->qi_min[qti])){
best_qii=qii;
}
}
@@ -2033,8 +2035,8 @@
efrag->qii=frag_qii[codedi][OC_INTER_FRAME][1];
frag->qi=qi;
}
- intra_bits+=mbintrabits+128>>8;
- inter_bits+=bits[OC_MODE_INTER_NOMV]+128>>8;
+ intra_bits+=mbintrabits+(1<<OC_BIT_SCALE-1)>>OC_BIT_SCALE;
+ inter_bits+=bits[OC_MODE_INTER_NOMV]+(1<<OC_BIT_SCALE-1)>>OC_BIT_SCALE;
continue;
}
/*Otherwise, add this to the coded MB list.*/
@@ -2126,7 +2128,9 @@
}
/*Bit costs are stored in the table with extra precision.
Round them down to whole bits here.*/
- for(modei=0;modei<OC_NMODES;modei++)bits[modei]=bits[modei]+128>>8;
+ for(modei=0;modei<OC_NMODES;modei++){
+ bits[modei]=bits[modei]+(1<<OC_BIT_SCALE-1)>>OC_BIT_SCALE;
+ }
/*Estimate the cost of coding the label for each mode.
See comments at oc_mode_scheme_chooser_cost() for a description of the
method.*/
@@ -2182,7 +2186,7 @@
frag->qi=_enc->qis[OC_INTER_FRAME][efrag->qii];
}
inter_bits+=bits[mb->mode];
- intra_bits+=mbintrabits+128>>8;
+ intra_bits+=mbintrabits+(1<<OC_BIT_SCALE-1)>>OC_BIT_SCALE;
oc_mode_scheme_chooser_update(&_enc->mode_scheme_chooser,mb->mode);
switch(mb->mode){
case OC_MODE_INTER_MV:{
@@ -2586,10 +2590,8 @@
_img[0].height!=(int)_enc->state.info.frame_height){
return OC_EINVAL;
}
- cwidth=_enc->state.info.frame_width;
- if(!(_enc->state.info.pixel_fmt&1))cwidth>>=1;
- cheight=_enc->state.info.frame_height;
- if(!(_enc->state.info.pixel_fmt&2))cheight>>=1;
+ cwidth=_enc->state.info.frame_width>>!(_enc->state.info.pixel_fmt&1);
+ cheight=_enc->state.info.frame_height>>!(_enc->state.info.pixel_fmt&2);
if(_img[1].width!=cwidth||_img[2].width!=cwidth||
_img[1].height!=cheight||_img[2].height!=cheight){
return OC_EINVAL;
More information about the commits
mailing list