Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / quicktime / udta.c
blob30f4d6cfa1c4d07ec9f6d4f562a46df9c7772118
1 #include "funcprotos.h"
2 #include "quicktime.h"
3 #include <string.h>
5 #define DEFAULT_INFO "Made with Quicktime for Linux"
6 static unsigned char cpy_tag[] = {0xa9, 'c', 'p', 'y'};
7 static unsigned char nam_tag[] = {0xa9, 'n', 'a', 'm'};
8 static unsigned char inf_tag[] = {0xa9, 'i', 'n', 'f'};
9 static unsigned char req_tag[] = {0xa9, 'r', 'e', 'q'};
10 static unsigned char enc_tag[] = {0xa9, 'e', 'n', 'c'};
12 int quicktime_udta_init(quicktime_udta_t *udta)
14 udta->copyright = 0;
15 udta->copyright_len = 0;
16 udta->name = 0;
17 udta->name_len = 0;
18 udta->require = 0;
19 udta->require_len = 0;
20 udta->encoder = 0;
21 udta->encoder_len = 0;
23 udta->info = malloc(strlen(DEFAULT_INFO) + 1);
24 udta->info_len = strlen(DEFAULT_INFO);
25 sprintf(udta->info, DEFAULT_INFO);
26 return 0;
29 int quicktime_udta_delete(quicktime_udta_t *udta)
31 if(udta->copyright_len)
33 free(udta->copyright);
35 if(udta->name_len)
37 free(udta->name);
39 if(udta->info_len)
41 free(udta->info);
43 if(udta->require_len)
45 free(udta->require);
47 if(udta->encoder_len)
49 free(udta->encoder);
51 // quicktime_udta_init(udta);
52 return 0;
55 void quicktime_udta_dump(quicktime_udta_t *udta)
57 printf(" user data (udta)\n");
58 if(udta->copyright_len) printf(" copyright -> %s\n", udta->copyright);
59 if(udta->name_len) printf(" name -> %s\n", udta->name);
60 if(udta->info_len) printf(" info -> %s\n", udta->info);
61 if(udta->require_len) printf(" require -> %s\n", udta->require);
62 if(udta->encoder_len) printf(" encoder -> %s\n", udta->encoder);
65 int quicktime_read_udta(quicktime_t *file, quicktime_udta_t *udta, quicktime_atom_t *udta_atom)
67 quicktime_atom_t leaf_atom;
68 int result = 0;
72 quicktime_atom_read_header(file, &leaf_atom);
75 if(quicktime_atom_is(&leaf_atom, cpy_tag))
77 result += quicktime_read_udta_string(file, &(udta->copyright), &(udta->copyright_len));
79 else
80 if(quicktime_atom_is(&leaf_atom, nam_tag))
82 result += quicktime_read_udta_string(file, &(udta->name), &(udta->name_len));
84 else
85 if(quicktime_atom_is(&leaf_atom, inf_tag))
87 result += quicktime_read_udta_string(file, &(udta->info), &(udta->info_len));
89 else
90 if(quicktime_atom_is(&leaf_atom, req_tag))
92 result += quicktime_read_udta_string(file, &(udta->require), &(udta->require_len));
94 else
95 if(quicktime_atom_is(&leaf_atom, enc_tag))
97 result += quicktime_read_udta_string(file, &(udta->encoder), &(udta->encoder_len));
99 else
101 quicktime_atom_skip(file, &leaf_atom);
103 }while(quicktime_position(file) < udta_atom->end);
106 return result;
109 void quicktime_write_udta(quicktime_t *file, quicktime_udta_t *udta)
111 quicktime_atom_t atom, subatom;
112 quicktime_atom_write_header(file, &atom, "udta");
114 if(udta->copyright_len)
116 quicktime_atom_write_header(file, &subatom, cpy_tag);
117 quicktime_write_udta_string(file, udta->copyright, udta->copyright_len);
118 quicktime_atom_write_footer(file, &subatom);
121 if(udta->name_len)
123 quicktime_atom_write_header(file, &subatom, nam_tag);
124 quicktime_write_udta_string(file, udta->name, udta->name_len);
125 quicktime_atom_write_footer(file, &subatom);
128 if(udta->info_len)
130 quicktime_atom_write_header(file, &subatom, inf_tag);
131 quicktime_write_udta_string(file, udta->info, udta->info_len);
132 quicktime_atom_write_footer(file, &subatom);
135 if(udta->require_len)
137 quicktime_atom_write_header(file, &subatom, req_tag);
138 quicktime_write_udta_string(file, udta->require, udta->require_len);
139 quicktime_atom_write_footer(file, &subatom);
142 if(udta->encoder_len)
144 quicktime_atom_write_header(file, &subatom, enc_tag);
145 quicktime_write_udta_string(file, udta->encoder, udta->encoder_len);
146 quicktime_atom_write_footer(file, &subatom);
149 quicktime_atom_write_footer(file, &atom);
152 int quicktime_read_udta_string(quicktime_t *file, char **string, int *size)
154 int result;
156 if(*size) free(*string);
157 *size = quicktime_read_int16(file); /* Size of string */
158 quicktime_read_int16(file); /* Discard language code */
159 *string = malloc(*size + 1);
160 result = quicktime_read_data(file, *string, *size);
161 (*string)[*size] = 0;
162 return !result;
165 int quicktime_write_udta_string(quicktime_t *file, char *string, int size)
167 int new_size = strlen(string);
168 int result;
170 quicktime_write_int16(file, new_size); /* String size */
171 quicktime_write_int16(file, 0); /* Language code */
172 result = quicktime_write_data(file, string, new_size);
173 return !result;
176 int quicktime_set_udta_string(char **string, int *size, char *new_string)
178 if(*size) free(*string);
179 *size = strlen(new_string) + 1;
180 *string = malloc(*size);
181 strcpy(*string, new_string);
182 return 0;