int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) { vp9_free_context_buffers(cm); vp9_set_mb_mi(cm, width, height); if (alloc_mi(cm, cm->mi_stride * calc_mi_size(cm->mi_rows))) goto fail; if (cm->use_gpu) { if (vp9_alloc_gpu_interface_buffers(cm)) goto fail; cm->is_background_map = (uint8_t *)vpx_calloc( cm->sb_rows * cm->sb_cols, sizeof(*cm->is_background_map)); if (!cm->is_background_map) goto fail; } cm->last_frame_seg_map = (uint8_t *)vpx_calloc(cm->mi_rows * cm->mi_cols, 1); if (!cm->last_frame_seg_map) goto fail; cm->above_context = (ENTROPY_CONTEXT *)vpx_calloc( 2 * mi_cols_aligned_to_sb(cm->mi_cols) * MAX_MB_PLANE, sizeof(*cm->above_context)); if (!cm->above_context) goto fail; cm->above_seg_context = (PARTITION_CONTEXT *)vpx_calloc( mi_cols_aligned_to_sb(cm->mi_cols), sizeof(*cm->above_seg_context)); if (!cm->above_seg_context) goto fail; return 0; fail: vp9_free_context_buffers(cm); return 1; }
int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) { vp9_free_context_buffers(cm); vp9_set_mb_mi(cm, width, height); if (cm->alloc_mi(cm, cm->mi_stride * calc_mi_size(cm->mi_rows))) goto fail; // Create the segmentation map structure and set to 0. free_seg_map(cm); if (alloc_seg_map(cm, cm->mi_rows * cm->mi_cols)) goto fail; cm->above_context = (ENTROPY_CONTEXT *)vpx_calloc( 2 * mi_cols_aligned_to_sb(cm->mi_cols) * MAX_MB_PLANE, sizeof(*cm->above_context)); if (!cm->above_context) goto fail; cm->above_seg_context = (PARTITION_CONTEXT *)vpx_calloc( mi_cols_aligned_to_sb(cm->mi_cols), sizeof(*cm->above_seg_context)); if (!cm->above_seg_context) goto fail; return 0; fail: vp9_free_context_buffers(cm); return 1; }
// Allocate storage for each tile column. // TODO(jzern): when max_threads <= 1 the same storage could be used for each // tile. static void alloc_tile_storage(VP9D_COMP *pbi, int tile_cols) { VP9_COMMON *const cm = &pbi->common; const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); int i, tile_col; CHECK_MEM_ERROR(cm, pbi->mi_streams, vpx_realloc(pbi->mi_streams, tile_cols * sizeof(*pbi->mi_streams))); for (tile_col = 0; tile_col < tile_cols; ++tile_col) { TileInfo tile; vp9_tile_init(&tile, cm, 0, tile_col); pbi->mi_streams[tile_col] = &cm->mi[cm->mi_rows * tile.mi_col_start]; } // 2 contexts per 'mi unit', so that we have one context per 4x4 txfm // block where mi unit size is 8x8. CHECK_MEM_ERROR(cm, pbi->above_context[0], vpx_realloc(pbi->above_context[0], sizeof(*pbi->above_context[0]) * MAX_MB_PLANE * 2 * aligned_mi_cols)); for (i = 1; i < MAX_MB_PLANE; ++i) { pbi->above_context[i] = pbi->above_context[0] + i * sizeof(*pbi->above_context[0]) * 2 * aligned_mi_cols; } // This is sized based on the entire frame. Each tile operates within its // column bounds. CHECK_MEM_ERROR(cm, pbi->above_seg_context, vpx_realloc(pbi->above_seg_context, sizeof(*pbi->above_seg_context) * aligned_mi_cols)); }
static size_t encode_tiles(VP9_COMP *cpi, uint8_t *data_ptr) { VP9_COMMON *const cm = &cpi->common; vpx_writer residual_bc; int tile_row, tile_col; TOKENEXTRA *tok_end; size_t total_size = 0; const int tile_cols = 1 << cm->log2_tile_cols; const int tile_rows = 1 << cm->log2_tile_rows; memset(cm->above_seg_context, 0, sizeof(*cm->above_seg_context) * mi_cols_aligned_to_sb(cm->mi_cols)); for (tile_row = 0; tile_row < tile_rows; tile_row++) { for (tile_col = 0; tile_col < tile_cols; tile_col++) { int tile_idx = tile_row * tile_cols + tile_col; TOKENEXTRA *tok = cpi->tile_tok[tile_row][tile_col]; tok_end = cpi->tile_tok[tile_row][tile_col] + cpi->tok_count[tile_row][tile_col]; if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1) vpx_start_encode(&residual_bc, data_ptr + total_size + 4); else vpx_start_encode(&residual_bc, data_ptr + total_size); write_modes(cpi, &cpi->tile_data[tile_idx].tile_info, &residual_bc, &tok, tok_end); assert(tok == tok_end); vpx_stop_encode(&residual_bc); if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1) { // size of this tile mem_put_be32(data_ptr + total_size, residual_bc.pos); total_size += 4; } total_size += residual_bc.pos; } } return total_size; }