Commit 4b37dc8d authored by Dmitry Kovalev's avatar Dmitry Kovalev
Browse files

Adding alloc_mi() function.

Change-Id: I3b944884c048f589c86e0169aeb3c3855bc8b729
parent 4d903f47
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "./vpx_config.h" #include "./vpx_config.h"
#include "vpx_mem/vpx_mem.h" #include "vpx_mem/vpx_mem.h"
...@@ -30,34 +29,6 @@ void vp9_update_mode_info_border(VP9_COMMON *cm, MODE_INFO *mi) { ...@@ -30,34 +29,6 @@ void vp9_update_mode_info_border(VP9_COMMON *cm, MODE_INFO *mi) {
vpx_memset(&mi[i * stride], 0, sizeof(MODE_INFO)); vpx_memset(&mi[i * stride], 0, sizeof(MODE_INFO));
} }
void vp9_free_frame_buffers(VP9_COMMON *cm) {
int i;
for (i = 0; i < FRAME_BUFFERS; i++) {
vp9_free_frame_buffer(&cm->frame_bufs[i].buf);
if (cm->frame_bufs[i].ref_count > 0 &&
cm->frame_bufs[i].raw_frame_buffer.data != NULL) {
cm->release_fb_cb(cm->cb_priv, &cm->frame_bufs[i].raw_frame_buffer);
cm->frame_bufs[i].ref_count = 0;
}
}
vp9_free_frame_buffer(&cm->post_proc_buffer);
vpx_free(cm->mip);
vpx_free(cm->prev_mip);
vpx_free(cm->last_frame_seg_map);
vpx_free(cm->mi_grid_base);
vpx_free(cm->prev_mi_grid_base);
cm->mip = NULL;
cm->prev_mip = NULL;
cm->last_frame_seg_map = NULL;
cm->mi_grid_base = NULL;
cm->prev_mi_grid_base = NULL;
}
static void set_mb_mi(VP9_COMMON *cm, int aligned_width, int aligned_height) { static void set_mb_mi(VP9_COMMON *cm, int aligned_width, int aligned_height) {
cm->mi_cols = aligned_width >> MI_SIZE_LOG2; cm->mi_cols = aligned_width >> MI_SIZE_LOG2;
cm->mi_rows = aligned_height >> MI_SIZE_LOG2; cm->mi_rows = aligned_height >> MI_SIZE_LOG2;
...@@ -75,7 +46,7 @@ static void setup_mi(VP9_COMMON *cm) { ...@@ -75,7 +46,7 @@ static void setup_mi(VP9_COMMON *cm) {
cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mode_info_stride + 1; cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mode_info_stride + 1;
vpx_memset(cm->mip, 0, vpx_memset(cm->mip, 0,
cm->mode_info_stride * (cm->mi_rows + 1) * sizeof(MODE_INFO)); cm->mode_info_stride * (cm->mi_rows + 1) * sizeof(*cm->mip));
vpx_memset(cm->mi_grid_base, 0, vpx_memset(cm->mi_grid_base, 0,
cm->mode_info_stride * (cm->mi_rows + 1) * cm->mode_info_stride * (cm->mi_rows + 1) *
...@@ -84,12 +55,66 @@ static void setup_mi(VP9_COMMON *cm) { ...@@ -84,12 +55,66 @@ static void setup_mi(VP9_COMMON *cm) {
vp9_update_mode_info_border(cm, cm->prev_mip); vp9_update_mode_info_border(cm, cm->prev_mip);
} }
static int alloc_mi(VP9_COMMON *cm, int mi_size) {
cm->mip = (MODE_INFO *)vpx_calloc(mi_size, sizeof(*cm->mip));
if (cm->mip == NULL)
return 1;
cm->prev_mip = (MODE_INFO *)vpx_calloc(mi_size, sizeof(*cm->prev_mip));
if (cm->prev_mip == NULL)
return 1;
cm->mi_grid_base =
(MODE_INFO **)vpx_calloc(mi_size, sizeof(*cm->mi_grid_base));
if (cm->mi_grid_base == NULL)
return 1;
cm->prev_mi_grid_base =
(MODE_INFO **)vpx_calloc(mi_size, sizeof(*cm->prev_mi_grid_base));
if (cm->prev_mi_grid_base == NULL)
return 1;
return 0;
}
static void free_mi(VP9_COMMON *cm) {
vpx_free(cm->mip);
vpx_free(cm->prev_mip);
vpx_free(cm->mi_grid_base);
vpx_free(cm->prev_mi_grid_base);
cm->mip = NULL;
cm->prev_mip = NULL;
cm->mi_grid_base = NULL;
cm->prev_mi_grid_base = NULL;
}
void vp9_free_frame_buffers(VP9_COMMON *cm) {
int i;
for (i = 0; i < FRAME_BUFFERS; ++i) {
vp9_free_frame_buffer(&cm->frame_bufs[i].buf);
if (cm->frame_bufs[i].ref_count > 0 &&
cm->frame_bufs[i].raw_frame_buffer.data != NULL) {
cm->release_fb_cb(cm->cb_priv, &cm->frame_bufs[i].raw_frame_buffer);
cm->frame_bufs[i].ref_count = 0;
}
}
vp9_free_frame_buffer(&cm->post_proc_buffer);
free_mi(cm);
vpx_free(cm->last_frame_seg_map);
cm->last_frame_seg_map = NULL;
}
int vp9_resize_frame_buffers(VP9_COMMON *cm, int width, int height) { int vp9_resize_frame_buffers(VP9_COMMON *cm, int width, int height) {
const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2); const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2);
const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2); const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2);
const int ss_x = cm->subsampling_x; const int ss_x = cm->subsampling_x;
const int ss_y = cm->subsampling_y; const int ss_y = cm->subsampling_y;
int mi_size;
if (vp9_realloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y, if (vp9_realloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y,
VP9_DEC_BORDER_IN_PIXELS, NULL, NULL, NULL) < 0) VP9_DEC_BORDER_IN_PIXELS, NULL, NULL, NULL) < 0)
...@@ -97,29 +122,8 @@ int vp9_resize_frame_buffers(VP9_COMMON *cm, int width, int height) { ...@@ -97,29 +122,8 @@ int vp9_resize_frame_buffers(VP9_COMMON *cm, int width, int height) {
set_mb_mi(cm, aligned_width, aligned_height); set_mb_mi(cm, aligned_width, aligned_height);
// Allocation free_mi(cm);
mi_size = cm->mode_info_stride * (cm->mi_rows + MI_BLOCK_SIZE); if (alloc_mi(cm, cm->mode_info_stride * (cm->mi_rows + MI_BLOCK_SIZE)))
vpx_free(cm->mip);
cm->mip = (MODE_INFO *)vpx_calloc(mi_size, sizeof(MODE_INFO));
if (!cm->mip)
goto fail;
vpx_free(cm->prev_mip);
cm->prev_mip = (MODE_INFO *)vpx_calloc(mi_size, sizeof(MODE_INFO));
if (!cm->prev_mip)
goto fail;
vpx_free(cm->mi_grid_base);
cm->mi_grid_base =
(MODE_INFO **)vpx_calloc(mi_size, sizeof(*cm->mi_grid_base));
if (!cm->mi_grid_base)
goto fail;
vpx_free(cm->prev_mi_grid_base);
cm->prev_mi_grid_base =
(MODE_INFO **)vpx_calloc(mi_size, sizeof(*cm->prev_mi_grid_base));
if (!cm->prev_mi_grid_base)
goto fail; goto fail;
setup_mi(cm); setup_mi(cm);
...@@ -144,7 +148,6 @@ int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) { ...@@ -144,7 +148,6 @@ int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) {
const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2); const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2);
const int ss_x = cm->subsampling_x; const int ss_x = cm->subsampling_x;
const int ss_y = cm->subsampling_y; const int ss_y = cm->subsampling_y;
int mi_size;
vp9_free_frame_buffers(cm); vp9_free_frame_buffers(cm);
...@@ -169,25 +172,7 @@ int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) { ...@@ -169,25 +172,7 @@ int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) {
set_mb_mi(cm, aligned_width, aligned_height); set_mb_mi(cm, aligned_width, aligned_height);
// Allocation if (alloc_mi(cm, cm->mode_info_stride * (cm->mi_rows + MI_BLOCK_SIZE)))
mi_size = cm->mode_info_stride * (cm->mi_rows + MI_BLOCK_SIZE);
cm->mip = (MODE_INFO *)vpx_calloc(mi_size, sizeof(MODE_INFO));
if (!cm->mip)
goto fail;
cm->prev_mip = (MODE_INFO *)vpx_calloc(mi_size, sizeof(MODE_INFO));
if (!cm->prev_mip)
goto fail;
cm->mi_grid_base =
(MODE_INFO **)vpx_calloc(mi_size, sizeof(*cm->mi_grid_base));
if (!cm->mi_grid_base)
goto fail;
cm->prev_mi_grid_base =
(MODE_INFO **)vpx_calloc(mi_size, sizeof(*cm->prev_mi_grid_base));
if (!cm->prev_mi_grid_base)
goto fail; goto fail;
setup_mi(cm); setup_mi(cm);
......
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