diff options
author | Kieran Kunhya <kierank@obe.tv> | 2017-11-04 20:41:06 +0300 |
---|---|---|
committer | Your Name <you@example.com> | 2017-11-04 21:06:45 +0300 |
commit | 03b82b3ab9883cef017e513c7d0b3b986b3b3e7b (patch) | |
tree | 56c68bb93e11ea3eed0869998566ad7f872861df /libavcodec/qsvenc_hevc.c | |
parent | 3357b68bc02d855a92656d7a474b22adb32ca1a7 (diff) |
h2645_parse: Allocate a single buffer per packet
Drastically reduces memory usage on pathological streams.
Fixes ticket #6789
Diffstat (limited to 'libavcodec/qsvenc_hevc.c')
-rw-r--r-- | libavcodec/qsvenc_hevc.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c index b0e5ace7c7..ff396b2784 100644 --- a/libavcodec/qsvenc_hevc.c +++ b/libavcodec/qsvenc_hevc.c @@ -56,6 +56,7 @@ static int generate_fake_vps(QSVEncContext *q, AVCodecContext *avctx) PutByteContext pbc; GetBitContext gb; + H2645RBSP sps_rbsp = { NULL }; H2645NAL sps_nal = { NULL }; HEVCSPS sps = { 0 }; HEVCVPS vps = { 0 }; @@ -69,8 +70,12 @@ static int generate_fake_vps(QSVEncContext *q, AVCodecContext *avctx) return AVERROR_UNKNOWN; } + av_fast_padded_malloc(&sps_rbsp.rbsp_buffer, &sps_rbsp.rbsp_buffer_alloc_size, avctx->extradata_size); + if (!sps_rbsp.rbsp_buffer) + return AVERROR(ENOMEM); + /* parse the SPS */ - ret = ff_h2645_extract_rbsp(avctx->extradata + 4, avctx->extradata_size - 4, &sps_nal, 1); + ret = ff_h2645_extract_rbsp(avctx->extradata + 4, avctx->extradata_size - 4, &sps_rbsp, &sps_nal, 1); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Error unescaping the SPS buffer\n"); return ret; @@ -78,7 +83,7 @@ static int generate_fake_vps(QSVEncContext *q, AVCodecContext *avctx) ret = init_get_bits8(&gb, sps_nal.data, sps_nal.size); if (ret < 0) { - av_freep(&sps_nal.rbsp_buffer); + av_freep(&sps_rbsp.rbsp_buffer); return ret; } @@ -87,13 +92,13 @@ static int generate_fake_vps(QSVEncContext *q, AVCodecContext *avctx) if (type != HEVC_NAL_SPS) { av_log(avctx, AV_LOG_ERROR, "Unexpected NAL type in the extradata: %d\n", type); - av_freep(&sps_nal.rbsp_buffer); + av_freep(&sps_rbsp.rbsp_buffer); return AVERROR_INVALIDDATA; } get_bits(&gb, 9); ret = ff_hevc_parse_sps(&sps, &gb, &sps_id, 0, NULL, avctx); - av_freep(&sps_nal.rbsp_buffer); + av_freep(&sps_rbsp.rbsp_buffer); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Error parsing the SPS\n"); return ret; |