static void alloc_mode_context(VP9_COMMON *cm, int num_4x4_blk, PICK_MODE_CONTEXT *ctx) { const int num_blk = (num_4x4_blk < 4 ? 4 : num_4x4_blk); const int num_pix = num_blk << 4; int i, k; ctx->num_4x4_blk = num_blk; CHECK_MEM_ERROR(cm, ctx->zcoeff_blk, vpx_calloc(num_4x4_blk, sizeof(uint8_t))); for (i = 0; i < MAX_MB_PLANE; ++i) { for (k = 0; k < 3; ++k) { CHECK_MEM_ERROR(cm, ctx->coeff[i][k], vpx_memalign(16, num_pix * sizeof(int16_t))); CHECK_MEM_ERROR(cm, ctx->qcoeff[i][k], vpx_memalign(16, num_pix * sizeof(int16_t))); CHECK_MEM_ERROR(cm, ctx->dqcoeff[i][k], vpx_memalign(16, num_pix * sizeof(int16_t))); CHECK_MEM_ERROR(cm, ctx->eobs[i][k], vpx_memalign(16, num_pix * sizeof(uint16_t))); ctx->coeff_pbuf[i][k] = ctx->coeff[i][k]; ctx->qcoeff_pbuf[i][k] = ctx->qcoeff[i][k]; ctx->dqcoeff_pbuf[i][k] = ctx->dqcoeff[i][k]; ctx->eobs_pbuf[i][k] = ctx->eobs[i][k]; } } }
void vp9_create_encoding_threads(VP9_COMP *cpi) { VP9_COMMON * const cm = &cpi->common; const VP9WorkerInterface * const winterface = vp9_get_worker_interface(); int i; CHECK_MEM_ERROR(cm, cpi->enc_thread_hndl, vpx_malloc(sizeof(*cpi->enc_thread_hndl) * cpi->max_threads)); for (i = 0; i < cpi->max_threads; ++i) { VP9Worker * const worker = &cpi->enc_thread_hndl[i]; winterface->init(worker); CHECK_MEM_ERROR(cm, worker->data1, vpx_memalign(32, sizeof(thread_context))); worker->data2 = NULL; if (i < cpi->max_threads - 1 && !winterface->reset(worker)) { vpx_internal_error(&cm->error, VPX_CODEC_ERROR, "Tile decoder thread creation failed"); } } // set row encoding hook for (i = 0; i < cpi->max_threads; ++i) { winterface->sync(&cpi->enc_thread_hndl[i]); cpi->enc_thread_hndl[i].hook = (VP9WorkerHook) encoding_thread_process; } CHECK_MEM_ERROR(cm, cpi->cur_sb_col, vpx_malloc(sizeof(*cpi->cur_sb_col) * cm->sb_rows)); // init cur sb col vpx_memset(cpi->cur_sb_col, -1, (sizeof(*cpi->cur_sb_col) * cm->sb_rows)); // set up nsync (currently unused). cpi->sync_range = get_sync_range(cpi->oxcf.width); }
static void create_enc_workers(VP9_COMP *cpi, int num_workers) { VP9_COMMON *const cm = &cpi->common; const VPxWorkerInterface *const winterface = vpx_get_worker_interface(); int i; // Only run once to create threads and allocate thread data. if (cpi->num_workers == 0) { int allocated_workers = num_workers; // While using SVC, we need to allocate threads according to the highest // resolution. When row based multithreading is enabled, it is OK to // allocate more threads than the number of max tile columns. if (cpi->use_svc && !cpi->row_mt) { int max_tile_cols = get_max_tile_cols(cpi); allocated_workers = VPXMIN(cpi->oxcf.max_threads, max_tile_cols); } CHECK_MEM_ERROR(cm, cpi->workers, vpx_malloc(allocated_workers * sizeof(*cpi->workers))); CHECK_MEM_ERROR(cm, cpi->tile_thr_data, vpx_calloc(allocated_workers, sizeof(*cpi->tile_thr_data))); for (i = 0; i < allocated_workers; i++) { VPxWorker *const worker = &cpi->workers[i]; EncWorkerData *thread_data = &cpi->tile_thr_data[i]; ++cpi->num_workers; winterface->init(worker); if (i < allocated_workers - 1) { thread_data->cpi = cpi; // Allocate thread data. CHECK_MEM_ERROR(cm, thread_data->td, vpx_memalign(32, sizeof(*thread_data->td))); vp9_zero(*thread_data->td); // Set up pc_tree. thread_data->td->leaf_tree = NULL; thread_data->td->pc_tree = NULL; vp9_setup_pc_tree(cm, thread_data->td); // Allocate frame counters in thread data. CHECK_MEM_ERROR(cm, thread_data->td->counts, vpx_calloc(1, sizeof(*thread_data->td->counts))); // Create threads if (!winterface->reset(worker)) vpx_internal_error(&cm->error, VPX_CODEC_ERROR, "Tile encoder thread creation failed"); } else { // Main thread acts as a worker and uses the thread data in cpi. thread_data->cpi = cpi; thread_data->td = &cpi->td; } winterface->sync(worker); } } }
// Allocate memory for row synchronization void vp9_row_mt_sync_mem_alloc(VP9RowMTSync *row_mt_sync, VP9_COMMON *cm, int rows) { row_mt_sync->rows = rows; #if CONFIG_MULTITHREAD { int i; CHECK_MEM_ERROR(cm, row_mt_sync->mutex_, vpx_malloc(sizeof(*row_mt_sync->mutex_) * rows)); if (row_mt_sync->mutex_) { for (i = 0; i < rows; ++i) { pthread_mutex_init(&row_mt_sync->mutex_[i], NULL); } } CHECK_MEM_ERROR(cm, row_mt_sync->cond_, vpx_malloc(sizeof(*row_mt_sync->cond_) * rows)); if (row_mt_sync->cond_) { for (i = 0; i < rows; ++i) { pthread_cond_init(&row_mt_sync->cond_[i], NULL); } } } #endif // CONFIG_MULTITHREAD CHECK_MEM_ERROR(cm, row_mt_sync->cur_col, vpx_malloc(sizeof(*row_mt_sync->cur_col) * rows)); // Set up nsync. row_mt_sync->sync_range = 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)); }
// Allocate memory for lf row synchronization void vp9_loop_filter_alloc(VP9LfSync *lf_sync, VP9_COMMON *cm, int rows, int width) { lf_sync->rows = rows; #if CONFIG_MULTITHREAD { int i; CHECK_MEM_ERROR(cm, lf_sync->mutex_, vpx_malloc(sizeof(*lf_sync->mutex_) * rows)); for (i = 0; i < rows; ++i) { pthread_mutex_init(&lf_sync->mutex_[i], NULL); } CHECK_MEM_ERROR(cm, lf_sync->cond_, vpx_malloc(sizeof(*lf_sync->cond_) * rows)); for (i = 0; i < rows; ++i) { pthread_cond_init(&lf_sync->cond_[i], NULL); } } #endif // CONFIG_MULTITHREAD CHECK_MEM_ERROR(cm, lf_sync->cur_sb_col, vpx_malloc(sizeof(*lf_sync->cur_sb_col) * rows)); // Set up nsync. lf_sync->sync_range = get_sync_range(width); }
void vp8cx_create_encoder_threads(VP8_COMP *cpi) { cpi->b_multi_threaded = 0; cpi->processor_core_count = 32; //vp8_get_proc_core_count(); CHECK_MEM_ERROR(cpi->tplist, vpx_malloc(sizeof(TOKENLIST) * cpi->common.mb_rows)); #if CONFIG_MULTITHREAD if (cpi->processor_core_count > 1 && cpi->oxcf.multi_threaded > 1) { int ithread; if (cpi->oxcf.multi_threaded > cpi->processor_core_count) cpi->encoding_thread_count = cpi->processor_core_count - 1; else cpi->encoding_thread_count = cpi->oxcf.multi_threaded - 1; CHECK_MEM_ERROR(cpi->h_encoding_thread, vpx_malloc(sizeof(pthread_t) * cpi->encoding_thread_count)); CHECK_MEM_ERROR(cpi->h_event_mbrencoding, vpx_malloc(sizeof(sem_t) * cpi->encoding_thread_count)); CHECK_MEM_ERROR(cpi->mb_row_ei, vpx_memalign(32, sizeof(MB_ROW_COMP) * cpi->encoding_thread_count)); vpx_memset(cpi->mb_row_ei, 0, sizeof(MB_ROW_COMP) * cpi->encoding_thread_count); CHECK_MEM_ERROR(cpi->en_thread_data, vpx_malloc(sizeof(ENCODETHREAD_DATA) * cpi->encoding_thread_count)); //cpi->h_event_main = CreateEvent(NULL, FALSE, FALSE, NULL); sem_init(&cpi->h_event_main, 0, 0); cpi->b_multi_threaded = 1; //printf("[VP8:] multi_threaded encoding is enabled with %d threads\n\n", (cpi->encoding_thread_count +1)); for (ithread = 0; ithread < cpi->encoding_thread_count; ithread++) { //cpi->h_event_mbrencoding[ithread] = CreateEvent(NULL, FALSE, FALSE, NULL); sem_init(&cpi->h_event_mbrencoding[ithread], 0, 0); cpi->en_thread_data[ithread].ithread = ithread; cpi->en_thread_data[ithread].ptr1 = (void *)cpi; cpi->en_thread_data[ithread].ptr2 = (void *)&cpi->mb_row_ei[ithread]; //printf(" call begin thread %d \n", ithread); //cpi->h_encoding_thread[ithread] = (HANDLE)_beginthreadex( // NULL, // security // 0, // stksize // thread_encoding_proc, // (&cpi->en_thread_data[ithread]), // Thread data // 0, // NULL); pthread_create(&cpi->h_encoding_thread[ithread], 0, thread_encoding_proc, (&cpi->en_thread_data[ithread])); } } #endif }
// This function sets up a tree of contexts such that at each square // partition level. There are contexts for none, horizontal, vertical, and // split. Along with a block_size value and a selected block_size which // represents the state of our search. void vp10_setup_pc_tree(VP10_COMMON *cm, ThreadData *td) { int i, j; const int leaf_nodes = 64; const int tree_nodes = 64 + 16 + 4 + 1; int pc_tree_index = 0; PC_TREE *this_pc; PICK_MODE_CONTEXT *this_leaf; int square_index = 1; int nodes; vpx_free(td->leaf_tree); CHECK_MEM_ERROR(cm, td->leaf_tree, vpx_calloc(leaf_nodes, sizeof(*td->leaf_tree))); vpx_free(td->pc_tree); CHECK_MEM_ERROR(cm, td->pc_tree, vpx_calloc(tree_nodes, sizeof(*td->pc_tree))); this_pc = &td->pc_tree[0]; this_leaf = &td->leaf_tree[0]; // 4x4 blocks smaller than 8x8 but in the same 8x8 block share the same // context so we only need to allocate 1 for each 8x8 block. for (i = 0; i < leaf_nodes; ++i) alloc_mode_context(cm, 1, &td->leaf_tree[i]); // Sets up all the leaf nodes in the tree. for (pc_tree_index = 0; pc_tree_index < leaf_nodes; ++pc_tree_index) { PC_TREE *const tree = &td->pc_tree[pc_tree_index]; tree->block_size = square[0]; alloc_tree_contexts(cm, tree, 4); tree->leaf_split[0] = this_leaf++; for (j = 1; j < 4; j++) tree->leaf_split[j] = tree->leaf_split[0]; } // Each node has 4 leaf nodes, fill each block_size level of the tree // from leafs to the root. for (nodes = 16; nodes > 0; nodes >>= 2) { for (i = 0; i < nodes; ++i) { PC_TREE *const tree = &td->pc_tree[pc_tree_index]; alloc_tree_contexts(cm, tree, 4 << (2 * square_index)); tree->block_size = square[square_index]; for (j = 0; j < 4; j++) tree->split[j] = this_pc++; ++pc_tree_index; } ++square_index; } td->pc_root = &td->pc_tree[tree_nodes - 1]; td->pc_root[0].none.best_mode_index = 2; }
VP9Decoder *vp9_decoder_create() { VP9Decoder *const pbi = vpx_memalign(32, sizeof(*pbi)); VP9_COMMON *const cm = pbi ? &pbi->common : NULL; if (!cm) return NULL; vp9_zero(*pbi); if (setjmp(cm->error.jmp)) { cm->error.setjmp = 0; vp9_decoder_remove(pbi); return NULL; } cm->error.setjmp = 1; CHECK_MEM_ERROR(cm, cm->fc, (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc))); CHECK_MEM_ERROR(cm, cm->frame_contexts, (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS, sizeof(*cm->frame_contexts))); pbi->need_resync = 1; initialize_dec(); // Initialize the references to not point to any frame buffers. vpx_memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map)); cm->current_video_frame = 0; pbi->ready_for_new_data = 1; cm->bit_depth = VPX_BITS_8; cm->dequant_bit_depth = VPX_BITS_8; cm->alloc_mi = vp9_dec_alloc_mi; cm->free_mi = vp9_dec_free_mi; cm->setup_mi = vp9_dec_setup_mi; // vp9_init_dequantizer() is first called here. Add check in // frame_init_dequantizer() to avoid unnecessary calling of // vp9_init_dequantizer() for every frame. vp9_init_dequantizer(cm); vp9_loop_filter_init(cm); cm->error.setjmp = 0; vp9_get_worker_interface()->init(&pbi->lf_worker); return pbi; }
VP10Decoder *vp10_decoder_create(BufferPool *const pool) { VP10Decoder *volatile const pbi = vpx_memalign(32, sizeof(*pbi)); VP10_COMMON *volatile const cm = pbi ? &pbi->common : NULL; if (!cm) return NULL; vp10_zero(*pbi); if (setjmp(cm->error.jmp)) { cm->error.setjmp = 0; vp10_decoder_remove(pbi); return NULL; } cm->error.setjmp = 1; CHECK_MEM_ERROR(cm, cm->fc, (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc))); CHECK_MEM_ERROR(cm, cm->frame_contexts, (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS, sizeof(*cm->frame_contexts))); pbi->need_resync = 1; once(initialize_dec); // Initialize the references to not point to any frame buffers. memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map)); memset(&cm->next_ref_frame_map, -1, sizeof(cm->next_ref_frame_map)); cm->current_video_frame = 0; pbi->ready_for_new_data = 1; pbi->common.buffer_pool = pool; cm->bit_depth = VPX_BITS_8; cm->dequant_bit_depth = VPX_BITS_8; cm->alloc_mi = vp10_dec_alloc_mi; cm->free_mi = vp10_dec_free_mi; cm->setup_mi = vp10_dec_setup_mi; vp10_loop_filter_init(cm); cm->error.setjmp = 0; vpx_get_worker_interface()->init(&pbi->lf_worker); return pbi; }
struct label_t * new_label(){ struct label_t* l; l = (struct label_t*) malloc(sizeof(struct label_t)); CHECK_MEM_ERROR(l); l->id = NULL; return l; }
/* * Creates a new scope and adds it to the tail of the list. */ struct scope_t *new_scope() { struct scope_t *temp_scope; temp_scope = (struct scope_t *) malloc(sizeof(struct scope_t)); CHECK_MEM_ERROR(temp_scope); temp_scope->attrId = -1; temp_scope->parent = NULL; temp_scope->program = NULL; temp_scope->class_scopes = NULL; temp_scope->cl = NULL; temp_scope->func_scopes = NULL; temp_scope->fd = NULL; temp_scope->temps = NULL; temp_scope->symbol_list = NULL; temp_scope->next = NULL; temp_scope->nextSibling = NULL; // Add it to the master list if(allScopes == NULL) { allScopes = temp_scope; } else { // Find the end of the list struct scope_t *end = allScopes; while(end->next != NULL) end = end->next; // Add temp_scope to the end of the master list end->next = temp_scope; } return temp_scope; }
/* ----------------------------------------------------------------------- * Returns a pointer to a new primitive_type * ----------------------------------------------------------------------- */ char *new_primitive_type(char *type) { char *t; t = (char *) malloc(strlen(type) + 1); /* +1 for '\0' */ CHECK_MEM_ERROR(t) strcpy(t, type); return t; }
/* ----------------------------------------------------------------------- * Checks if str is set to NULL; if so, it initializes it and copies in it * the string "(null)" to imitate the correct libc behaviour in linux's * glibc. The Solaris libc is so naive. * ----------------------------------------------------------------------- */ void error_check_not_null(char **str) { if (*str == NULL) { *str = (char *) malloc (strlen("(null)") + 1); CHECK_MEM_ERROR((*str)) strcpy(*str, "(null)"); } }
struct if_code_t * new_if_code(){ struct if_code_t* ic; ic = (struct if_code_t*)malloc(sizeof(struct if_code_t)); CHECK_MEM_ERROR(ic); ic->var = NULL; ic->true_target = NULL; ic->false_target = NULL; return ic; }
struct op_code_t* new_op_code(){ struct op_code_t* oc; oc = (struct op_code_t*) malloc(sizeof(struct op_code_t)); CHECK_MEM_ERROR(oc); oc->v1 = NULL; oc->v2 = NULL; oc->relop = -1; return oc; }
/* ----------------------------------------------------------------------- * Returns a pointer to the new primary * ----------------------------------------------------------------------- */ struct primary_t *new_primary() { struct primary_t *p; p = (struct primary_t *) malloc(sizeof(struct primary_t)); CHECK_MEM_ERROR(p) p->type = -1; return p; }
/* ----------------------------------------------------------------------- * Returns a pointer to a new identifier * ----------------------------------------------------------------------- */ char *new_identifier(char *text) { char *id; id = (char *) malloc(strlen(text) + 1); /* +1 for '\0' */ CHECK_MEM_ERROR(id) strcpy(id, text); return id; }
/* ----------------------------------------------------------------------- * Outputs an error message if an array variable index is outside the * array's boundaries * ----------------------------------------------------------------------- */ void error_array_index_out_of_bounds(int line_number, long index, long min, long max) { char *e; e = (char *) malloc(MAX_ERROR_SIZE); CHECK_MEM_ERROR(e) sprintf(e, "Array index %ld is out of the range (%ld,%ld)", index, min, max); error(line_number, e); }
/* ----------------------------------------------------------------------- * Outputs an error message if an array declaration contains an * invalid range * ----------------------------------------------------------------------- */ void error_array_range_invalid(int line_number, long min, long max) { char *e; e = (char *) malloc(MAX_ERROR_SIZE); CHECK_MEM_ERROR(e) sprintf(e, "Invalid array range (%ld,%ld)", min, max); error(line_number, e); }
/* ----------------------------------------------------------------------- * Outputs an error message if the program does not have a class named * the same as the program * ----------------------------------------------------------------------- */ void error_missing_program_class() { char *e; e = (char *) malloc(MAX_ERROR_SIZE); CHECK_MEM_ERROR(e) sprintf(e, "Missing program class"); error(-1, e); }
/* ----------------------------------------------------------------------- * Outputs an error message if an impossible/defective state was reached * ----------------------------------------------------------------------- */ void error_unknown(int line_number) { char *e; e = (char *) malloc(MAX_ERROR_SIZE); CHECK_MEM_ERROR(e) sprintf(e, ERROR_UNKNOWN); error(line_number, e); }
/* ----------------------------------------------------------------------- * Returns a pointer to a new print_statement * ----------------------------------------------------------------------- */ struct print_statement_t *new_print_statement() { struct print_statement_t *ps; ps = (struct print_statement_t *) malloc(sizeof(struct print_statement_t)); CHECK_MEM_ERROR(ps) ps->va = NULL; return ps; }
/* ----------------------------------------------------------------------- * Outputs an error message if there are too many (more than one) signs * in a factor * ----------------------------------------------------------------------- */ void error_too_many_signs(int line_number) { char *e; e = (char *) malloc(MAX_ERROR_SIZE); CHECK_MEM_ERROR(e) sprintf(e, "Too many signs"); error(line_number, e); }
/* ----------------------------------------------------------------------- * Returns a pointer to a new attribute_designator * ----------------------------------------------------------------------- */ struct attribute_designator_t *new_attribute_designator() { struct attribute_designator_t *fd; fd = (struct attribute_designator_t *) malloc(sizeof(struct attribute_designator_t)); CHECK_MEM_ERROR(fd) fd->va = NULL; fd->id = NULL; return fd; }
/* ----------------------------------------------------------------------- * Returns a pointer to a new while_statement * ----------------------------------------------------------------------- */ struct while_statement_t *new_while_statement() { struct while_statement_t *ws; ws = (struct while_statement_t *) malloc(sizeof(struct while_statement_t)); CHECK_MEM_ERROR(ws) ws->e = NULL; ws->s = NULL; return ws; }
/* ----------------------------------------------------------------------- * Returns a pointer to a new indexed_variable * ----------------------------------------------------------------------- */ struct indexed_variable_t *new_indexed_variable() { struct indexed_variable_t *iv; iv = (struct indexed_variable_t *) malloc(sizeof(struct indexed_variable_t)); CHECK_MEM_ERROR(iv) iv->va = NULL; iv->iel = NULL; return iv; }
/* ----------------------------------------------------------------------- * Returns a pointer to a new method_designator * ----------------------------------------------------------------------- */ struct method_designator_t *new_method_designator() { struct method_designator_t *md; md = (struct method_designator_t *) malloc(sizeof(struct method_designator_t)); CHECK_MEM_ERROR(md) md->va = NULL; md->fd = NULL; return md; }
/* ----------------------------------------------------------------------- * Returns a pointer to the new factor * ----------------------------------------------------------------------- */ struct factor_t *new_factor() { struct factor_t *f; f = (struct factor_t *) malloc(sizeof(struct factor_t)); CHECK_MEM_ERROR(f) f->type = -1; return f; }
/* ----------------------------------------------------------------------- * Returns a pointer to a new class_block * ----------------------------------------------------------------------- */ struct class_block_t *new_class_block() { struct class_block_t *cb; cb = (struct class_block_t *) malloc(sizeof(struct class_block_t)); CHECK_MEM_ERROR(cb) cb->vdl = NULL; cb->fdl = NULL; return cb; }