Commit 5d493143 authored by hui su's avatar hui su Committed by Hui Su
Browse files

Palette: avoid memory leak with encoder buffers

For multi-thread encoding, previously the encoder buffers are
allocated at every frame, but only freed at the end of encoding,
causing memory leaks.

Change-Id: Id0e9d7fba8330e82be9cec1d42b7d4b017b8d772
parent 26843a01
......@@ -2633,7 +2633,7 @@ void av1_remove_compressor(AV1_COMP *cpi) {
if (t < cpi->num_workers - 1) {
#if CONFIG_PALETTE
if (cpi->common.allow_screen_content_tools)
aom_free(thread_data->td->mb.palette_buffer);
aom_free(thread_data->td->palette_buffer);
#endif // CONFIG_PALETTE
aom_free(thread_data->td->counts);
av1_free_pc_tree(thread_data->td);
......
......@@ -324,6 +324,10 @@ typedef struct ThreadData {
VAR_TREE *var_tree;
VAR_TREE *var_root[MAX_MIB_SIZE_LOG2 - MIN_MIB_SIZE_LOG2 + 1];
#if CONFIG_PALETTE
PALETTE_BUFFER *palette_buffer;
#endif // CONFIG_PALETTE
} ThreadData;
struct EncWorkerData;
......
......@@ -101,6 +101,15 @@ void av1_encode_tiles_mt(AV1_COMP *cpi) {
CHECK_MEM_ERROR(cm, thread_data->td->counts,
aom_calloc(1, sizeof(*thread_data->td->counts)));
#if CONFIG_PALETTE
// Allocate buffers used by palette coding mode.
if (cpi->common.allow_screen_content_tools) {
CHECK_MEM_ERROR(
cm, thread_data->td->palette_buffer,
aom_memalign(16, sizeof(*thread_data->td->palette_buffer)));
}
#endif // CONFIG_PALETTE
// Create threads
if (!winterface->reset(worker))
aom_internal_error(&cm->error, AOM_CODEC_ERROR,
......@@ -134,12 +143,8 @@ void av1_encode_tiles_mt(AV1_COMP *cpi) {
}
#if CONFIG_PALETTE
// Allocate buffers used by palette coding mode.
if (cpi->common.allow_screen_content_tools && i < num_workers - 1) {
MACROBLOCK *x = &thread_data->td->mb;
CHECK_MEM_ERROR(cm, x->palette_buffer,
aom_memalign(16, sizeof(*x->palette_buffer)));
}
if (cpi->common.allow_screen_content_tools && i < num_workers - 1)
thread_data->td->mb.palette_buffer = thread_data->td->palette_buffer;
#endif // CONFIG_PALETTE
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment