return rv;
}
-static uint32_t aac_afh_seek_cb(void *user_data, uint64_t pos)
+static off_t aac_afh_seek_cb(void *user_data, off_t offset, int whence)
{
struct aac_afh_context *c = user_data;
- c->fpos = pos;
- return 0;
+
+ if (whence == SEEK_SET)
+ c->fpos = offset;
+ else if (whence == SEEK_CUR)
+ c->fpos += offset;
+ else if (whence == SEEK_END)
+ c->fpos = c->mapsize + offset;
+ else
+ assert(false);
+ return c->fpos;
}
static int aac_afh_open(const void *map, size_t mapsize, void **afh_context)
return read(fd, dest, want);
}
-static uint32_t aac_afh_meta_seek_cb(void *user_data, uint64_t pos)
+static off_t aac_afh_meta_seek_cb(void *user_data, off_t offset, int whence)
{
int fd = *(int *)user_data;
- return lseek(fd, pos, SEEK_SET);
+ off_t ret = lseek(fd, offset, whence);
+
+ assert(ret != (off_t)-1);
+ return ret;
}
static ssize_t aac_afh_meta_write_cb(void *user_data, void *dest, size_t count)
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);
struct mp4_callback {
ssize_t (*read)(void *user_data, void *buffer, size_t length);
ssize_t (*write)(void *user_data, void *buffer, size_t count);
- uint32_t (*seek)(void *user_data, uint64_t position);
+ off_t (*seek)(void *user_data, off_t offset, int whence);
uint32_t (*truncate)(void *user_data);
void *user_data;
};