[Cvs-annodex] commit (annodex): libannodex/trunk/src/importers/anx_import_anx.c libannodex/trunk/src/importers/anx_import_ogg.c libannodex/trunk/src/libannodex/anx_import.c libannodex/trunk/src/libannodex/anx_write.c libannodex/trunk/src/tools/anxenc.c

shans nobody at lists.annodex.net
Mon Nov 20 00:50:22 UTC 2006


Update of /var/local/lib/svn/annodex (new revision 2551)

Modified files:
   libannodex/trunk/src/importers/anx_import_anx.c
   libannodex/trunk/src/importers/anx_import_ogg.c
   libannodex/trunk/src/libannodex/anx_import.c
   libannodex/trunk/src/libannodex/anx_write.c
   libannodex/trunk/src/tools/anxenc.c

Log Message:
Fixed bug in anxenc that was causing duplicate eos packets
Modified anx_media_eos to check eos status of each track rather than stream as a whole
Some debug message and indenting changes



Modified: libannodex/trunk/src/importers/anx_import_anx.c
===================================================================
--- libannodex/trunk/src/importers/anx_import_anx.c	2006-11-18 09:08:12 UTC (rev 2550)
+++ libannodex/trunk/src/importers/anx_import_anx.c	2006-11-20 00:50:21 UTC (rev 2551)
@@ -41,7 +41,7 @@
 #include <annodex/anx_import.h>
 #include <annodex/annodex.h>
 
-/*#define DEBUG*/
+#define DEBUG
 #define ANX_ANX_DEPRECATED 1
 
 #if ANX_ANX_DEPRECATED

Modified: libannodex/trunk/src/importers/anx_import_ogg.c
===================================================================
--- libannodex/trunk/src/importers/anx_import_ogg.c	2006-11-18 09:08:12 UTC (rev 2550)
+++ libannodex/trunk/src/importers/anx_import_ogg.c	2006-11-20 00:50:21 UTC (rev 2551)
@@ -319,126 +319,138 @@
 
       /* Check the CMML header is of correct length */
       if (op->bytes > 28)
-	aod->cmml_granuleshift = (int)header[28];
+        aod->cmml_granuleshift = (int)header[28];
       else
-	aod->cmml_granuleshift = 0;
+        aod->cmml_granuleshift = 0;
 
+#ifdef DEBUG
+      printf("read_packet_headers: setting cmml_need_keygranule to %d\n",
+                      aod->cmml_granuleshift != 0);
+#endif
       if (aod->cmml_granuleshift == 0)
-	aod->cmml_need_keygranule = 0;
+        aod->cmml_need_keygranule = 0;
       else
