[xiph-commits] r3765 - in liboggz/trunk/src: liboggz tools

giles at svn.annodex.net giles at svn.annodex.net
Tue Nov 4 12:25:31 PST 2008


Author: giles
Date: 2008-11-04 12:25:31 -0800 (Tue, 04 Nov 2008)
New Revision: 3765

Modified:
   liboggz/trunk/src/liboggz/oggz_auto.c
   liboggz/trunk/src/tools/oggz_tools.c
Log:
Update granulepos scheme to the new Dirac spec. Patch from David Flynn.


Modified: liboggz/trunk/src/liboggz/oggz_auto.c
===================================================================
--- liboggz/trunk/src/liboggz/oggz_auto.c	2008-11-04 19:45:14 UTC (rev 3764)
+++ liboggz/trunk/src/liboggz/oggz_auto.c	2008-11-04 20:25:31 UTC (rev 3765)
@@ -359,31 +359,27 @@
 static int
 auto_dirac (OGGZ * oggz, long serialno, unsigned char * data, long length, void * user_data)
 {
-  char keyframe_granule_shift = 32;
-  int keyframe_shift;
+  int granule_shift = 22; /* not a typo */
   dirac_info *info;
 
   info = malloc(sizeof(dirac_info));
 
   dirac_parse_info(info, data, length);
 
-  /*
-  FIXME: where is this in Ogg Dirac?
-  keyframe_granule_shift = (char) ((header[40] & 0x03) << 3);
-  keyframe_granule_shift |= (header[41] & 0xe0) >> 5;
-  */
-  keyframe_shift = keyframe_granule_shift;
-
 #ifdef DEBUG
-  printf ("Got dirac fps %d/%d, keyframe_shift %d\n",
-	  fps_numerator, fps_denominator, keyframe_shift);
+  printf ("Got dirac fps %d/%d granule_shift %d\n",
+    fps_numerator, fps_denominator, granule_shift);
 #endif
 
-  oggz_set_granulerate (oggz, serialno, (ogg_int64_t)info->fps_numerator,
-                        OGGZ_AUTO_MULT * (ogg_int64_t)info->fps_denominator);
-  oggz_set_granuleshift (oggz, serialno, keyframe_shift);
+  /* the granulerate is twice the frame rate (in order to handle interlace)
+   * it is also multiplied by (1<<9) since the decode time is stored in
+   * the top 32bits of granulepos, but the granule_shift is 22. */
+  oggz_set_granulerate (oggz, serialno,
+ 	2*(1<<9)*(ogg_int64_t)info->fps_numerator,
+        OGGZ_AUTO_MULT * (ogg_int64_t)info->fps_denominator);
+  oggz_set_granuleshift (oggz, serialno, granule_shift);
 
-  oggz_stream_set_numheaders (oggz, serialno, 3);
+  oggz_stream_set_numheaders (oggz, serialno, 0);
 
   free(info);
   return 1;

Modified: liboggz/trunk/src/tools/oggz_tools.c
===================================================================
--- liboggz/trunk/src/tools/oggz_tools.c	2008-11-04 19:45:14 UTC (rev 3764)
+++ liboggz/trunk/src/tools/oggz_tools.c	2008-11-04 20:25:31 UTC (rev 3765)
@@ -454,9 +454,20 @@
     iframe = granulepos >> granuleshift;
     pframe = granulepos - (iframe << granuleshift);
 
-    ret = fprintf (stream, "%" PRId64 "|%" PRId64, iframe, pframe);
-  }
+    if (oggz_stream_get_content (oggz, serialno) != OGGZ_CONTENT_DIRAC) {
+      ret = fprintf (stream, "%" PRId64 "|%" PRId64, iframe, pframe);
+    } else {
+      uint32_t pt = (iframe + pframe) >> 9;
+      uint16_t dist = ((iframe & 0xff) << 8) | (pframe & 0xff);
+      uint16_t delay = pframe >> 9;
+      int64_t dt = pt - delay;
+      ret = fprintf (stream,
+		     "(pt:%u,dt:%" PRId64 ",dist:%hu,delay:%hu)",
+		     pt, dt, dist, delay);
+    }
 
+}
+
   return ret;
 }
 



More information about the commits mailing list