aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/hevc_ps.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2015-04-03 22:16:10 +0200
committerMichael Niedermayer <michaelni@gmx.at>2015-04-03 22:16:10 +0200
commit235863463abcfda0e428bf1a79009316b2dd7895 (patch)
treed80957807fc0675407ceca1a509c6077bed2512c /libavcodec/hevc_ps.c
parent41dde62d7f4121495150fe0e0db26fc25c737901 (diff)
parentdf528b11ac607de13a7c438f2a51f2119f71a03c (diff)
downloadffmpeg-235863463abcfda0e428bf1a79009316b2dd7895.tar.gz
Merge commit 'df528b11ac607de13a7c438f2a51f2119f71a03c'
* 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>
Diffstat (limited to 'libavcodec/hevc_ps.c')
-rw-r--r--libavcodec/hevc_ps.c59
1 files changed, 46 insertions, 13 deletions
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index f6e7ab93fd..6a1a8f60a9 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -69,6 +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)
{
@@ -462,7 +505,7 @@ int ff_hevc_decode_nal_vps(HEVCContext *s)
!memcmp(s->vps_list[vps_id]->data, vps_buf->data, vps_buf->size)) {
av_buffer_unref(&vps_buf);
} else {
- av_buffer_unref(&s->vps_list[vps_id]);
+ remove_vps(s, vps_id);
s->vps_list[vps_id] = vps_buf;
}
@@ -1137,17 +1180,7 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
!memcmp(s->sps_list[sps_id]->data, sps_buf->data, sps_buf->size)) {
av_buffer_unref(&sps_buf);
} else {
- for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++) {
- if (s->pps_list[i] && ((HEVCPPS*)s->pps_list[i]->data)->sps_id == sps_id)
- av_buffer_unref(&s->pps_list[i]);
- }
- if (s->sps_list[sps_id] && s->sps == (HEVCSPS*)s->sps_list[sps_id]->data) {
- av_buffer_unref(&s->current_sps);
- s->current_sps = av_buffer_ref(s->sps_list[sps_id]);
- if (!s->current_sps)
- s->sps = NULL;
- }
- av_buffer_unref(&s->sps_list[sps_id]);
+ remove_sps(s, sps_id);
s->sps_list[sps_id] = sps_buf;
}
@@ -1559,7 +1592,7 @@ int ff_hevc_decode_nal_pps(HEVCContext *s)
goto err;
}
- av_buffer_unref(&s->pps_list[pps_id]);
+ remove_pps(s, pps_id);
s->pps_list[pps_id] = pps_buf;
return 0;