[cvs-annodex] commit (/annodex): libannodex/trunk/include/annodex/anx_import.h libannodex/trunk/include/annodex/anx_track.h libannodex/trunk/include/annodex/anx_types.h libannodex/trunk/src/importers/anx_import_anx.c libannodex/trunk/src/importers/anx_import_ogg.c libannodex/trunk/src/importers/anx_import_sndfile.c libannodex/trunk/src/libannodex/anx_import.c libannodex/trunk/src/libannodex/anx_import_private.h libannodex/trunk/src/libannodex/anx_read.c libannodex/trunk/src/libannodex/anx_track.c libannodex/trunk/src/libannodex/anx_write.c libannodex/trunk/src/tools/anxinfo.c

conrad nobody at lists.annodex.net
Fri Jan 21 15:27:32 EST 2005


Update of /annodex (new revision 689)

Modified files:
   libannodex/trunk/include/annodex/anx_import.h
   libannodex/trunk/include/annodex/anx_track.h
   libannodex/trunk/include/annodex/anx_types.h
   libannodex/trunk/src/importers/anx_import_anx.c
   libannodex/trunk/src/importers/anx_import_ogg.c
   libannodex/trunk/src/importers/anx_import_sndfile.c
   libannodex/trunk/src/libannodex/anx_import.c
   libannodex/trunk/src/libannodex/anx_import_private.h
   libannodex/trunk/src/libannodex/anx_read.c
   libannodex/trunk/src/libannodex/anx_track.c
   libannodex/trunk/src/libannodex/anx_write.c
   libannodex/trunk/src/tools/anxinfo.c

Log Message:
add support for basegranule, preroll, granuleshift throughout


Modified: libannodex/trunk/include/annodex/anx_import.h
===================================================================
--- libannodex/trunk/include/annodex/anx_import.h	2005-01-20 15:07:34 UTC (rev 688)
+++ libannodex/trunk/include/annodex/anx_import.h	2005-01-21 04:27:28 UTC (rev 689)
@@ -154,6 +154,9 @@
   anx_int64_t end_granule;
   anx_int64_t current_granule;
   int eos;
+  anx_int64_t basegranule;/*< Base granule */
+  int preroll;            /*< Preroll */
+  int granuleshift;       /*< Granuleshift */
 };
 
 struct _AnxSource {

Modified: libannodex/trunk/include/annodex/anx_track.h
===================================================================
--- libannodex/trunk/include/annodex/anx_track.h	2005-01-20 15:07:34 UTC (rev 688)
+++ libannodex/trunk/include/annodex/anx_track.h	2005-01-21 04:27:28 UTC (rev 689)
@@ -96,6 +96,30 @@
 double anx_track_granules_to_time (ANNODEX * annodex, long serialno,
 				   anx_int64_t granules);
 
+/**
+ * Query the basegranule of a track in an annodex
+ * \param annodex an ANNODEX* handle
+ * \param serialno the serialno of the track to query
+ * \returns the basegranule
+ */
+long anx_track_get_basegranule (ANNODEX * annodex, long serialno);
+
+/**
+ * Query the preroll of a track in an annodex
+ * \param annodex an ANNODEX* handle
+ * \param serialno the serialno of the track to query
+ * \returns the preroll
+ */
+int anx_track_get_preroll (ANNODEX * annodex, long serialno);
+
+/**
+ * Query the granuleshift of a track in an annodex
+ * \param annodex an ANNODEX* handle
+ * \param serialno the serialno of the track to query
+ * \returns the granuleshift
+ */
+int anx_track_get_granuleshift(ANNODEX * annodex, long serialno);
+
 #ifdef __cplusplus
 }
 #endif

Modified: libannodex/trunk/include/annodex/anx_types.h
===================================================================
--- libannodex/trunk/include/annodex/anx_types.h	2005-01-20 15:07:34 UTC (rev 688)
+++ libannodex/trunk/include/annodex/anx_types.h	2005-01-21 04:27:28 UTC (rev 689)
@@ -68,6 +68,9 @@
   long nr_header_packets; /*< number of extra header packets */
   anx_int64_t granule_rate_n;  /*< the granule rate numerator */
   anx_int64_t granule_rate_d;  /*< the granule rate denominator */
+  anx_int64_t basegranule;     /*< Base granule */
+  int preroll;            /*< Preroll */
+  int granuleshift;       /*< Granuleshift */
 };
 
 

