[xiph-commits] r14353 - in trunk: theora/include/theora theora/lib theora/lib/dec theora/lib/enc theora-exp/include/theora theora-exp/lib

tterribe at svn.xiph.org tterribe at svn.xiph.org
Fri Jan 4 11:52:38 PST 2008


Author: tterribe
Date: 2008-01-04 11:52:38 -0800 (Fri, 04 Jan 2008)
New Revision: 14353

Modified:
   trunk/theora-exp/include/theora/codec.h
   trunk/theora-exp/lib/encvbr.c
   trunk/theora-exp/lib/internal.h
   trunk/theora-exp/lib/recode.c
   trunk/theora-exp/lib/state.c
   trunk/theora/include/theora/codec.h
   trunk/theora/include/theora/theora.h
   trunk/theora/lib/dec/state.c
   trunk/theora/lib/enc/encoder_toplevel.c
   trunk/theora/lib/internal.h
Log:
Port the new granule position scheme for 3.2.1 schemes to the theora-exp branch.
Change the way it works in mainline so that the frame counts are always kept in
 synch with the value in the granule position, so that they don't need to be
 adjusted every time we translate between the two.
Finish documentation clarifications.


Modified: trunk/theora/include/theora/codec.h
===================================================================
--- trunk/theora/include/theora/codec.h	2008-01-04 19:33:42 UTC (rev 14352)
+++ trunk/theora/include/theora/codec.h	2008-01-04 19:52:38 UTC (rev 14353)
@@ -444,13 +444,14 @@
  * \endcode
  * \return the version number.*/
 extern ogg_uint32_t th_version_number(void);
-/**Converts a granule position to an absolute frame number.
+/**Converts a granule position to an absolute frame index, starting at
+ *  <tt>0</tt>.
  * The granule position is interpreted in the context of a given
  *  #th_enc_ctx or #th_dec_ctx handle (either will suffice).
  * \param _encdec  A previously allocated #th_enc_ctx or #th_dec_ctx
  *                  handle.
  * \param _granpos The granule position to convert.
- * \returns The absolute frame number corresponding to \a _granpos.
+ * \returns The absolute frame index corresponding to \a _granpos.
  * \retval -1 The given granule position was invalid (i.e. negative).*/
 extern ogg_int64_t th_granule_frame(void *_encdec,ogg_int64_t _granpos);
 /**Converts a granule position to an absolute time in seconds.
@@ -460,6 +461,9 @@
  *                  handle.
  * \param _granpos The granule position to convert.
  * \return The absolute time in seconds corresponding to \a _granpos.
+ *         This is the "end time" for the frame, or the latest time it should
+ *          be displayed.
+ *         It is not the presentation time.
  * \retval -1 The given granule position was invalid (i.e. negative).*/
 extern double th_granule_time(void *_encdec,ogg_int64_t _granpos);
 /**Determines whether a Theora packet is a header or not.

Modified: trunk/theora/include/theora/theora.h
===================================================================
--- trunk/theora/include/theora/theora.h	2008-01-04 19:33:42 UTC (rev 14352)
+++ trunk/theora/include/theora/theora.h	2008-01-04 19:52:38 UTC (rev 14353)
@@ -698,8 +698,8 @@
 int theora_granule_shift(theora_info *ti);
 
 /**
- * Convert a granulepos to an absolute frame index. The granulepos is
- * interpreted in the context of a given theora_state handle.
+ * Convert a granulepos to an absolute frame index, starting at 0.
+ * The granulepos is interpreted in the context of a given theora_state handle.
  * 
  * Note that while the granulepos encodes the frame count (i.e. starting
  * from 1) this call returns the frame index, starting from zero. Thus
@@ -723,6 +723,9 @@
  * \param th A previously initialized theora_state handle (encode or decode)
  * \param granulepos The granulepos to convert.
  * \returns The absolute time in seconds corresponding to \a granulepos.
+ *          This is the "end time" for the frame, or the latest time it should
+ *           be displayed.
+ *          It is not the presentation time.
  * \retval -1. The given granulepos is undefined (i.e. negative), or
  * \retval -1. The function has been disabled because floating 
  *              point support is not available.

Modified: trunk/theora/lib/dec/state.c
===================================================================
--- trunk/theora/lib/dec/state.c	2008-01-04 19:33:42 UTC (rev 14352)
+++ trunk/theora/lib/dec/state.c	2008-01-04 19:52:38 UTC (rev 14353)
@@ -544,6 +544,7 @@
 
 
 int oc_state_init(oc_theora_state *_state,const th_info *_info){
+  int old_granpos;
   /*First validate the parameters.*/
   if(_info==NULL)return TH_EFAULT;
   /*The width and height of the encoded frame must be multiples of 16.
@@ -579,8 +580,15 @@
   if(_info->keyframe_granule_shift<0||_info->keyframe_granule_shift>31){
     _state->info.keyframe_granule_shift=31;
   }
-  _state->keyframe_num=0;
-  _state->curframe_num=-1;
+  _state->keyframe_num=1;
+  _state->curframe_num=0;
+  /*3.2.0 streams mark the frame index instead of the frame count.
+    This was changed with stream version 3.2.1 to conform to other Ogg
+     codecs.
+    We subtract an extra one from the frame number for old streams.*/
+  old_granpos=!TH_VERSION_CHECK(_info,3,2,1);
+  _state->curframe_num-=old_granpos;
+  _state->keyframe_num-=old_granpos;
   return 0;
 }
 