-	aod->cmml_need_keygranule = 1;
+        aod->cmml_need_keygranule = 1;
     } else {
       if (aot == NULL) {
-	aot = (AnxOggTrack *) anx_malloc (sizeof (AnxOggTrack));
-	memset (aot, 0, sizeof(AnxOggTrack));
-	need_insert = 1;
+        aot = (AnxOggTrack *) anx_malloc (sizeof (AnxOggTrack));
+        memset (aot, 0, sizeof(AnxOggTrack));
+        need_insert = 1;
       }
       
       track = &(aot->source_track);
       track->eos = 0;
 
       if (!strncmp ((char *)&header[1], "vorbis", 6)) {
-	track->content_type = anxogg_strdup (VORBIS_CONTENT_TYPE);
-	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;
+      	track->content_type = anxogg_strdup (VORBIS_CONTENT_TYPE);
+        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 = anxogg_strdup (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 = 3;
-	track->granuleshift = 0;
+        track->content_type = anxogg_strdup (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 = 3;
+        track->granuleshift = 0;
       } else if (!strncmp ((char *)&op->packet[1], "theora", 6)) {
-	char keyframe_granule_shift = 0;
-	track->content_type = anxogg_strdup (THEORA_CONTENT_TYPE);
+        char keyframe_granule_shift = 0;
+        track->content_type = anxogg_strdup (THEORA_CONTENT_TYPE);
 #if USE_THEORA_PRE_ALPHA_3_FORMAT
-	/* old header format, used by Theora alpha 2 and earlier */
-	keyframe_granule_shift =  (header[36] & 0xf8) >> 3;
+        /* old header format, used by Theora alpha 2 and earlier */
+        keyframe_granule_shift =  (header[36] & 0xf8) >> 3;
 #else
-	keyframe_granule_shift =  (header[40] & 0x03) /* 00000011 */ << 3;
-	keyframe_granule_shift |= (header[41] & 0xe0) /* 11100000 */ >> 5;
+        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;
+        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]);
-	track->granule_rate_d = INT32_BE_AT(&header[26]);
+        track->granule_rate_n = INT32_BE_AT(&header[22]);
+        track->granule_rate_d = INT32_BE_AT(&header[26]);
 #endif
-	track->nr_header_packets = 3;
-	track->basegranule = 0;
-	track->preroll = 0;
-	track->granuleshift = keyframe_granule_shift;
+        track->nr_header_packets = 3;
+        track->basegranule = 0;
+        track->preroll = 0;
+        track->granuleshift = keyframe_granule_shift;
       } else if (!strncmp ((char *)&op->packet[0], "fishead", 8)) {
-	need_insert = 0;
-	aod->skeleton_serialno = serialno;
+        need_insert = 0;
+        aod->skeleton_serialno = serialno;
       } else if (!strncmp ((char *)&op->packet[0], "AnxData", 7)) {
-	AnxParams * params;
-	long n;
-	char * buf;
+        AnxParams * params;
+        long n;
+        char * buf;
 
-	/* Mark this track as anxv2, and don't copy the AnxData packet
-	 * into the bitstream */
-	aot->anxv2_ignore_packet = 1;
+        /* Mark this track as anxv2, and don't copy the AnxData packet
+         * into the bitstream */
+        aot->anxv2_ignore_packet = 1;
 
-	/* Set default values, these will be overwritten if the track
-	 * actually contains a content type we can parse */
+        /* Set default values, these will be overwritten if the track
+         * actually contains a content type we can parse */
 
-	/* Ensure params is NUL terminated */
-	n = op->bytes - ANX_DATA_SIZE;
-	buf = anx_malloc (n+1);
-	memcpy (buf, (char *)header + ANX_DATA_SIZE, n);
-	buf[n] = '\0';
+        /* Ensure params is NUL terminated */
+        n = op->bytes - ANX_DATA_SIZE;
+        buf = anx_malloc (n+1);
+        memcpy (buf, (char *)header + ANX_DATA_SIZE, n);
+        buf[n] = '\0';
 
-	params = anx_params_new_parse (buf, ANX_PARAMS_HEADERS);
-	track->content_type =
-	  anxogg_strdup (anx_params_get (params, "Content-Type"));
-	track->id =
-	  anxogg_strdup (anx_params_get (params, "ID"));
-	anx_params_free (params);
+        params = anx_params_new_parse (buf, ANX_PARAMS_HEADERS);
+        track->content_type =
+	         anxogg_strdup (anx_params_get (params, "Content-Type"));
+        track->id =
+	         anxogg_strdup (anx_params_get (params, "ID"));
+        anx_params_free (params);
 
-	anx_free (buf);
+        anx_free (buf);
 
-	track->granule_rate_n = INT64_LE_AT(&header[8]);
-	track->granule_rate_d = INT64_LE_AT(&header[16]);
-	track->nr_header_packets = INT32_LE_AT(&header[24]);
-	track->preroll = 0;
-	track->granuleshift = 0;
+        track->granule_rate_n = INT64_LE_AT(&header[8]);
+        track->granule_rate_d = INT64_LE_AT(&header[16]);
+        track->nr_header_packets = INT32_LE_AT(&header[24]);
+        track->preroll = 0;
+        track->granuleshift = 0;
 
-	if (!strcmp (track->content_type, CMML_CONTENT_TYPE)) {
-	  need_insert = 0;
-	  aod->cmml_serialno = serialno;
-	  aod->cmml_granuleshift = 0;
-	  aod->cmml_need_keygranule = 0;
-	}
+        if (!strcmp (track->content_type, CMML_CONTENT_TYPE)) {
+           need_insert = 0;
+           aod->cmml_serialno = serialno;
+           aod->cmml_granuleshift = 0;
+#ifdef DEBUG
+           printf("read_packet_headers: setting need_keygranule to 0\n");
+#endif
+	         aod->cmml_need_keygranule = 0;
+	      }
 
-      } else if (!strncmp ((char *)&op->packet[1], "video", 5) && 
-		 !strncmp ((char *)&op->packet[9], "XVID", 4)) {
-	track->content_type = anxogg_strdup (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 if 
+      (
+        !strncmp ((char *)&op->packet[1], "video", 5) 
+        && 
+		    !strncmp ((char *)&op->packet[9], "XVID", 4)
+      ) {
+        track->content_type = anxogg_strdup (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 (aot);
-	return OGGZ_STOP_ERR;
+        anx_free (aot);
+        return OGGZ_STOP_ERR;
       }
 
       aod->nr_headers_remaining += track->nr_header_packets;
       aod->headers_unread += track->nr_header_packets;
 
       if (track->granuleshift > 0) {
-	aod->use_granule_seek = 1;
-	aot->need_keygranule = 1;
+        aod->use_granule_seek = 1;
+        aot->need_keygranule = 1;
       }
 
       if (need_insert) {
@@ -592,10 +604,11 @@
   AnxOggPacket * aop;
   AnxSource * m = aod->anx_source;
   AnxSourceTrack * track = NULL;
+  anx_int64_t gp = oggz_tell_granulepos(oggz);
 
 #ifdef DEBUG
   fprintf (aod->df, "anxogg::read_packet_data IN: %010ld, granulepos %llx\n",
-	  serialno, op->granulepos);
+	  serialno, gp);
 #endif
 
   if (!(aod->cmml_serialno != -1 && serialno == aod->cmml_serialno)) {
@@ -621,45 +634,52 @@
 
 #ifdef DEBUG
       fprintf (aod->df, "aod->cmml_serialno %010ld, op->granulepos %lld\n",
-	      aod->cmml_serialno, op->granulepos);
+	      aod->cmml_serialno, gp);
 #endif
 
-      if (op->granulepos == -1) {
-	return OGGZ_STOP_ERR;
+      if (gp == -1) {
+	      return OGGZ_STOP_ERR;
       }
-      at_time = gp_to_time (aod->oggz, serialno, op->granulepos);
+      at_time = gp_to_time (aod->oggz, serialno, gp);
       
 #ifdef DEBUG
       {
-	char * header = (char *)op->packet;
-	fprintf (aod->df,
-		 "anxogg::read_packet_data: got CMML <%c%c%c%c> at %f\n",
-		header[1], header[2], header[3], header[4], at_time);
+        char * header = (char *)op->packet;
+        fprintf (aod->df,
+                  "anxogg::read_packet_data: got CMML <%c%c%c%c> at %f\n",
+                  header[1], header[2], header[3], header[4], at_time);
       }
 #endif
 
       /* If this content doesn't use cmml_granuleshift, and this clip is
        * before the start_time, drop it */
-      if (aod->cmml_granuleshift == 0 && op->bytes > 6 &&
-	  !strncmp ((char *)op->packet, "<clip", 5) &&
-	  at_time < aod->anx_source->start_time-TOLERANCE) {
+      if 
+      (
+        aod->cmml_granuleshift == 0 && op->bytes > 6 
+        &&
+        !strncmp ((char *)op->packet, "<clip", 5) 
+        &&
+	      at_time < aod->anx_source->start_time-TOLERANCE
+      ) 
+      {
 #ifdef DEBUG
-	fprintf (aod->df,
-		 "anxogg::read_packet_data: CMML clip too early, dropping\n");
+	      fprintf (aod->df,
+		            "anxogg::read_packet_data: CMML clip too early, dropping\n");
 #endif
-	return OGGZ_STOP_OK;
+        return OGGZ_STOP_OK;
       }
 
-      if (aod->import_cmml)
-	aod->import_cmml ((char *)op->packet, op->bytes, at_time,
-			  aod->import_user_data);
+      if (aod->import_cmml) {
+      	aod->import_cmml ((char *)op->packet, op->bytes, at_time,
+			                      aod->import_user_data);
+      }
       return OGGZ_CONTINUE;
     } else {
       if (aot->anxv2_ignore_packet) {
-	aot->anxv2_ignore_packet = 0;
-	op->b_o_s = 1;
+        aot->anxv2_ignore_packet = 0;
+        op->b_o_s = 1;
       } else {
-	aod->got_non_bos = 1;
+        aod->got_non_bos = 1;
       }
     }
   }
@@ -674,8 +694,8 @@
   }
 
   if (aod->nr_headers_remaining == 0 && !aod->got_end && 
-      (m->end_time != -1.0) && (op->granulepos != -1)) {
-    ogg_int64_t granule = gp_to_granule (oggz, serialno, op->granulepos);
+      (m->end_time != -1.0) && (gp != -1)) {
+        ogg_int64_t granule = gp_to_granule (oggz, serialno, gp);
     if (granule >= track->end_granule) {
 #ifdef DEBUG
       fprintf (aod->df, "anxogg::read_packet_data: got_end\n");
@@ -722,15 +742,21 @@
 #endif
     }
 
-    if (aod->need_seek == NEED_SEEK_PENDING &&
-	aod->nr_headers_remaining == 0 &&
-	m->start_time != 0.0) {
+    if 
+    (
+      aod->need_seek == NEED_SEEK_PENDING 
+      &&
+	    aod->nr_headers_remaining == 0 
+      &&
+	    m->start_time != 0.0
+    ) 
+    {
       if (oggz_seek_units (oggz, 0, SEEK_CUR) >= 0) {
 #ifdef DEBUG
-	fprintf (aod->df, "anxogg::read_packet_data NEED seek\n");
+      	fprintf (aod->df, "anxogg::read_packet_data NEED seek\n");
 #endif
-	aod->need_seek = NEED_SEEK;
-	return OGGZ_CONTINUE;
+        aod->need_seek = NEED_SEEK;
+        return OGGZ_CONTINUE;
       }
     }
   }
@@ -745,9 +771,9 @@
   int i, n;
 
 #ifdef DEBUG
-  fprintf (aod->df, "anxogg::granuleinfo_update_state cmml %010ld %s\n",
-	   aod->cmml_serialno,
-	   aod->cmml_need_keygranule ? "needs keygranule" : "no keygranule");
+  //fprintf (aod->df, "anxogg::granuleinfo_update_state cmml %010ld %s\n",
+	//   aod->cmml_serialno,
+	//   aod->cmml_need_keygranule ? "needs keygranule" : "no keygranule");
 #endif
 
   if (aod->cmml_serialno != -1 && aod->cmml_need_keygranule) return 0;
@@ -773,6 +799,14 @@
   return 0;
 }
 
+/*
+ * look for tracks, extract granule information.  This is a preprocessor
+ * step that scans until info is found for all tracks.  When all tracks
+ * are found, granuleinfo_update_state will set the state to FILTER and the
+ * loop will end.
+ *
+ * NOTE THAT this starts scanning from the specified startpos for the media.
+ */
 static int
 read_page_granuleinfo (OGGZ * oggz, const ogg_page * og, long serialno,
 		       void * user_data)
@@ -785,14 +819,25 @@
   double offset, start_time;
 
 #ifdef DEBUG
-  fprintf (aod->df, "read_page_granuleinfo: track %010ld\n", serialno);
+  static int page=0;
+  fprintf (aod->df, "read_page_granuleinfo: track %010ld page %d", serialno,
+                  page++);
 #endif
 
   granulepos = ogg_page_granulepos ((ogg_page *)og);
 
+#ifdef DEBUG
+  fprintf(aod->df, " granulepos %llx cmml_serialno %d", granulepos, 
+                  aod->cmml_serialno);
+  fprintf(aod->df, " bytepos %d\n", oggz_tell(oggz));
+#endif
+  
   if (aod->cmml_serialno != -1 && serialno == aod->cmml_serialno) {
     if (!aod->cmml_need_keygranule) return OGGZ_STOP_OK;
 
+#ifdef DEBUG
+    fprintf (aod->df, "read_page_granuleinfo: cmml_need_keygranule -> 0\n");
+#endif
     aod->cmml_need_keygranule = 0;
 
     /* If this content does use cmml_granuleshift, and this clip is right at
@@ -815,6 +860,7 @@
     aot = (AnxOggTrack *) oggz_table_lookup (aod->logicals, serialno);
     if (aot == NULL) {
       /* If this track is not in the table, ignore it. */
+      printf("NULL aot\n");
       return OGGZ_STOP_OK;
     }
 
@@ -829,8 +875,10 @@
       /* XXX: vaguely similar reasoning to CMML above */
       start_time = aod->anx_source->start_time;
       offset = gp_to_time (aod->oggz, serialno, granulepos);
+      printf("offset %f start_time %f TOLERANCE %f\n", offset, start_time,
+                      TOLERANCE);
       if (offset-TOLERANCE <= start_time) {
-	return OGGZ_STOP_OK;
+        return OGGZ_STOP_OK;
       }
       /* End XXX: */
 #endif
@@ -843,11 +891,12 @@
       offset = gp_to_time (aod->oggz, serialno, aot->keygranule);
       aot->keygranule_time = offset;
       if (aod->min_granule_seek == 0.0 || offset < aod->min_granule_seek)
-	aod->min_granule_seek = offset;
+        aod->min_granule_seek = offset;
       
 #ifdef DEBUG
       fprintf (aod->df,
-	       "read_page_granuleinfo: ^^^ has keygranule %lld (%lld|0) (%f seconds) (granuleshift %d)\n",
+	      "read_page_granuleinfo: ^^^ has keygranule "
+        "%lld (%lld|0) (%f seconds) (granuleshift %d)\n",
 	      aot->keygranule, iframe, offset, track->granuleshift);
 #endif
     }
@@ -888,7 +937,13 @@
   end_time = aod->anx_source->end_time;
 
   if (end_time == -1.0) {
+#ifdef DEBUG
+    printf("calling oggz_seek with whence of %d\n", SEEK_END);
+#endif
     end_offset = oggz_seek (aod->oggz, 0, SEEK_END);
+#ifdef DEBUG
+    fprintf (aod->df, "anxogg_setup: end_offset is %d\n", end_offset);
+#endif
 
     /* Find the actual end time */
     units_at = oggz_seek_units (aod->oggz, 0, SEEK_END);
@@ -1007,6 +1062,7 @@
   OGGZ * oggz;
   long n;
 
+  
   if ((oggz = oggz_open ((char *)path, OGGZ_READ | OGGZ_AUTO)) == NULL)
     return NULL;
 

Modified: libannodex/trunk/src/libannodex/anx_import.c
===================================================================
--- libannodex/trunk/src/libannodex/anx_import.c	2006-11-18 09:08:12 UTC (rev 2550)
+++ libannodex/trunk/src/libannodex/anx_import.c	2006-11-20 00:50:21 UTC (rev 2551)
@@ -51,8 +51,6 @@
 #include "anx_private.h"
 #include "content_type.h"
 
-/* #define DEBUG */
-
 #include "fix_dl.h"
 
 #ifdef WIN32
@@ -60,6 +58,8 @@
 #define S_ISREG(x) TRUE
 #endif
 
+//#define DEBUG
+
 static AnxList * importer_plugins = NULL;
 static AnxList * media_importers = NULL;
 
@@ -214,8 +214,12 @@
 
   for (l = media_importers; l; l = l->next) {
     importer = (AnxImporter *)l->data;
-    if (!strcasecmp (importer->content_type, content_type))
+    if (!strcasecmp (importer->content_type, content_type)) {
+#ifdef DEBUG
+      printf("%s\n", importer->content_type);
+#endif
       return importer;
+    }
   }
 
   return NULL;
@@ -519,7 +523,26 @@
 int
 anx_media_eos (AnxSource * media)
 {
+  AnxSourceTrack  * track_data;
+  AnxList         * track_list;
+    
   if (media == NULL) return 0;
+  
+  track_list = media->tracks;
+   
+  while (track_list != NULL) {
+    track_data = (AnxSourceTrack *)(track_list->data);
+#ifdef DEBUG
+    printf("track %p has eos %d\n", (void *)track_data, track_data->eos);
+#endif
+    if (track_data->eos == 0)
+      return 0;
+    track_list = track_list->next;
+
+  }
+
+  media->eos = 1;
+  
   return media->eos;
 }
 

Modified: libannodex/trunk/src/libannodex/anx_write.c
===================================================================
--- libannodex/trunk/src/libannodex/anx_write.c	2006-11-18 09:08:12 UTC (rev 2550)
+++ libannodex/trunk/src/libannodex/anx_write.c	2006-11-20 00:50:21 UTC (rev 2551)
@@ -44,7 +44,7 @@
 #include "anx_private.h"
 #include "anx_snprint.h" /* anx_strdup */
 
-/*#define DEBUG*/
+/* #define DEBUG */
 
 /* set to 0 or 1 */
 #define FLUSH_ALWAYS 0
@@ -392,10 +392,11 @@
 
   /* If we are at the end of the stream, mark media as done */
   for (l = writer->medias; l; l = l->next) {
+    
     media = (AnxSource *)l->data;
     if (!anx_media_eos (media)) {
 #ifdef DEBUG
-      printf ("anx_writer_update_eos: found one not at eos\n");
+      printf ("anx_writer_update_eos: found %p not at eos\n", media);
 #endif
       at_eos = 0;
       break;
@@ -1055,7 +1056,6 @@
   return anx_init_eos_packet (annodex, annodex->cmml_serialno, granulepos);
 }
 
-
 static long
 anx_writer_sync (ANNODEX * annodex)
 {
@@ -1102,28 +1102,28 @@
       printf ("anx_writer_sync: NEED a BOS\n");
 #endif
       for (l = writer->tracks; l; l = l->next) {
-	wsub = (AnxWriterTrack *)l->data;
-	if (!wsub->written_bos) {
+        wsub = (AnxWriterTrack *)l->data;
+        if (!wsub->written_bos) {
 
-	  anx_writer_set_wsub (annodex, wsub);
-	  if (anx_writer_read_media (annodex) == -1) {
+          anx_writer_set_wsub (annodex, wsub);
+          if (anx_writer_read_media (annodex) == -1) {
 #ifdef DEBUG
-	    printf ("anx_writer_sync: fill_media returned -1\n");
+            printf ("anx_writer_sync: fill_media returned -1\n");
 #endif
-	  }
+          }
 
-	  anx_init_media_packet (annodex, OGGZ_FLUSH_BEFORE|OGGZ_FLUSH_AFTER);
-	  writer->secondary_headers_remaining--;
-	  made_packet = 1;
-	  break;
-	}
+          anx_init_media_packet (annodex, OGGZ_FLUSH_BEFORE|OGGZ_FLUSH_AFTER);
+          writer->secondary_headers_remaining--;
+          made_packet = 1;
+          break;
+        }
       }
 
       if (l == NULL) {
 #ifdef DEBUG
-	if (!made_packet) printf ("anx_writer_sync: no BOS found\n");
+        if (!made_packet) printf ("anx_writer_sync: no BOS found\n");
 #endif
-	writer->need_bos = 0;
+        writer->need_bos = 0;
       }
     } else if (writer->need_cmml_fisbone) {
 #ifdef DEBUG
@@ -1137,17 +1137,17 @@
       printf ("anx_writer_sync: NEED fisbone\n");
 #endif
       for (l = writer->tracks; l; l = l->next) {
-	wsub = (AnxWriterTrack *)l->data;
-	if (!wsub->written_fisbone) {
-	  anx_init_wsub_fisbone_packet (annodex, wsub);
-	  writer->secondary_headers_remaining--;
-	  made_packet = 1;
-	  break;
-	}
+        wsub = (AnxWriterTrack *)l->data;
+        if (!wsub->written_fisbone) {
+          anx_init_wsub_fisbone_packet (annodex, wsub);
+          writer->secondary_headers_remaining--;
+          made_packet = 1;
+          break;
+        }
       }
 
       if (l == NULL) {
-	writer->need_fisbone = 0;
+        writer->need_fisbone = 0;
       }
     } else if (writer->need_cmml_preamble) {
 #ifdef DEBUG
@@ -1166,18 +1166,18 @@
     } else if (writer->secondary_headers_remaining > 0) {
 #ifdef DEBUG
       printf ("anx_write_sync: NEED %d secondaries remaing\n",
-	      writer->secondary_headers_remaining);
+        writer->secondary_headers_remaining);
 #endif
 
       if (anx_writer_get_soonest_media (annodex) == -1) {
 #ifdef DEBUG
-	printf ("anx_writer_sync: get_soonest_media returned -1\n");
+        printf ("anx_writer_sync: get_soonest_media returned -1\n");
 #endif
       }
 
       if (anx_writer_read_media (annodex) == -1) {
 #ifdef DEBUG
-	printf ("anx_writer_sync: read_media returned -1\n");
+        printf ("anx_writer_sync: read_media returned -1\n");
 #endif
       }
 
@@ -1193,90 +1193,94 @@
     } else if (annodex->pending_command) {
 
       command_offset =
-	anx_command_get_time_offset (annodex, annodex->pending_command);
+          anx_command_get_time_offset (annodex, annodex->pending_command);
 
       current_offset = anx_tell_time (annodex);
-
+  
       /* While current offset >= pending offset and we haven't made a packet
        * yet, handle next command */
 
 #ifdef DEBUG
       printf ("\nanx_write: [%f] next command at %f\n", current_offset,
-	      command_offset);
+         command_offset);
 #endif
       
       while (!made_packet &&
-	     ((current_offset > command_offset-TOLERANCE) ||
-	      (current_offset == 0.0 && command_offset == 0.0))) {
+                ((current_offset > command_offset-TOLERANCE) ||
+                (current_offset == 0.0 && command_offset == 0.0))) {
 
-	annodex->current_command = annodex->pending_command;
+        annodex->current_command = annodex->pending_command;
 
 #ifdef DEBUG
-	printf ("\t[%f] writing %p\n", current_offset,
-		annodex->pending_command);
+        printf ("\t[%f] writing %p\n", current_offset,
+                    annodex->pending_command);
 #endif
 
-	command_type =
-	  anx_command_get_type (annodex, annodex->pending_command);
+        command_type =
+            anx_command_get_type (annodex, annodex->pending_command);
 
-	switch (command_type) {
-	case ANX_CMD_NOOP:
-	  break;
-	case ANX_CMD_INSERT_CLIP:
-	  anx_init_clip_packet (annodex);
-	  made_packet = 1;
-	  break;
-	case ANX_CMD_CLEAR_CLIP:
-	  anx_init_clear_clip_packet (annodex);
-	  made_packet = 1;
-	  break;
-	case ANX_CMD_LOAD_MEDIA:
-	  break;
-	case ANX_CMD_UNLOAD_MEDIA:
-	  break;
-	default:
-	  break;
-	}
+        switch (command_type) {
+        case ANX_CMD_NOOP:
+          break;
+        case ANX_CMD_INSERT_CLIP:
+          anx_init_clip_packet (annodex);
+          made_packet = 1;
+          break;
+        case ANX_CMD_CLEAR_CLIP:
+          anx_init_clear_clip_packet (annodex);
+          made_packet = 1;
+          break;
+        case ANX_CMD_LOAD_MEDIA:
+          break;
+        case ANX_CMD_UNLOAD_MEDIA:
+          break;
+        default:
+          break;
+        }
 
 #ifdef DEBUG
-	printf ("\t[%f] pending_command before: %p\n",
-		current_offset, annodex->pending_command);
+        printf ("\t[%f] pending_command before: %p\n",
+              current_offset, annodex->pending_command);
 #endif
 	
-	annodex->pending_command =
-	  anx_command_next (annodex, annodex->pending_command);
+        annodex->pending_command =
+                      anx_command_next (annodex, annodex->pending_command);
 
 #ifdef DEBUG
-	printf ("\t[%f] pending_command after : %p\n",
-		current_offset, annodex->pending_command);
+        printf ("\t[%f] pending_command after : %p\n",
+                                current_offset, annodex->pending_command);
 #endif
 
-	if (made_packet || annodex->pending_command == NULL) break;
+        if (made_packet || annodex->pending_command == NULL) break;
 
-	command_offset =
-	  anx_command_get_time_offset (annodex, annodex->pending_command);
+        command_offset =
+              anx_command_get_time_offset (annodex, annodex->pending_command);
 
-	current_offset = anx_tell_time (annodex);
+        current_offset = anx_tell_time (annodex);
 
 #ifdef DEBUG
-	printf ("anx_write: [%f] next command at %f\n", current_offset,
-		command_offset);
+        printf ("anx_write: [%f] next command at %f\n", current_offset,
+                	command_offset);
 #endif
       }
     }
 
-    /* Create a media packet */
+  /* Create a media packet */
     if (made_packet == 0) {
 
+#ifdef DEBUG
+      printf ("anx_writer_sync: no packet, creating one\n");
+#endif
+      
       if (anx_writer_get_soonest_media (annodex) == -1) {
 #ifdef DEBUG
-	printf ("anx_writer_sync: get_soonest_media returned -1\n");
+        printf ("anx_writer_sync: get_soonest_media returned -1\n");
 #endif
       }
 
       if (anx_writer_read_media (annodex) == -1) {
 #ifdef DEBUG
-	printf ("anx_writer_sync: read_media returned -1\n");
+        printf ("anx_writer_sync: read_media returned -1\n");
 #endif
       }
 
@@ -1296,32 +1300,32 @@
       made_packet = 1;
     } else {
       for (l = writer->tracks; l; l = l->next) {
-	wsub = (AnxWriterTrack *)l->data;
-	if (!wsub->written_eos) {
-	  track = (AnxTrack *)wsub;
+	      wsub = (AnxWriterTrack *)l->data;
+        if (!wsub->written_eos) {
+          track = (AnxTrack *)wsub;
 #ifdef DEBUG
-	  printf ("anx_writer_sync: writing eos for %s\n", 
-		  track->content_type);
+          printf ("anx_writer_sync: writing eos for %s\n", 
+                        track->content_type);
 #endif
 #if 0
 	  granulepos = (anx_int64_t) anx_tell_time (annodex) * 
 	    track->granule_rate_n / track->granule_rate_d;
 #else
 	  /* Hack a fake ++granulepos for this zero-length packet */
-	  granulepos = wsub->last_granulepos+1;
+          granulepos = wsub->last_granulepos+1;
 #endif
-	  anx_init_eos_packet (annodex, track->serialno, granulepos);
-	  wsub->written_eos = 1;
-	  made_packet = 1;
-	  break;
-	}
+          anx_init_eos_packet (annodex, track->serialno, granulepos);
+          wsub->written_eos = 1;
+          made_packet = 1;
+          break;
+        }
       }
       
       if (l == NULL) {
 #ifdef DEBUG
-	printf ("anx_writer_sync: setting writer->eos\n");
+        printf ("anx_writer_sync: setting writer->eos\n");
 #endif
-	writer->eos = 1;
+        writer->eos = 1;
       }
     }
   } else {
@@ -1330,6 +1334,9 @@
 #endif    
   }
 
+#ifdef DEBUG
+  printf("anx_writer_sync: returning %d\n", writer->eos);
+#endif 
   return writer->eos;
 }
 

Modified: libannodex/trunk/src/tools/anxenc.c
===================================================================
--- libannodex/trunk/src/tools/anxenc.c	2006-11-18 09:08:12 UTC (rev 2550)
+++ libannodex/trunk/src/tools/anxenc.c	2006-11-20 00:50:21 UTC (rev 2551)
@@ -45,6 +45,8 @@
 
 #include "common.h"
 
+/* #define DEBUG */
+
 /*
  * usage ()
  *
@@ -168,12 +170,23 @@
       anx_exit_err (anx, "Failed anx_writer_output");
     }
 
+    if (n < 0) {
+      break;
+    }
+    
     if ((n_written = fwrite (buf, 1, (size_t)n, outfile)) < n) {
       if (ferror(outfile) != 0)
 	print_debug (2, "Error writing output file\n");
       else
 	print_debug (2, "Error: short write; wrote %ld bytes\n", n_written);
     }
+
+#ifdef DEBUG
+    static int position = 0;
+    printf ("anxenc: writing %d(%d) bytes at %x\n", n, n_written, position);
+    position += n_written;
+#endif
+    
   }
 
   if (anx_close (anx) != NULL) {


-- 
shans



More information about the cvs-annodex mailing list