[xiph-commits] r3512 - in liboggz/trunk: include/oggz src/liboggz src/tools

conrad at svn.annodex.net conrad at svn.annodex.net
Thu Mar 20 03:30:19 PDT 2008


Author: conrad
Date: 2008-03-20 03:30:14 -0700 (Thu, 20 Mar 2008)
New Revision: 3512

Modified:
   liboggz/trunk/include/oggz/oggz_constants.h
   liboggz/trunk/src/liboggz/oggz_auto.c
   liboggz/trunk/src/liboggz/oggz_auto.h
   liboggz/trunk/src/liboggz/oggz_comments.c
   liboggz/trunk/src/tools/oggz_tools.c
   liboggz/trunk/src/tools/oggzdump.c
   liboggz/trunk/src/tools/oggzrip.c
Log:
add Kate support to liboggz and oggzinfo, oggzdump, oggzrip etc.
See http://wiki.xiph.org/index.php/OggKate. Patch from ogg.k.ogg.k


Modified: liboggz/trunk/include/oggz/oggz_constants.h
===================================================================
--- liboggz/trunk/include/oggz/oggz_constants.h	2008-03-20 10:09:54 UTC (rev 3511)
+++ liboggz/trunk/include/oggz/oggz_constants.h	2008-03-20 10:30:14 UTC (rev 3512)
@@ -111,6 +111,7 @@
   OGGZ_CONTENT_FLAC,
   OGGZ_CONTENT_ANXDATA,
   OGGZ_CONTENT_CELT,
+  OGGZ_CONTENT_KATE,
   OGGZ_CONTENT_UNKNOWN
 } OggzStreamContent;
 

Modified: liboggz/trunk/src/liboggz/oggz_auto.c
===================================================================
--- liboggz/trunk/src/liboggz/oggz_auto.c	2008-03-20 10:09:54 UTC (rev 3511)
+++ liboggz/trunk/src/liboggz/oggz_auto.c	2008-03-20 10:30:14 UTC (rev 3512)
@@ -140,6 +140,7 @@
   char keyframe_granule_shift = 0;
   int keyframe_shift;
 
+  /* TODO: this should check against 42 for the relevant version numbers */
   if (op->bytes < 41) return 0;
 
   fps_numerator = INT32_BE_AT(&header[22]);
@@ -157,7 +158,7 @@
   keyframe_shift = intlog (keyframe_granule_shift - 1);
 #else
   keyframe_granule_shift = (char) ((header[40] & 0x03) << 3);
-  keyframe_granule_shift |= (header[41] & 0xe0) >> 5;
+  keyframe_granule_shift |= (header[41] & 0xe0) >> 5; /* see TODO above */
   keyframe_shift = keyframe_granule_shift;
 #endif
 
@@ -326,6 +327,36 @@
 }
 
 static int
+auto_kate (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data)
+{
+  unsigned char * header = op->packet;
+  ogg_int32_t gps_numerator, gps_denominator;
+  unsigned char granule_shift = 0;
+  int numheaders;
+
+  if (op->bytes < 64) return 0;
+
+  gps_numerator = INT32_LE_AT(&header[24]);
+  gps_denominator = INT32_LE_AT(&header[28]);
+
+  granule_shift = (header[15]);
+  numheaders = (header[11]);
+
+#ifdef DEBUG
+  printf ("Got kate gps %d/%d, granule shift %d\n",
+	  gps_numerator, gps_denominator, granule_shift);
+#endif
+
+  oggz_set_granulerate (oggz, serialno, gps_numerator,
+			OGGZ_AUTO_MULT * gps_denominator);
+  oggz_set_granuleshift (oggz, serialno, granule_shift);
+ 
+  oggz_stream_set_numheaders (oggz, serialno, numheaders);
+
+  return 1;
+}
+
+static int
 auto_fisbone (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data)
 {
   unsigned char * header = op->packet;
@@ -1011,6 +1042,7 @@
   {"\177FLAC", 4, "Flac", auto_flac, auto_calc_flac, NULL},
   {"AnxData", 7, "AnxData", auto_anxdata, NULL, NULL},
   {"CELT    ", 8, "CELT", auto_celt, auto_calc_celt, NULL},
+  {"\200kate\0\0\0\0", 9, "Kate", auto_kate, NULL, NULL},
   {"", 0, "Unknown", NULL, NULL, NULL}
 }; 
 
