[xiph-commits] r3747 - libannodex/trunk/src/importers

conrad at svn.annodex.net conrad at svn.annodex.net
Wed Oct 29 04:06:02 PDT 2008


Author: conrad
Date: 2008-10-29 04:06:02 -0700 (Wed, 29 Oct 2008)
New Revision: 3747

Modified:
   libannodex/trunk/src/importers/anx_import_ogg.c
Log:
anx_import_ogg: use oggz functions instead of reading bos headers directly


Modified: libannodex/trunk/src/importers/anx_import_ogg.c
===================================================================
--- libannodex/trunk/src/importers/anx_import_ogg.c	2008-10-28 07:45:16 UTC (rev 3746)
+++ libannodex/trunk/src/importers/anx_import_ogg.c	2008-10-29 11:06:02 UTC (rev 3747)
@@ -316,6 +316,7 @@
   AnxOggTrack * aot = NULL;
   AnxSource * m = aod->anx_source;
   AnxSourceTrack * track = NULL;
+  OggzStreamContent content;
   int need_insert = 1;
   int got_headers = 0;
 
@@ -325,18 +326,15 @@
   }
 
   if (op->b_o_s) {
-    if (!strncmp ((char *)header, "CMML", 5)) {
+    content = oggz_stream_get_content (oggz, serialno);
+
+    if (content == OGGZ_CONTENT_CMML) {
       /* Don't insert this into the media */
       need_insert = 0;
 	
       aod->cmml_serialno = serialno;
+      aod->cmml_granuleshift = oggz_get_granuleshift (oggz, serialno);
 
-      /* Check the CMML header is of correct length */
-      if (op->bytes > 28)
-        aod->cmml_granuleshift = (int)header[28];
-      else
-        aod->cmml_granuleshift = 0;
-
 #ifdef DEBUG
       fprintf(aod->df, 
                   "read_packet_headers: setting cmml_need_keygranule to %d\n",
@@ -355,114 +353,90 @@
       
       track = &(aot->source_track);
       track->eos = 0;
+      track->nr_header_packets = oggz_stream_get_numheaders (oggz, serialno);
+      oggz_get_granulerate (oggz, serialno,
+                            &track->granule_rate_n,
+                            &track->granule_rate_d);
+      track->granuleshift = oggz_get_granuleshift (oggz, serialno);
+      track->content_type = anxogg_strdup (oggz_stream_get_content_type (oggz, serialno));
 
-      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;
+      switch (content) {
+      case OGGZ_CONTENT_VORBIS:
         if (m->start_time < 1.0) {
           track->basegranule = 0;
         } else {
           track->basegranule = (m->start_time - 1.0) * track->granule_rate_n;
         }
         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]);
+        break;
+      case OGGZ_CONTENT_SPEEX:
         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);
-#if USE_THEORA_PRE_ALPHA_3_FORMAT
-        /* 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;
-#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]);
-        track->granule_rate_d = INT32_BE_AT(&header[26]);
-#endif
-        track->nr_header_packets = 3;
+        break;
+      case OGGZ_CONTENT_THEORA:
         track->basegranule = 0;
         track->preroll = 0;
-        track->granuleshift = keyframe_granule_shift;
-      } else if (!strncmp ((char *)&op->packet[0], "fishead", 8)) {
+        break;
+      case OGGZ_CONTENT_SKELETON:
         need_insert = 0;
         aod->skeleton_serialno = serialno;
-      } else if (!strncmp ((char *)&op->packet[0], "AnxData", 7)) {
-        AnxParams * params;
-        long n;
-        char * buf;
+        break;
+      case OGGZ_CONTENT_ANX2: /* AnxData */
+        {
+          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 =
+          params = anx_params_new_parse (buf, ANX_PARAMS_HEADERS);
+          track->content_type =
 	         anxogg_strdup (anx_params_get (params, "Content-Type"));
-        track->id =
+          track->id =
 	         anxogg_strdup (anx_params_get (params, "ID"));
-        anx_params_free (params);
+          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->preroll = 0;
 
-        if (!strcmp (track->content_type, CMML_CONTENT_TYPE)) {
-           need_insert = 0;
-           aod->cmml_serialno = serialno;
-           aod->cmml_granuleshift = 0;
+          if (!strcmp (track->content_type, CMML_CONTENT_TYPE)) {
+             need_insert = 0;
+             aod->cmml_serialno = serialno;
+             aod->cmml_granuleshift = 0;
 #ifdef DEBUG
-           fprintf(aod->df,
-                      "read_packet_headers: setting need_keygranule to 0\n");
+             fprintf(aod->df,
+                     "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 {
-        anx_free (aot);
-        return OGGZ_STOP_ERR;
+	             aod->cmml_need_keygranule = 0;
+	  }
+        }
+        break;
+      default:
+        /* Content type not known by Oggz */
+        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;
+        }
       }
 
       aod->nr_headers_remaining += track->nr_header_packets;



More information about the commits mailing list