diff options
author | Kieran Kunhya <kierank@obe.tv> | 2017-11-04 17:41:06 +0000 |
---|---|---|
committer | Your Name <you@example.com> | 2017-11-04 18:06:45 +0000 |
commit | 03b82b3ab9883cef017e513c7d0b3b986b3b3e7b (patch) | |
tree | 56c68bb93e11ea3eed0869998566ad7f872861df /libavcodec/h2645_parse.c | |
parent | 3357b68bc02d855a92656d7a474b22adb32ca1a7 (diff) | |
download | ffmpeg-03b82b3ab9883cef017e513c7d0b3b986b3b3e7b.tar.gz |
h2645_parse: Allocate a single buffer per packet
Drastically reduces memory usage on pathological streams.
Fixes ticket #6789
Diffstat (limited to 'libavcodec/h2645_parse.c')
-rw-r--r-- | libavcodec/h2645_parse.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c index 3fbbaf4d29..e6c40381b0 100644 --- a/libavcodec/h2645_parse.c +++ b/libavcodec/h2645_parse.c @@ -31,11 +31,10 @@ #include "h2645_parse.h" int ff_h2645_extract_rbsp(const uint8_t *src, int length, - H2645NAL *nal, int small_padding) + H2645RBSP *rbsp, H2645NAL *nal, int small_padding) { int i, si, di; uint8_t *dst; - int64_t padding = small_padding ? 0 : MAX_MBPAIR_SIZE; nal->skipped_bytes = 0; #define STARTCODE_TEST \ @@ -92,11 +91,7 @@ int ff_h2645_extract_rbsp(const uint8_t *src, int length, } else if (i > length) i = length; - av_fast_padded_malloc(&nal->rbsp_buffer, &nal->rbsp_buffer_size, - length + padding); - if (!nal->rbsp_buffer) - return AVERROR(ENOMEM); - + nal->rbsp_buffer = &rbsp->rbsp_buffer[rbsp->rbsp_buffer_size]; dst = nal->rbsp_buffer; memcpy(dst, src, i); @@ -145,6 +140,8 @@ nsc: nal->size = di; nal->raw_data = src; nal->raw_size = si; + rbsp->rbsp_buffer_size += si; + return si; } @@ -270,9 +267,14 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, GetByteContext bc; int consumed, ret = 0; int next_avc = is_nalff ? 0 : length; + int64_t padding = small_padding ? 0 : MAX_MBPAIR_SIZE; bytestream2_init(&bc, buf, length); + av_fast_padded_malloc(&pkt->rbsp.rbsp_buffer, &pkt->rbsp.rbsp_buffer_alloc_size, length + padding); + if (!pkt->rbsp.rbsp_buffer) + return AVERROR(ENOMEM); + pkt->rbsp.rbsp_buffer_size = 0; pkt->nb_nals = 0; while (bytestream2_get_bytes_left(&bc) >= 4) { H2645NAL *nal; @@ -341,7 +343,7 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, } nal = &pkt->nals[pkt->nb_nals]; - consumed = ff_h2645_extract_rbsp(bc.buffer, extract_length, nal, small_padding); + consumed = ff_h2645_extract_rbsp(bc.buffer, extract_length, &pkt->rbsp, nal, small_padding); if (consumed < 0) return consumed; @@ -385,9 +387,10 @@ void ff_h2645_packet_uninit(H2645Packet *pkt) { int i; for (i = 0; i < pkt->nals_allocated; i++) { - av_freep(&pkt->nals[i].rbsp_buffer); av_freep(&pkt->nals[i].skipped_bytes_pos); } av_freep(&pkt->nals); pkt->nals_allocated = 0; + av_freep(&pkt->rbsp.rbsp_buffer); + pkt->rbsp.rbsp_buffer_alloc_size = pkt->rbsp.rbsp_buffer_size = 0; } |