From 7a2d6fb4d204e87f2d8091d47e9e535035fcf280 Mon Sep 17 00:00:00 2001 From: "herman.chen" Date: Mon, 29 Aug 2016 16:22:24 +0800 Subject: [PATCH] [legacy]: reduce encoder memory usage Do not allocate buffer on encoder init. Only allocate when it is necessary. Change-Id: I9a152084e1b09dfaad1692e3cac1f3bc828cf451 Signed-off-by: herman.chen --- mpp/legacy/vpu_api_legacy.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mpp/legacy/vpu_api_legacy.cpp b/mpp/legacy/vpu_api_legacy.cpp index ae23ec73..f3d1cf4f 100644 --- a/mpp/legacy/vpu_api_legacy.cpp +++ b/mpp/legacy/vpu_api_legacy.cpp @@ -280,8 +280,6 @@ RK_S32 VpuApiLegacy::init(VpuCodecContext *ctx, RK_U8 *extraData, RK_U32 extra_s enc_in_fmt = (EncInputPictureType)param->format; - outData = mpp_malloc(RK_U8, (param->width * param->height)); - mpp_cfg.width = param->width; mpp_cfg.height = param->height; mpp_cfg.format = vpu_pic_type_remap_to_mpp(enc_in_fmt); @@ -872,9 +870,14 @@ RK_S32 VpuApiLegacy::encoder_getstream(VpuCodecContext *ctx, EncoderOut_t *aEncO RK_U32 flag = mpp_packet_get_flag(packet); size_t length = mpp_packet_get_length(packet); - mpp_assert(length); + if (NULL == outData) + outData = mpp_malloc(RK_U8, (ctx->width * ctx->height)); + + mpp_assert(outData); + mpp_assert(length >= 4); // remove first 00 00 00 01 length -= 4; + aEncOut->data = outData; aEncOut->size = (RK_S32)length; aEncOut->timeUs = pts;