1 #include "funcprotos.h"
6 void quicktime_stco_init(quicktime_stco_t *stco)
10 stco->total_entries = 0;
11 stco->entries_allocated = 0;
14 void quicktime_stco_delete(quicktime_stco_t *stco)
16 if(stco->total_entries) free(stco->table);
17 stco->total_entries = 0;
18 stco->entries_allocated = 0;
21 void quicktime_stco_init_common(quicktime_t *file, quicktime_stco_t *stco)
23 if(!stco->entries_allocated)
25 stco->entries_allocated = 2048;
26 stco->total_entries = 0;
27 stco->table = (quicktime_stco_table_t*)malloc(sizeof(quicktime_stco_table_t) * stco->entries_allocated);
28 /*printf("quicktime_stco_init_common %x\n", stco->table); */
32 void quicktime_stco_dump(quicktime_stco_t *stco)
35 printf(" chunk offset\n");
36 printf(" version %d\n", stco->version);
37 printf(" flags %ld\n", stco->flags);
38 printf(" total_entries %ld\n", stco->total_entries);
39 for(i = 0; i < stco->total_entries; i++)
41 printf(" offset %d 0x%jx\n", i, stco->table[i].offset);
45 void quicktime_read_stco(quicktime_t *file, quicktime_stco_t *stco)
48 stco->version = quicktime_read_char(file);
49 stco->flags = quicktime_read_int24(file);
50 stco->total_entries = quicktime_read_int32(file);
51 stco->entries_allocated = stco->total_entries;
52 stco->table = (quicktime_stco_table_t*)calloc(1, sizeof(quicktime_stco_table_t) * stco->entries_allocated);
53 for(i = 0; i < stco->total_entries; i++)
55 stco->table[i].offset = quicktime_read_uint32(file);
59 void quicktime_read_stco64(quicktime_t *file, quicktime_stco_t *stco)
62 stco->version = quicktime_read_char(file);
63 stco->flags = quicktime_read_int24(file);
64 stco->total_entries = quicktime_read_int32(file);
65 stco->entries_allocated = stco->total_entries;
66 stco->table = (quicktime_stco_table_t*)calloc(1, sizeof(quicktime_stco_table_t) * stco->entries_allocated);
67 for(i = 0; i < stco->total_entries; i++)
69 stco->table[i].offset = quicktime_read_int64(file);
73 void quicktime_write_stco(quicktime_t *file, quicktime_stco_t *stco)
76 quicktime_atom_t atom;
77 // quicktime_atom_write_header(file, &atom, "stco");
78 quicktime_atom_write_header(file, &atom, "co64");
80 quicktime_write_char(file, stco->version);
81 quicktime_write_int24(file, stco->flags);
82 quicktime_write_int32(file, stco->total_entries);
83 for(i = 0; i < stco->total_entries; i++)
85 quicktime_write_int64(file, stco->table[i].offset);
88 quicktime_atom_write_footer(file, &atom);
92 void quicktime_update_stco(quicktime_stco_t *stco, long chunk, int64_t offset)
95 printf("quicktime_update_stco chunk must start at 1. chunk=%ld\n", chunk);
97 if(chunk > stco->entries_allocated)
99 stco->entries_allocated = chunk * 2;
100 //printf("quicktime_update_stco 1\n");
101 stco->table = (quicktime_stco_table_t*)realloc(stco->table,
102 sizeof(quicktime_stco_table_t) * stco->entries_allocated);
103 //printf("quicktime_update_stco 2\n");
106 stco->table[chunk - 1].offset = offset;
107 if(chunk > stco->total_entries) stco->total_entries = chunk;