r1013: Select the entire clip title when a clip is edited or created.
[cinelerra_cv/ct.git] / quicktime / stco.c
blob4c7a2b3716b1dea569fddd2567861e63e2b5d1c7
1 #include "funcprotos.h"
2 #include "quicktime.h"
6 void quicktime_stco_init(quicktime_stco_t *stco)
8 stco->version = 0;
9 stco->flags = 0;
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)
34 int i;
35 printf(" chunk offset\n");
36 printf(" version %d\n", stco->version);
37 printf(" flags %d\n", stco->flags);
38 printf(" total_entries %d\n", stco->total_entries);
39 for(i = 0; i < stco->total_entries; i++)
41 printf(" offset %d %llx\n", i, stco->table[i].offset);
45 void quicktime_read_stco(quicktime_t *file, quicktime_stco_t *stco)
47 int i;
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)
61 int i;
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)
75 int i;
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);
91 // Chunk starts at 1
92 void quicktime_update_stco(quicktime_stco_t *stco, long chunk, int64_t offset)
94 long i;
95 if(chunk <= 0)
96 printf("quicktime_update_stco chunk must start at 1. chunk=%d\n",
97 chunk);
99 if(chunk > stco->entries_allocated)
101 stco->entries_allocated = chunk * 2;
102 //printf("quicktime_update_stco 1\n");
103 stco->table = (quicktime_stco_table_t*)realloc(stco->table,
104 sizeof(quicktime_stco_table_t) * stco->entries_allocated);
105 //printf("quicktime_update_stco 2\n");
108 stco->table[chunk - 1].offset = offset;
109 if(chunk > stco->total_entries) stco->total_entries = chunk;