Merge commit 'df528b11ac607de13a7c438f2a51f2119f71a03c'
authorMichael Niedermayer <michaelni@gmx.at>
Fri, 3 Apr 2015 20:16:10 +0000 (22:16 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Fri, 3 Apr 2015 20:16:10 +0000 (22:16 +0200)
* commit 'df528b11ac607de13a7c438f2a51f2119f71a03c':
  hevc: make sure no dangling pointers remain around on VPS/SPS change

Conflicts:
libavcodec/hevc_ps.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/hevc_ps.c

@@@ -69,6 -70,42 +69,49 @@@ static const AVRational vui_sar[] = 
      {  2,   1 },
  };
  
+ static void remove_pps(HEVCContext *s, int id)
+ {
+     if (s->pps_list[id] && s->pps == (const HEVCPPS*)s->pps_list[id]->data)
+         s->pps = NULL;
+     av_buffer_unref(&s->pps_list[id]);
+ }
+ static void remove_sps(HEVCContext *s, int id)
+ {
+     int i;
+     if (s->sps_list[id]) {
+         if (s->sps == (const HEVCSPS*)s->sps_list[id]->data)
+             s->sps = NULL;
+         /* drop all PPS that depend on this SPS */
+         for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++)
+             if (s->pps_list[i] && ((HEVCPPS*)s->pps_list[i]->data)->sps_id == id)
+                 remove_pps(s, i);
++
++        if (s->sps_list[id] && s->sps == (HEVCSPS*)s->sps_list[id]->data) {
++            av_buffer_unref(&s->current_sps);
++            s->current_sps = av_buffer_ref(s->sps_list[id]);
++            if (!s->current_sps)
++                s->sps = NULL;
++        }
+     }
+     av_buffer_unref(&s->sps_list[id]);
+ }
+ static void remove_vps(HEVCContext *s, int id)
+ {
+     int i;
+     if (s->vps_list[id]) {
+         if (s->vps == (const HEVCVPS*)s->vps_list[id]->data)
+             s->vps = NULL;
+         for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++)
+             if (s->sps_list[i] && ((HEVCSPS*)s->sps_list[i]->data)->vps_id == id)
+                 remove_sps(s, i);
+     }
+     av_buffer_unref(&s->vps_list[id]);
+ }
  int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps,
                                    const HEVCSPS *sps, int is_slice_header)
  {
@@@ -1553,13 -1343,7 +1586,13 @@@ int ff_hevc_decode_nal_pps(HEVCContext 
          }
      }
  
-     av_buffer_unref(&s->pps_list[pps_id]);
 +    if (get_bits_left(gb) < 0) {
 +        av_log(s->avctx, AV_LOG_ERROR,
 +               "Overread PPS by %d bits\n", -get_bits_left(gb));
 +        goto err;
 +    }
 +
+     remove_pps(s, pps_id);
      s->pps_list[pps_id] = pps_buf;
  
      return 0;