[xiph-commits] r17276 - experimental/derf/theora-ptalarbvorm/lib

tterribe at svn.xiph.org tterribe at svn.xiph.org
Fri Jun 4 22:57:05 PDT 2010


Author: tterribe
Date: 2010-06-04 22:57:05 -0700 (Fri, 04 Jun 2010)
New Revision: 17276

Modified:
   experimental/derf/theora-ptalarbvorm/lib/analyze.c
   experimental/derf/theora-ptalarbvorm/lib/decinfo.c
   experimental/derf/theora-ptalarbvorm/lib/encint.h
   experimental/derf/theora-ptalarbvorm/lib/encode.c
Log:
Fix various overflow issues exposed by larger RMSE values in mode training and
 the removal of the DC skip-prevention flag, as well as some other minor
 clean-up of r17174.


Modified: experimental/derf/theora-ptalarbvorm/lib/analyze.c
===================================================================
--- experimental/derf/theora-ptalarbvorm/lib/analyze.c	2010-06-05 05:32:45 UTC (rev 17275)
+++ experimental/derf/theora-ptalarbvorm/lib/analyze.c	2010-06-05 05:57:05 UTC (rev 17276)
@@ -1844,7 +1844,7 @@
         best_qii=qii;
       }
     }
-    if(_skip_ssd[bi]<UINT_MAX&&nskipped<3){
+    if(_skip_ssd[bi]<(UINT_MAX>>OC_BIT_SCALE)&&nskipped<3){
       *(ft+1)=*&fr;
       oc_fr_skip_block(ft+1);
       cur_overhead=ft[1].bits-fr.bits<<OC_BIT_SCALE;
@@ -1925,7 +1925,7 @@
           best_qii=qii;
         }
       }
