return ret;
}
-struct stdmeta_entry {
- const char *atom;
- const char *name;
-};
-
-static const char *find_standard_meta(const char *name)
-{
- const struct stdmeta_entry stdmetas[] = {
- {"\xA9" "nam", "title"},
- {"\xA9" "ART", "artist"},
- {"\xA9" "alb", "album"},
- {"\xA9" "day", "date"},
- {"\xA9" "cmt", "comment"},
- };
-
- for (unsigned n = 0; n < ARRAY_SIZE(stdmetas); n++)
- if (!strcasecmp(name, stdmetas[n].name))
- return stdmetas[n].atom;
- return NULL;
-}
-
-static uint32_t create_ilst(const struct mp4_metadata *meta, void **out_buffer,
- uint32_t * out_size)
+static void *create_ilst(const struct mp4_metadata *meta, uint32_t *out_size)
{
struct membuffer *buf = membuffer_create();
- unsigned metaptr;
-
- for (metaptr = 0; metaptr < meta->count; metaptr++) {
- struct mp4_tag *tag = meta->tags + metaptr;
- const char *std_meta_atom = find_standard_meta(tag->item);
- if (std_meta_atom)
- membuffer_write_std_tag(buf, std_meta_atom, tag->value);
+ unsigned n;
+
+ for (n = 0; n < meta->count; n++) {
+ struct mp4_tag *tag = meta->tags + n;
+ const char *atom_name;
+ if (!strcasecmp(tag->item, "title"))
+ atom_name = "\xA9" "nam";
+ else if (!strcasecmp(tag->item, "artist"))
+ atom_name = "\xA9" "ART";
+ else if (!strcasecmp(tag->item, "album"))
+ atom_name = "\xA9" "alb";
+ else if (!strcasecmp(tag->item, "date"))
+ atom_name = "\xA9" "day";
+ else if (!strcasecmp(tag->item, "comment"))
+ atom_name = "\xA9" "cmt";
else
- PARA_ERROR_LOG("invalid tag item: %s\n", tag->item);
+ assert(false);
+ membuffer_write_std_tag(buf, atom_name, tag->value);
}
*out_size = membuffer_get_size(buf);
- *out_buffer = membuffer_detach(buf);
- return 1;
+ return membuffer_detach(buf);
}
static void membuffer_write_atom(struct membuffer *buf, const char *name, unsigned size,
uint32_t ilst_size;
void *ilst_buffer;
- if (!create_ilst(meta, &ilst_buffer, &ilst_size))
- return 0;
+ ilst_buffer = create_ilst(meta, &ilst_size);
buf = membuffer_create();
-
membuffer_write_int32(buf, 0);
membuffer_write_atom(buf, "ilst", ilst_size, ilst_buffer);
free(ilst_buffer);
ret = read_int32(f, &ilst_size);
if (ret <= 0)
return NULL;
- if (!create_ilst(&f->meta, &new_ilst_buffer, &new_ilst_size))
- return NULL;
+ new_ilst_buffer = create_ilst(&f->meta, &new_ilst_size);
size_delta = new_ilst_size - (ilst_size - 8);
*out_size = total_size + size_delta;
out_buffer = para_malloc(*out_size);