Modified: libannodex/trunk/src/importers/anx_import_anx.c
===================================================================
--- libannodex/trunk/src/importers/anx_import_anx.c	2005-01-20 15:07:34 UTC (rev 688)
+++ libannodex/trunk/src/importers/anx_import_anx.c	2005-01-21 04:27:28 UTC (rev 689)
@@ -156,8 +156,8 @@
 
 static int
 read_track (ANNODEX * anx, long serialno, char * id, char * content_type,
-		anx_int64_t granule_rate_n, anx_int64_t granule_rate_d,
-		int nr_header_packets, void * user_data)
+	    anx_int64_t granule_rate_n, anx_int64_t granule_rate_d,
+	    int nr_header_packets, void * user_data)
 {
   AnxAnxData * aad = (AnxAnxData *)user_data;
   AnxSource * media = aad->anx_media;
@@ -193,6 +193,10 @@
     }
   }
 
+  track->basegranule = anx_track_get_basegranule (anx, serialno);
+  track->preroll = anx_track_get_preroll (anx, serialno);
+  track->granuleshift = anx_track_get_granuleshift (anx, serialno);
+
   if (add_track (aad, serialno, track) == NULL) return -1;
 
   media->tracks = anx_list_append (media->tracks, track);
@@ -319,6 +323,10 @@
   aad = anx_malloc (sizeof (AnxAnxData));
   m->custom_data = aad;
 
+#ifdef DEBUG
+  printf ("anxanx_open: opening %s\n", path);
+#endif
+
   if ((anxr = anx_open ((char *)path, ANX_READ)) == NULL)
     return NULL;
 
@@ -353,6 +361,9 @@
     while (!anx_ready (anxr) && (n = anx_read (anxr, 1024)) > 0);
   }
 
+#ifdef DEBUG
+  printf ("anxanx_open: got media %p\n", (void *)m);
+#endif
 
   return m;
 }
