1 #include "funcprotos.h"
4 #define DEFAULT_INFO "Made with Quicktime for Linux"
6 int quicktime_udta_init(quicktime_udta_t
*udta
)
9 udta
->copyright_len
= 0;
13 udta
->info
= malloc(strlen(DEFAULT_INFO
) + 1);
14 udta
->info_len
= strlen(DEFAULT_INFO
);
15 sprintf(udta
->info
, DEFAULT_INFO
);
19 int quicktime_udta_delete(quicktime_udta_t
*udta
)
21 if(udta
->copyright_len
)
23 free(udta
->copyright
);
33 // quicktime_udta_init(udta);
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
;
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
));
59 if(quicktime_atom_is(&leaf_atom
, "©nam"))
61 result
+= quicktime_read_udta_string(file
, &(udta
->name
), &(udta
->name_len
));
64 if(quicktime_atom_is(&leaf_atom
, "©inf"))
66 result
+= quicktime_read_udta_string(file
, &(udta
->info
), &(udta
->info_len
));
69 quicktime_atom_skip(file
, &leaf_atom
);
70 }while(quicktime_position(file
) < udta_atom
->end
);
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
);
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
);
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
)
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;
117 int quicktime_write_udta_string(quicktime_t
*file
, char *string
, int size
)
119 int new_size
= strlen(string
);
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
);
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
);