[cvs-annodex] commit (/annodex): libannodex/trunk/src/importers/anx_import_ogg.c

conrad nobody at lists.annodex.net
Sun Feb 27 09:47:33 EST 2005


Update of /annodex (new revision 974)

Modified files:
   libannodex/trunk/src/importers/anx_import_ogg.c

Log Message:
Fix detection of end when importing ogg streams (bug #68, reported by Jan Schmidt)).
+ The check for whether we're beyond the end was using the raw granulepos, not
taking granuleshift into account. This subsequently always triggered a false
positive for tracks using granuelshift (eg. theora).
+ This patch adds a gp_to_granule() helper function in the ogg importer.


Modified: libannodex/trunk/src/importers/anx_import_ogg.c
===================================================================
--- libannodex/trunk/src/importers/anx_import_ogg.c	2005-02-26 22:06:08 UTC (rev 973)
+++ libannodex/trunk/src/importers/anx_import_ogg.c	2005-02-26 22:47:32 UTC (rev 974)
@@ -195,23 +195,35 @@
   return (*(ogg_int64_t *)ucptr);
 }
 
-static double
-gp_to_time (OGGZ * oggz, long serialno, ogg_int64_t granulepos)
+static ogg_int64_t
+gp_to_granule (OGGZ * oggz, long serialno, ogg_int64_t granulepos)
 {
   int granuleshift;
   ogg_int64_t iframe, pframe;
-  ogg_int64_t gr_n, gr_d;
 
   granuleshift = oggz_get_granuleshift (oggz, serialno);
 
-  if (oggz_get_granulerate (oggz, serialno, &gr_n, &gr_d) != 0) return -1.0;
-
   iframe = granulepos >> granuleshift;
   pframe = granulepos - (iframe << granuleshift);
-  return (double)((iframe + pframe) * gr_d) / ((double)gr_n * SUBSECONDS);
+
+  return (iframe + pframe);
+
 }
 
 static double
+gp_to_time (OGGZ * oggz, long serialno, ogg_int64_t granulepos)
+{
+  ogg_int64_t gr_n, gr_d;
+  ogg_int64_t granule;
+
+  if (oggz_get_granulerate (oggz, serialno, &gr_n, &gr_d) != 0) return -1.0;
+
+  granule = gp_to_granule (oggz, serialno, granulepos);
+
+  return (double)(granule * gr_d) / ((double)gr_n * SUBSECONDS);
+}
+
+static double
 anxogg_seek_update (AnxSource * source)
 {
   AnxOggData * aod = (AnxOggData *)source->custom_data;
@@ -247,6 +259,9 @@
 #endif
 
   if (source->end_time != -1.0 && offset >= source->end_time) {
+#ifdef DEBUG
+    printf ("anxoggg: seek update > end_time %f\n", source->end_time);
+#endif
     aod->got_end = 1;
   }
 
@@ -395,7 +410,7 @@
 	oggz_table_insert (aod->logicals, serialno, aot);
 
 #ifdef DEBUG
-	printf ("anxogg::read_packet: Added track for (%010ld): %ld/%ld, +%d headers\n", serialno,
+	printf ("anxogg::read_packet_headers: Added track for (%010ld): %ld/%ld, +%d headers\n", serialno,
 		(long)track->granule_rate_n, (long)track->granule_rate_d,
 		(int)track->nr_header_packets);
 #endif
@@ -413,14 +428,17 @@
 
 	if (m->end_time != -1.0) {
 	  track->end_granule =
-	    m->end_time * track->granule_rate_n /
-	    track->granule_rate_d;
+	    m->end_time * track->granule_rate_n / track->granule_rate_d;
+#ifdef DEBUG
+	  printf ("anxogg::read_packet_headers: end_granule %lld\n",
+		  track->end_granule);
+#endif
 	}
       }
 
       if (need_insert) {
 #ifdef DEBUG
-	printf ("anxogg::read_packet: adding track for %s\n", track->content_type);
+	printf ("anxogg::read_packet_headers: adding track for %s\n", track->content_type);
 #endif
 	m->tracks = anx_list_append (m->tracks, track);
       }
@@ -558,9 +576,14 @@
   }
 
   if (aod->nr_headers_remaining == 0 && !aod->got_end && 
-      (m->end_time != -1.0) && (op->granulepos != -1) &&
-      (op->granulepos >= track->end_granule)) {
-    aod->got_end = 1;
+      (m->end_time != -1.0) && (op->granulepos != -1)) {
+    ogg_int64_t granule = gp_to_granule (oggz, serialno, op->granulepos);
+    if (granule >= track->end_granule) {
+#ifdef DEBUG
+      printf ("anxogg::read_packet: got_end\n");
+#endif
+      aod->got_end = 1;
+    }
   }
 
 #ifdef DEBUG


-- 
conrad



More information about the cvs-annodex mailing list