@@ -362,6 +373,10 @@
 {
   AnxAnxData * aad = (AnxAnxData *)media->custom_data;
 
+#ifdef DEBUG
+  printf ("anxanx_read_update: in\n");
+#endif
+
  do_read:
 
   while ((aad->media_packets == NULL) &&

Modified: libannodex/trunk/src/importers/anx_import_ogg.c
===================================================================
--- libannodex/trunk/src/importers/anx_import_ogg.c	2005-01-20 15:07:34 UTC (rev 688)
+++ libannodex/trunk/src/importers/anx_import_ogg.c	2005-01-21 04:27:28 UTC (rev 689)
@@ -170,11 +170,17 @@
       track->granule_rate_n = (anx_int64_t) INT32_LE_AT(&header[12]);
       track->granule_rate_d = 1;
       track->nr_header_packets = 3;
+      track->basegranule = 0;
+      track->preroll = 2;
+      track->granuleshift = 0;
     } else if (!strncmp ((char *)&op->packet[0], "Speex   ", 8)) {
       track->content_type = SPEEX_CONTENT_TYPE;
       track->granule_rate_n = (ogg_int64_t) INT32_LE_AT(&header[36]);
       track->granule_rate_d = 1;
       track->nr_header_packets = 2 + (ogg_int64_t) INT32_LE_AT(&header[68]);
+      track->basegranule = 0;
+      track->preroll = 0;
+      track->granuleshift = 0;
     } else if (!strncmp ((char *)&op->packet[1], "theora", 6)) {
       char keyframe_granule_shift = 0;
       track->content_type = THEORA_CONTENT_TYPE;
@@ -185,16 +191,28 @@
       keyframe_granule_shift =  (header[40] & 0x03) /* 00000011 */ << 3;
       keyframe_granule_shift |= (header[41] & 0xe0) /* 11100000 */ >> 5;
 #endif
+
+#if USE_ANNODEX2_GRANULERATE
       track->granule_rate_n = INT32_BE_AT(&header[22]) *
 	(1 << keyframe_granule_shift) / 1000000;
       track->granule_rate_d = INT32_BE_AT(&header[26]) / 1000000;
+#else /* anx v3 */
+      track->granule_rate_n = INT32_BE_AT(&header[22]) / 1000000;
+      track->granule_rate_d = INT32_BE_AT(&header[26]) / 1000000;
+#endif
       track->nr_header_packets = 3;
+      track->basegranule = 0;
+      track->preroll = 0;
+      track->granuleshift = keyframe_granule_shift;
     } else if (!strncmp ((char *)&op->packet[1], "video", 5) && 
 	       !strncmp ((char *)&op->packet[9], "XVID", 4)) {
       track->content_type = XVID_CONTENT_TYPE;
       track->granule_rate_n = (ogg_int64_t) 25;
       track->granule_rate_d = 1;
       track->nr_header_packets = 2;
+      track->basegranule = 0;
+      track->preroll = 0;
+      track->granuleshift = 0;
     } else {
       anx_free (track);
       return -1;
@@ -308,8 +326,7 @@
   m->current_track = NULL;
   m->current_time = start_time;
 
-  /* PADDING::: Fix here */
-  aod = anx_malloc (sizeof (AnxOggData));
+  aod = (AnxOggData *) anx_malloc (sizeof (AnxOggData));
 
 #ifdef DEBUG
   printf ("anxogg: open %s t=%f\n", path, start_time);

Modified: libannodex/trunk/src/importers/anx_import_sndfile.c
===================================================================
--- libannodex/trunk/src/importers/anx_import_sndfile.c	2005-01-20 15:07:34 UTC (rev 688)
+++ libannodex/trunk/src/importers/anx_import_sndfile.c	2005-01-21 04:27:28 UTC (rev 689)
@@ -204,6 +204,10 @@
   track->current_granule = 0;
   track->eos = 0;
 
+  track->basegranule = 0;
+  track->preroll = 0;
+  track->granuleshift = 0;
+
   if (end_time != -1.0) {
     track->end_granule = end_time * sf_info->samplerate;
   } else {

Modified: libannodex/trunk/src/libannodex/anx_import.c
===================================================================
--- libannodex/trunk/src/libannodex/anx_import.c	2005-01-20 15:07:34 UTC (rev 688)
+++ libannodex/trunk/src/libannodex/anx_import.c	2005-01-21 04:27:28 UTC (rev 689)
@@ -363,7 +363,9 @@
 		      char ** id, char ** content_type,
 		      long * nr_header_packets,
 		      anx_int64_t * granule_rate_n,
-		      anx_int64_t * granule_rate_d)
+		      anx_int64_t * granule_rate_d,
+		      anx_int64_t * basegranule,
+		      int * preroll, int * granuleshift)
 {
   AnxList * l;
   AnxSourceTrack * track;
@@ -378,6 +380,9 @@
       *nr_header_packets = track->nr_header_packets;
       *granule_rate_n = track->granule_rate_n;
       *granule_rate_d = track->granule_rate_d;
+      *basegranule = track->basegranule;
+      *preroll = track->preroll;
+      *granuleshift = track->granuleshift;
       return 0;
     }
     i++;

Modified: libannodex/trunk/src/libannodex/anx_import_private.h
===================================================================
--- libannodex/trunk/src/libannodex/anx_import_private.h	2005-01-20 15:07:34 UTC (rev 688)
+++ libannodex/trunk/src/libannodex/anx_import_private.h	2005-01-21 04:27:28 UTC (rev 689)
@@ -67,7 +67,9 @@
 		       char ** id, char ** content_type,
 		       long * nr_header_packets,
 		       anx_int64_t * granule_rate_n,
-		       anx_int64_t * granule_rate_d);
+		       anx_int64_t * granule_rate_d,
+		       anx_int64_t * basegranule,
+		       int * preroll, int * granuleshift);
 
 int anx_media_current_track (AnxSource * source);
 anx_int64_t anx_media_tell (AnxSource * source);

Modified: libannodex/trunk/src/libannodex/anx_read.c
===================================================================
--- libannodex/trunk/src/libannodex/anx_read.c	2005-01-20 15:07:34 UTC (rev 688)
+++ libannodex/trunk/src/libannodex/anx_read.c	2005-01-21 04:27:28 UTC (rev 689)
@@ -330,15 +330,20 @@
   track->granule_rate_n = _le_64 (*((ogg_int64_t *)&data[20]));
   track->granule_rate_d = _le_64 (*((ogg_int64_t *)&data[28]));
   track->nr_header_packets = _le_32 (*((ogg_int32_t *)&data[16]));
