Commit d0b92985 authored by conrad's avatar conrad

add Kate support to liboggz and oggzinfo, oggzdump, oggzrip etc.

See http://wiki.xiph.org/index.php/OggKate. Patch from ogg.k.ogg.k


git-svn-id: http://svn.annodex.net/liboggz/trunk@3512 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent c2ca2126
......@@ -111,6 +111,7 @@ typedef enum OggzStreamContent {
OGGZ_CONTENT_FLAC,
OGGZ_CONTENT_ANXDATA,
OGGZ_CONTENT_CELT,
OGGZ_CONTENT_KATE,
OGGZ_CONTENT_UNKNOWN
} OggzStreamContent;
......
......@@ -140,6 +140,7 @@ auto_theora (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data)
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 @@ auto_theora (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data)
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
......@@ -325,6 +326,36 @@ auto_cmml (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data)
return 1;
}
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)
{
......@@ -1011,6 +1042,7 @@ const oggz_auto_contenttype_t oggz_auto_codec_ident[] = {
{"\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 @@ oggz_auto_read_comments (OGGZ * oggz, oggz_stream_t * stream, long serialno,
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;
}
......
......@@ -428,6 +428,50 @@ This was the Theora header for theora-alpha2:
*/
/**
* 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__ */
......@@ -733,6 +733,8 @@ oggz_comment_generate(OGGZ * oggz, long serialno,
{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 @@ oggz_comment_generate(OGGZ * oggz, long serialno,
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 @@ oggz_comment_generate(OGGZ * oggz, long serialno,
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,
......
......@@ -238,6 +238,37 @@ ot_oggpcm2_info (unsigned char * data, long len)
return buf;
}
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)
{
......@@ -283,6 +314,7 @@ static const OTCodecInfoFunc codec_ident[] = {
ot_flac_info, /* FLAC */
NULL, /* ANXDATA */
ot_celt_info, /* CELT */
ot_kate_info, /* KATE */
NULL /* UNKOWN */
};
......
......@@ -90,7 +90,7 @@ usage (char * progname)
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");
......
......@@ -94,7 +94,7 @@ usage (char * progname)
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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment