]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - mp4.c
mp4: Provide whence parameter for the seek callback.
[paraslash.git] / mp4.c
diff --git a/mp4.c b/mp4.c
index fc8c41b4af919358350812cae68033611c5d33c4..08812c89b18345bb238ae117572ea9fc8c67b3d6 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -45,7 +45,6 @@ struct mp4_track {
 
 struct mp4 {
        const struct mp4_callback *cb;
-       int64_t current_position;
 
        uint64_t moov_offset;
        uint64_t moov_size;
@@ -57,8 +56,6 @@ struct mp4 {
        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 */
@@ -83,7 +80,6 @@ static int read_data(struct mp4 *f, void *data, size_t size)
                /* 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;
@@ -212,17 +208,14 @@ static int atom_read_header(struct mp4 *f, uint8_t *atom_type,
        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)
@@ -696,7 +689,6 @@ static int open_file(const struct mp4_callback *cb, bool meta_only, struct mp4 *
 
        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);
@@ -979,7 +971,6 @@ static int write_data(struct mp4 *f, void *data, size_t size)
                                continue;
                        return -ERRNO_TO_PARA_ERROR(errno);
                }
-               f->current_position += ret;
                size -= ret;
        }
        return 1;
@@ -1003,7 +994,8 @@ int mp4_meta_update(struct mp4 *f)
                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);