+  track->basegranule = _le_64 (*((ogg_int64_t *)&data[36]));
+  track->preroll = (int)_le_32 (*((ogg_int32_t *)&data[44]));
+  track->granuleshift = (int)(*((unsigned char *)&data[48]));
 
   reader->tracks = anx_list_append (reader->tracks, track);
 
 #ifdef DEBUG
-  printf ("Got fisbone for serialno %010ld\n\tgranule_rate %ld/%ld\t%d headers\t%s\t%s\n",
+  printf ("Got fisbone for serialno %010ld\n\tgranule_rate %ld/%ld\t%ld headers\t%s\t%s\n",
 	  track->serialno,
 	  (long)track->granule_rate_n,
 	  (long)track->granule_rate_d,
 	  track->nr_header_packets, content_type, id);
+  printf ("\tbasegranule %lld\tpreroll %d\tgranuleshift %d\n",
+	  track->basegranule, track->preroll, track->granuleshift);
 #endif
 
 #if 0

Modified: libannodex/trunk/src/libannodex/anx_track.c
===================================================================
--- libannodex/trunk/src/libannodex/anx_track.c	2005-01-20 15:07:34 UTC (rev 688)
+++ libannodex/trunk/src/libannodex/anx_track.c	2005-01-21 04:27:28 UTC (rev 689)
@@ -53,7 +53,15 @@
   s->nr_header_packets = track->nr_header_packets;
   s->granule_rate_n = track->granule_rate_n;
   s->granule_rate_d = track->granule_rate_d;
+  s->basegranule = track->basegranule;
+  s->preroll = track->preroll;
+  s->granuleshift = track->granuleshift;
 
+#ifdef DEBUG
+  printf ("anx_track_clone: basegranule %lld\tpreroll %d\tgranuleshift %d\n",
+	  s->basegranule, s->preroll, s->granuleshift);
+#endif
+
   return s;
 }
 
@@ -243,3 +251,53 @@
   return _anx_granules_to_time (annodex, serialno, granules);
 }
 
+long
+anx_track_get_basegranule (ANNODEX * annodex, long serialno)
+{
+  AnxTrack * track;
+  
+  if (annodex == NULL) return -1L;
+  
+  track = anx_get_track (annodex, serialno);
+  
+  if (track == NULL || track->basegranule == -1) {
+    anx_set_error (annodex, ANX_ERR_NOTREADY);
+    return -1L;
+  }
+  
+  return track->basegranule;
+}
+
+int
+anx_track_get_preroll (ANNODEX * annodex, long serialno)
+{
+  AnxTrack * track;
+
+  if (annodex == NULL) return -1;
+
+  track = anx_get_track (annodex, serialno);
+
+  if (track == NULL || track->preroll == -1) {
+    anx_set_error (annodex, ANX_ERR_NOTREADY);
+    return -1;
+  }
+
+  return track->preroll;
+}
+
+int
+anx_track_get_granuleshift(ANNODEX * annodex, long serialno)
+{
+  AnxTrack * track;
+
+  if (annodex == NULL) return -1;
+
+  track = anx_get_track (annodex, serialno);
+
+  if (track == NULL || track->granuleshift == -1) {
+    anx_set_error (annodex, ANX_ERR_NOTREADY);
+    return -1;
+  }
+
+  return track->granuleshift;
+}

Modified: libannodex/trunk/src/libannodex/anx_write.c
===================================================================
--- libannodex/trunk/src/libannodex/anx_write.c	2005-01-20 15:07:34 UTC (rev 688)
+++ libannodex/trunk/src/libannodex/anx_write.c	2005-01-21 04:27:28 UTC (rev 689)
@@ -144,7 +144,8 @@
 static AnxWriterTrack *
 anx_writer_add_track (ANNODEX * annodex, AnxSource * media, int media_index,
 		      char * id, char * content_type, long nr_header_packets,
-		      anx_int64_t granule_rate_n, anx_int64_t granule_rate_d)
+		      anx_int64_t granule_rate_n, anx_int64_t granule_rate_d,
+		      anx_int64_t basegranule, int preroll, int granuleshift)
 {
   AnxWriter * writer = &annodex->x.writer;
   AnxWriterTrack * wsub;
@@ -163,6 +164,9 @@
   track->nr_header_packets = nr_header_packets;
   track->granule_rate_n = granule_rate_n;
   track->granule_rate_d = granule_rate_d;
+  track->basegranule = basegranule;
+  track->preroll = preroll;
+  track->granuleshift = granuleshift;
 
   wsub->media = media;
   wsub->media_index = media_index;
@@ -203,12 +207,15 @@
   char * id, * content_type;
   long nr_header_packets;
   anx_int64_t granule_rate, rate_interval;
+  anx_int64_t basegranule;
+  int preroll, granuleshift;
 
   if (media != NULL) {
     for (i = 0; ; i++) {
       ret = anx_media_query_track (media, i, &id, &content_type,
 				   &nr_header_packets,
-				   &granule_rate, &rate_interval);
+				   &granule_rate, &rate_interval,
+				   &basegranule, &preroll, &granuleshift);
 
       if (ret < 0) break;
       
@@ -216,7 +223,8 @@
       printf ("anx_writer: adding track %d for %s\n", i, content_type);
 #endif
       anx_writer_add_track (annodex, media, i, id, content_type,
-			    nr_header_packets, granule_rate, rate_interval);
+			    nr_header_packets, granule_rate, rate_interval,
+			    basegranule, preroll, granuleshift);
     }
 
     writer->medias = anx_list_append (writer->medias, media);