@@ -1251,14 +1259,11 @@
     ogg_int64_t pframe;
     iframe=_granpos>>state->info.keyframe_granule_shift;
     pframe=_granpos-(iframe<<state->info.keyframe_granule_shift);
-
-    /* 3.2.0 streams mark the frame index instead of the frame count
-     * this was changed with stream version 3.2.1 */ 
-    if(state->info.version_subminor < 1) {
-      return iframe+pframe;
-    } else {
-      return iframe+pframe - 1;
-    }
+    /*3.2.0 streams store the frame index in the granule position.
+      3.2.1 and later store the frame count.
+      We return the index, so adjust the value if we have a 3.2.1 or later
+       stream.*/
+    return iframe+pframe-TH_VERSION_CHECK(&state->info,3,2,1);
   }
   return -1;
 }
@@ -1267,7 +1272,8 @@
   oc_theora_state *state;
   state=(oc_theora_state *)_encdec;
   if(_granpos>=0){
-      return (th_granule_frame(_encdec,_granpos)+1)*((double)state->info.fps_denominator/state->info.fps_numerator);
+    return (th_granule_frame(_encdec, _granpos)+1)*(
+     (double)state->info.fps_denominator/state->info.fps_numerator);
   }
   return -1;
 }

Modified: trunk/theora/lib/enc/encoder_toplevel.c
===================================================================
--- trunk/theora/lib/enc/encoder_toplevel.c	2008-01-04 19:33:42 UTC (rev 14352)
+++ trunk/theora/lib/enc/encoder_toplevel.c	2008-01-04 19:52:38 UTC (rev 14353)
@@ -1403,7 +1403,7 @@
     ogg_int64_t iframe=granulepos>>pbi->keyframe_granule_shift;
     ogg_int64_t pframe=granulepos-(iframe<<pbi->keyframe_granule_shift);
 
-    return (iframe+pframe);
+    return (iframe+pframe-1);
   }
 
   return(-1);

Modified: trunk/theora/lib/internal.h
===================================================================
--- trunk/theora/lib/internal.h	2008-01-04 19:33:42 UTC (rev 14352)
+++ trunk/theora/lib/internal.h	2008-01-04 19:52:38 UTC (rev 14353)
@@ -49,6 +49,10 @@
 # define TH_VERSION_MAJOR (3)
 # define TH_VERSION_MINOR (2)
 # define TH_VERSION_SUB   (1)
+# define TH_VERSION_CHECK(_info,_maj,_min,_sub) \
+ ((_info)->version_major>(_maj)||(_info)->version_major==(_maj)&& \
+ ((_info)->version_minor>(_min)||(_info)->version_minor==(_min)&& \
+ (_info)->version_subminor>=(_sub)))
 
 /*A keyframe.*/
 #define OC_INTRA_FRAME (0)

Modified: trunk/theora-exp/include/theora/codec.h
===================================================================
--- trunk/theora-exp/include/theora/codec.h	2008-01-04 19:33:42 UTC (rev 14352)
+++ trunk/theora-exp/include/theora/codec.h	2008-01-04 19:52:38 UTC (rev 14353)
@@ -447,12 +447,13 @@
  * \endcode
  * \return the version number.*/
 extern ogg_uint32_t th_version_number(void);
-/**Converts a granule position to an absolute frame number.
+/**Converts a granule position to an absolute frame index, starting at
+ *  <tt>0</tt>.
  * The granule position is interpreted in the context of a given
  *  #th_enc_ctx or #th_dec_ctx handle (either will suffice).
  * \param _encdec  A previously allocated #th_enc_ctx or #th_dec_ctx handle.
  * \param _granpos The granule position to convert.
- * \returns The absolute frame number corresponding to \a _granpos.
+ * \returns The absolute frame index corresponding to \a _granpos.
  * \retval -1 The given granule position was invalid (i.e. negative).*/
 extern ogg_int64_t th_granule_frame(void *_encdec,ogg_int64_t _granpos);
 /**Converts a granule position to an absolute time in seconds.
@@ -461,6 +462,9 @@
  * \param _encdec  A previously allocated #th_enc_ctx or #th_dec_ctx handle.
  * \param _granpos The granule position to convert.
  * \return The absolute time in seconds corresponding to \a _granpos.
+ *         This is the "end time" for the frame, or the latest time it should
+ *          be displayed.
+ *         It is not the presentation time.
  * \retval -1 The given granule position was invalid (i.e. negative).*/
 extern double th_granule_time(void *_encdec,ogg_int64_t _granpos);
 /**Determines whether a Theora packet is a header or not.

Modified: trunk/theora-exp/lib/encvbr.c
===================================================================
--- trunk/theora-exp/lib/encvbr.c	2008-01-04 19:33:42 UTC (rev 14352)
+++ trunk/theora-exp/lib/encvbr.c	2008-01-04 19:52:38 UTC (rev 14353)
@@ -1288,7 +1288,7 @@
   oc_enc_ctx *enc;
   int         ret;
   enc=_stage->enc;
-  if(enc->state.curframe_num==0||
+  if(enc->state.curframe_num==1||
    enc->state.curframe_num-enc->state.keyframe_num>=
    enc->keyframe_frequency_force){
     enc->state.frame_type=OC_INTRA_FRAME;

Modified: trunk/theora-exp/lib/internal.h
===================================================================
--- trunk/theora-exp/lib/internal.h	2008-01-04 19:33:42 UTC (rev 14352)
+++ trunk/theora-exp/lib/internal.h	2008-01-04 19:52:38 UTC (rev 14353)
@@ -20,7 +20,11 @@
 /*Theora bitstream version.*/
 # define TH_VERSION_MAJOR (3)
 # define TH_VERSION_MINOR (2)
