Mercurial > audlegacy-plugins
comparison src/demac/apev2.c @ 2200:d10f13536b94
removed ugly callback
author | Eugene Zagidullin <e.asphyx@gmail.com> |
---|---|
date | Fri, 30 Nov 2007 04:55:41 +0300 |
parents | 8b3c2fe608c9 |
children | ed6c81bd9016 |
comparison
equal
deleted
inserted
replaced
2199:8b3c2fe608c9 | 2200:d10f13536b94 |
---|---|
39 | 39 |
40 #define FLAGS_HEADER_EXISTS (1 << 31) | 40 #define FLAGS_HEADER_EXISTS (1 << 31) |
41 #define FLAGS_HEADER (1 << 29) | 41 #define FLAGS_HEADER (1 << 29) |
42 #define APE_SIGNATURE MKTAG64('A', 'P', 'E', 'T', 'A', 'G', 'E', 'X') | 42 #define APE_SIGNATURE MKTAG64('A', 'P', 'E', 'T', 'A', 'G', 'E', 'X') |
43 | 43 |
44 typedef struct { | 44 /*typedef struct { |
45 int tag_items; | 45 int tag_items; |
46 int tag_size; | 46 int tag_size; |
47 VFSFile *vfd; | 47 VFSFile *vfd; |
48 } iterator_pvt_t; | 48 } iterator_pvt_t;*/ |
49 | 49 |
50 mowgli_dictionary_t* parse_apev2_tag(VFSFile *vfd) { | 50 mowgli_dictionary_t* parse_apev2_tag(VFSFile *vfd) { |
51 unsigned char tmp[TMP_BUFSIZE+1]; | 51 unsigned char tmp[TMP_BUFSIZE+1]; |
52 unsigned char tmp2[TMP_BUFSIZE+1]; | 52 unsigned char tmp2[TMP_BUFSIZE+1]; |
53 guint64 signature; | 53 guint64 signature; |
127 put_le32(items, vfd); | 127 put_le32(items, vfd); |
128 put_le32(flags, vfd); | 128 put_le32(flags, vfd); |
129 aud_vfs_fwrite(&filling, 1, 8, vfd); | 129 aud_vfs_fwrite(&filling, 1, 8, vfd); |
130 } | 130 } |
131 | 131 |
132 static int foreach_cb (mowgli_dictionary_elem_t *delem, void *privdata) { | |
133 iterator_pvt_t *s = (iterator_pvt_t*)privdata; | |
134 guint32 item_size, item_flags=0; | |
135 if (s->vfd == NULL) { | |
136 | |
137 if(strlen((char*)(delem->data)) != 0) { | |
138 s->tag_items++; | |
139 s->tag_size += strlen((char*)(delem->key)) + strlen((char*)(delem->data)) + 9; /* length in bytes not symbols */ | |
140 } | |
141 | |
142 } else { | |
143 | |
144 if( (item_size = strlen((char*)delem->data)) != 0 ) { | |
145 #ifdef DEBUG | |
146 fprintf(stderr, "Writing field %s = %s\n", (char*)delem->key, (char*)delem->data); | |
147 #endif | |
148 put_le32(item_size, s->vfd); | |
149 put_le32(item_flags, s->vfd); /* all set to zero */ | |
150 aud_vfs_fwrite(delem->key, 1, strlen((char*)delem->key) + 1, s->vfd); /* null-terminated */ | |
151 aud_vfs_fwrite(delem->data, 1, item_size, s->vfd); | |
152 } | |
153 } | |
154 | |
155 return 1; | |
156 } | |
157 | |
158 gboolean write_apev2_tag(VFSFile *vfd, mowgli_dictionary_t *tag) { | 132 gboolean write_apev2_tag(VFSFile *vfd, mowgli_dictionary_t *tag) { |
159 guint64 signature; | 133 guint64 signature; |
160 guint32 tag_version; | 134 guint32 tag_version; |
161 guint32 tag_size, tag_items = 0, tag_flags; | 135 guint32 tag_size, tag_items = 0, tag_flags; |
136 guint32 item_size, item_flags=0; | |
162 long file_size; | 137 long file_size; |
138 void *current_field; | |
163 | 139 |
164 if (vfd == NULL || tag == NULL) return FALSE; | 140 if (vfd == NULL || tag == NULL) return FALSE; |
165 | 141 |
166 aud_vfs_fseek(vfd, -32, SEEK_END); | 142 aud_vfs_fseek(vfd, -32, SEEK_END); |
167 signature = get_le64(vfd); | 143 signature = get_le64(vfd); |
192 #endif | 168 #endif |
193 if(aud_vfs_truncate(vfd, file_size) < 0) return FALSE; | 169 if(aud_vfs_truncate(vfd, file_size) < 0) return FALSE; |
194 } | 170 } |
195 aud_vfs_fseek(vfd, 0, SEEK_END); | 171 aud_vfs_fseek(vfd, 0, SEEK_END); |
196 | 172 |
197 iterator_pvt_t state; | 173 mowgli_dictionary_iteration_state_t state; |
198 memset(&state, 0, sizeof(iterator_pvt_t)); | |
199 | 174 |
200 state.tag_size = 32; /* footer size */ | 175 tag_size = 32; /* footer size */ |
201 mowgli_dictionary_foreach(tag, foreach_cb, &state); /* let's count tag size */ | 176 /* let's count tag size */ |
202 tag_size = state.tag_size; | 177 tag_items = 0; |
203 tag_items = state.tag_items; | 178 MOWGLI_DICTIONARY_FOREACH(current_field, &state, tag) { |
179 if(strlen((char*)current_field) != 0) { | |
180 tag_items++; | |
181 tag_size += strlen((char*)state.cur->key) + strlen((char*)current_field) + 9; /* length in bytes not symbols */ | |
182 } | |
183 } | |
204 | 184 |
205 if(tag_items == 0) { | 185 if(tag_items == 0) { |
206 #ifdef DEBUG | 186 #ifdef DEBUG |
207 fprintf(stderr, "tag stripped, all done\n"); | 187 fprintf(stderr, "tag stripped, all done\n"); |
208 #endif | 188 #endif |
209 return TRUE; /* old tag is stripped, new one is empty */ | 189 return TRUE; /* old tag is stripped, new one is empty */ |
210 } | 190 } |
211 | 191 |
212 write_header_or_footer(2000, tag_size, tag_items, FLAGS_HEADER | FLAGS_HEADER_EXISTS, vfd); /* header */ | 192 write_header_or_footer(2000, tag_size, tag_items, FLAGS_HEADER | FLAGS_HEADER_EXISTS, vfd); /* header */ |
213 state.vfd = vfd; | 193 MOWGLI_DICTIONARY_FOREACH(current_field, &state, tag) { |
214 mowgli_dictionary_foreach(tag, foreach_cb, &state); | 194 if( (item_size = strlen((char*)current_field)) != 0 ) { |
195 #ifdef DEBUG | |
196 fprintf(stderr, "Writing field %s = %s\n", (char*)state.cur->key, (char*)current_field); | |
197 #endif | |
198 put_le32(item_size, vfd); | |
199 put_le32(item_flags, vfd); /* all set to zero */ | |
200 aud_vfs_fwrite(state.cur->key, 1, strlen((char*)state.cur->key) + 1, vfd); /* null-terminated */ | |
201 aud_vfs_fwrite(current_field, 1, item_size, vfd); | |
202 } | |
203 } | |
215 write_header_or_footer(2000, tag_size, tag_items, FLAGS_HEADER_EXISTS, vfd); /* footer */ | 204 write_header_or_footer(2000, tag_size, tag_items, FLAGS_HEADER_EXISTS, vfd); /* footer */ |
216 | 205 |
217 return TRUE; | 206 return TRUE; |
218 } | 207 } |
219 | 208 |