Skip to content

Commit 37c2802

Browse files
committed
Add mr_free_mem_loc enc func to vpx_codec_iface_t
Add the mr_free_mem_loc encoder function to vpx_codec_iface_t. This eliminates a leak of VP8 implementation detail in vpx_codec_enc_init_multi_ver(). Copy vpx_rational_t by using struct assignments. Change-Id: I6e2d58fb13c077111e614d016bb635fc03e8c5fd
1 parent e922e89 commit 37c2802

6 files changed

Lines changed: 29 additions & 17 deletions

File tree

vp8/vp8_cx_iface.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* be found in the AUTHORS file in the root of the source tree.
99
*/
1010

11+
#include <assert.h>
1112
#include <limits.h>
1213
#include <stdint.h>
1314
#include <stdlib.h>
@@ -396,8 +397,7 @@ static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf,
396397
if (mr_cfg) {
397398
oxcf->mr_total_resolutions = mr_cfg->mr_total_resolutions;
398399
oxcf->mr_encoder_id = mr_cfg->mr_encoder_id;
399-
oxcf->mr_down_sampling_factor.num = mr_cfg->mr_down_sampling_factor.num;
400-
oxcf->mr_down_sampling_factor.den = mr_cfg->mr_down_sampling_factor.den;
400+
oxcf->mr_down_sampling_factor = mr_cfg->mr_down_sampling_factor;
401401
oxcf->mr_low_res_mode_info = mr_cfg->mr_low_res_mode_info;
402402
}
403403
#else
@@ -667,11 +667,22 @@ static vpx_codec_err_t vp8e_mr_alloc_mem(const vpx_codec_enc_cfg_t *cfg,
667667
}
668668
#else
669669
(void)cfg;
670-
(void)mem_loc;
670+
*mem_loc = NULL;
671671
#endif
672672
return res;
673673
}
674674

675+
static void vp8e_mr_free_mem(void *mem_loc) {
676+
#if CONFIG_MULTI_RES_ENCODING
677+
LOWER_RES_FRAME_INFO *shared_mem_loc = (LOWER_RES_FRAME_INFO *)mem_loc;
678+
free(shared_mem_loc->mb_info);
679+
free(mem_loc);
680+
#else
681+
(void)mem_loc;
682+
assert(!mem_loc);
683+
#endif
684+
}
685+
675686
static vpx_codec_err_t vp8e_init(vpx_codec_ctx_t *ctx,
676687
vpx_codec_priv_enc_mr_cfg_t *mr_cfg) {
677688
vpx_codec_err_t res = VPX_CODEC_OK;
@@ -754,10 +765,7 @@ static vpx_codec_err_t vp8e_destroy(vpx_codec_alg_priv_t *ctx) {
754765
/* Free multi-encoder shared memory */
755766
if (ctx->oxcf.mr_total_resolutions > 0 &&
756767
(ctx->oxcf.mr_encoder_id == ctx->oxcf.mr_total_resolutions - 1)) {
757-
LOWER_RES_FRAME_INFO *shared_mem_loc =
758-
(LOWER_RES_FRAME_INFO *)ctx->oxcf.mr_low_res_mode_info;
759-
free(shared_mem_loc->mb_info);
760-
free(ctx->oxcf.mr_low_res_mode_info);
768+
vp8e_mr_free_mem(ctx->oxcf.mr_low_res_mode_info);
761769
}
762770
#endif
763771

@@ -1431,5 +1439,6 @@ CODEC_INTERFACE(vpx_codec_vp8_cx) = {
14311439
NULL,
14321440
vp8e_get_preview,
14331441
vp8e_mr_alloc_mem,
1442+
vp8e_mr_free_mem,
14341443
} /* encoder functions */
14351444
};

vp8/vp8_dx_iface.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ CODEC_INTERFACE(vpx_codec_vp8_dx) = {
747747
NULL, /* vpx_codec_enc_config_set_fn_t */
748748
NULL, /* vpx_codec_get_global_headers_fn_t */
749749
NULL, /* vpx_codec_get_preview_frame_fn_t */
750-
NULL /* vpx_codec_enc_mr_get_mem_loc_fn_t */
750+
NULL, /* vpx_codec_enc_mr_get_mem_loc_fn_t */
751+
NULL /* vpx_codec_enc_mr_free_mem_loc_fn_t */
751752
}
752753
};

