Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #include "onyx_int.h" |
michael@0 | 12 | #include "vp8/common/threading.h" |
michael@0 | 13 | #include "vp8/common/common.h" |
michael@0 | 14 | #include "vp8/common/extend.h" |
michael@0 | 15 | #include "bitstream.h" |
michael@0 | 16 | #include "encodeframe.h" |
michael@0 | 17 | |
michael@0 | 18 | #if CONFIG_MULTITHREAD |
michael@0 | 19 | |
michael@0 | 20 | extern void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x, int ok_to_skip); |
michael@0 | 21 | |
michael@0 | 22 | extern void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm); |
michael@0 | 23 | |
michael@0 | 24 | static THREAD_FUNCTION thread_loopfilter(void *p_data) |
michael@0 | 25 | { |
michael@0 | 26 | VP8_COMP *cpi = (VP8_COMP *)(((LPFTHREAD_DATA *)p_data)->ptr1); |
michael@0 | 27 | VP8_COMMON *cm = &cpi->common; |
michael@0 | 28 | |
michael@0 | 29 | while (1) |
michael@0 | 30 | { |
michael@0 | 31 | if (cpi->b_multi_threaded == 0) |
michael@0 | 32 | break; |
michael@0 | 33 | |
michael@0 | 34 | if (sem_wait(&cpi->h_event_start_lpf) == 0) |
michael@0 | 35 | { |
michael@0 | 36 | if (cpi->b_multi_threaded == 0) /* we're shutting down */ |
michael@0 | 37 | break; |
michael@0 | 38 | |
michael@0 | 39 | vp8_loopfilter_frame(cpi, cm); |
michael@0 | 40 | |
michael@0 | 41 | sem_post(&cpi->h_event_end_lpf); |
michael@0 | 42 | } |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | return 0; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | static |
michael@0 | 49 | THREAD_FUNCTION thread_encoding_proc(void *p_data) |
michael@0 | 50 | { |
michael@0 | 51 | int ithread = ((ENCODETHREAD_DATA *)p_data)->ithread; |
michael@0 | 52 | VP8_COMP *cpi = (VP8_COMP *)(((ENCODETHREAD_DATA *)p_data)->ptr1); |
michael@0 | 53 | MB_ROW_COMP *mbri = (MB_ROW_COMP *)(((ENCODETHREAD_DATA *)p_data)->ptr2); |
michael@0 | 54 | ENTROPY_CONTEXT_PLANES mb_row_left_context; |
michael@0 | 55 | |
michael@0 | 56 | while (1) |
michael@0 | 57 | { |
michael@0 | 58 | if (cpi->b_multi_threaded == 0) |
michael@0 | 59 | break; |
michael@0 | 60 | |
michael@0 | 61 | if (sem_wait(&cpi->h_event_start_encoding[ithread]) == 0) |
michael@0 | 62 | { |
michael@0 | 63 | const int nsync = cpi->mt_sync_range; |
michael@0 | 64 | VP8_COMMON *cm = &cpi->common; |
michael@0 | 65 | int mb_row; |
michael@0 | 66 | MACROBLOCK *x = &mbri->mb; |
michael@0 | 67 | MACROBLOCKD *xd = &x->e_mbd; |
michael@0 | 68 | TOKENEXTRA *tp ; |
michael@0 | 69 | #if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING |
michael@0 | 70 | TOKENEXTRA *tp_start = cpi->tok + (1 + ithread) * (16 * 24); |
michael@0 | 71 | const int num_part = (1 << cm->multi_token_partition); |
michael@0 | 72 | #endif |
michael@0 | 73 | |
michael@0 | 74 | int *segment_counts = mbri->segment_counts; |
michael@0 | 75 | int *totalrate = &mbri->totalrate; |
michael@0 | 76 | |
michael@0 | 77 | if (cpi->b_multi_threaded == 0) /* we're shutting down */ |
michael@0 | 78 | break; |
michael@0 | 79 | |
michael@0 | 80 | for (mb_row = ithread + 1; mb_row < cm->mb_rows; mb_row += (cpi->encoding_thread_count + 1)) |
michael@0 | 81 | { |
michael@0 | 82 | |
michael@0 | 83 | int recon_yoffset, recon_uvoffset; |
michael@0 | 84 | int mb_col; |
michael@0 | 85 | int ref_fb_idx = cm->lst_fb_idx; |
michael@0 | 86 | int dst_fb_idx = cm->new_fb_idx; |
michael@0 | 87 | int recon_y_stride = cm->yv12_fb[ref_fb_idx].y_stride; |
michael@0 | 88 | int recon_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride; |
michael@0 | 89 | int map_index = (mb_row * cm->mb_cols); |
michael@0 | 90 | volatile const int *last_row_current_mb_col; |
michael@0 | 91 | volatile int *current_mb_col = &cpi->mt_current_mb_col[mb_row]; |
michael@0 | 92 | |
michael@0 | 93 | #if (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING) |
michael@0 | 94 | vp8_writer *w = &cpi->bc[1 + (mb_row % num_part)]; |
michael@0 | 95 | #else |
michael@0 | 96 | tp = cpi->tok + (mb_row * (cm->mb_cols * 16 * 24)); |
michael@0 | 97 | cpi->tplist[mb_row].start = tp; |
michael@0 | 98 | #endif |
michael@0 | 99 | |
michael@0 | 100 | last_row_current_mb_col = &cpi->mt_current_mb_col[mb_row - 1]; |
michael@0 | 101 | |
michael@0 | 102 | /* reset above block coeffs */ |
michael@0 | 103 | xd->above_context = cm->above_context; |
michael@0 | 104 | xd->left_context = &mb_row_left_context; |
michael@0 | 105 | |
michael@0 | 106 | vp8_zero(mb_row_left_context); |
michael@0 | 107 | |
michael@0 | 108 | xd->up_available = (mb_row != 0); |
michael@0 | 109 | recon_yoffset = (mb_row * recon_y_stride * 16); |
michael@0 | 110 | recon_uvoffset = (mb_row * recon_uv_stride * 8); |
michael@0 | 111 | |
michael@0 | 112 | /* Set the mb activity pointer to the start of the row. */ |
michael@0 | 113 | x->mb_activity_ptr = &cpi->mb_activity_map[map_index]; |
michael@0 | 114 | |
michael@0 | 115 | /* for each macroblock col in image */ |
michael@0 | 116 | for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) |
michael@0 | 117 | { |
michael@0 | 118 | *current_mb_col = mb_col - 1; |
michael@0 | 119 | |
michael@0 | 120 | if ((mb_col & (nsync - 1)) == 0) |
michael@0 | 121 | { |
michael@0 | 122 | while (mb_col > (*last_row_current_mb_col - nsync)) |
michael@0 | 123 | { |
michael@0 | 124 | x86_pause_hint(); |
michael@0 | 125 | thread_sleep(0); |
michael@0 | 126 | } |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | #if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING |
michael@0 | 130 | tp = tp_start; |
michael@0 | 131 | #endif |
michael@0 | 132 | |
michael@0 | 133 | /* Distance of Mb to the various image edges. |
michael@0 | 134 | * These specified to 8th pel as they are always compared |
michael@0 | 135 | * to values that are in 1/8th pel units |
michael@0 | 136 | */ |
michael@0 | 137 | xd->mb_to_left_edge = -((mb_col * 16) << 3); |
michael@0 | 138 | xd->mb_to_right_edge = ((cm->mb_cols - 1 - mb_col) * 16) << 3; |
michael@0 | 139 | xd->mb_to_top_edge = -((mb_row * 16) << 3); |
michael@0 | 140 | xd->mb_to_bottom_edge = ((cm->mb_rows - 1 - mb_row) * 16) << 3; |
michael@0 | 141 | |
michael@0 | 142 | /* Set up limit values for motion vectors used to prevent |
michael@0 | 143 | * them extending outside the UMV borders |
michael@0 | 144 | */ |
michael@0 | 145 | x->mv_col_min = -((mb_col * 16) + (VP8BORDERINPIXELS - 16)); |
michael@0 | 146 | x->mv_col_max = ((cm->mb_cols - 1 - mb_col) * 16) + (VP8BORDERINPIXELS - 16); |
michael@0 | 147 | x->mv_row_min = -((mb_row * 16) + (VP8BORDERINPIXELS - 16)); |
michael@0 | 148 | x->mv_row_max = ((cm->mb_rows - 1 - mb_row) * 16) + (VP8BORDERINPIXELS - 16); |
michael@0 | 149 | |
michael@0 | 150 | xd->dst.y_buffer = cm->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset; |
michael@0 | 151 | xd->dst.u_buffer = cm->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset; |
michael@0 | 152 | xd->dst.v_buffer = cm->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset; |
michael@0 | 153 | xd->left_available = (mb_col != 0); |
michael@0 | 154 | |
michael@0 | 155 | x->rddiv = cpi->RDDIV; |
michael@0 | 156 | x->rdmult = cpi->RDMULT; |
michael@0 | 157 | |
michael@0 | 158 | /* Copy current mb to a buffer */ |
michael@0 | 159 | vp8_copy_mem16x16(x->src.y_buffer, x->src.y_stride, x->thismb, 16); |
michael@0 | 160 | |
michael@0 | 161 | if (cpi->oxcf.tuning == VP8_TUNE_SSIM) |
michael@0 | 162 | vp8_activity_masking(cpi, x); |
michael@0 | 163 | |
michael@0 | 164 | /* Is segmentation enabled */ |
michael@0 | 165 | /* MB level adjustment to quantizer */ |
michael@0 | 166 | if (xd->segmentation_enabled) |
michael@0 | 167 | { |
michael@0 | 168 | /* Code to set segment id in xd->mbmi.segment_id for |
michael@0 | 169 | * current MB (with range checking) |
michael@0 | 170 | */ |
michael@0 | 171 | if (cpi->segmentation_map[map_index + mb_col] <= 3) |
michael@0 | 172 | xd->mode_info_context->mbmi.segment_id = cpi->segmentation_map[map_index + mb_col]; |
michael@0 | 173 | else |
michael@0 | 174 | xd->mode_info_context->mbmi.segment_id = 0; |
michael@0 | 175 | |
michael@0 | 176 | vp8cx_mb_init_quantizer(cpi, x, 1); |
michael@0 | 177 | } |
michael@0 | 178 | else |
michael@0 | 179 | /* Set to Segment 0 by default */ |
michael@0 | 180 | xd->mode_info_context->mbmi.segment_id = 0; |
michael@0 | 181 | |
michael@0 | 182 | x->active_ptr = cpi->active_map + map_index + mb_col; |
michael@0 | 183 | |
michael@0 | 184 | if (cm->frame_type == KEY_FRAME) |
michael@0 | 185 | { |
michael@0 | 186 | *totalrate += vp8cx_encode_intra_macroblock(cpi, x, &tp); |
michael@0 | 187 | #ifdef MODE_STATS |
michael@0 | 188 | y_modes[xd->mbmi.mode] ++; |
michael@0 | 189 | #endif |
michael@0 | 190 | } |
michael@0 | 191 | else |
michael@0 | 192 | { |
michael@0 | 193 | *totalrate += vp8cx_encode_inter_macroblock(cpi, x, &tp, recon_yoffset, recon_uvoffset, mb_row, mb_col); |
michael@0 | 194 | |
michael@0 | 195 | #ifdef MODE_STATS |
michael@0 | 196 | inter_y_modes[xd->mbmi.mode] ++; |
michael@0 | 197 | |
michael@0 | 198 | if (xd->mbmi.mode == SPLITMV) |
michael@0 | 199 | { |
michael@0 | 200 | int b; |
michael@0 | 201 | |
michael@0 | 202 | for (b = 0; b < xd->mbmi.partition_count; b++) |
michael@0 | 203 | { |
michael@0 | 204 | inter_b_modes[x->partition->bmi[b].mode] ++; |
michael@0 | 205 | } |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | #endif |
michael@0 | 209 | |
michael@0 | 210 | /* Special case code for cyclic refresh |
michael@0 | 211 | * If cyclic update enabled then copy |
michael@0 | 212 | * xd->mbmi.segment_id; (which may have been updated |
michael@0 | 213 | * based on mode during |
michael@0 | 214 | * vp8cx_encode_inter_macroblock()) back into the |
michael@0 | 215 | * global segmentation map |
michael@0 | 216 | */ |
michael@0 | 217 | if ((cpi->current_layer == 0) && |
michael@0 | 218 | (cpi->cyclic_refresh_mode_enabled && |
michael@0 | 219 | xd->segmentation_enabled)) |
michael@0 | 220 | { |
michael@0 | 221 | const MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi; |
michael@0 | 222 | cpi->segmentation_map[map_index + mb_col] = mbmi->segment_id; |
michael@0 | 223 | |
michael@0 | 224 | /* If the block has been refreshed mark it as clean |
michael@0 | 225 | * (the magnitude of the -ve influences how long it |
michael@0 | 226 | * will be before we consider another refresh): |
michael@0 | 227 | * Else if it was coded (last frame 0,0) and has |
michael@0 | 228 | * not already been refreshed then mark it as a |
michael@0 | 229 | * candidate for cleanup next time (marked 0) else |
michael@0 | 230 | * mark it as dirty (1). |
michael@0 | 231 | */ |
michael@0 | 232 | if (mbmi->segment_id) |
michael@0 | 233 | cpi->cyclic_refresh_map[map_index + mb_col] = -1; |
michael@0 | 234 | else if ((mbmi->mode == ZEROMV) && (mbmi->ref_frame == LAST_FRAME)) |
michael@0 | 235 | { |
michael@0 | 236 | if (cpi->cyclic_refresh_map[map_index + mb_col] == 1) |
michael@0 | 237 | cpi->cyclic_refresh_map[map_index + mb_col] = 0; |
michael@0 | 238 | } |
michael@0 | 239 | else |
michael@0 | 240 | cpi->cyclic_refresh_map[map_index + mb_col] = 1; |
michael@0 | 241 | |
michael@0 | 242 | } |
michael@0 | 243 | } |
michael@0 | 244 | |
michael@0 | 245 | #if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING |
michael@0 | 246 | /* pack tokens for this MB */ |
michael@0 | 247 | { |
michael@0 | 248 | int tok_count = tp - tp_start; |
michael@0 | 249 | pack_tokens(w, tp_start, tok_count); |
michael@0 | 250 | } |
michael@0 | 251 | #else |
michael@0 | 252 | cpi->tplist[mb_row].stop = tp; |
michael@0 | 253 | #endif |
michael@0 | 254 | /* Increment pointer into gf usage flags structure. */ |
michael@0 | 255 | x->gf_active_ptr++; |
michael@0 | 256 | |
michael@0 | 257 | /* Increment the activity mask pointers. */ |
michael@0 | 258 | x->mb_activity_ptr++; |
michael@0 | 259 | |
michael@0 | 260 | /* adjust to the next column of macroblocks */ |
michael@0 | 261 | x->src.y_buffer += 16; |
michael@0 | 262 | x->src.u_buffer += 8; |
michael@0 | 263 | x->src.v_buffer += 8; |
michael@0 | 264 | |
michael@0 | 265 | recon_yoffset += 16; |
michael@0 | 266 | recon_uvoffset += 8; |
michael@0 | 267 | |
michael@0 | 268 | /* Keep track of segment usage */ |
michael@0 | 269 | segment_counts[xd->mode_info_context->mbmi.segment_id]++; |
michael@0 | 270 | |
michael@0 | 271 | /* skip to next mb */ |
michael@0 | 272 | xd->mode_info_context++; |
michael@0 | 273 | x->partition_info++; |
michael@0 | 274 | xd->above_context++; |
michael@0 | 275 | } |
michael@0 | 276 | |
michael@0 | 277 | vp8_extend_mb_row( &cm->yv12_fb[dst_fb_idx], |
michael@0 | 278 | xd->dst.y_buffer + 16, |
michael@0 | 279 | xd->dst.u_buffer + 8, |
michael@0 | 280 | xd->dst.v_buffer + 8); |
michael@0 | 281 | |
michael@0 | 282 | *current_mb_col = mb_col + nsync; |
michael@0 | 283 | |
michael@0 | 284 | /* this is to account for the border */ |
michael@0 | 285 | xd->mode_info_context++; |
michael@0 | 286 | x->partition_info++; |
michael@0 | 287 | |
michael@0 | 288 | x->src.y_buffer += 16 * x->src.y_stride * (cpi->encoding_thread_count + 1) - 16 * cm->mb_cols; |
michael@0 | 289 | x->src.u_buffer += 8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols; |
michael@0 | 290 | x->src.v_buffer += 8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols; |
michael@0 | 291 | |
michael@0 | 292 | xd->mode_info_context += xd->mode_info_stride * cpi->encoding_thread_count; |
michael@0 | 293 | x->partition_info += xd->mode_info_stride * cpi->encoding_thread_count; |
michael@0 | 294 | x->gf_active_ptr += cm->mb_cols * cpi->encoding_thread_count; |
michael@0 | 295 | |
michael@0 | 296 | if (mb_row == cm->mb_rows - 1) |
michael@0 | 297 | { |
michael@0 | 298 | sem_post(&cpi->h_event_end_encoding); /* signal frame encoding end */ |
michael@0 | 299 | } |
michael@0 | 300 | } |
michael@0 | 301 | } |
michael@0 | 302 | } |
michael@0 | 303 | |
michael@0 | 304 | /* printf("exit thread %d\n", ithread); */ |
michael@0 | 305 | return 0; |
michael@0 | 306 | } |
michael@0 | 307 | |
michael@0 | 308 | static void setup_mbby_copy(MACROBLOCK *mbdst, MACROBLOCK *mbsrc) |
michael@0 | 309 | { |
michael@0 | 310 | |
michael@0 | 311 | MACROBLOCK *x = mbsrc; |
michael@0 | 312 | MACROBLOCK *z = mbdst; |
michael@0 | 313 | int i; |
michael@0 | 314 | |
michael@0 | 315 | z->ss = x->ss; |
michael@0 | 316 | z->ss_count = x->ss_count; |
michael@0 | 317 | z->searches_per_step = x->searches_per_step; |
michael@0 | 318 | z->errorperbit = x->errorperbit; |
michael@0 | 319 | |
michael@0 | 320 | z->sadperbit16 = x->sadperbit16; |
michael@0 | 321 | z->sadperbit4 = x->sadperbit4; |
michael@0 | 322 | |
michael@0 | 323 | /* |
michael@0 | 324 | z->mv_col_min = x->mv_col_min; |
michael@0 | 325 | z->mv_col_max = x->mv_col_max; |
michael@0 | 326 | z->mv_row_min = x->mv_row_min; |
michael@0 | 327 | z->mv_row_max = x->mv_row_max; |
michael@0 | 328 | */ |
michael@0 | 329 | |
michael@0 | 330 | z->short_fdct4x4 = x->short_fdct4x4; |
michael@0 | 331 | z->short_fdct8x4 = x->short_fdct8x4; |
michael@0 | 332 | z->short_walsh4x4 = x->short_walsh4x4; |
michael@0 | 333 | z->quantize_b = x->quantize_b; |
michael@0 | 334 | z->quantize_b_pair = x->quantize_b_pair; |
michael@0 | 335 | z->optimize = x->optimize; |
michael@0 | 336 | |
michael@0 | 337 | /* |
michael@0 | 338 | z->mvc = x->mvc; |
michael@0 | 339 | z->src.y_buffer = x->src.y_buffer; |
michael@0 | 340 | z->src.u_buffer = x->src.u_buffer; |
michael@0 | 341 | z->src.v_buffer = x->src.v_buffer; |
michael@0 | 342 | */ |
michael@0 | 343 | |
michael@0 | 344 | z->mvcost[0] = x->mvcost[0]; |
michael@0 | 345 | z->mvcost[1] = x->mvcost[1]; |
michael@0 | 346 | z->mvsadcost[0] = x->mvsadcost[0]; |
michael@0 | 347 | z->mvsadcost[1] = x->mvsadcost[1]; |
michael@0 | 348 | |
michael@0 | 349 | z->token_costs = x->token_costs; |
michael@0 | 350 | z->inter_bmode_costs = x->inter_bmode_costs; |
michael@0 | 351 | z->mbmode_cost = x->mbmode_cost; |
michael@0 | 352 | z->intra_uv_mode_cost = x->intra_uv_mode_cost; |
michael@0 | 353 | z->bmode_costs = x->bmode_costs; |
michael@0 | 354 | |
michael@0 | 355 | for (i = 0; i < 25; i++) |
michael@0 | 356 | { |
michael@0 | 357 | z->block[i].quant = x->block[i].quant; |
michael@0 | 358 | z->block[i].quant_fast = x->block[i].quant_fast; |
michael@0 | 359 | z->block[i].quant_shift = x->block[i].quant_shift; |
michael@0 | 360 | z->block[i].zbin = x->block[i].zbin; |
michael@0 | 361 | z->block[i].zrun_zbin_boost = x->block[i].zrun_zbin_boost; |
michael@0 | 362 | z->block[i].round = x->block[i].round; |
michael@0 | 363 | z->block[i].src_stride = x->block[i].src_stride; |
michael@0 | 364 | } |
michael@0 | 365 | |
michael@0 | 366 | z->q_index = x->q_index; |
michael@0 | 367 | z->act_zbin_adj = x->act_zbin_adj; |
michael@0 | 368 | z->last_act_zbin_adj = x->last_act_zbin_adj; |
michael@0 | 369 | |
michael@0 | 370 | { |
michael@0 | 371 | MACROBLOCKD *xd = &x->e_mbd; |
michael@0 | 372 | MACROBLOCKD *zd = &z->e_mbd; |
michael@0 | 373 | |
michael@0 | 374 | /* |
michael@0 | 375 | zd->mode_info_context = xd->mode_info_context; |
michael@0 | 376 | zd->mode_info = xd->mode_info; |
michael@0 | 377 | |
michael@0 | 378 | zd->mode_info_stride = xd->mode_info_stride; |
michael@0 | 379 | zd->frame_type = xd->frame_type; |
michael@0 | 380 | zd->up_available = xd->up_available ; |
michael@0 | 381 | zd->left_available = xd->left_available; |
michael@0 | 382 | zd->left_context = xd->left_context; |
michael@0 | 383 | zd->last_frame_dc = xd->last_frame_dc; |
michael@0 | 384 | zd->last_frame_dccons = xd->last_frame_dccons; |
michael@0 | 385 | zd->gold_frame_dc = xd->gold_frame_dc; |
michael@0 | 386 | zd->gold_frame_dccons = xd->gold_frame_dccons; |
michael@0 | 387 | zd->mb_to_left_edge = xd->mb_to_left_edge; |
michael@0 | 388 | zd->mb_to_right_edge = xd->mb_to_right_edge; |
michael@0 | 389 | zd->mb_to_top_edge = xd->mb_to_top_edge ; |
michael@0 | 390 | zd->mb_to_bottom_edge = xd->mb_to_bottom_edge; |
michael@0 | 391 | zd->gf_active_ptr = xd->gf_active_ptr; |
michael@0 | 392 | zd->frames_since_golden = xd->frames_since_golden; |
michael@0 | 393 | zd->frames_till_alt_ref_frame = xd->frames_till_alt_ref_frame; |
michael@0 | 394 | */ |
michael@0 | 395 | zd->subpixel_predict = xd->subpixel_predict; |
michael@0 | 396 | zd->subpixel_predict8x4 = xd->subpixel_predict8x4; |
michael@0 | 397 | zd->subpixel_predict8x8 = xd->subpixel_predict8x8; |
michael@0 | 398 | zd->subpixel_predict16x16 = xd->subpixel_predict16x16; |
michael@0 | 399 | zd->segmentation_enabled = xd->segmentation_enabled; |
michael@0 | 400 | zd->mb_segement_abs_delta = xd->mb_segement_abs_delta; |
michael@0 | 401 | vpx_memcpy(zd->segment_feature_data, xd->segment_feature_data, |
michael@0 | 402 | sizeof(xd->segment_feature_data)); |
michael@0 | 403 | |
michael@0 | 404 | vpx_memcpy(zd->dequant_y1_dc, xd->dequant_y1_dc, |
michael@0 | 405 | sizeof(xd->dequant_y1_dc)); |
michael@0 | 406 | vpx_memcpy(zd->dequant_y1, xd->dequant_y1, sizeof(xd->dequant_y1)); |
michael@0 | 407 | vpx_memcpy(zd->dequant_y2, xd->dequant_y2, sizeof(xd->dequant_y2)); |
michael@0 | 408 | vpx_memcpy(zd->dequant_uv, xd->dequant_uv, sizeof(xd->dequant_uv)); |
michael@0 | 409 | |
michael@0 | 410 | #if 1 |
michael@0 | 411 | /*TODO: Remove dequant from BLOCKD. This is a temporary solution until |
michael@0 | 412 | * the quantizer code uses a passed in pointer to the dequant constants. |
michael@0 | 413 | * This will also require modifications to the x86 and neon assembly. |
michael@0 | 414 | * */ |
michael@0 | 415 | for (i = 0; i < 16; i++) |
michael@0 | 416 | zd->block[i].dequant = zd->dequant_y1; |
michael@0 | 417 | for (i = 16; i < 24; i++) |
michael@0 | 418 | zd->block[i].dequant = zd->dequant_uv; |
michael@0 | 419 | zd->block[24].dequant = zd->dequant_y2; |
michael@0 | 420 | #endif |
michael@0 | 421 | |
michael@0 | 422 | |
michael@0 | 423 | vpx_memcpy(z->rd_threshes, x->rd_threshes, sizeof(x->rd_threshes)); |
michael@0 | 424 | vpx_memcpy(z->rd_thresh_mult, x->rd_thresh_mult, |
michael@0 | 425 | sizeof(x->rd_thresh_mult)); |
michael@0 | 426 | |
michael@0 | 427 | z->zbin_over_quant = x->zbin_over_quant; |
michael@0 | 428 | z->zbin_mode_boost_enabled = x->zbin_mode_boost_enabled; |
michael@0 | 429 | z->zbin_mode_boost = x->zbin_mode_boost; |
michael@0 | 430 | |
michael@0 | 431 | vpx_memset(z->error_bins, 0, sizeof(z->error_bins)); |
michael@0 | 432 | } |
michael@0 | 433 | } |
michael@0 | 434 | |
michael@0 | 435 | void vp8cx_init_mbrthread_data(VP8_COMP *cpi, |
michael@0 | 436 | MACROBLOCK *x, |
michael@0 | 437 | MB_ROW_COMP *mbr_ei, |
michael@0 | 438 | int count |
michael@0 | 439 | ) |
michael@0 | 440 | { |
michael@0 | 441 | |
michael@0 | 442 | VP8_COMMON *const cm = & cpi->common; |
michael@0 | 443 | MACROBLOCKD *const xd = & x->e_mbd; |
michael@0 | 444 | int i; |
michael@0 | 445 | |
michael@0 | 446 | for (i = 0; i < count; i++) |
michael@0 | 447 | { |
michael@0 | 448 | MACROBLOCK *mb = & mbr_ei[i].mb; |
michael@0 | 449 | MACROBLOCKD *mbd = &mb->e_mbd; |
michael@0 | 450 | |
michael@0 | 451 | mbd->subpixel_predict = xd->subpixel_predict; |
michael@0 | 452 | mbd->subpixel_predict8x4 = xd->subpixel_predict8x4; |
michael@0 | 453 | mbd->subpixel_predict8x8 = xd->subpixel_predict8x8; |
michael@0 | 454 | mbd->subpixel_predict16x16 = xd->subpixel_predict16x16; |
michael@0 | 455 | mb->gf_active_ptr = x->gf_active_ptr; |
michael@0 | 456 | |
michael@0 | 457 | vpx_memset(mbr_ei[i].segment_counts, 0, sizeof(mbr_ei[i].segment_counts)); |
michael@0 | 458 | mbr_ei[i].totalrate = 0; |
michael@0 | 459 | |
michael@0 | 460 | mb->partition_info = x->pi + x->e_mbd.mode_info_stride * (i + 1); |
michael@0 | 461 | |
michael@0 | 462 | mbd->mode_info_context = cm->mi + x->e_mbd.mode_info_stride * (i + 1); |
michael@0 | 463 | mbd->mode_info_stride = cm->mode_info_stride; |
michael@0 | 464 | |
michael@0 | 465 | mbd->frame_type = cm->frame_type; |
michael@0 | 466 | |
michael@0 | 467 | mb->src = * cpi->Source; |
michael@0 | 468 | mbd->pre = cm->yv12_fb[cm->lst_fb_idx]; |
michael@0 | 469 | mbd->dst = cm->yv12_fb[cm->new_fb_idx]; |
michael@0 | 470 | |
michael@0 | 471 | mb->src.y_buffer += 16 * x->src.y_stride * (i + 1); |
michael@0 | 472 | mb->src.u_buffer += 8 * x->src.uv_stride * (i + 1); |
michael@0 | 473 | mb->src.v_buffer += 8 * x->src.uv_stride * (i + 1); |
michael@0 | 474 | |
michael@0 | 475 | vp8_build_block_offsets(mb); |
michael@0 | 476 | |
michael@0 | 477 | mbd->left_context = &cm->left_context; |
michael@0 | 478 | mb->mvc = cm->fc.mvc; |
michael@0 | 479 | |
michael@0 | 480 | setup_mbby_copy(&mbr_ei[i].mb, x); |
michael@0 | 481 | |
michael@0 | 482 | mbd->fullpixel_mask = 0xffffffff; |
michael@0 | 483 | if(cm->full_pixel) |
michael@0 | 484 | mbd->fullpixel_mask = 0xfffffff8; |
michael@0 | 485 | |
michael@0 | 486 | vp8_zero(mb->coef_counts); |
michael@0 | 487 | vp8_zero(x->ymode_count); |
michael@0 | 488 | mb->skip_true_count = 0; |
michael@0 | 489 | vp8_zero(mb->MVcount); |
michael@0 | 490 | mb->prediction_error = 0; |
michael@0 | 491 | mb->intra_error = 0; |
michael@0 | 492 | vp8_zero(mb->count_mb_ref_frame_usage); |
michael@0 | 493 | mb->mbs_tested_so_far = 0; |
michael@0 | 494 | } |
michael@0 | 495 | } |
michael@0 | 496 | |
michael@0 | 497 | int vp8cx_create_encoder_threads(VP8_COMP *cpi) |
michael@0 | 498 | { |
michael@0 | 499 | const VP8_COMMON * cm = &cpi->common; |
michael@0 | 500 | |
michael@0 | 501 | cpi->b_multi_threaded = 0; |
michael@0 | 502 | cpi->encoding_thread_count = 0; |
michael@0 | 503 | cpi->b_lpf_running = 0; |
michael@0 | 504 | |
michael@0 | 505 | if (cm->processor_core_count > 1 && cpi->oxcf.multi_threaded > 1) |
michael@0 | 506 | { |
michael@0 | 507 | int ithread; |
michael@0 | 508 | int th_count = cpi->oxcf.multi_threaded - 1; |
michael@0 | 509 | int rc = 0; |
michael@0 | 510 | |
michael@0 | 511 | /* don't allocate more threads than cores available */ |
michael@0 | 512 | if (cpi->oxcf.multi_threaded > cm->processor_core_count) |
michael@0 | 513 | th_count = cm->processor_core_count - 1; |
michael@0 | 514 | |
michael@0 | 515 | /* we have th_count + 1 (main) threads processing one row each */ |
michael@0 | 516 | /* no point to have more threads than the sync range allows */ |
michael@0 | 517 | if(th_count > ((cm->mb_cols / cpi->mt_sync_range) - 1)) |
michael@0 | 518 | { |
michael@0 | 519 | th_count = (cm->mb_cols / cpi->mt_sync_range) - 1; |
michael@0 | 520 | } |
michael@0 | 521 | |
michael@0 | 522 | if(th_count == 0) |
michael@0 | 523 | return 0; |
michael@0 | 524 | |
michael@0 | 525 | CHECK_MEM_ERROR(cpi->h_encoding_thread, |
michael@0 | 526 | vpx_malloc(sizeof(pthread_t) * th_count)); |
michael@0 | 527 | CHECK_MEM_ERROR(cpi->h_event_start_encoding, |
michael@0 | 528 | vpx_malloc(sizeof(sem_t) * th_count)); |
michael@0 | 529 | CHECK_MEM_ERROR(cpi->mb_row_ei, |
michael@0 | 530 | vpx_memalign(32, sizeof(MB_ROW_COMP) * th_count)); |
michael@0 | 531 | vpx_memset(cpi->mb_row_ei, 0, sizeof(MB_ROW_COMP) * th_count); |
michael@0 | 532 | CHECK_MEM_ERROR(cpi->en_thread_data, |
michael@0 | 533 | vpx_malloc(sizeof(ENCODETHREAD_DATA) * th_count)); |
michael@0 | 534 | |
michael@0 | 535 | sem_init(&cpi->h_event_end_encoding, 0, 0); |
michael@0 | 536 | |
michael@0 | 537 | cpi->b_multi_threaded = 1; |
michael@0 | 538 | cpi->encoding_thread_count = th_count; |
michael@0 | 539 | |
michael@0 | 540 | /* |
michael@0 | 541 | printf("[VP8:] multi_threaded encoding is enabled with %d threads\n\n", |
michael@0 | 542 | (cpi->encoding_thread_count +1)); |
michael@0 | 543 | */ |
michael@0 | 544 | |
michael@0 | 545 | for (ithread = 0; ithread < th_count; ithread++) |
michael@0 | 546 | { |
michael@0 | 547 | ENCODETHREAD_DATA *ethd = &cpi->en_thread_data[ithread]; |
michael@0 | 548 | |
michael@0 | 549 | /* Setup block ptrs and offsets */ |
michael@0 | 550 | vp8_setup_block_ptrs(&cpi->mb_row_ei[ithread].mb); |
michael@0 | 551 | vp8_setup_block_dptrs(&cpi->mb_row_ei[ithread].mb.e_mbd); |
michael@0 | 552 | |
michael@0 | 553 | sem_init(&cpi->h_event_start_encoding[ithread], 0, 0); |
michael@0 | 554 | |
michael@0 | 555 | ethd->ithread = ithread; |
michael@0 | 556 | ethd->ptr1 = (void *)cpi; |
michael@0 | 557 | ethd->ptr2 = (void *)&cpi->mb_row_ei[ithread]; |
michael@0 | 558 | |
michael@0 | 559 | rc = pthread_create(&cpi->h_encoding_thread[ithread], 0, |
michael@0 | 560 | thread_encoding_proc, ethd); |
michael@0 | 561 | if(rc) |
michael@0 | 562 | break; |
michael@0 | 563 | } |
michael@0 | 564 | |
michael@0 | 565 | if(rc) |
michael@0 | 566 | { |
michael@0 | 567 | /* shutdown other threads */ |
michael@0 | 568 | cpi->b_multi_threaded = 0; |
michael@0 | 569 | for(--ithread; ithread >= 0; ithread--) |
michael@0 | 570 | { |
michael@0 | 571 | pthread_join(cpi->h_encoding_thread[ithread], 0); |
michael@0 | 572 | sem_destroy(&cpi->h_event_start_encoding[ithread]); |
michael@0 | 573 | } |
michael@0 | 574 | sem_destroy(&cpi->h_event_end_encoding); |
michael@0 | 575 | |
michael@0 | 576 | /* free thread related resources */ |
michael@0 | 577 | vpx_free(cpi->h_event_start_encoding); |
michael@0 | 578 | vpx_free(cpi->h_encoding_thread); |
michael@0 | 579 | vpx_free(cpi->mb_row_ei); |
michael@0 | 580 | vpx_free(cpi->en_thread_data); |
michael@0 | 581 | |
michael@0 | 582 | return -1; |
michael@0 | 583 | } |
michael@0 | 584 | |
michael@0 | 585 | |
michael@0 | 586 | { |
michael@0 | 587 | LPFTHREAD_DATA * lpfthd = &cpi->lpf_thread_data; |
michael@0 | 588 | |
michael@0 | 589 | sem_init(&cpi->h_event_start_lpf, 0, 0); |
michael@0 | 590 | sem_init(&cpi->h_event_end_lpf, 0, 0); |
michael@0 | 591 | |
michael@0 | 592 | lpfthd->ptr1 = (void *)cpi; |
michael@0 | 593 | rc = pthread_create(&cpi->h_filter_thread, 0, thread_loopfilter, |
michael@0 | 594 | lpfthd); |
michael@0 | 595 | |
michael@0 | 596 | if(rc) |
michael@0 | 597 | { |
michael@0 | 598 | /* shutdown other threads */ |
michael@0 | 599 | cpi->b_multi_threaded = 0; |
michael@0 | 600 | for(--ithread; ithread >= 0; ithread--) |
michael@0 | 601 | { |
michael@0 | 602 | sem_post(&cpi->h_event_start_encoding[ithread]); |
michael@0 | 603 | pthread_join(cpi->h_encoding_thread[ithread], 0); |
michael@0 | 604 | sem_destroy(&cpi->h_event_start_encoding[ithread]); |
michael@0 | 605 | } |
michael@0 | 606 | sem_destroy(&cpi->h_event_end_encoding); |
michael@0 | 607 | sem_destroy(&cpi->h_event_end_lpf); |
michael@0 | 608 | sem_destroy(&cpi->h_event_start_lpf); |
michael@0 | 609 | |
michael@0 | 610 | /* free thread related resources */ |
michael@0 | 611 | vpx_free(cpi->h_event_start_encoding); |
michael@0 | 612 | vpx_free(cpi->h_encoding_thread); |
michael@0 | 613 | vpx_free(cpi->mb_row_ei); |
michael@0 | 614 | vpx_free(cpi->en_thread_data); |
michael@0 | 615 | |
michael@0 | 616 | return -2; |
michael@0 | 617 | } |
michael@0 | 618 | } |
michael@0 | 619 | } |
michael@0 | 620 | return 0; |
michael@0 | 621 | } |
michael@0 | 622 | |
michael@0 | 623 | void vp8cx_remove_encoder_threads(VP8_COMP *cpi) |
michael@0 | 624 | { |
michael@0 | 625 | if (cpi->b_multi_threaded) |
michael@0 | 626 | { |
michael@0 | 627 | /* shutdown other threads */ |
michael@0 | 628 | cpi->b_multi_threaded = 0; |
michael@0 | 629 | { |
michael@0 | 630 | int i; |
michael@0 | 631 | |
michael@0 | 632 | for (i = 0; i < cpi->encoding_thread_count; i++) |
michael@0 | 633 | { |
michael@0 | 634 | sem_post(&cpi->h_event_start_encoding[i]); |
michael@0 | 635 | pthread_join(cpi->h_encoding_thread[i], 0); |
michael@0 | 636 | |
michael@0 | 637 | sem_destroy(&cpi->h_event_start_encoding[i]); |
michael@0 | 638 | } |
michael@0 | 639 | |
michael@0 | 640 | sem_post(&cpi->h_event_start_lpf); |
michael@0 | 641 | pthread_join(cpi->h_filter_thread, 0); |
michael@0 | 642 | } |
michael@0 | 643 | |
michael@0 | 644 | sem_destroy(&cpi->h_event_end_encoding); |
michael@0 | 645 | sem_destroy(&cpi->h_event_end_lpf); |
michael@0 | 646 | sem_destroy(&cpi->h_event_start_lpf); |
michael@0 | 647 | |
michael@0 | 648 | /* free thread related resources */ |
michael@0 | 649 | vpx_free(cpi->h_event_start_encoding); |
michael@0 | 650 | vpx_free(cpi->h_encoding_thread); |
michael@0 | 651 | vpx_free(cpi->mb_row_ei); |
michael@0 | 652 | vpx_free(cpi->en_thread_data); |
michael@0 | 653 | } |
michael@0 | 654 | } |
michael@0 | 655 | #endif |