shithub: dav1d

Download patch

ref: 951b0c98033989c6532e144e94ee017d560c6d04
parent: 3a4445bd11bc948c28b3e0706c599213ac221870
author: Janne Grunau <janne-vlc@jannau.net>
date: Fri Nov 23 16:40:29 EST 2018

scalable: output only frames of the highest selected spatial layer

Fixes #188.

--- a/include/dav1d/picture.h
+++ b/include/dav1d/picture.h
@@ -144,6 +144,7 @@
     int fullrange;
 
     Dav1dFilmGrainData film_grain; ///< film grain parameters
+    int spatial_id; ///< spatial id of the frame for scalable AV1
 } Dav1dPictureParameters;
 
 typedef struct Dav1dPicture {
--- a/src/decode.c
+++ b/src/decode.c
@@ -3111,6 +3111,7 @@
     f->sr_cur.p.p.chr = f->seq_hdr.chr;
     f->sr_cur.p.p.fullrange = f->seq_hdr.color_range;
     f->sr_cur.p.m = f->tile[0].data.m;
+    f->sr_cur.p.p.spatial_id = f->frame_hdr.spatial_id;
 
     if (f->frame_hdr.super_res.enabled) {
         res = dav1d_picture_alloc_copy(&f->cur, f->frame_hdr.width[0], &f->sr_cur.p);
--- a/src/levels.h
+++ b/src/levels.h
@@ -487,6 +487,7 @@
         int present, update;
         Dav1dFilmGrainData data;
     } film_grain;
+    int temporal_id, spatial_id;
 } Av1FrameHeader;
 
 #define QINDEX_RANGE 256
--- a/src/lib.c
+++ b/src/lib.c
@@ -186,6 +186,15 @@
     int has_grain = fgdata->num_y_points || fgdata->num_uv_points[0] ||
                     fgdata->num_uv_points[1];
 
+    // skip lower spatial layers
+    if (c->operating_point_idc && !c->all_layers) {
+        const int max_spatial_id = ulog2(c->operating_point_idc >> 8);
+        if (max_spatial_id > in->p.spatial_id) {
+            dav1d_picture_unref(in);
+            return 0;
+        }
+    }
+
     // If there is nothing to be done, skip the allocation/copy
     if (!c->apply_grain || !has_grain) {
         dav1d_picture_move_ref(out, in);
--- a/src/obu.c
+++ b/src/obu.c
@@ -1150,7 +1150,7 @@
     const int has_length_field = dav1d_get_bits(&gb, 1);
     dav1d_get_bits(&gb, 1); // reserved
 
-    int temporal_id, spatial_id;
+    int temporal_id = 0, spatial_id = 0;
     if (has_extension) {
         temporal_id = dav1d_get_bits(&gb, 3);
         spatial_id = dav1d_get_bits(&gb, 2);
@@ -1234,6 +1234,8 @@
     case OBU_FRAME_HDR:
         c->have_frame_hdr = 0;
         if (!c->have_seq_hdr) goto error;
+        c->frame_hdr.temporal_id = temporal_id;
+        c->frame_hdr.spatial_id = spatial_id;
         if ((res = parse_frame_hdr(c, &gb)) < 0)
             return res;
         for (int n = 0; n < c->n_tile_data; n++)