-      if(_skip_ssd[bi]<UINT_MAX){
+      if(_skip_ssd[bi]<(UINT_MAX>>OC_BIT_SCALE)){
         cur_ssd=_skip_ssd[bi]<<OC_BIT_SCALE;
         cur_cost=OC_MODE_RD_COST(ssd+cur_ssd,rate,lambda);
         if(cur_cost<=best_cost){
@@ -1955,11 +1955,10 @@
   const ptrdiff_t        *sb_map;
   const oc_mb_map_plane  *mb_map;
   const unsigned char    *map_idxs;
+  oc_mv                  *mvs;
   int                     map_nidxs;
   ogg_int64_t             mask;
   unsigned                uncoded_ssd;
-  int                     uncoded_dc;
-  unsigned                dc_dequant;
   int                     mapii;
   int                     mapi;
   int                     pli;
@@ -1974,13 +1973,13 @@
   frags=_enc->state.frags;
   frag_buf_offs=_enc->state.frag_buf_offs;
   sb_map=_enc->state.sb_maps[_mbi>>2][_mbi&3];
-  dc_dequant=_pipe->dequant[0][0][1][0];
+  mvs=_enc->mb_info[_mbi].block_mv;
   for(bi=0;bi<4;bi++){
     fragi=sb_map[bi];
     frag_offs=frag_buf_offs[fragi];
     oc_enc_frag_sub(_enc,buffer,src+frag_offs,ref+frag_offs,ystride);
     borderi=frags[fragi].borderi;
-    uncoded_ssd=uncoded_dc=0;
+    uncoded_ssd=0;
     if(borderi<0){
       for(pi=0;pi<64;pi++){
         uncoded_ssd+=buffer[pi]*buffer[pi];
@@ -1993,14 +1992,13 @@
         uncoded_ssd+=buffer[pi]*buffer[pi];
       }
     }
-    /*Scale to match DCT domain.*/
-    uncoded_ssd<<=4;
-    uncoded_ssd=OC_RD_SCALE(uncoded_ssd,_rd_scale[bi]);
-    /*Motion is a special case; if there is more than a full-pixel motion 
-      against the prior frame, penalize skipping. TODO: The factor of 
-      two here is a kludge, but it tested out better than a hard limit*/
-    if(_enc->mb_info[_mbi].block_mv[bi][0]!=0||
-      _enc->mb_info[_mbi].block_mv[bi][1]!=0)uncoded_ssd*=2;
+    /*Scale to match DCT domain and RD.*/
+    uncoded_ssd=OC_RD_SKIP_SCALE(uncoded_ssd,_rd_scale[bi]);
+    /*Motion is a special case; if there is more than a full-pixel motion
+       against the prior frame, penalize skipping.
+      TODO: The factor of two here is a kludge, but it tested out better than a
+       hard limit.*/
+    if(mvs[bi][0]!=0||mvs[bi][1]!=0)uncoded_ssd*=2;
     _pipe->skip_ssd[0][fragi-_pipe->froffset[0]]=_ssd[bi]=uncoded_ssd;
   }
   mb_map=(const oc_mb_map_plane *)_enc->state.mb_maps[_mbi];
@@ -2008,9 +2006,9 @@
   map_idxs=OC_MB_MAP_IDXS[_enc->state.info.pixel_fmt];
   map_nidxs=(map_nidxs-4>>1)+4;
   mapii=4;
+  mvs=_enc->mb_info[_mbi].unref_mv;
   for(pli=1;pli<3;pli++){
     ystride=_enc->state.ref_ystride[pli];
-    dc_dequant=_pipe->dequant[pli][0][1][0];
     for(;mapii<map_nidxs;mapii++){
       mapi=map_idxs[mapii];
       bi=mapi&3;
@@ -2018,7 +2016,7 @@
       frag_offs=frag_buf_offs[fragi];
       oc_enc_frag_sub(_enc,buffer,src+frag_offs,ref+frag_offs,ystride);
       borderi=frags[fragi].borderi;
-      uncoded_ssd=uncoded_dc=0;
+      uncoded_ssd=0;
       if(borderi<0){
         for(pi=0;pi<64;pi++){
           uncoded_ssd+=buffer[pi]*buffer[pi];
@@ -2030,14 +2028,13 @@
           uncoded_ssd+=buffer[pi]*buffer[pi];
         }
       }
-      /*Scale to match DCT domain.*/
-      uncoded_ssd<<=4;
-      uncoded_ssd=OC_RD_SCALE(uncoded_ssd,_rd_scale[4]);
-      /*Motion is a special case; if there is more than a full-pixel motion 
-        against the prior frame, penalize skipping. TODO: The factor of 
-        two here is a kludge, but it tested out better than a hard limit*/
-      if(_enc->mb_info[_mbi].unref_mv[OC_FRAME_PREV][0]!=0||
-        _enc->mb_info[_mbi].unref_mv[OC_FRAME_PREV][1]!=0)uncoded_ssd*=2;
+      /*Scale to match DCT domain and RD.*/
+      uncoded_ssd=OC_RD_SKIP_SCALE(uncoded_ssd,_rd_scale[4]);
+      /*Motion is a special case; if there is more than a full-pixel motion
+         against the prior frame, penalize skipping.
+        TODO: The factor of two here is a kludge, but it tested out better than
+         a hard limit*/
+      if(mvs[OC_FRAME_PREV][0]!=0||mvs[OC_FRAME_PREV][1]!=0)uncoded_ssd*=2;
       _pipe->skip_ssd[pli][fragi-_pipe->froffset[pli]]=_ssd[mapii]=uncoded_ssd;
     }
     map_nidxs=(map_nidxs-4<<1)+4;

Modified: experimental/derf/theora-ptalarbvorm/lib/decinfo.c
===================================================================
--- experimental/derf/theora-ptalarbvorm/lib/decinfo.c	2010-06-05 05:32:45 UTC (rev 17275)
+++ experimental/derf/theora-ptalarbvorm/lib/decinfo.c	2010-06-05 05:57:05 UTC (rev 17276)
@@ -128,6 +128,10 @@
    _tc->comments*sizeof(_tc->comment_lengths[0]));
   _tc->user_comments=(char **)_ogg_malloc(
    _tc->comments*sizeof(_tc->user_comments[0]));
+  if(_tc->comment_lengths==NULL||_tc->user_comments==NULL){
+    _tc->comments=0;
+    return TH_EFAULT;
+  }
   for(i=0;i<_tc->comments;i++){
     len=oc_unpack_length(_opb);
     if(len<0||len>oc_pack_bytes_left(_opb)){

Modified: experimental/derf/theora-ptalarbvorm/lib/encint.h
===================================================================
--- experimental/derf/theora-ptalarbvorm/lib/encint.h	2010-06-05 05:32:45 UTC (rev 17275)
+++ experimental/derf/theora-ptalarbvorm/lib/encint.h	2010-06-05 05:57:05 UTC (rev 17276)
@@ -76,12 +76,28 @@
   These are only equivalent within a single block; when more than one block is
    being considered, the former is the interpretation used.*/
 
-#define OC_RD_SCALE_BITS (12-OC_BIT_SCALE)
-#define OC_RD_ISCALE_BITS (11)
+/*This must be at least 4 for OC_RD_SKIP_SCALE() to work below.*/
+# define OC_RD_SCALE_BITS (12-OC_BIT_SCALE)
+# define OC_RD_ISCALE_BITS (11)
 
-#define OC_RD_SCALE(_ssd,_rd_scale) \
- ((_ssd)*(_rd_scale)+((1<<OC_RD_SCALE_BITS)>>1)>>OC_RD_SCALE_BITS)
-#define OC_RD_ISCALE(_lambda,_rd_iscale) \
+/*This macro is applied to _ssd values with just 4 bits of headroom
+   ((15-OC_RMSE_SCALE)*2+OC_BIT_SCALE+2); since we want to allow rd_scales as
+   large as 16, and need additional fractional bits, our only recourse that
+   doesn't lose precision on blocks with very small SSDs is to use a wider
+   multiply.*/
+# if LONG_MAX>2147483647
+#  define OC_RD_SCALE(_ssd,_rd_scale) \
+ ((unsigned)((unsigned long)(_ssd)*(_rd_scale) \
+ +((1<<OC_RD_SCALE_BITS)>>1)>>OC_RD_SCALE_BITS))
+# else
+#  define OC_RD_SCALE(_ssd,_rd_scale) \
+ (((_ssd)>>OC_RD_SCALE_BITS)*(_rd_scale) \
+ +(((_ssd)&(1<<OC_RD_SCALE_BITS)-1)*(_rd_scale) \
+ +((1<<OC_RD_SCALE_BITS)>>1)>>OC_RD_SCALE_BITS))
+# endif
+# define OC_RD_SKIP_SCALE(_ssd,_rd_scale) \
+ ((_ssd)*(_rd_scale)+((1<<OC_RD_SCALE_BITS-4)>>1)>>OC_RD_SCALE_BITS-4)
+# define OC_RD_ISCALE(_lambda,_rd_iscale) \
  ((_lambda)*(_rd_iscale)+((1<<OC_RD_ISCALE_BITS)>>1)>>OC_RD_ISCALE_BITS)
 
 

Modified: experimental/derf/theora-ptalarbvorm/lib/encode.c
===================================================================
--- experimental/derf/theora-ptalarbvorm/lib/encode.c	2010-06-05 05:32:45 UTC (rev 17275)
+++ experimental/derf/theora-ptalarbvorm/lib/encode.c	2010-06-05 05:57:05 UTC (rev 17276)
@@ -870,7 +870,7 @@
    also supports dropping frames by inserting 0 byte packets).
   However, almost every _Theora_ player used to get this wrong (and many still
    do), and it wasn't until we started shipping a post-VP3 encoder that
-   actually non-VP3 features that this began to be discovered and fixed,
+   actually used non-VP3 features that this began to be discovered and fixed,
    despite being in the standard since 2004.
   The pack buffer must be reset before calling this function.*/
 static void oc_enc_drop_frame_pack(oc_enc_ctx *_enc){



More information about the commits mailing list