r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / quicktime / udta.c
blobf5942708302bc4dcf1649ec253e01585e6c21251
1 #include "funcprotos.h"
2 #include "quicktime.h"
4 #define DEFAULT_INFO "Made with Quicktime for Linux"
6 int quicktime_udta_init(quicktime_udta_t *udta)
8 udta->copyright = 0;
9 udta->copyright_len = 0;
10 udta->name = 0;
11 udta->name_len = 0;
13 udta->info = malloc(strlen(DEFAULT_INFO) + 1);
14 udta->info_len = strlen(DEFAULT_INFO);
15 sprintf(udta->info, DEFAULT_INFO);
16 return 0;
19 int quicktime_udta_delete(quicktime_udta_t *udta)
21 if(udta->copyright_len)
23 free(udta->copyright);
25 if(udta->name_len)
27 free(udta->name);
29 if(udta->info_len)
31 free(udta->info);
33 // quicktime_udta_init(udta);
34 return 0;
37 void quicktime_udta_dump(quicktime_udta_t *udta)
39 printf(" user data (udta)\n");
40 if(udta->copyright_len) printf(" copyright -> %s\n", udta->copyright);
41 if(udta->name_len) printf(" name -> %s\n", udta->name);
42 if(udta->info_len) printf(" info -> %s\n", udta->info);
45 int quicktime_read_udta(quicktime_t *file, quicktime_udta_t *udta, quicktime_atom_t *udta_atom)
47 quicktime_atom_t leaf_atom;
48 int result = 0;
52 quicktime_atom_read_header(file, &leaf_atom);
54 if(quicktime_atom_is(&leaf_atom, "©cpy"))
56 result += quicktime_read_udta_string(file, &(udta->copyright), &(udta->copyright_len));
58 else
59 if(quicktime_atom_is(&leaf_atom, "©nam"))
61 result += quicktime_read_udta_string(file, &(udta->name), &(udta->name_len));
63 else
64 if(quicktime_atom_is(&leaf_atom, "©inf"))
66 result += quicktime_read_udta_string(file, &(udta->info), &(udta->info_len));
68 else
69 quicktime_atom_skip(file, &leaf_atom);
70 }while(quicktime_position(file) < udta_atom->end);
72 return result;
75 void quicktime_write_udta(quicktime_t *file, quicktime_udta_t *udta)
77 quicktime_atom_t atom, subatom;
78 quicktime_atom_write_header(file, &atom, "udta");
80 if(udta->copyright_len)
82 quicktime_atom_write_header(file, &subatom, "©cpy");
83 quicktime_write_udta_string(file, udta->copyright, udta->copyright_len);
84 quicktime_atom_write_footer(file, &subatom);
87 if(udta->name_len)
89 quicktime_atom_write_header(file, &subatom, "©nam");
90 quicktime_write_udta_string(file, udta->name, udta->name_len);
91 quicktime_atom_write_footer(file, &subatom);
94 if(udta->info_len)
96 quicktime_atom_write_header(file, &subatom, "©inf");
97 quicktime_write_udta_string(file, udta->info, udta->info_len);
98 quicktime_atom_write_footer(file, &subatom);
101 quicktime_atom_write_footer(file, &atom);
104 int quicktime_read_udta_string(quicktime_t *file, char **string, int *size)
106 int result;
108 if(*size) free(*string);
109 *size = quicktime_read_int16(file); /* Size of string */
110 quicktime_read_int16(file); /* Discard language code */
111 *string = malloc(*size + 1);
112 result = quicktime_read_data(file, *string, *size);
113 (*string)[*size] = 0;
114 return !result;
117 int quicktime_write_udta_string(quicktime_t *file, char *string, int size)
119 int new_size = strlen(string);
120 int result;
122 quicktime_write_int16(file, new_size); /* String size */
123 quicktime_write_int16(file, 0); /* Language code */
124 result = quicktime_write_data(file, string, new_size);
125 return !result;
128 int quicktime_set_udta_string(char **string, int *size, char *new_string)
130 if(*size) free(*string);
131 *size = strlen(new_string) + 1;
132 *string = malloc(*size);
133 strcpy(*string, new_string);
134 return 0;