@@ -467,6 +475,11 @@
 
   if (track == NULL) return -1;
 
+#ifdef DEBUG
+  printf ("anx_init_fisbone_packet: basegranule %lld\tpreroll %d\tgranuleshift %d\n",
+	  track->basegranule, track->preroll, track->granuleshift);
+#endif
+
   params = anx_params_append (params, "Content-Type", track->content_type);
   params = anx_params_append (params, "ID", track->id);
 
@@ -500,16 +513,13 @@
   *(ogg_int64_t *)b = _le_64 (track->granule_rate_d);
   b += 8;
 
-  /* XXX: basegranule */
-  *(ogg_int64_t *)b = _le_64 (0);
+  *(ogg_int64_t *)b = _le_64 (track->basegranule);
   b += 8;
 
-  /* XXX: preroll */
-  *(ogg_int64_t *)b = _le_32 (0);
+  *(ogg_int32_t *)b = _le_32 (track->preroll);
   b += 4;
 
-  /* XXX: granuleshift */
-  *(unsigned char *)b = 0;
+  *(unsigned char *)b = (unsigned char)track->granuleshift;
   b += 1;
 
   b = (char *)buf + FISBONE_SIZE;
@@ -987,7 +997,7 @@
     
     if (writer->need_fishead) {
 #ifdef DEBUG
-      printf ("anx_writer_sync: NEED mapping\n");
+      printf ("anx_writer_sync: NEED fishead\n");
 #endif
       anx_init_fishead_packet (annodex);
       writer->need_fishead = 0;
@@ -1036,7 +1046,7 @@
       made_packet = 1;
     } else if (writer->need_fisbone) {
 #ifdef DEBUG
-      printf ("anx_writer_sync: NEED anxdata\n");
+      printf ("anx_writer_sync: NEED fisbone\n");
 #endif
       for (l = writer->tracks; l; l = l->next) {
 	wsub = (AnxWriterTrack *)l->data;
@@ -1289,6 +1299,9 @@
   writer->anno_track.nr_header_packets = 1;
   writer->anno_track.granule_rate_n = CMML_GRANULE_RATE_N;
   writer->anno_track.granule_rate_d = CMML_GRANULE_RATE_D;
+  writer->anno_track.basegranule = 0;
+  writer->anno_track.preroll = 0;
+  writer->anno_track.granuleshift = 0;
 
   writer->eos = 0; /* end of stream */
 

Modified: libannodex/trunk/src/tools/anxinfo.c
===================================================================
--- libannodex/trunk/src/tools/anxinfo.c	2005-01-20 15:07:34 UTC (rev 688)
+++ libannodex/trunk/src/tools/anxinfo.c	2005-01-21 04:27:28 UTC (rev 689)
@@ -219,7 +219,10 @@
     printf ("%-20s%010ld  %12s %7ld %-20s\n",
 	    s->id ? s->id : "-- unidentified --",
 	    s->serialno, buf, s->nr_header_packets, s->content_type);
-
+    printf ("\tbasegranule %lld\tpreroll %d\tgranuleshift %d\n",
+	    s->basegranule,
+	    s->preroll,
+	    anx_track_get_granuleshift (anx, s->serialno));
   }
 
   if (verbose) {


-- 
conrad



More information about the cvs-annodex mailing list