Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_encoder.c

Issue 592203002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encoder.h ('k') | source/libvpx/vp9/encoder/vp9_firstpass.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // Scan frames from current to arf frame. 323 // Scan frames from current to arf frame.
324 // This function re-enables segmentation if appropriate. 324 // This function re-enables segmentation if appropriate.
325 vp9_update_mbgraph_stats(cpi); 325 vp9_update_mbgraph_stats(cpi);
326 326
327 // If segmentation was enabled set those features needed for the 327 // If segmentation was enabled set those features needed for the
328 // arf itself. 328 // arf itself.
329 if (seg->enabled) { 329 if (seg->enabled) {
330 seg->update_map = 1; 330 seg->update_map = 1;
331 seg->update_data = 1; 331 seg->update_data = 1;
332 332
333 qi_delta = vp9_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875); 333 qi_delta = vp9_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875,
334 cm->bit_depth);
334 vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); 335 vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2);
335 vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); 336 vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
336 337
337 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); 338 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
338 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); 339 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
339 340
340 // Where relevant assume segment data is delta data 341 // Where relevant assume segment data is delta data
341 seg->abs_delta = SEGMENT_DELTADATA; 342 seg->abs_delta = SEGMENT_DELTADATA;
342 } 343 }
343 } else if (seg->enabled) { 344 } else if (seg->enabled) {
344 // All other frames if segmentation has been enabled 345 // All other frames if segmentation has been enabled
345 346
346 // First normal frame in a valid gf or alt ref group 347 // First normal frame in a valid gf or alt ref group
347 if (rc->frames_since_golden == 0) { 348 if (rc->frames_since_golden == 0) {
348 // Set up segment features for normal frames in an arf group 349 // Set up segment features for normal frames in an arf group
349 if (rc->source_alt_ref_active) { 350 if (rc->source_alt_ref_active) {
350 seg->update_map = 0; 351 seg->update_map = 0;
351 seg->update_data = 1; 352 seg->update_data = 1;
352 seg->abs_delta = SEGMENT_DELTADATA; 353 seg->abs_delta = SEGMENT_DELTADATA;
353 354
354 qi_delta = vp9_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125); 355 qi_delta = vp9_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125,
356 cm->bit_depth);
355 vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); 357 vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2);
356 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); 358 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
357 359
358 vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); 360 vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
359 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); 361 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
360 362
361 // Segment coding disabled for compred testing 363 // Segment coding disabled for compred testing
362 if (high_q || (cpi->static_mb_pct == 100)) { 364 if (high_q || (cpi->static_mb_pct == 100)) {
363 vp9_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); 365 vp9_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
364 vp9_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); 366 vp9_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 406
405 // No updates.. leave things as they are. 407 // No updates.. leave things as they are.
406 seg->update_map = 0; 408 seg->update_map = 0;
407 seg->update_data = 0; 409 seg->update_data = 0;
408 } 410 }
409 } 411 }
410 } 412 }
411 413
412 static void update_reference_segmentation_map(VP9_COMP *cpi) { 414 static void update_reference_segmentation_map(VP9_COMP *cpi) {
413 VP9_COMMON *const cm = &cpi->common; 415 VP9_COMMON *const cm = &cpi->common;
414 MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible; 416 MODE_INFO *mi_8x8_ptr = cm->mi;
415 uint8_t *cache_ptr = cm->last_frame_seg_map; 417 uint8_t *cache_ptr = cm->last_frame_seg_map;
416 int row, col; 418 int row, col;
417 419
418 for (row = 0; row < cm->mi_rows; row++) { 420 for (row = 0; row < cm->mi_rows; row++) {
419 MODE_INFO **mi_8x8 = mi_8x8_ptr; 421 MODE_INFO *mi_8x8 = mi_8x8_ptr;
420 uint8_t *cache = cache_ptr; 422 uint8_t *cache = cache_ptr;
421 for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++) 423 for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++)
422 cache[0] = mi_8x8[0]->mbmi.segment_id; 424 cache[0] = mi_8x8[0].src_mi->mbmi.segment_id;
423 mi_8x8_ptr += cm->mi_stride; 425 mi_8x8_ptr += cm->mi_stride;
424 cache_ptr += cm->mi_cols; 426 cache_ptr += cm->mi_cols;
425 } 427 }
426 } 428 }
427 429
428 static void alloc_raw_frame_buffers(VP9_COMP *cpi) { 430 static void alloc_raw_frame_buffers(VP9_COMP *cpi) {
429 VP9_COMMON *cm = &cpi->common; 431 VP9_COMMON *cm = &cpi->common;
430 const VP9EncoderConfig *oxcf = &cpi->oxcf; 432 const VP9EncoderConfig *oxcf = &cpi->oxcf;
431 433
432 cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height, 434 cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 } 551 }
550 552
551 static void init_config(struct VP9_COMP *cpi, VP9EncoderConfig *oxcf) { 553 static void init_config(struct VP9_COMP *cpi, VP9EncoderConfig *oxcf) {
552 VP9_COMMON *const cm = &cpi->common; 554 VP9_COMMON *const cm = &cpi->common;
553 555
554 cpi->oxcf = *oxcf; 556 cpi->oxcf = *oxcf;
555 cpi->framerate = oxcf->init_framerate; 557 cpi->framerate = oxcf->init_framerate;
556 558
557 cm->profile = oxcf->profile; 559 cm->profile = oxcf->profile;
558 cm->bit_depth = oxcf->bit_depth; 560 cm->bit_depth = oxcf->bit_depth;
561 #if CONFIG_VP9_HIGHBITDEPTH
562 cm->use_highbitdepth = oxcf->use_highbitdepth;
563 #endif
559 cm->color_space = UNKNOWN; 564 cm->color_space = UNKNOWN;
560 565
561 cm->width = oxcf->width; 566 cm->width = oxcf->width;
562 cm->height = oxcf->height; 567 cm->height = oxcf->height;
563 vp9_alloc_compressor_data(cpi); 568 vp9_alloc_compressor_data(cpi);
564 569
565 // Spatial scalability. 570 // Spatial scalability.
566 cpi->svc.number_spatial_layers = oxcf->ss_number_layers; 571 cpi->svc.number_spatial_layers = oxcf->ss_number_layers;
567 // Temporal scalability. 572 // Temporal scalability.
568 cpi->svc.number_temporal_layers = oxcf->ts_number_layers; 573 cpi->svc.number_temporal_layers = oxcf->ts_number_layers;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 if (cm->profile != oxcf->profile) 611 if (cm->profile != oxcf->profile)
607 cm->profile = oxcf->profile; 612 cm->profile = oxcf->profile;
608 cm->bit_depth = oxcf->bit_depth; 613 cm->bit_depth = oxcf->bit_depth;
609 614
610 if (cm->profile <= PROFILE_1) 615 if (cm->profile <= PROFILE_1)
611 assert(cm->bit_depth == VPX_BITS_8); 616 assert(cm->bit_depth == VPX_BITS_8);
612 else 617 else
613 assert(cm->bit_depth > VPX_BITS_8); 618 assert(cm->bit_depth > VPX_BITS_8);
614 619
615 cpi->oxcf = *oxcf; 620 cpi->oxcf = *oxcf;
621 #if CONFIG_VP9_HIGHBITDEPTH
622 if (cpi->oxcf.use_highbitdepth) {
623 cpi->mb.e_mbd.bd = (int)cm->bit_depth;
624 }
625 #endif
616 626
617 rc->baseline_gf_interval = DEFAULT_GF_INTERVAL; 627 rc->baseline_gf_interval = DEFAULT_GF_INTERVAL;
618 628
619 cpi->refresh_golden_frame = 0; 629 cpi->refresh_golden_frame = 0;
620 cpi->refresh_last_frame = 1; 630 cpi->refresh_last_frame = 1;
621 cm->refresh_frame_context = 1; 631 cm->refresh_frame_context = 1;
622 cm->reset_frame_context = 0; 632 cm->reset_frame_context = 0;
623 633
624 vp9_reset_segment_features(&cm->seg); 634 vp9_reset_segment_features(&cm->seg);
625 vp9_set_high_precision_mv(cpi, 0); 635 vp9_set_high_precision_mv(cpi, 0);
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 vp9_set_speed_features(cpi); 984 vp9_set_speed_features(cpi);
975 985
976 // Allocate memory to store variances for a frame. 986 // Allocate memory to store variances for a frame.
977 CHECK_MEM_ERROR(cm, cpi->source_diff_var, 987 CHECK_MEM_ERROR(cm, cpi->source_diff_var,
978 vpx_calloc(cm->MBs, sizeof(diff))); 988 vpx_calloc(cm->MBs, sizeof(diff)));
979 cpi->source_var_thresh = 0; 989 cpi->source_var_thresh = 0;
980 cpi->frames_till_next_var_check = 0; 990 cpi->frames_till_next_var_check = 0;
981 991
982 // Default rd threshold factors for mode selection 992 // Default rd threshold factors for mode selection
983 for (i = 0; i < BLOCK_SIZES; ++i) { 993 for (i = 0; i < BLOCK_SIZES; ++i) {
984 for (j = 0; j < MAX_MODES; ++j) 994 for (j = 0; j < MAX_MODES; ++j) {
985 cpi->rd.thresh_freq_fact[i][j] = 32; 995 cpi->rd.thresh_freq_fact[i][j] = 32;
996 cpi->rd.mode_map[i][j] = j;
997 }
986 } 998 }
987 999
988 #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF)\ 1000 #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF)\
989 cpi->fn_ptr[BT].sdf = SDF; \ 1001 cpi->fn_ptr[BT].sdf = SDF; \
990 cpi->fn_ptr[BT].sdaf = SDAF; \ 1002 cpi->fn_ptr[BT].sdaf = SDAF; \
991 cpi->fn_ptr[BT].vf = VF; \ 1003 cpi->fn_ptr[BT].vf = VF; \
992 cpi->fn_ptr[BT].svf = SVF; \ 1004 cpi->fn_ptr[BT].svf = SVF; \
993 cpi->fn_ptr[BT].svaf = SVAF; \ 1005 cpi->fn_ptr[BT].svaf = SVAF; \
994 cpi->fn_ptr[BT].sdx3f = SDX3F; \ 1006 cpi->fn_ptr[BT].sdx3f = SDX3F; \
995 cpi->fn_ptr[BT].sdx8f = SDX8F; \ 1007 cpi->fn_ptr[BT].sdx8f = SDX8F; \
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 struct vpx_codec_cx_pkt pkt; 1277 struct vpx_codec_cx_pkt pkt;
1266 int i; 1278 int i;
1267 PSNR_STATS psnr; 1279 PSNR_STATS psnr;
1268 calc_psnr(cpi->Source, cpi->common.frame_to_show, &psnr); 1280 calc_psnr(cpi->Source, cpi->common.frame_to_show, &psnr);
1269 for (i = 0; i < 4; ++i) { 1281 for (i = 0; i < 4; ++i) {
1270 pkt.data.psnr.samples[i] = psnr.samples[i]; 1282 pkt.data.psnr.samples[i] = psnr.samples[i];
1271 pkt.data.psnr.sse[i] = psnr.sse[i]; 1283 pkt.data.psnr.sse[i] = psnr.sse[i];
1272 pkt.data.psnr.psnr[i] = psnr.psnr[i]; 1284 pkt.data.psnr.psnr[i] = psnr.psnr[i];
1273 } 1285 }
1274 pkt.kind = VPX_CODEC_PSNR_PKT; 1286 pkt.kind = VPX_CODEC_PSNR_PKT;
1275 vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt); 1287 if (is_two_pass_svc(cpi))
1288 cpi->svc.layer_context[cpi->svc.spatial_layer_id].psnr_pkt = pkt.data.psnr;
1289 else
1290 vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt);
1276 } 1291 }
1277 1292
1278 int vp9_use_as_reference(VP9_COMP *cpi, int ref_frame_flags) { 1293 int vp9_use_as_reference(VP9_COMP *cpi, int ref_frame_flags) {
1279 if (ref_frame_flags > 7) 1294 if (ref_frame_flags > 7)
1280 return -1; 1295 return -1;
1281 1296
1282 cpi->ref_frame_flags = ref_frame_flags; 1297 cpi->ref_frame_flags = ref_frame_flags;
1283 return 0; 1298 return 0;
1284 } 1299 }
1285 1300
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
2226 break; 2241 break;
2227 case 6: 2242 case 6:
2228 l = 150; 2243 l = 150;
2229 break; 2244 break;
2230 } 2245 }
2231 vp9_denoise(cpi->Source, cpi->Source, l); 2246 vp9_denoise(cpi->Source, cpi->Source, l);
2232 } 2247 }
2233 #endif 2248 #endif
2234 2249
2235 #if CONFIG_INTERNAL_STATS 2250 #if CONFIG_INTERNAL_STATS
2236 int i; 2251 {
2237 for (i = 0; i < MAX_MODES; ++i) 2252 int i;
2238 cpi->mode_chosen_counts[i] = 0; 2253 for (i = 0; i < MAX_MODES; ++i)
2254 cpi->mode_chosen_counts[i] = 0;
2255 }
2239 #endif 2256 #endif
2240 2257
2241 vp9_set_speed_features(cpi); 2258 vp9_set_speed_features(cpi);
2242 2259
2243 vp9_set_rd_speed_thresholds(cpi); 2260 vp9_set_rd_speed_thresholds(cpi);
2244 vp9_set_rd_speed_thresholds_sub8x8(cpi); 2261 vp9_set_rd_speed_thresholds_sub8x8(cpi);
2245 2262
2246 // Decide q and q bounds. 2263 // Decide q and q bounds.
2247 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index); 2264 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index);
2248 2265
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2377 vp9_rc_get_one_pass_cbr_params(cpi); 2394 vp9_rc_get_one_pass_cbr_params(cpi);
2378 } else { 2395 } else {
2379 vp9_rc_get_one_pass_vbr_params(cpi); 2396 vp9_rc_get_one_pass_vbr_params(cpi);
2380 } 2397 }
2381 encode_frame_to_data_rate(cpi, size, dest, frame_flags); 2398 encode_frame_to_data_rate(cpi, size, dest, frame_flags);
2382 } 2399 }
2383 2400
2384 static void Pass2Encode(VP9_COMP *cpi, size_t *size, 2401 static void Pass2Encode(VP9_COMP *cpi, size_t *size,
2385 uint8_t *dest, unsigned int *frame_flags) { 2402 uint8_t *dest, unsigned int *frame_flags) {
2386 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; 2403 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED;
2387
2388 vp9_rc_get_second_pass_params(cpi);
2389 encode_frame_to_data_rate(cpi, size, dest, frame_flags); 2404 encode_frame_to_data_rate(cpi, size, dest, frame_flags);
2390
2391 vp9_twopass_postencode_update(cpi); 2405 vp9_twopass_postencode_update(cpi);
2392 } 2406 }
2393 2407
2394 static void init_motion_estimation(VP9_COMP *cpi) { 2408 static void init_motion_estimation(VP9_COMP *cpi) {
2395 int y_stride = cpi->scaled_source.y_stride; 2409 int y_stride = cpi->scaled_source.y_stride;
2396 2410
2397 if (cpi->sf.mv.search_method == NSTEP) { 2411 if (cpi->sf.mv.search_method == NSTEP) {
2398 vp9_init3smotion_compensation(&cpi->ss_cfg, y_stride); 2412 vp9_init3smotion_compensation(&cpi->ss_cfg, y_stride);
2399 } else if (cpi->sf.mv.search_method == DIAMOND) { 2413 } else if (cpi->sf.mv.search_method == DIAMOND) {
2400 vp9_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); 2414 vp9_init_dsmotion_compensation(&cpi->ss_cfg, y_stride);
(...skipping 26 matching lines...) Expand all
2427 VP9_COMMON *cm = &cpi->common; 2441 VP9_COMMON *cm = &cpi->common;
2428 struct vpx_usec_timer timer; 2442 struct vpx_usec_timer timer;
2429 int res = 0; 2443 int res = 0;
2430 const int subsampling_x = sd->uv_width < sd->y_width; 2444 const int subsampling_x = sd->uv_width < sd->y_width;
2431 const int subsampling_y = sd->uv_height < sd->y_height; 2445 const int subsampling_y = sd->uv_height < sd->y_height;
2432 2446
2433 check_initial_width(cpi, subsampling_x, subsampling_y); 2447 check_initial_width(cpi, subsampling_x, subsampling_y);
2434 2448
2435 vpx_usec_timer_start(&timer); 2449 vpx_usec_timer_start(&timer);
2436 2450
2437 #if CONFIG_SPATIAL_SVC 2451 if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, frame_flags))
2438 if (is_two_pass_svc(cpi))
2439 res = vp9_svc_lookahead_push(cpi, cpi->lookahead, sd, time_stamp, end_time,
2440 frame_flags);
2441 else
2442 #endif
2443 res = vp9_lookahead_push(cpi->lookahead,
2444 sd, time_stamp, end_time, frame_flags);
2445 if (res)
2446 res = -1; 2452 res = -1;
2447 vpx_usec_timer_mark(&timer); 2453 vpx_usec_timer_mark(&timer);
2448 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer); 2454 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer);
2449 2455
2450 if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && 2456 if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) &&
2451 (subsampling_x != 1 || subsampling_y != 1)) { 2457 (subsampling_x != 1 || subsampling_y != 1)) {
2452 vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, 2458 vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM,
2453 "Non-4:2:0 color space requires profile 1 or 3"); 2459 "Non-4:2:0 color space requires profile 1 or 3");
2454 res = -1; 2460 res = -1;
2455 } 2461 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2564 VP9_COMMON *const cm = &cpi->common; 2570 VP9_COMMON *const cm = &cpi->common;
2565 MACROBLOCKD *const xd = &cpi->mb.e_mbd; 2571 MACROBLOCKD *const xd = &cpi->mb.e_mbd;
2566 RATE_CONTROL *const rc = &cpi->rc; 2572 RATE_CONTROL *const rc = &cpi->rc;
2567 struct vpx_usec_timer cmptimer; 2573 struct vpx_usec_timer cmptimer;
2568 YV12_BUFFER_CONFIG *force_src_buffer = NULL; 2574 YV12_BUFFER_CONFIG *force_src_buffer = NULL;
2569 struct lookahead_entry *last_source = NULL; 2575 struct lookahead_entry *last_source = NULL;
2570 struct lookahead_entry *source = NULL; 2576 struct lookahead_entry *source = NULL;
2571 MV_REFERENCE_FRAME ref_frame; 2577 MV_REFERENCE_FRAME ref_frame;
2572 int arf_src_index; 2578 int arf_src_index;
2573 2579
2574 if (is_two_pass_svc(cpi) && oxcf->pass == 2) { 2580 if (is_two_pass_svc(cpi)) {
2575 #if CONFIG_SPATIAL_SVC 2581 #if CONFIG_SPATIAL_SVC
2576 vp9_svc_lookahead_peek(cpi, cpi->lookahead, 0, 1); 2582 vp9_svc_start_frame(cpi);
2577 #endif 2583 #endif
2578 vp9_restore_layer_context(cpi); 2584 if (oxcf->pass == 2)
2585 vp9_restore_layer_context(cpi);
2579 } 2586 }
2580 2587
2581 vpx_usec_timer_start(&cmptimer); 2588 vpx_usec_timer_start(&cmptimer);
2582 2589
2583 vp9_set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); 2590 vp9_set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV);
2584 2591
2585 // Normal defaults 2592 // Normal defaults
2586 cm->reset_frame_context = 0; 2593 cm->reset_frame_context = 0;
2587 cm->refresh_frame_context = 1; 2594 cm->refresh_frame_context = 1;
2588 cpi->refresh_last_frame = 1; 2595 cpi->refresh_last_frame = 1;
2589 cpi->refresh_golden_frame = 0; 2596 cpi->refresh_golden_frame = 0;
2590 cpi->refresh_alt_ref_frame = 0; 2597 cpi->refresh_alt_ref_frame = 0;
2591 2598
2592 // Should we encode an arf frame. 2599 // Should we encode an arf frame.
2593 arf_src_index = get_arf_src_index(cpi); 2600 arf_src_index = get_arf_src_index(cpi);
2594 if (arf_src_index) { 2601 if (arf_src_index) {
2595 assert(arf_src_index <= rc->frames_to_key); 2602 assert(arf_src_index <= rc->frames_to_key);
2596 2603
2597 #if CONFIG_SPATIAL_SVC 2604 if ((source = vp9_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) {
2598 if (is_two_pass_svc(cpi))
2599 source = vp9_svc_lookahead_peek(cpi, cpi->lookahead, arf_src_index, 0);
2600 else
2601 #endif
2602 source = vp9_lookahead_peek(cpi->lookahead, arf_src_index);
2603 if (source != NULL) {
2604 cpi->alt_ref_source = source; 2605 cpi->alt_ref_source = source;
2605 2606
2606 #if CONFIG_SPATIAL_SVC 2607 #if CONFIG_SPATIAL_SVC
2607 if (is_two_pass_svc(cpi) && cpi->svc.spatial_layer_id > 0) { 2608 if (is_two_pass_svc(cpi) && cpi->svc.spatial_layer_id > 0) {
2608 int i; 2609 int i;
2609 // Reference a hidden frame from a lower layer 2610 // Reference a hidden frame from a lower layer
2610 for (i = cpi->svc.spatial_layer_id - 1; i >= 0; --i) { 2611 for (i = cpi->svc.spatial_layer_id - 1; i >= 0; --i) {
2611 if (oxcf->ss_play_alternate[i]) { 2612 if (oxcf->ss_play_alternate[i]) {
2612 cpi->gld_fb_idx = cpi->svc.layer_context[i].alt_ref_idx; 2613 cpi->gld_fb_idx = cpi->svc.layer_context[i].alt_ref_idx;
2613 break; 2614 break;
(...skipping 17 matching lines...) Expand all
2631 rc->is_src_frame_alt_ref = 0; 2632 rc->is_src_frame_alt_ref = 0;
2632 rc->source_alt_ref_pending = 0; 2633 rc->source_alt_ref_pending = 0;
2633 } else { 2634 } else {
2634 rc->source_alt_ref_pending = 0; 2635 rc->source_alt_ref_pending = 0;
2635 } 2636 }
2636 } 2637 }
2637 2638
2638 if (!source) { 2639 if (!source) {
2639 // Get last frame source. 2640 // Get last frame source.
2640 if (cm->current_video_frame > 0) { 2641 if (cm->current_video_frame > 0) {
2641 #if CONFIG_SPATIAL_SVC 2642 if ((last_source = vp9_lookahead_peek(cpi->lookahead, -1)) == NULL)
2642 if (is_two_pass_svc(cpi))
2643 last_source = vp9_svc_lookahead_peek(cpi, cpi->lookahead, -1, 0);
2644 else
2645 #endif
2646 last_source = vp9_lookahead_peek(cpi->lookahead, -1);
2647 if (last_source == NULL)
2648 return -1; 2643 return -1;
2649 } 2644 }
2650 2645
2651 // Read in the source frame. 2646 // Read in the source frame.
2652 #if CONFIG_SPATIAL_SVC 2647 #if CONFIG_SPATIAL_SVC
2653 if (is_two_pass_svc(cpi)) 2648 if (is_two_pass_svc(cpi))
2654 source = vp9_svc_lookahead_pop(cpi, cpi->lookahead, flush); 2649 source = vp9_svc_lookahead_pop(cpi, cpi->lookahead, flush);
2655 else 2650 else
2656 #endif 2651 #endif
2657 source = vp9_lookahead_pop(cpi->lookahead, flush); 2652 source = vp9_lookahead_pop(cpi->lookahead, flush);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2704 2699
2705 // start with a 0 size frame 2700 // start with a 0 size frame
2706 *size = 0; 2701 *size = 0;
2707 2702
2708 /* find a free buffer for the new frame, releasing the reference previously 2703 /* find a free buffer for the new frame, releasing the reference previously
2709 * held. 2704 * held.
2710 */ 2705 */
2711 cm->frame_bufs[cm->new_fb_idx].ref_count--; 2706 cm->frame_bufs[cm->new_fb_idx].ref_count--;
2712 cm->new_fb_idx = get_free_fb(cm); 2707 cm->new_fb_idx = get_free_fb(cm);
2713 2708
2709 // For two pass encodes analyse the first pass stats and determine
2710 // the bit allocation and other parameters for this frame / group of frames.
2711 if ((oxcf->pass == 2) && (!cpi->use_svc || is_two_pass_svc(cpi))) {
2712 vp9_rc_get_second_pass_params(cpi);
2713 }
2714
2714 if (!cpi->use_svc && cpi->multi_arf_allowed) { 2715 if (!cpi->use_svc && cpi->multi_arf_allowed) {
2715 if (cm->frame_type == KEY_FRAME) { 2716 if (cm->frame_type == KEY_FRAME) {
2716 init_buffer_indices(cpi); 2717 init_buffer_indices(cpi);
2717 } else if (oxcf->pass == 2) { 2718 } else if (oxcf->pass == 2) {
2718 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; 2719 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
2719 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; 2720 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index];
2720 } 2721 }
2721 } 2722 }
2722 2723
2723 cpi->frame_flags = *frame_flags; 2724 cpi->frame_flags = *frame_flags;
(...skipping 18 matching lines...) Expand all
2742 2743
2743 alloc_util_frame_buffers(cpi); 2744 alloc_util_frame_buffers(cpi);
2744 init_motion_estimation(cpi); 2745 init_motion_estimation(cpi);
2745 2746
2746 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { 2747 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
2747 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; 2748 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)];
2748 YV12_BUFFER_CONFIG *const buf = &cm->frame_bufs[idx].buf; 2749 YV12_BUFFER_CONFIG *const buf = &cm->frame_bufs[idx].buf;
2749 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1]; 2750 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1];
2750 ref_buf->buf = buf; 2751 ref_buf->buf = buf;
2751 ref_buf->idx = idx; 2752 ref_buf->idx = idx;
2753 #if CONFIG_VP9_HIGHBITDEPTH
2754 vp9_setup_scale_factors_for_frame(&ref_buf->sf,
2755 buf->y_crop_width, buf->y_crop_height,
2756 cm->width, cm->height,
2757 (buf->flags & YV12_FLAG_HIGHBITDEPTH) ?
2758 1 : 0);
2759 #else
2752 vp9_setup_scale_factors_for_frame(&ref_buf->sf, 2760 vp9_setup_scale_factors_for_frame(&ref_buf->sf,
2753 buf->y_crop_width, buf->y_crop_height, 2761 buf->y_crop_width, buf->y_crop_height,
2754 cm->width, cm->height); 2762 cm->width, cm->height);
2755 2763 #endif
2756 if (vp9_is_scaled(&ref_buf->sf)) 2764 if (vp9_is_scaled(&ref_buf->sf))
2757 vp9_extend_frame_borders(buf); 2765 vp9_extend_frame_borders(buf);
2758 } 2766 }
2759 2767
2760 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); 2768 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME);
2761 2769
2762 if (oxcf->aq_mode == VARIANCE_AQ) { 2770 if (oxcf->aq_mode == VARIANCE_AQ) {
2763 vp9_vaq_init(); 2771 vp9_vaq_init();
2764 } 2772 }
2765 2773
2766 if (oxcf->pass == 1 && 2774 if (oxcf->pass == 1 &&
2767 (!cpi->use_svc || is_two_pass_svc(cpi))) { 2775 (!cpi->use_svc || is_two_pass_svc(cpi))) {
2768 const int lossless = is_lossless_requested(oxcf); 2776 const int lossless = is_lossless_requested(oxcf);
2777 #if CONFIG_VP9_HIGHBITDEPTH
2778 if (cpi->oxcf.use_highbitdepth)
2779 cpi->mb.fwd_txm4x4 = lossless ? vp9_high_fwht4x4 : vp9_high_fdct4x4;
2780 else
2781 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4;
2782 cpi->mb.high_itxm_add = lossless ? vp9_high_iwht4x4_add :
2783 vp9_high_idct4x4_add;
2784 #else
2769 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4; 2785 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4;
2786 #endif
2770 cpi->mb.itxm_add = lossless ? vp9_iwht4x4_add : vp9_idct4x4_add; 2787 cpi->mb.itxm_add = lossless ? vp9_iwht4x4_add : vp9_idct4x4_add;
2771 vp9_first_pass(cpi, source); 2788 vp9_first_pass(cpi, source);
2772 } else if (oxcf->pass == 2 && 2789 } else if (oxcf->pass == 2 &&
2773 (!cpi->use_svc || is_two_pass_svc(cpi))) { 2790 (!cpi->use_svc || is_two_pass_svc(cpi))) {
2774 Pass2Encode(cpi, size, dest, frame_flags); 2791 Pass2Encode(cpi, size, dest, frame_flags);
2775 } else if (cpi->use_svc) { 2792 } else if (cpi->use_svc) {
2776 SvcEncode(cpi, size, dest, frame_flags); 2793 SvcEncode(cpi, size, dest, frame_flags);
2777 } else { 2794 } else {
2778 // One pass encode 2795 // One pass encode
2779 Pass0Encode(cpi, size, dest, frame_flags); 2796 Pass0Encode(cpi, size, dest, frame_flags);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2875 frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u, &v); 2892 frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u, &v);
2876 cpi->total_ssimg_y += y; 2893 cpi->total_ssimg_y += y;
2877 cpi->total_ssimg_u += u; 2894 cpi->total_ssimg_u += u;
2878 cpi->total_ssimg_v += v; 2895 cpi->total_ssimg_v += v;
2879 cpi->total_ssimg_all += frame_all; 2896 cpi->total_ssimg_all += frame_all;
2880 } 2897 }
2881 } 2898 }
2882 } 2899 }
2883 2900
2884 #endif 2901 #endif
2902
2903 if (is_two_pass_svc(cpi) && cm->show_frame) {
2904 ++cpi->svc.spatial_layer_to_encode;
2905 if (cpi->svc.spatial_layer_to_encode >= cpi->svc.number_spatial_layers)
2906 cpi->svc.spatial_layer_to_encode = 0;
2907 }
2885 return 0; 2908 return 0;
2886 } 2909 }
2887 2910
2888 int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest, 2911 int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest,
2889 vp9_ppflags_t *flags) { 2912 vp9_ppflags_t *flags) {
2890 VP9_COMMON *cm = &cpi->common; 2913 VP9_COMMON *cm = &cpi->common;
2891 #if !CONFIG_VP9_POSTPROC 2914 #if !CONFIG_VP9_POSTPROC
2892 (void)flags; 2915 (void)flags;
2893 #endif 2916 #endif
2894 2917
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
3046 if (flags & VP8_EFLAG_NO_UPD_ARF) 3069 if (flags & VP8_EFLAG_NO_UPD_ARF)
3047 upd ^= VP9_ALT_FLAG; 3070 upd ^= VP9_ALT_FLAG;
3048 3071
3049 vp9_update_reference(cpi, upd); 3072 vp9_update_reference(cpi, upd);
3050 } 3073 }
3051 3074
3052 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { 3075 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) {
3053 vp9_update_entropy(cpi, 0); 3076 vp9_update_entropy(cpi, 0);
3054 } 3077 }
3055 } 3078 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encoder.h ('k') | source/libvpx/vp9/encoder/vp9_firstpass.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698