static int32_t tag_add_field(struct mp4ff_metadata *tags, const char *item,
const char *value, int32_t len)
{
- void *backup = (void *) tags->tags;
-
if (!item || (item && !*item) || !value)
return 0;
-
- tags->tags = (struct mp4ff_tag *)realloc(tags->tags,
+ tags->tags = para_realloc(tags->tags,
(tags->count + 1) * sizeof(struct mp4ff_tag));
- if (!tags->tags) {
- free(backup);
- return 0;
+ tags->tags[tags->count].item = para_strdup(item);
+ tags->tags[tags->count].len = len;
+ if (len >= 0) {
+ tags->tags[tags->count].value = para_malloc(len + 1);
+ memcpy(tags->tags[tags->count].value, value, len);
+ tags->tags[tags->count].value[len] = 0;
} else {
- tags->tags[tags->count].item = para_strdup(item);
- tags->tags[tags->count].len = len;
- if (len >= 0) {
- tags->tags[tags->count].value = para_malloc(len + 1);
- memcpy(tags->tags[tags->count].value, value, len);
- tags->tags[tags->count].value[len] = 0;
- } else {
- tags->tags[tags->count].value = para_strdup(value);
- }
- tags->count++;
- return 1;
+ tags->tags[tags->count].value = para_strdup(value);
}
+ tags->count++;
+ return 1;
}
static const char *ID3v1GenreList[] = {
return chunk_offset2;
}
+/**
+ * Return the number of milliseconds of the given track.
+ *
+ * \param f As returned by \ref mp4ff_open_read(), must not be NULL.
+ * \param track Between zero and the value returned by \ref mp4ff_total_tracks().
+ *
+ * The function returns zero if the audio file is of zero length or contains a
+ * corrupt track header.
+ */
+uint64_t mp4ff_get_duration(const struct mp4ff *f, int32_t track)
+{
+ const struct mp4ff_track *t = f->track[track];
+
+ if (t->timeScale == 0)
+ return 0;
+ return t->duration * 1000 / t->timeScale;
+}
+
void mp4ff_set_sample_position(struct mp4ff *f, int32_t track, int32_t sample)
{
int32_t offset = sample_to_offset(f, track, sample);
do {
buf->allocated <<= 1;
} while (dest_size > buf->allocated);
-
- {
- void *newptr = realloc(buf->data, buf->allocated);
- if (newptr == 0) {
- free(buf->data);
- buf->data = 0;
- buf->error = 1;
- return 0;
- }
- buf->data = newptr;
- }
+ buf->data = para_realloc(buf->data, buf->allocated);
}
if (ptr)
if (buf->error)
return 0;
-
- ret = realloc(buf->data, buf->written);
-
- if (ret == 0)
- free(buf->data);
-
+ ret = para_realloc(buf->data, buf->written);
buf->data = 0;
buf->error = 1;
-
return ret;
}