1 #include "funcprotos.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
)
15 udta
->copyright_len
= 0;
19 udta
->require_len
= 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
);
29 int quicktime_udta_delete(quicktime_udta_t
*udta
)
31 if(udta
->copyright_len
)
33 free(udta
->copyright
);
51 // quicktime_udta_init(udta);
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
;
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
));
80 if(quicktime_atom_is(&leaf_atom
, nam_tag
))
82 result
+= quicktime_read_udta_string(file
, &(udta
->name
), &(udta
->name_len
));
85 if(quicktime_atom_is(&leaf_atom
, inf_tag
))
87 result
+= quicktime_read_udta_string(file
, &(udta
->info
), &(udta
->info_len
));
90 if(quicktime_atom_is(&leaf_atom
, req_tag
))
92 result
+= quicktime_read_udta_string(file
, &(udta
->require
), &(udta
->require_len
));
95 if(quicktime_atom_is(&leaf_atom
, enc_tag
))
97 result
+= quicktime_read_udta_string(file
, &(udta
->encoder
), &(udta
->encoder_len
));
101 quicktime_atom_skip(file
, &leaf_atom
);
103 }while(quicktime_position(file
) < udta_atom
->end
);
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
);
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
);
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
)
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;
165 int quicktime_write_udta_string(quicktime_t
*file
, char *string
, int size
)
167 int new_size
= strlen(string
);
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
);
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
);