@@ -1105,11 +1137,17 @@
       if (op->bytes > 7 && memcmp (op->packet, "\201theora", 7) == 0)
         offset = 7;
       break;
+    case OGGZ_CONTENT_KATE:
+      if (op->bytes > 9 && memcmp (op->packet, "\201kate\0\0\0\0", 9) == 0) {
+        offset = 9;
+      }
+      break;
     case OGGZ_CONTENT_FLAC:
       if (op->bytes > 4 && (op->packet[0] & 0x7) == 4) {
         len = (op->packet[1]<<16) + (op->packet[2]<<8) + op->packet[3];
         offset = 4;
       }
+      break;
     default:
       break;
   }

Modified: liboggz/trunk/src/liboggz/oggz_auto.h
===================================================================
--- liboggz/trunk/src/liboggz/oggz_auto.h	2008-03-20 10:09:54 UTC (rev 3511)
+++ liboggz/trunk/src/liboggz/oggz_auto.h	2008-03-20 10:30:14 UTC (rev 3512)
@@ -428,6 +428,50 @@
 
  */
 
+/**
+ * Kate bitstream version 0.1
+ *
+ * Default field type: LITTLE ENDIAN unsigned integer
+
+ 0               1               2               3              |
+ 0                   1                   2                   3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1| Byte
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| packtype      | Identifier char[8]: 'kate\0\0\0\0'            | 0-3
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| kate magic continued                                          | 4-7
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| kate magic    | version major | version minor | num headers   | 8-11
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| text encoding | directionality| reserved - 0  | granule shift | 12-15
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| reserved - 0                                                  | 16-19
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| reserved - 0                                                  | 20-23
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| granule rate numerator                                        | 24-27
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| granule rate denominator                                      | 28-31
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| language (NUL terminated)                                     | 32-35
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| language (continued)                                          | 36-39
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| language (continued)                                          | 40-43
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| language (continued)                                          | 44-47
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| category (NUL terminated)                                     | 48-51
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| category (continued)                                          | 52-55
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| category (continued)                                          | 56-59
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+| category (continued)                                          | 60-63
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ */
+
 int oggz_auto_identify (OGGZ *oggz, ogg_page *og, long serialno);
 
 #endif /* __OGGZ_AUTO_H__ */

Modified: liboggz/trunk/src/liboggz/oggz_comments.c
===================================================================
--- liboggz/trunk/src/liboggz/oggz_comments.c	2008-03-20 10:09:54 UTC (rev 3511)
+++ liboggz/trunk/src/liboggz/oggz_comments.c	2008-03-20 10:30:14 UTC (rev 3512)
@@ -733,6 +733,8 @@
     {0x81, 0x74, 0x68, 0x65, 0x6f, 0x72, 0x61};
   const unsigned char preamble_flac[4] =
     {0x04, 0x00, 0x00, 0x00};
+  const unsigned char preamble_kate[9] =
+    {0x81, 0x6b, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, 0x00};
 
 
   switch(packet_type) {
@@ -748,6 +750,10 @@
       preamble_length = sizeof preamble_flac;
       preamble = preamble_flac;
       break;
+    case OGGZ_CONTENT_KATE:
+      preamble_length = sizeof preamble_kate;
+      preamble = preamble_kate;
+      break;
     case OGGZ_CONTENT_PCM:
     case OGGZ_CONTENT_SPEEX:
       preamble_length = 0;
@@ -808,7 +814,7 @@
   return c_packet;
 }
 
