shithub: dav1d

Download patch

ref: 718f9254f19268f02f082530322d91c78f1ab2a3
parent: ae08430fba74624a971e7bf77ec1a31bbb26a034
author: Ronald S. Bultje <rsbultje@gmail.com>
date: Wed Nov 28 06:20:30 EST 2018

ivf: store offset and timestamp in pkt.m

--- a/tools/input/ivf.c
+++ b/tools/input/ivf.c
@@ -44,6 +44,10 @@
     return ((uint32_t)p[3] << 24U) | (p[2] << 16U) | (p[1] << 8U) | p[0];
 }
 
+static uint64_t rl64(const uint8_t *const p) {
+    return (((uint64_t) rl32(&p[4])) << 32) | rl32(p);
+}
+
 static int ivf_open(IvfInputContext *const c, const char *const file,
                     unsigned fps[2], unsigned *const num_frames)
 {
@@ -87,16 +91,20 @@
 }
 
 static int ivf_read(IvfInputContext *const c, Dav1dData *const buf) {
-    uint8_t data[4];
+    uint8_t data[8];
     uint8_t *ptr;
     int res;
 
+    const off_t off = ftello(c->f);
     if ((res = fread(data, 4, 1, c->f)) != 1)
         return -1; // EOF
-    fseek(c->f, 8, SEEK_CUR); // skip timestamp
     const ptrdiff_t sz = rl32(data);
+    if ((res = fread(data, 8, 1, c->f)) != 1)
+        return -1; // EOF
     ptr = dav1d_data_create(buf, sz);
     if (!ptr) return -1;
+    buf->m.offset = off;
+    buf->m.timestamp = rl64(data);
     if ((res = fread(ptr, sz, 1, c->f)) != 1) {
         fprintf(stderr, "Failed to read frame data: %s\n", strerror(errno));
         dav1d_data_unref(buf);