Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / quicktime / stbl.c
bloba89e8166916a5bda053342ea963eb21c6f4df4f2
1 #include "funcprotos.h"
2 #include "quicktime.h"
4 void quicktime_stbl_init(quicktime_stbl_t *stbl)
6 stbl->version = 0;
7 stbl->flags = 0;
8 quicktime_stsd_init(&(stbl->stsd));
9 quicktime_stts_init(&(stbl->stts));
10 quicktime_stss_init(&(stbl->stss));
11 quicktime_stsc_init(&(stbl->stsc));
12 quicktime_stsz_init(&(stbl->stsz));
13 quicktime_stco_init(&(stbl->stco));
16 void quicktime_stbl_init_video(quicktime_t *file,
17 quicktime_stbl_t *stbl,
18 int frame_w,
19 int frame_h,
20 int time_scale,
21 float frame_rate,
22 char *compressor)
24 //printf("quicktime_stbl_init_video 1\n");
25 quicktime_stsd_init_video(file, &(stbl->stsd), frame_w, frame_h, frame_rate, compressor);
26 //printf("quicktime_stbl_init_video 1 %d %f\n", time_scale, frame_rate);
27 quicktime_stts_init_video(file, &(stbl->stts), time_scale, frame_rate);
28 //printf("quicktime_stbl_init_video 1\n");
29 quicktime_stsc_init_video(file, &(stbl->stsc));
30 //printf("quicktime_stbl_init_video 1\n");
31 quicktime_stsz_init_video(file, &(stbl->stsz));
32 //printf("quicktime_stbl_init_video 1\n");
33 quicktime_stco_init_common(file, &(stbl->stco));
34 //printf("quicktime_stbl_init_video 2\n");
38 void quicktime_stbl_init_audio(quicktime_t *file,
39 quicktime_stbl_t *stbl,
40 int channels,
41 int sample_rate,
42 int bits,
43 char *compressor)
45 quicktime_stsd_init_audio(file, &(stbl->stsd),
46 channels,
47 sample_rate,
48 bits,
49 compressor);
50 quicktime_stts_init_audio(file, &(stbl->stts), sample_rate);
51 quicktime_stsc_init_audio(file, &(stbl->stsc), sample_rate);
52 quicktime_stsz_init_audio(file, &(stbl->stsz), channels, bits, compressor);
53 quicktime_stco_init_common(file, &(stbl->stco));
56 void quicktime_stbl_delete(quicktime_stbl_t *stbl)
58 quicktime_stsd_delete(&(stbl->stsd));
59 quicktime_stts_delete(&(stbl->stts));
60 quicktime_stss_delete(&(stbl->stss));
61 quicktime_stsc_delete(&(stbl->stsc));
62 quicktime_stsz_delete(&(stbl->stsz));
63 quicktime_stco_delete(&(stbl->stco));
66 void quicktime_stbl_dump(void *minf_ptr, quicktime_stbl_t *stbl)
68 printf(" sample table\n");
69 quicktime_stsd_dump(minf_ptr, &(stbl->stsd));
70 quicktime_stts_dump(&(stbl->stts));
71 quicktime_stss_dump(&(stbl->stss));
72 quicktime_stsc_dump(&(stbl->stsc));
73 quicktime_stsz_dump(&(stbl->stsz));
74 quicktime_stco_dump(&(stbl->stco));
77 int quicktime_read_stbl(quicktime_t *file, quicktime_minf_t *minf, quicktime_stbl_t *stbl, quicktime_atom_t *parent_atom)
79 quicktime_atom_t leaf_atom;
83 quicktime_atom_read_header(file, &leaf_atom);
85 //printf("quicktime_read_stbl 1\n");
86 /* mandatory */
87 if(quicktime_atom_is(&leaf_atom, "stsd"))
89 quicktime_read_stsd(file, minf, &(stbl->stsd));
90 /* Some codecs store extra information at the end of this */
91 quicktime_atom_skip(file, &leaf_atom);
93 else
94 if(quicktime_atom_is(&leaf_atom, "stts"))
95 { quicktime_read_stts(file, &(stbl->stts)); }
96 else
97 if(quicktime_atom_is(&leaf_atom, "stss"))
98 { quicktime_read_stss(file, &(stbl->stss)); }
99 else
100 if(quicktime_atom_is(&leaf_atom, "stsc"))
102 quicktime_read_stsc(file, &(stbl->stsc));
104 * Minolta DimageZ3 pads stsc with zeroes
105 * so we need to jump to next atom explicitly
107 quicktime_atom_skip(file, &leaf_atom);
109 else
110 if(quicktime_atom_is(&leaf_atom, "stsz"))
111 { quicktime_read_stsz(file, &(stbl->stsz)); }
112 else
113 if(quicktime_atom_is(&leaf_atom, "co64"))
114 { quicktime_read_stco64(file, &(stbl->stco)); }
115 else
116 if(quicktime_atom_is(&leaf_atom, "stco"))
117 { quicktime_read_stco(file, &(stbl->stco)); }
118 else
120 quicktime_atom_skip(file, &leaf_atom);
122 }while(quicktime_position(file) < parent_atom->end);
124 return 0;
127 void quicktime_write_stbl(quicktime_t *file, quicktime_minf_t *minf, quicktime_stbl_t *stbl)
129 quicktime_atom_t atom;
130 quicktime_atom_write_header(file, &atom, "stbl");
132 quicktime_write_stsd(file, minf, &(stbl->stsd));
133 quicktime_write_stts(file, &(stbl->stts));
134 quicktime_write_stss(file, &(stbl->stss));
135 quicktime_write_stsc(file, &(stbl->stsc));
136 quicktime_write_stsz(file, &(stbl->stsz));
137 quicktime_write_stco(file, &(stbl->stco));
139 quicktime_atom_write_footer(file, &atom);