00001 #include "funcprotos.h"
00002 #include "quicktime.h"
00003
00004
00005
00006 void quicktime_stco_init(quicktime_stco_t *stco)
00007 {
00008 stco->version = 0;
00009 stco->flags = 0;
00010 stco->total_entries = 0;
00011 stco->entries_allocated = 0;
00012 }
00013
00014 void quicktime_stco_delete(quicktime_stco_t *stco)
00015 {
00016 if(stco->total_entries) free(stco->table);
00017 stco->total_entries = 0;
00018 stco->entries_allocated = 0;
00019 }
00020
00021 void quicktime_stco_init_common(quicktime_t *file, quicktime_stco_t *stco)
00022 {
00023 if(!stco->entries_allocated)
00024 {
00025 stco->entries_allocated = 2048;
00026 stco->total_entries = 0;
00027 stco->table = (quicktime_stco_table_t*)malloc(sizeof(quicktime_stco_table_t) * stco->entries_allocated);
00028
00029 }
00030 }
00031
00032 void quicktime_stco_dump(quicktime_stco_t *stco)
00033 {
00034 int i;
00035 printf(" chunk offset\n");
00036 printf(" version %d\n", stco->version);
00037 printf(" flags %d\n", stco->flags);
00038 printf(" total_entries %d\n", stco->total_entries);
00039 for(i = 0; i < stco->total_entries; i++)
00040 {
00041 printf(" offset %d %llx\n", i, stco->table[i].offset);
00042 }
00043 }
00044
00045 void quicktime_read_stco(quicktime_t *file, quicktime_stco_t *stco)
00046 {
00047 int i;
00048 stco->version = quicktime_read_char(file);
00049 stco->flags = quicktime_read_int24(file);
00050 stco->total_entries = quicktime_read_int32(file);
00051 stco->entries_allocated = stco->total_entries;
00052 stco->table = (quicktime_stco_table_t*)calloc(1, sizeof(quicktime_stco_table_t) * stco->entries_allocated);
00053 for(i = 0; i < stco->total_entries; i++)
00054 {
00055 stco->table[i].offset = quicktime_read_uint32(file);
00056 }
00057 }
00058
00059 void quicktime_read_stco64(quicktime_t *file, quicktime_stco_t *stco)
00060 {
00061 int i;
00062 stco->version = quicktime_read_char(file);
00063 stco->flags = quicktime_read_int24(file);
00064 stco->total_entries = quicktime_read_int32(file);
00065 stco->entries_allocated = stco->total_entries;
00066 stco->table = (quicktime_stco_table_t*)calloc(1, sizeof(quicktime_stco_table_t) * stco->entries_allocated);
00067 for(i = 0; i < stco->total_entries; i++)
00068 {
00069 stco->table[i].offset = quicktime_read_int64(file);
00070 }
00071 }
00072
00073 void quicktime_write_stco(quicktime_t *file, quicktime_stco_t *stco)
00074 {
00075 int i;
00076 quicktime_atom_t atom;
00077
00078 quicktime_atom_write_header(file, &atom, "co64");
00079
00080 quicktime_write_char(file, stco->version);
00081 quicktime_write_int24(file, stco->flags);
00082 quicktime_write_int32(file, stco->total_entries);
00083 for(i = 0; i < stco->total_entries; i++)
00084 {
00085 quicktime_write_int64(file, stco->table[i].offset);
00086 }
00087
00088 quicktime_atom_write_footer(file, &atom);
00089 }
00090
00091
00092 void quicktime_update_stco(quicktime_stco_t *stco, long chunk, int64_t offset)
00093 {
00094 long i;
00095 if(chunk <= 0)
00096 printf("quicktime_update_stco chunk must start at 1. chunk=%d\n",
00097 chunk);
00098
00099 if(chunk > stco->entries_allocated)
00100 {
00101 stco->entries_allocated = chunk * 2;
00102
00103 stco->table = (quicktime_stco_table_t*)realloc(stco->table,
00104 sizeof(quicktime_stco_table_t) * stco->entries_allocated);
00105
00106 }
00107
00108 stco->table[chunk - 1].offset = offset;
00109 if(chunk > stco->total_entries) stco->total_entries = chunk;
00110 }
00111