int vp8_denoiser_allocate(VP8_DENOISER *denoiser, int width, int height) { int i; assert(denoiser); for (i = 0; i < MAX_REF_FRAMES; i++) { denoiser->yv12_running_avg[i].flags = 0; if (vp8_yv12_alloc_frame_buffer(&(denoiser->yv12_running_avg[i]), width, height, VP8BORDERINPIXELS) < 0) { vp8_denoiser_free(denoiser); return 1; } vpx_memset(denoiser->yv12_running_avg[i].buffer_alloc, 0, denoiser->yv12_running_avg[i].frame_size); } denoiser->yv12_mc_running_avg.flags = 0; if (vp8_yv12_alloc_frame_buffer(&(denoiser->yv12_mc_running_avg), width, height, VP8BORDERINPIXELS) < 0) { vp8_denoiser_free(denoiser); return 1; } vpx_memset(denoiser->yv12_mc_running_avg.buffer_alloc, 0, denoiser->yv12_mc_running_avg.frame_size); return 0; }
struct lookahead_ctx* vp8_lookahead_init(unsigned int width, unsigned int height, unsigned int depth) { struct lookahead_ctx *ctx = NULL; unsigned int i; /* Clamp the lookahead queue depth */ if(depth < 1) depth = 1; else if(depth > MAX_LAG_BUFFERS) depth = MAX_LAG_BUFFERS; /* Keep last frame in lookahead buffer by increasing depth by 1.*/ depth += 1; /* Align the buffer dimensions */ width = (width + 15) & ~15; height = (height + 15) & ~15; /* Allocate the lookahead structures */ ctx = calloc(1, sizeof(*ctx)); if(ctx) { ctx->max_sz = depth; ctx->buf = calloc(depth, sizeof(*ctx->buf)); if(!ctx->buf) goto bail; for(i=0; i<depth; i++) if (vp8_yv12_alloc_frame_buffer(&ctx->buf[i].img, width, height, VP8BORDERINPIXELS)) goto bail; } return ctx; bail: vp8_lookahead_destroy(ctx); return NULL; }
int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height) { int i; vp8_de_alloc_frame_buffers(oci); /* our internal buffers are always multiples of 16 */ if ((width & 0xf) != 0) width += 16 - (width & 0xf); if ((height & 0xf) != 0) height += 16 - (height & 0xf); for (i = 0; i < NUM_YV12_BUFFERS; i++) { oci->fb_idx_ref_cnt[0] = 0; if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height, VP8BORDERINPIXELS) < 0) { vp8_de_alloc_frame_buffers(oci); return ALLOC_FAILURE; } } oci->new_fb_idx = 0; oci->lst_fb_idx = 1; oci->gld_fb_idx = 2; oci->alt_fb_idx = 3; oci->fb_idx_ref_cnt[0] = 1; oci->fb_idx_ref_cnt[1] = 1; oci->fb_idx_ref_cnt[2] = 1; oci->fb_idx_ref_cnt[3] = 1; if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16, VP8BORDERINPIXELS) < 0) { vp8_de_alloc_frame_buffers(oci); return ALLOC_FAILURE; } if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0) { vp8_de_alloc_frame_buffers(oci); return ALLOC_FAILURE; } oci->mb_rows = height >> 4; oci->mb_cols = width >> 4; oci->MBs = oci->mb_rows * oci->mb_cols; oci->mode_info_stride = oci->mb_cols + 1; oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO)); if (!oci->mip) { vp8_de_alloc_frame_buffers(oci); return ALLOC_FAILURE; } oci->mi = oci->mip + oci->mode_info_stride + 1; oci->above_context = vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1); if (!oci->above_context) { vp8_de_alloc_frame_buffers(oci); return ALLOC_FAILURE; } vp8_update_mode_info_border(oci->mi, oci->mb_rows, oci->mb_cols); return 0; }
int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height) { int i; vp8_de_alloc_frame_buffers(oci); if ((width & 0xf) != 0) width += 16 - (width & 0xf); if ((height & 0xf) != 0) height += 16 - (height & 0xf); for (i = 0; i < NUM_YV12_BUFFERS; i++) { oci->fb_idx_ref_cnt[i] = 0; oci->yv12_fb[i].flags = 0; if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height, VP8BORDERINPIXELS) < 0) goto allocation_fail; } oci->new_fb_idx = 0; oci->lst_fb_idx = 1; oci->gld_fb_idx = 2; oci->alt_fb_idx = 3; oci->fb_idx_ref_cnt[0] = 1; oci->fb_idx_ref_cnt[1] = 1; oci->fb_idx_ref_cnt[2] = 1; oci->fb_idx_ref_cnt[3] = 1; if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16, VP8BORDERINPIXELS) < 0) goto allocation_fail; oci->mb_rows = height >> 4; oci->mb_cols = width >> 4; oci->MBs = oci->mb_rows * oci->mb_cols; oci->mode_info_stride = oci->mb_cols + 1; oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO)); if (!oci->mip) goto allocation_fail; oci->mi = oci->mip + oci->mode_info_stride + 1; oci->above_context = vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1); if (!oci->above_context) goto allocation_fail; #if CONFIG_POSTPROC if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0) goto allocation_fail; oci->post_proc_buffer_int_used = 0; vpx_memset(&oci->postproc_state, 0, sizeof(oci->postproc_state)); vpx_memset(oci->post_proc_buffer.buffer_alloc, 128, oci->post_proc_buffer.frame_size); oci->pp_limits_buffer = vpx_memalign(16, 24 * ((oci->mb_cols + 1) & ~1)); if (!oci->pp_limits_buffer) goto allocation_fail; #endif return 0; allocation_fail: vp8_de_alloc_frame_buffers(oci); return 1; }
int vp9_alloc_frame_buffers(VP9_COMMON *oci, int width, int height) { int i; int aligned_width, aligned_height; vp9_de_alloc_frame_buffers(oci); /* our internal buffers are always multiples of 16 */ aligned_width = (width + 15) & ~15; aligned_height = (height + 15) & ~15; for (i = 0; i < NUM_YV12_BUFFERS; i++) { oci->fb_idx_ref_cnt[i] = 0; if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height, VP9BORDERINPIXELS) < 0) { vp9_de_alloc_frame_buffers(oci); return 1; } } oci->new_fb_idx = NUM_YV12_BUFFERS - 1; oci->fb_idx_ref_cnt[oci->new_fb_idx] = 1; for (i = 0; i < 3; i++) oci->active_ref_idx[i] = i; for (i = 0; i < NUM_REF_FRAMES; i++) { oci->ref_frame_map[i] = i; oci->fb_idx_ref_cnt[i] = 1; } if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16, VP9BORDERINPIXELS) < 0) { vp9_de_alloc_frame_buffers(oci); return 1; } if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP9BORDERINPIXELS) < 0) { vp9_de_alloc_frame_buffers(oci); return 1; } oci->mb_rows = aligned_height >> 4; oci->mb_cols = aligned_width >> 4; oci->MBs = oci->mb_rows * oci->mb_cols; oci->mode_info_stride = oci->mb_cols + 1; oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO)); if (!oci->mip) { vp9_de_alloc_frame_buffers(oci); return 1; } oci->mi = oci->mip + oci->mode_info_stride + 1; /* allocate memory for last frame MODE_INFO array */ oci->prev_mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO)); if (!oci->prev_mip) { vp9_de_alloc_frame_buffers(oci); return 1; } oci->prev_mi = oci->prev_mip + oci->mode_info_stride + 1; oci->above_context = vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * (3 + oci->mb_cols), 1); if (!oci->above_context) { vp9_de_alloc_frame_buffers(oci); return 1; } vp9_update_mode_info_border(oci, oci->mip); vp9_update_mode_info_in_image(oci, oci->mi); return 0; }
int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height) { int i; vp8_de_alloc_frame_buffers(oci); /* our internal buffers are always multiples of 16 */ if ((width & 0xf) != 0) width += 16 - (width & 0xf); if ((height & 0xf) != 0) height += 16 - (height & 0xf); for (i = 0; i < NUM_YV12_BUFFERS; i++) { oci->fb_idx_ref_cnt[i] = 0; oci->yv12_fb[i].flags = 0; if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height, VP8BORDERINPIXELS) < 0) goto allocation_fail; } oci->new_fb_idx = 0; oci->lst_fb_idx = 1; oci->gld_fb_idx = 2; oci->alt_fb_idx = 3; oci->fb_idx_ref_cnt[0] = 1; oci->fb_idx_ref_cnt[1] = 1; oci->fb_idx_ref_cnt[2] = 1; oci->fb_idx_ref_cnt[3] = 1; if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16, VP8BORDERINPIXELS) < 0) goto allocation_fail; oci->mb_rows = height >> 4; oci->mb_cols = width >> 4; oci->MBs = oci->mb_rows * oci->mb_cols; oci->mode_info_stride = oci->mb_cols + 1; oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO)); if (!oci->mip) goto allocation_fail; oci->mi = oci->mip + oci->mode_info_stride + 1; /* Allocation of previous mode info will be done in vp8_decode_frame() * as it is a decoder only data */ oci->above_context = vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1); if (!oci->above_context) goto allocation_fail; #if CONFIG_POSTPROC if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0) goto allocation_fail; oci->post_proc_buffer_int_used = 0; vpx_memset(&oci->postproc_state, 0, sizeof(oci->postproc_state)); vpx_memset(oci->post_proc_buffer.buffer_alloc, 128, oci->post_proc_buffer.frame_size); /* Allocate buffer to store post-processing filter coefficients. * * Note: Round up mb_cols to support SIMD reads */ oci->pp_limits_buffer = vpx_memalign(16, 24 * ((oci->mb_cols + 1) & ~1)); if (!oci->pp_limits_buffer) goto allocation_fail; #endif return 0; allocation_fail: vp8_de_alloc_frame_buffers(oci); return 1; }
int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height) { int i; vp8_de_alloc_frame_buffers(oci); /* our internal buffers are always multiples of 16 */ if ((width & 0xf) != 0) width += 16 - (width & 0xf); if ((height & 0xf) != 0) height += 16 - (height & 0xf); for (i = 0; i < NUM_YV12_BUFFERS; i++) { oci->fb_idx_ref_cnt[i] = 0; oci->yv12_fb[i].flags = 0; if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height, VP8BORDERINPIXELS) < 0) { vp8_de_alloc_frame_buffers(oci); return 1; } } oci->new_fb_idx = 0; oci->lst_fb_idx = 1; oci->gld_fb_idx = 2; oci->alt_fb_idx = 3; oci->fb_idx_ref_cnt[0] = 1; oci->fb_idx_ref_cnt[1] = 1; oci->fb_idx_ref_cnt[2] = 1; oci->fb_idx_ref_cnt[3] = 1; if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16, VP8BORDERINPIXELS) < 0) { vp8_de_alloc_frame_buffers(oci); return 1; } if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0) { vp8_de_alloc_frame_buffers(oci); return 1; } oci->post_proc_buffer_int_used = 0; oci->mb_rows = height >> 4; oci->mb_cols = width >> 4; oci->MBs = oci->mb_rows * oci->mb_cols; oci->mode_info_stride = oci->mb_cols + 1; oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO)); if (!oci->mip) { vp8_de_alloc_frame_buffers(oci); return 1; } oci->mi = oci->mip + oci->mode_info_stride + 1; /* allocate memory for last frame MODE_INFO array */ #if CONFIG_ERROR_CONCEALMENT oci->prev_mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO)); if (!oci->prev_mip) { vp8_de_alloc_frame_buffers(oci); return 1; } oci->prev_mi = oci->prev_mip + oci->mode_info_stride + 1; #else oci->prev_mip = NULL; oci->prev_mi = NULL; #endif oci->above_context = vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1); if (!oci->above_context) { vp8_de_alloc_frame_buffers(oci); return 1; } update_mode_info_border(oci->mi, oci->mb_rows, oci->mb_cols); #if CONFIG_ERROR_CONCEALMENT update_mode_info_border(oci->prev_mi, oci->mb_rows, oci->mb_cols); #endif return 0; }