[xiph-commits] r13856 - in trunk/theora: . lib lib/dec lib/enc tests

giles at svn.xiph.org giles at svn.xiph.org
Tue Sep 18 00:17:58 PDT 2007


Author: giles
Date: 2007-09-18 00:17:58 -0700 (Tue, 18 Sep 2007)
New Revision: 13856

Modified:
   trunk/theora/CHANGES
   trunk/theora/lib/dec/state.c
   trunk/theora/lib/enc/encoder_toplevel.c
   trunk/theora/lib/internal.h
   trunk/theora/tests/granulepos.c
Log:
Change the granulepos mapping scheme used for the Ogg embedding to use 
the count of decodeable frames, instead of the index. This is similar
to what other codecs are doing, and in theory conceptually simpler.

This change was originally proposed by Thomas Vander Stichele.

Since this is a bitstream change, the stream version number has
been bumped to 3.2.1. The decoder will correctly support both
the older 3.2.0 granulepos scheme and the new one. By spec,
old decoders should attempt to play 3.2.1 streams, but sync
will be off by one in the less noticeable direction.

Patch from Maik Merten.


Modified: trunk/theora/CHANGES
===================================================================
--- trunk/theora/CHANGES	2007-09-18 07:06:19 UTC (rev 13855)
+++ trunk/theora/CHANGES	2007-09-18 07:17:58 UTC (rev 13856)
@@ -1,6 +1,9 @@
 libtheora 1.0beta1 (unreleased)
 
- - No notable changes yet.
+ - Granulepos scheme modified to match other codecs. This bumps
+   the bitstream revision to 3.2.1. Bitstreams marked 3.2.0 are
+   handled correctly by this decoder. Older decoders will show
+   a one frame sync error in the less noticable direction.
 
 libtheora 1.0alpha8 (2007 September 18)
 

Modified: trunk/theora/lib/dec/state.c
===================================================================
--- trunk/theora/lib/dec/state.c	2007-09-18 07:06:19 UTC (rev 13855)
+++ trunk/theora/lib/dec/state.c	2007-09-18 07:17:58 UTC (rev 13856)
@@ -1182,7 +1182,16 @@
     ogg_int64_t pframe;
     iframe=_granpos>>state->info.keyframe_granule_shift;
     pframe=_granpos-(iframe<<state->info.keyframe_granule_shift);
-    return iframe+pframe;
+
+    /* 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 == 0
+       && state->info.version_minor == 2
+       && state->info.version_major == 3) {
+      return iframe+pframe + 1;
+    } else {
+      return iframe+pframe;
+    }
   }
   return -1;
 }
@@ -1191,12 +1200,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)*(
-     (double)state->info.fps_denominator/state->info.fps_numerator);
+      return th_granule_frame(_encdec, _granpos)*((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	2007-09-18 07:06:19 UTC (rev 13855)
+++ trunk/theora/lib/enc/encoder_toplevel.c	2007-09-18 07:17:58 UTC (rev 13856)
@@ -1126,8 +1126,8 @@
   cpi->packetflag=1;
 
   t->granulepos=
-    ((cpi->CurrentFrame-cpi->LastKeyFrame-1)<<cpi->pb.keyframe_granule_shift)+
-    cpi->LastKeyFrame-1;
+    ((cpi->CurrentFrame - cpi->LastKeyFrame)<<cpi->pb.keyframe_granule_shift)+
+    cpi->LastKeyFrame - 1;
 
   return 0;
 }
@@ -1348,6 +1348,7 @@
   memset(th,0,sizeof(*th));
 }
 
+
 /* returns, in seconds, absolute time of current packet in given
    logical stream */
 static double theora_encode_granule_time(theora_state *th,

Modified: trunk/theora/lib/internal.h
===================================================================
--- trunk/theora/lib/internal.h	2007-09-18 07:06:19 UTC (rev 13855)
+++ trunk/theora/lib/internal.h	2007-09-18 07:17:58 UTC (rev 13856)
@@ -41,12 +41,12 @@
 # endif
 
 /*This library's version.*/
-# define OC_VENDOR_STRING "Xiph.Org libTheora I 20070823 3 2 0"
+# define OC_VENDOR_STRING "Xiph.Org libTheora I 20070915 3 2 1"
 
 /*Theora bitstream version.*/
 # define TH_VERSION_MAJOR (3)
 # define TH_VERSION_MINOR (2)
-# define TH_VERSION_SUB   (0)
+# define TH_VERSION_SUB   (1)
 
 /*A keyframe.*/
 #define OC_INTRA_FRAME (0)

Modified: trunk/theora/tests/granulepos.c
===================================================================
--- trunk/theora/tests/granulepos.c	2007-09-18 07:06:19 UTC (rev 13855)
+++ trunk/theora/tests/granulepos.c	2007-09-18 07:17:58 UTC (rev 13856)
@@ -109,10 +109,10 @@
     last_granule = op.granulepos;
     keyframe = op.granulepos >> shift;
     keydist = op.granulepos - (keyframe << shift);
-    if ((keyframe + keydist) != frame)
-      FAIL ("encoder granulepos does not map to the correct frame index");
+    if ((keyframe + keydist) != frame + 1)
+      FAIL ("encoder granulepos does not map to the correct frame number");
     tframe = theora_granule_frame (&th, op.granulepos);
-    if (tframe != frame)
+    if (tframe != frame + 1)
       FAIL ("theora_granule_frame returned incorrect results");
 #if DEBUG
     printf("++ frame %d granulepos %lld %d:%d %d %.3lfs\n", 



More information about the commits mailing list