-/* In Flac, OggPCM, Speex, Theora and Vorbis the comment packet will
+/* In Flac, OggPCM, Speex, Theora Vorbis, and Kate the comment packet will
    be second in the stream, i.e. packetno=1, and it will have granulepos=0 */
 ogg_packet *
 oggz_comments_generate(OGGZ * oggz, long serialno,

Modified: liboggz/trunk/src/tools/oggz_tools.c
===================================================================
--- liboggz/trunk/src/tools/oggz_tools.c	2008-03-20 10:09:54 UTC (rev 3511)
+++ liboggz/trunk/src/tools/oggz_tools.c	2008-03-20 10:30:14 UTC (rev 3512)
@@ -239,6 +239,37 @@
 }
 
 static char *
+ot_kate_info (unsigned char * data, long len)
+{
+  char * buf;
+
+  static const size_t KATE_INFO_BUFFER_LEN =
+    1 /* tab */
+  +10 /* "Language: " */
+  +15 /* 15 chars + NUL for language */
+   +1 /* \n */
+   +1 /* tab */
+  +10 /* "Category: " */
+  +15 /* 15 chars + NUL for category */
+   +1 /* \n */
+   +1;/* terminating NUL */
+
+  if (len < 64) return NULL;
+
+  buf = malloc (KATE_INFO_BUFFER_LEN);
+
+  /* Are these headers coming from some standard ? If so, need to find what should these be for Kate */
+  snprintf (buf, KATE_INFO_BUFFER_LEN,
+	    "\tLanguage: %s\n"
+            "\tCategory: %s\n",
+	    &data[32], &data[48]);
+
+#undef KATE_INFO_BUFFER_LEN
+
+  return buf;
+}
+
+static char *
 ot_skeleton_info (unsigned char * data, long len)
 {
   char * buf;
@@ -283,6 +314,7 @@
   ot_flac_info,     /* FLAC */
   NULL,             /* ANXDATA */
   ot_celt_info,     /* CELT */
+  ot_kate_info,     /* KATE */
   NULL              /* UNKOWN */
 };
 

Modified: liboggz/trunk/src/tools/oggzdump.c
===================================================================
--- liboggz/trunk/src/tools/oggzdump.c	2008-03-20 10:09:54 UTC (rev 3511)
+++ liboggz/trunk/src/tools/oggzdump.c	2008-03-20 10:30:14 UTC (rev 3512)
@@ -90,7 +90,7 @@
   printf ("  -c content-type, --content-type content-type\n");
   printf ("                         Dump only the logical bitstreams for a specified\n");
   printf ("                         content-type. The following codecs are currently\n");
-  printf ("                         detected: theora, vorbis, speex, cmml\n");
+  printf ("                         detected: theora, vorbis, speex, cmml, kate\n");
   printf ("  -s serialno, --serialno serialno\n");
   printf ("                         Dump only the logical bitstream with specified serialno\n");
   printf ("  -O, --hide-offset      Hide the byte offset of each packet\n");

Modified: liboggz/trunk/src/tools/oggzrip.c
===================================================================
--- liboggz/trunk/src/tools/oggzrip.c	2008-03-20 10:09:54 UTC (rev 3511)
+++ liboggz/trunk/src/tools/oggzrip.c	2008-03-20 10:30:14 UTC (rev 3512)
@@ -94,7 +94,7 @@
   printf ("  -c content-type --content-type content-type\n");
   printf ("                         Filter by content-type.  The following codec\n");
   printf ("                         names are currently detected: \"theora\",\n");
-  printf ("                         \"vorbis\", \"speex\", \"cmml\"\n");
+  printf ("                         \"vorbis\", \"speex\", \"cmml\", \"kate\"\n");
   printf ("\nMiscellaneous options\n");
   printf ("  -o filename, --output filename\n");
   printf ("                         Specify output filename\n");



More information about the commits mailing list