aom_codec_err_t av1_copy_reference_dec(AV1Decoder *pbi, int idx, YV12_BUFFER_CONFIG *sd) { AV1_COMMON *cm = &pbi->common; const YV12_BUFFER_CONFIG *const cfg = get_ref_frame(cm, idx); if (cfg == NULL) { aom_internal_error(&cm->error, AOM_CODEC_ERROR, "No reference frame"); return AOM_CODEC_ERROR; } if (!equal_dimensions(cfg, sd)) aom_internal_error(&cm->error, AOM_CODEC_ERROR, "Incorrect buffer dimensions"); else aom_yv12_copy_frame(cfg, sd); return cm->error.error_code; }
aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm, int idx, YV12_BUFFER_CONFIG *sd) { YV12_BUFFER_CONFIG *ref_buf = NULL; // Get the destination reference buffer. ref_buf = get_ref_frame(cm, idx); if (ref_buf == NULL) { aom_internal_error(&cm->error, AOM_CODEC_ERROR, "No reference frame"); return AOM_CODEC_ERROR; } if (!equal_dimensions(ref_buf, sd)) { aom_internal_error(&cm->error, AOM_CODEC_ERROR, "Incorrect buffer dimensions"); } else { // Overwrite the reference frame buffer. aom_yv12_copy_frame(sd, ref_buf); } return cm->error.error_code; }
void av1_encode_tiles_mt(AV1_COMP *cpi) { AV1_COMMON *const cm = &cpi->common; const int tile_cols = cm->tile_cols; const AVxWorkerInterface *const winterface = aom_get_worker_interface(); const int num_workers = AOMMIN(cpi->oxcf.max_threads, tile_cols); int i; av1_init_tile_data(cpi); // Only run once to create threads and allocate thread data. if (cpi->num_workers == 0) { CHECK_MEM_ERROR(cm, cpi->workers, aom_malloc(num_workers * sizeof(*cpi->workers))); CHECK_MEM_ERROR(cm, cpi->tile_thr_data, aom_calloc(num_workers, sizeof(*cpi->tile_thr_data))); for (i = 0; i < num_workers; i++) { AVxWorker *const worker = &cpi->workers[i]; EncWorkerData *const thread_data = &cpi->tile_thr_data[i]; ++cpi->num_workers; winterface->init(worker); thread_data->cpi = cpi; if (i < num_workers - 1) { // Allocate thread data. CHECK_MEM_ERROR(cm, thread_data->td, aom_memalign(32, sizeof(*thread_data->td))); av1_zero(*thread_data->td); // Set up pc_tree. thread_data->td->leaf_tree = NULL; thread_data->td->pc_tree = NULL; av1_setup_pc_tree(cm, thread_data->td); // Set up variance tree if needed. if (cpi->sf.partition_search_type == VAR_BASED_PARTITION) av1_setup_var_tree(cm, thread_data->td); // Allocate frame counters in thread data. CHECK_MEM_ERROR(cm, thread_data->td->counts, aom_calloc(1, sizeof(*thread_data->td->counts))); // Create threads if (!winterface->reset(worker)) aom_internal_error(&cm->error, AOM_CODEC_ERROR, "Tile encoder thread creation failed"); } else { // Main thread acts as a worker and uses the thread data in cpi. thread_data->td = &cpi->td; } winterface->sync(worker); } } for (i = 0; i < num_workers; i++) { AVxWorker *const worker = &cpi->workers[i]; EncWorkerData *thread_data; worker->hook = (AVxWorkerHook)enc_worker_hook; worker->data1 = &cpi->tile_thr_data[i]; worker->data2 = NULL; thread_data = (EncWorkerData *)worker->data1; // Before encoding a frame, copy the thread data from cpi. if (thread_data->td != &cpi->td) { thread_data->td->mb = cpi->td.mb; thread_data->td->rd_counts = cpi->td.rd_counts; } if (thread_data->td->counts != &cpi->common.counts) { memcpy(thread_data->td->counts, &cpi->common.counts, sizeof(cpi->common.counts)); } #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))); } #endif // CONFIG_PALETTE } // Encode a frame for (i = 0; i < num_workers; i++) { AVxWorker *const worker = &cpi->workers[i]; EncWorkerData *const thread_data = (EncWorkerData *)worker->data1; // Set the starting tile for each thread. thread_data->start = i; if (i == cpi->num_workers - 1) winterface->execute(worker); else winterface->launch(worker); } // Encoding ends. for (i = 0; i < num_workers; i++) { AVxWorker *const worker = &cpi->workers[i]; winterface->sync(worker); } for (i = 0; i < num_workers; i++) { AVxWorker *const worker = &cpi->workers[i]; EncWorkerData *const thread_data = (EncWorkerData *)worker->data1; // Accumulate counters. if (i < cpi->num_workers - 1) { av1_accumulate_frame_counts(&cm->counts, thread_data->td->counts); accumulate_rd_opt(&cpi->td, thread_data->td); } } }