vp9/vp9_cx_iface.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,8 @@ CODEC_INTERFACE(vpx_codec_vp9_cx) = {
22922292
encoder_set_config, // vpx_codec_enc_config_set_fn_t
22932293
encoder_get_global_headers, // vpx_codec_get_global_headers_fn_t
22942294
encoder_get_preview, // vpx_codec_get_preview_frame_fn_t
2295-
NULL // vpx_codec_enc_mr_get_mem_loc_fn_t
2295+
NULL, // vpx_codec_enc_mr_get_mem_loc_fn_t
2296+
NULL // vpx_codec_enc_mr_free_mem_loc_fn_t
22962297
}
22972298
};
22982299

vp9/vp9_dx_iface.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ CODEC_INTERFACE(vpx_codec_vp9_dx) = {
737737
NULL, // vpx_codec_enc_config_set_fn_t
738738
NULL, // vpx_codec_get_global_headers_fn_t
739739
NULL, // vpx_codec_get_preview_frame_fn_t
740-
NULL // vpx_codec_enc_mr_get_mem_loc_fn_t
740+
NULL, // vpx_codec_enc_mr_get_mem_loc_fn_t
741+
NULL // vpx_codec_enc_mr_free_mem_loc_fn_t
741742
}
742743
};

vpx/internal/vpx_codec_internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ typedef vpx_image_t *(*vpx_codec_get_preview_frame_fn_t)(
269269
typedef vpx_codec_err_t (*vpx_codec_enc_mr_get_mem_loc_fn_t)(
270270
const vpx_codec_enc_cfg_t *cfg, void **mem_loc);
271271

272+
typedef void (*vpx_codec_enc_mr_free_mem_loc_fn_t)(void *mem_loc);
273+
272274
/*!\brief usage configuration mapping
273275
*
274276
* This structure stores the mapping between usage identifiers and
@@ -318,6 +320,8 @@ struct vpx_codec_iface {
318320
get_preview; /**< \copydoc ::vpx_codec_get_preview_frame_fn_t */
319321
vpx_codec_enc_mr_get_mem_loc_fn_t
320322
mr_get_mem_loc; /**< \copydoc ::vpx_codec_enc_mr_get_mem_loc_fn_t */
323+
vpx_codec_enc_mr_free_mem_loc_fn_t
324+
mr_free_mem_loc; /**< \copydoc ::vpx_codec_enc_mr_free_mem_loc_fn_t */
321325
} enc;
322326
};
323327

vpx/src/vpx_encoder.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
#include <assert.h>
1616
#include <limits.h>
1717
#include <stdint.h>
18-
#include <stdlib.h>
1918
#include <string.h>
20-
#include "vp8/common/blockd.h"
2119
#include "vpx_config.h"
2220
#include "vpx/internal/vpx_codec_internal.h"
2321

@@ -91,7 +89,7 @@ vpx_codec_err_t vpx_codec_enc_init_multi_ver(
9189
#if CONFIG_MULTI_RES_ENCODING
9290
int mem_loc_owned = 0;
9391
#endif
94-
void *mem_loc = NULL;
92+
void *mem_loc;
9593

9694
if (iface->enc.mr_get_mem_loc == NULL) return VPX_CODEC_INCAPABLE;
9795

@@ -107,8 +105,7 @@ vpx_codec_err_t vpx_codec_enc_init_multi_ver(
107105
mr_cfg.mr_low_res_mode_info = mem_loc;
108106
mr_cfg.mr_total_resolutions = num_enc;
109107
mr_cfg.mr_encoder_id = num_enc - 1 - i;
110-
mr_cfg.mr_down_sampling_factor.num = dsf->num;
111-
mr_cfg.mr_down_sampling_factor.den = dsf->den;
108+
mr_cfg.mr_down_sampling_factor = *dsf;
112109

113110
ctx->iface = iface;
114111
ctx->name = iface->name;
@@ -137,8 +134,7 @@ vpx_codec_err_t vpx_codec_enc_init_multi_ver(
137134
#if CONFIG_MULTI_RES_ENCODING
138135
if (!mem_loc_owned) {
139136
assert(mem_loc);
140-
free(((LOWER_RES_FRAME_INFO *)mem_loc)->mb_info);
141-
free(mem_loc);
137+
iface->enc.mr_free_mem_loc(mem_loc);
142138
}
143139
#endif
144140
return SAVE_STATUS(ctx, res);

0 commit comments

Comments
 (0)