-# define TH_VERSION_SUB   (0)
+# define TH_VERSION_SUB   (1)
+# define TH_VERSION_CHECK(_info,_maj,_min,_sub) \
+ ((_info)->version_major>(_maj)||(_info)->version_major==(_maj)&& \
+ ((_info)->version_minor>(_min)||(_info)->version_minor==(_min)&& \
+ (_info)->version_subminor>=(_sub)))
 
 /*A keyframe.*/
 #define OC_INTRA_FRAME (0)

Modified: trunk/theora-exp/lib/recode.c
===================================================================
--- trunk/theora-exp/lib/recode.c	2008-01-04 19:33:42 UTC (rev 14352)
+++ trunk/theora-exp/lib/recode.c	2008-01-04 19:52:38 UTC (rev 14353)
@@ -1048,15 +1048,15 @@
 
 
 th_rec_ctx *th_recode_alloc(const th_info *_info,const th_setup_info *_setup){
-  oc_rec_ctx *dec;
+  oc_rec_ctx *rec;
   if(_info==NULL||_setup==NULL)return NULL;
-  dec=_ogg_malloc(sizeof(*dec));
-  if(oc_rec_init(dec,_info,_setup)<0){
-    _ogg_free(dec);
+  rec=_ogg_malloc(sizeof(*rec));
+  if(oc_rec_init(rec,_info,_setup)<0){
+    _ogg_free(rec);
     return NULL;
   }
-  dec->state.curframe_num=0;
-  return dec;
+  rec->state.curframe_num++;
+  return rec;
 }
 
 void th_recode_free(th_rec_ctx *_rec){

Modified: trunk/theora-exp/lib/state.c
===================================================================
--- trunk/theora-exp/lib/state.c	2008-01-04 19:33:42 UTC (rev 14352)
+++ trunk/theora-exp/lib/state.c	2008-01-04 19:52:38 UTC (rev 14353)
@@ -529,6 +529,7 @@
 
 
 int oc_state_init(oc_theora_state *_state,const th_info *_info){
+  int old_granpos;
   /*First validate the parameters.*/
   if(_info==NULL)return TH_EFAULT;
   /*The width and height of the encoded frame must be multiples of 16.
@@ -564,8 +565,15 @@
   if(_info->keyframe_granule_shift<0||_info->keyframe_granule_shift>31){
     _state->info.keyframe_granule_shift=31;
   }
-  _state->keyframe_num=0;
-  _state->curframe_num=-1;
+  _state->keyframe_num=1;
+  _state->curframe_num=0;
+  /*3.2.0 streams mark the frame index instead of the frame count.
+    This was changed with stream version 3.2.1 to conform to other Ogg
+     codecs.
+    We subtract an extra one from the frame number for old streams.*/
+  old_granpos=!TH_VERSION_CHECK(_info,3,2,1);
+  _state->curframe_num-=old_granpos;
+  _state->keyframe_num-=old_granpos;
   return 0;
 }
 
@@ -1132,7 +1140,7 @@
     ogg_int64_t pframe;
     iframe=_granpos>>state->info.keyframe_granule_shift;
     pframe=_granpos-(iframe<<state->info.keyframe_granule_shift);
-    return iframe+pframe;
+    return iframe+pframe-TH_VERSION_CHECK(&state->info,3,2,1);
   }
   return -1;
 }
@@ -1141,11 +1149,7 @@
   oc_theora_state *state;
   state=(oc_theora_state *)_encdec;
   if(_granpos>=0){
-    ogg_int64_t iframe;
-    ogg_int64_t pframe;
-    iframe=_granpos>>state->info.keyframe_granule_shift;
-    pframe=_granpos-(iframe<<state->info.keyframe_granule_shift);
-    return (iframe+pframe)*(
+    return (th_granule_frame(_encdec,_granpos)+1)*(
      (double)state->info.fps_denominator/state->info.fps_numerator);
   }
   return -1;



More information about the commits mailing list