Commit 16749569 authored by Ralph Giles's avatar Ralph Giles

Fix theora length calculation (can't use granpos directly, need to do

keyframe shifting trickery).

Fix comment parser, which was broken, then became more broken, and now 
works without crashing.

svn path=/trunk/vorbis-tools/; revision=9444
parent 3bea128a
......@@ -156,7 +156,8 @@ static void error(char *format, ...)
va_end(ap);
}
static void check_xiph_comment(stream_processor *stream, int i, char *comment)
static void check_xiph_comment(stream_processor *stream, int i, char *comment,
int comment_length)
{
char *sep = strchr(comment, '=');
char *decoded;
......@@ -188,10 +189,10 @@ static void check_xiph_comment(stream_processor *stream, int i, char *comment)
val = comment;
j = sep-comment[i]+1;
while(j < comment[i])
j = sep-comment+1;
while(j < comment_length)
{
remaining = comment[i] - j;
remaining = comment_length - j;
if((val[j] & 0x80) == 0)
bytes = 1;
else if((val[j] & 0x40) == 0x40) {
......@@ -306,7 +307,6 @@ static void theora_process(stream_processor *stream, ogg_page *page)
ogg_packet packet;
misc_theora_info *inf = stream->data;
int i, header=0;
int k;
ogg_stream_pagein(&stream->os, page);
if(inf->doneheaders < 3)
......@@ -386,7 +386,8 @@ static void theora_process(stream_processor *stream, ogg_page *page)
for(i=0; i < inf->tc.comments; i++) {
char *comment = inf->tc.user_comments[i];
check_xiph_comment(stream, i, comment);
check_xiph_comment(stream, i, comment,
inf->tc.comment_lengths[i]);
}
}
}
......@@ -418,7 +419,9 @@ static void theora_end(stream_processor *stream)
double bitrate, time;
/* This should be lastgranulepos - startgranulepos, or something like that*/
time = (double)inf->lastgranulepos /
ogg_int64_t iframe=inf->lastgranulepos>>inf->ti.granule_shift;
ogg_int64_t pframe=inf->lastgranulepos-(iframe<<inf->ti.granule_shift);
time = (double)(iframe+pframe) /
((float)inf->ti.fps_numerator/(float)inf->ti.fps_denominator);
minutes = (long)time / 60;
seconds = (long)time - minutes*60;
......@@ -512,7 +515,8 @@ static void vorbis_process(stream_processor *stream, ogg_page *page )
for(i=0; i < inf->vc.comments; i++) {
char *comment = inf->vc.user_comments[i];
check_xiph_comment(stream, i, comment);
check_xiph_comment(stream, i, comment,
inf->vc.comment_lengths[i]);
}
}
}
......
......@@ -96,7 +96,7 @@ static int _theora_unpack_info(theora_info *ci, oggpack_buffer *opb){
ci->quality=ret;
theora_read(opb,5,&ret);
ci->keyframe_frequency_force=1<<ret;
ci->granule_shift = ret;
theora_read(opb,2,&ret);
ci->pixelformat=ret;
......
......@@ -82,14 +82,14 @@ typedef struct {
unsigned char version_minor;
unsigned char version_subminor;
int granule_shift;
void *codec_setup;
/* encode only */
int dropframes_p;
int keyframe_auto_p;
ogg_uint32_t keyframe_frequency;
ogg_uint32_t keyframe_frequency_force; /* also used for decode init to
get granpos shift correct */
ogg_uint32_t keyframe_data_target_bitrate;
ogg_int32_t keyframe_auto_threshold;
ogg_uint32_t keyframe_mindistance;
......@@ -181,3 +181,5 @@ typedef struct theora_comment{
extern int theora_decode_header(theora_info *ci, theora_comment *cc,
ogg_packet *op);
void theora_info_clear(theora_info *c);
void theora_comment_clear(theora_comment *tc);
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