Added support for files with an index header but no index entries

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34431 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
David McPaul
2009-12-01 22:06:31 +00:00
parent 375ddaad85
commit 1f7d28238c
2 changed files with 27 additions and 5 deletions
@@ -96,7 +96,7 @@ asf_init(asf_file_t *file)
tmp = asf_parse_header(file);
if (tmp < 0) {
debug_printf("error parsing header: %d", tmp);
printf("error parsing header: %d\n", tmp);
return tmp;
}
file->position += tmp;
@@ -104,7 +104,7 @@ asf_init(asf_file_t *file)
tmp = asf_parse_data(file);
if (tmp < 0) {
debug_printf("error parsing data object: %d", tmp);
printf("error parsing data object: %d\n", tmp);
return tmp;
}
file->position += tmp;
@@ -124,7 +124,7 @@ asf_init(asf_file_t *file)
file->index_position < file->file_size && !file->index) {
tmp = asf_parse_index(file);
if (tmp < 0) {
debug_printf("Error finding index object! %d", tmp);
printf("Error finding index object! %d\n", tmp);
break;
}
@@ -152,7 +152,7 @@ asf_init(asf_file_t *file)
for (tmp = 0; tmp < ASF_MAX_STREAMS; tmp++) {
if (file->streams[tmp].type != ASF_STREAM_TYPE_NONE) {
debug_printf("stream %d of type %d found!", tmp, file->streams[tmp].type);
debug_printf("stream %d of type %s found!", tmp, file->streams[tmp].type == 1 ? "Audio" : file->streams[tmp].type == 2 ? "Video" : "Unknown");
}
}
@@ -269,7 +269,14 @@ asf_seek_to_msec(asf_file_t *file, int64_t msec)
return ASF_ERROR_SEEK;
}
if (file->index) {
if (file->index && file->index->entry_count == 0) {
// Some sort of Constant packet size?
/* Calculate current packet from index header */
packet = msec * 10000 / file->index->entry_time_interval;
new_msec = msec;
} else if (file->index && file->index->entry_count > 0) {
uint32_t index_entry;
/* Fetch current packet from index entry structure */
@@ -363,6 +363,7 @@ asf_parse_index(asf_file_t *file)
/* read the raw data of an index header */
tmp = asf_byteio_read(idata, 56, iostream);
if (tmp < 0) {
printf("Could not read index header\n");
return tmp;
}
@@ -392,6 +393,18 @@ asf_parse_index(asf_file_t *file)
index->max_packet_count = asf_byteio_getDWLE(idata + 48);
index->entry_count = asf_byteio_getDWLE(idata + 52);
printf("INDEX\n");
printf("Total Index Entries %d\n",index->entry_count);
printf("Index Size in bytes %Ld\n",index->size);
printf("Index Max Packet Count %d\n",index->max_packet_count);
printf("Index Entry Time Interval %Ld\n",index->entry_time_interval);
if (index->entry_count == 0) {
printf("Index has no entries\n");
file->index = index;
return index->size;
}
if (index->entry_count * 6 + 56 > index->size) {
free(index);
return ASF_ERROR_INVALID_LENGTH;
@@ -403,8 +416,10 @@ asf_parse_index(asf_file_t *file)
free(index);
return ASF_ERROR_OUTOFMEM;
}
tmp = asf_byteio_read(entry_data, entry_data_size, iostream);
if (tmp < 0) {
printf("Could not read entry data\n");
free(index);
free(entry_data);
return tmp;