struct mp4 {
const struct mp4_callback *cb;
- int64_t current_position;
uint64_t moov_offset;
uint64_t moov_size;
uint32_t udta_size;
uint8_t last_atom;
- uint64_t file_size;
-
/* incremental track index while reading the file */
int32_t total_tracks;
/* track data */
/* regard EAGAIN as an error as reads should be blocking. */
if (ret <= 0)
return ret < 0? -1 : 0;
- f->current_position += ret;
size -= ret;
}
return 1;
return 1;
}
-static int64_t get_position(const struct mp4 *f)
+static off_t get_position(const struct mp4 *f)
{
- return f->current_position;
+ return f->cb->seek(f->cb->user_data, 0, SEEK_CUR);
}
-static int32_t set_position(struct mp4 *f, int64_t position)
+static void set_position(struct mp4 *f, off_t position)
{
- f->cb->seek(f->cb->user_data, position);
- f->current_position = position;
-
- return 0;
+ f->cb->seek(f->cb->user_data, position, SEEK_SET);
}
static int read_stsz(struct mp4 *f)
f->cb = cb;
while ((ret = atom_read_header(f, &atom_type, &header_size, &size)) > 0) {
- f->file_size += size;
f->last_atom = atom_type;
if (atom_type != ATOM_MOOV || size <= header_size) { /* skip */
set_position(f, get_position(f) + size - header_size);
continue;
return -ERRNO_TO_PARA_ERROR(errno);
}
- f->current_position += ret;
size -= ret;
}
return 1;
ret = write_data(f, "free", 4); /* rename old moov to free */
if (ret < 0)
goto free_moov;
- set_position(f, f->file_size); /* write new moov atom at EOF */
+ /* write new moov atom at EOF */
+ f->cb->seek(f->cb->user_data, 0, SEEK_END);
} else /* overwrite old moov atom */
set_position(f, f->moov_offset);
write_u32_be(buf, new_moov_size + 8);