summaryrefslogtreecommitdiff
path: root/libavcodec/h264_parser.c
diff options
context:
space:
mode:
authorKieran Kunhya <kierank@obe.tv>2017-11-04 17:41:06 +0000
committerYour Name <you@example.com>2017-11-04 18:06:45 +0000
commit03b82b3ab9883cef017e513c7d0b3b986b3b3e7b (patch)
tree56c68bb93e11ea3eed0869998566ad7f872861df /libavcodec/h264_parser.c
parent3357b68bc02d855a92656d7a474b22adb32ca1a7 (diff)
h2645_parse: Allocate a single buffer per packet
Drastically reduces memory usage on pathological streams. Fixes ticket #6789
Diffstat (limited to 'libavcodec/h264_parser.c')
-rw-r--r--libavcodec/h264_parser.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index dd0a965af0..39f97e00a6 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -243,6 +243,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
const uint8_t * const buf, int buf_size)
{
H264ParseContext *p = s->priv_data;
+ H2645RBSP rbsp = { NULL };
H2645NAL nal = { NULL };
int buf_index, next_avc;
unsigned int pps_id;
@@ -263,6 +264,10 @@ static inline int parse_nal_units(AVCodecParserContext *s,
if (!buf_size)
return 0;
+ av_fast_padded_malloc(&rbsp.rbsp_buffer, &rbsp.rbsp_buffer_alloc_size, buf_size);
+ if (!rbsp.rbsp_buffer)
+ return AVERROR(ENOMEM);
+
buf_index = 0;
next_avc = p->is_avc ? 0 : buf_size;
for (;;) {
@@ -300,7 +305,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
}
break;
}
- consumed = ff_h2645_extract_rbsp(buf + buf_index, src_length, &nal, 1);
+ consumed = ff_h2645_extract_rbsp(buf + buf_index, src_length, &rbsp, &nal, 1);
if (consumed < 0)
break;
@@ -544,18 +549,18 @@ static inline int parse_nal_units(AVCodecParserContext *s,
p->last_frame_num = p->poc.frame_num;
}
- av_freep(&nal.rbsp_buffer);
+ av_freep(&rbsp.rbsp_buffer);
return 0; /* no need to evaluate the rest */
}
}
if (q264) {
- av_freep(&nal.rbsp_buffer);
+ av_freep(&rbsp.rbsp_buffer);
return 0;
}
/* didn't find a picture! */
av_log(avctx, AV_LOG_ERROR, "missing picture in access unit with size %d\n", buf_size);
fail:
- av_freep(&nal.rbsp_buffer);
+ av_freep(&rbsp.rbsp_buffer);
return -1;
}