OLD | NEW |
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 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 mi_row += MI_BLOCK_SIZE) { | 478 mi_row += MI_BLOCK_SIZE) { |
479 vp9_zero(cpi->mb.e_mbd.left_seg_context); | 479 vp9_zero(cpi->mb.e_mbd.left_seg_context); |
480 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; | 480 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; |
481 mi_col += MI_BLOCK_SIZE) | 481 mi_col += MI_BLOCK_SIZE) |
482 write_modes_sb(cpi, tile, w, tok, tok_end, mi_row, mi_col, | 482 write_modes_sb(cpi, tile, w, tok, tok_end, mi_row, mi_col, |
483 BLOCK_64X64); | 483 BLOCK_64X64); |
484 } | 484 } |
485 } | 485 } |
486 | 486 |
487 static void build_tree_distribution(VP9_COMP *cpi, TX_SIZE tx_size, | 487 static void build_tree_distribution(VP9_COMP *cpi, TX_SIZE tx_size, |
488 vp9_coeff_stats *coef_branch_ct) { | 488 vp9_coeff_stats *coef_branch_ct, |
489 vp9_coeff_probs_model *coef_probs = cpi->frame_coef_probs[tx_size]; | 489 vp9_coeff_probs_model *coef_probs) { |
490 vp9_coeff_count *coef_counts = cpi->coef_counts[tx_size]; | 490 vp9_coeff_count *coef_counts = cpi->coef_counts[tx_size]; |
491 unsigned int (*eob_branch_ct)[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS] = | 491 unsigned int (*eob_branch_ct)[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS] = |
492 cpi->common.counts.eob_branch[tx_size]; | 492 cpi->common.counts.eob_branch[tx_size]; |
493 int i, j, k, l, m; | 493 int i, j, k, l, m; |
494 | 494 |
495 for (i = 0; i < PLANE_TYPES; ++i) { | 495 for (i = 0; i < PLANE_TYPES; ++i) { |
496 for (j = 0; j < REF_TYPES; ++j) { | 496 for (j = 0; j < REF_TYPES; ++j) { |
497 for (k = 0; k < COEF_BANDS; ++k) { | 497 for (k = 0; k < COEF_BANDS; ++k) { |
498 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { | 498 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { |
499 vp9_tree_probs_from_distribution(vp9_coef_tree, | 499 vp9_tree_probs_from_distribution(vp9_coef_tree, |
500 coef_branch_ct[i][j][k][l], | 500 coef_branch_ct[i][j][k][l], |
501 coef_counts[i][j][k][l]); | 501 coef_counts[i][j][k][l]); |
502 coef_branch_ct[i][j][k][l][0][1] = eob_branch_ct[i][j][k][l] - | 502 coef_branch_ct[i][j][k][l][0][1] = eob_branch_ct[i][j][k][l] - |
503 coef_branch_ct[i][j][k][l][0][0]; | 503 coef_branch_ct[i][j][k][l][0][0]; |
504 for (m = 0; m < UNCONSTRAINED_NODES; ++m) | 504 for (m = 0; m < UNCONSTRAINED_NODES; ++m) |
505 coef_probs[i][j][k][l][m] = get_binary_prob( | 505 coef_probs[i][j][k][l][m] = get_binary_prob( |
506 coef_branch_ct[i][j][k][l][m][0], | 506 coef_branch_ct[i][j][k][l][m][0], |
507 coef_branch_ct[i][j][k][l][m][1]); | 507 coef_branch_ct[i][j][k][l][m][1]); |
508 } | 508 } |
509 } | 509 } |
510 } | 510 } |
511 } | 511 } |
512 } | 512 } |
513 | 513 |
514 static void update_coef_probs_common(vp9_writer* const bc, VP9_COMP *cpi, | 514 static void update_coef_probs_common(vp9_writer* const bc, VP9_COMP *cpi, |
515 TX_SIZE tx_size, | 515 TX_SIZE tx_size, |
516 vp9_coeff_stats *frame_branch_ct) { | 516 vp9_coeff_stats *frame_branch_ct, |
517 vp9_coeff_probs_model *new_frame_coef_probs = cpi->frame_coef_probs[tx_size]; | 517 vp9_coeff_probs_model *new_coef_probs) { |
518 vp9_coeff_probs_model *old_frame_coef_probs = | 518 vp9_coeff_probs_model *old_coef_probs = cpi->common.fc.coef_probs[tx_size]; |
519 cpi->common.fc.coef_probs[tx_size]; | |
520 const vp9_prob upd = DIFF_UPDATE_PROB; | 519 const vp9_prob upd = DIFF_UPDATE_PROB; |
521 const int entropy_nodes_update = UNCONSTRAINED_NODES; | 520 const int entropy_nodes_update = UNCONSTRAINED_NODES; |
522 int i, j, k, l, t; | 521 int i, j, k, l, t; |
523 switch (cpi->sf.use_fast_coef_updates) { | 522 switch (cpi->sf.use_fast_coef_updates) { |
524 case TWO_LOOP: { | 523 case TWO_LOOP: { |
525 /* dry run to see if there is any udpate at all needed */ | 524 /* dry run to see if there is any udpate at all needed */ |
526 int savings = 0; | 525 int savings = 0; |
527 int update[2] = {0, 0}; | 526 int update[2] = {0, 0}; |
528 for (i = 0; i < PLANE_TYPES; ++i) { | 527 for (i = 0; i < PLANE_TYPES; ++i) { |
529 for (j = 0; j < REF_TYPES; ++j) { | 528 for (j = 0; j < REF_TYPES; ++j) { |
530 for (k = 0; k < COEF_BANDS; ++k) { | 529 for (k = 0; k < COEF_BANDS; ++k) { |
531 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { | 530 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { |
532 for (t = 0; t < entropy_nodes_update; ++t) { | 531 for (t = 0; t < entropy_nodes_update; ++t) { |
533 vp9_prob newp = new_frame_coef_probs[i][j][k][l][t]; | 532 vp9_prob newp = new_coef_probs[i][j][k][l][t]; |
534 const vp9_prob oldp = old_frame_coef_probs[i][j][k][l][t]; | 533 const vp9_prob oldp = old_coef_probs[i][j][k][l][t]; |
535 int s; | 534 int s; |
536 int u = 0; | 535 int u = 0; |
537 if (t == PIVOT_NODE) | 536 if (t == PIVOT_NODE) |
538 s = vp9_prob_diff_update_savings_search_model( | 537 s = vp9_prob_diff_update_savings_search_model( |
539 frame_branch_ct[i][j][k][l][0], | 538 frame_branch_ct[i][j][k][l][0], |
540 old_frame_coef_probs[i][j][k][l], &newp, upd); | 539 old_coef_probs[i][j][k][l], &newp, upd); |
541 else | 540 else |
542 s = vp9_prob_diff_update_savings_search( | 541 s = vp9_prob_diff_update_savings_search( |
543 frame_branch_ct[i][j][k][l][t], oldp, &newp, upd); | 542 frame_branch_ct[i][j][k][l][t], oldp, &newp, upd); |
544 if (s > 0 && newp != oldp) | 543 if (s > 0 && newp != oldp) |
545 u = 1; | 544 u = 1; |
546 if (u) | 545 if (u) |
547 savings += s - (int)(vp9_cost_zero(upd)); | 546 savings += s - (int)(vp9_cost_zero(upd)); |
548 else | 547 else |
549 savings -= (int)(vp9_cost_zero(upd)); | 548 savings -= (int)(vp9_cost_zero(upd)); |
550 update[u]++; | 549 update[u]++; |
551 } | 550 } |
552 } | 551 } |
553 } | 552 } |
554 } | 553 } |
555 } | 554 } |
556 | 555 |
557 // printf("Update %d %d, savings %d\n", update[0], update[1], savings); | 556 // printf("Update %d %d, savings %d\n", update[0], update[1], savings); |
558 /* Is coef updated at all */ | 557 /* Is coef updated at all */ |
559 if (update[1] == 0 || savings < 0) { | 558 if (update[1] == 0 || savings < 0) { |
560 vp9_write_bit(bc, 0); | 559 vp9_write_bit(bc, 0); |
561 return; | 560 return; |
562 } | 561 } |
563 vp9_write_bit(bc, 1); | 562 vp9_write_bit(bc, 1); |
564 for (i = 0; i < PLANE_TYPES; ++i) { | 563 for (i = 0; i < PLANE_TYPES; ++i) { |
565 for (j = 0; j < REF_TYPES; ++j) { | 564 for (j = 0; j < REF_TYPES; ++j) { |
566 for (k = 0; k < COEF_BANDS; ++k) { | 565 for (k = 0; k < COEF_BANDS; ++k) { |
567 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { | 566 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { |
568 // calc probs and branch cts for this frame only | 567 // calc probs and branch cts for this frame only |
569 for (t = 0; t < entropy_nodes_update; ++t) { | 568 for (t = 0; t < entropy_nodes_update; ++t) { |
570 vp9_prob newp = new_frame_coef_probs[i][j][k][l][t]; | 569 vp9_prob newp = new_coef_probs[i][j][k][l][t]; |
571 vp9_prob *oldp = old_frame_coef_probs[i][j][k][l] + t; | 570 vp9_prob *oldp = old_coef_probs[i][j][k][l] + t; |
572 const vp9_prob upd = DIFF_UPDATE_PROB; | 571 const vp9_prob upd = DIFF_UPDATE_PROB; |
573 int s; | 572 int s; |
574 int u = 0; | 573 int u = 0; |
575 if (t == PIVOT_NODE) | 574 if (t == PIVOT_NODE) |
576 s = vp9_prob_diff_update_savings_search_model( | 575 s = vp9_prob_diff_update_savings_search_model( |
577 frame_branch_ct[i][j][k][l][0], | 576 frame_branch_ct[i][j][k][l][0], |
578 old_frame_coef_probs[i][j][k][l], &newp, upd); | 577 old_coef_probs[i][j][k][l], &newp, upd); |
579 else | 578 else |
580 s = vp9_prob_diff_update_savings_search( | 579 s = vp9_prob_diff_update_savings_search( |
581 frame_branch_ct[i][j][k][l][t], | 580 frame_branch_ct[i][j][k][l][t], |
582 *oldp, &newp, upd); | 581 *oldp, &newp, upd); |
583 if (s > 0 && newp != *oldp) | 582 if (s > 0 && newp != *oldp) |
584 u = 1; | 583 u = 1; |
585 vp9_write(bc, u, upd); | 584 vp9_write(bc, u, upd); |
586 if (u) { | 585 if (u) { |
587 /* send/use new probability */ | 586 /* send/use new probability */ |
588 vp9_write_prob_diff_update(bc, newp, *oldp); | 587 vp9_write_prob_diff_update(bc, newp, *oldp); |
(...skipping 16 matching lines...) Expand all Loading... |
605 cpi->sf.use_fast_coef_updates == ONE_LOOP_REDUCED ? | 604 cpi->sf.use_fast_coef_updates == ONE_LOOP_REDUCED ? |
606 COEF_BANDS >> 1 : COEF_BANDS; | 605 COEF_BANDS >> 1 : COEF_BANDS; |
607 int updates = 0; | 606 int updates = 0; |
608 int noupdates_before_first = 0; | 607 int noupdates_before_first = 0; |
609 for (i = 0; i < PLANE_TYPES; ++i) { | 608 for (i = 0; i < PLANE_TYPES; ++i) { |
610 for (j = 0; j < REF_TYPES; ++j) { | 609 for (j = 0; j < REF_TYPES; ++j) { |
611 for (k = 0; k < COEF_BANDS; ++k) { | 610 for (k = 0; k < COEF_BANDS; ++k) { |
612 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { | 611 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { |
613 // calc probs and branch cts for this frame only | 612 // calc probs and branch cts for this frame only |
614 for (t = 0; t < entropy_nodes_update; ++t) { | 613 for (t = 0; t < entropy_nodes_update; ++t) { |
615 vp9_prob newp = new_frame_coef_probs[i][j][k][l][t]; | 614 vp9_prob newp = new_coef_probs[i][j][k][l][t]; |
616 vp9_prob *oldp = old_frame_coef_probs[i][j][k][l] + t; | 615 vp9_prob *oldp = old_coef_probs[i][j][k][l] + t; |
617 int s; | 616 int s; |
618 int u = 0; | 617 int u = 0; |
619 if (l >= prev_coef_contexts_to_update || | 618 if (l >= prev_coef_contexts_to_update || |
620 k >= coef_band_to_update) { | 619 k >= coef_band_to_update) { |
621 u = 0; | 620 u = 0; |
622 } else { | 621 } else { |
623 if (t == PIVOT_NODE) | 622 if (t == PIVOT_NODE) |
624 s = vp9_prob_diff_update_savings_search_model( | 623 s = vp9_prob_diff_update_savings_search_model( |
625 frame_branch_ct[i][j][k][l][0], | 624 frame_branch_ct[i][j][k][l][0], |
626 old_frame_coef_probs[i][j][k][l], &newp, upd); | 625 old_coef_probs[i][j][k][l], &newp, upd); |
627 else | 626 else |
628 s = vp9_prob_diff_update_savings_search( | 627 s = vp9_prob_diff_update_savings_search( |
629 frame_branch_ct[i][j][k][l][t], | 628 frame_branch_ct[i][j][k][l][t], |
630 *oldp, &newp, upd); | 629 *oldp, &newp, upd); |
631 if (s > 0 && newp != *oldp) | 630 if (s > 0 && newp != *oldp) |
632 u = 1; | 631 u = 1; |
633 } | 632 } |
634 updates += u; | 633 updates += u; |
635 if (u == 0 && updates == 0) { | 634 if (u == 0 && updates == 0) { |
636 noupdates_before_first++; | 635 noupdates_before_first++; |
(...skipping 26 matching lines...) Expand all Loading... |
663 default: | 662 default: |
664 assert(0); | 663 assert(0); |
665 } | 664 } |
666 } | 665 } |
667 | 666 |
668 static void update_coef_probs(VP9_COMP *cpi, vp9_writer* w) { | 667 static void update_coef_probs(VP9_COMP *cpi, vp9_writer* w) { |
669 const TX_MODE tx_mode = cpi->common.tx_mode; | 668 const TX_MODE tx_mode = cpi->common.tx_mode; |
670 const TX_SIZE max_tx_size = tx_mode_to_biggest_tx_size[tx_mode]; | 669 const TX_SIZE max_tx_size = tx_mode_to_biggest_tx_size[tx_mode]; |
671 TX_SIZE tx_size; | 670 TX_SIZE tx_size; |
672 vp9_coeff_stats frame_branch_ct[TX_SIZES][PLANE_TYPES]; | 671 vp9_coeff_stats frame_branch_ct[TX_SIZES][PLANE_TYPES]; |
| 672 vp9_coeff_probs_model frame_coef_probs[TX_SIZES][PLANE_TYPES]; |
673 | 673 |
674 vp9_clear_system_state(); | 674 vp9_clear_system_state(); |
675 | 675 |
676 for (tx_size = TX_4X4; tx_size <= TX_32X32; ++tx_size) | 676 for (tx_size = TX_4X4; tx_size <= TX_32X32; ++tx_size) |
677 build_tree_distribution(cpi, tx_size, frame_branch_ct[tx_size]); | 677 build_tree_distribution(cpi, tx_size, frame_branch_ct[tx_size], |
| 678 frame_coef_probs[tx_size]); |
678 | 679 |
679 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) | 680 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) |
680 update_coef_probs_common(w, cpi, tx_size, frame_branch_ct[tx_size]); | 681 update_coef_probs_common(w, cpi, tx_size, frame_branch_ct[tx_size], |
| 682 frame_coef_probs[tx_size]); |
681 } | 683 } |
682 | 684 |
683 static void encode_loopfilter(struct loopfilter *lf, | 685 static void encode_loopfilter(struct loopfilter *lf, |
684 struct vp9_write_bit_buffer *wb) { | 686 struct vp9_write_bit_buffer *wb) { |
685 int i; | 687 int i; |
686 | 688 |
687 // Encode the loop filter level and type | 689 // Encode the loop filter level and type |
688 vp9_wb_write_literal(wb, lf->filter_level, 6); | 690 vp9_wb_write_literal(wb, lf->filter_level, 6); |
689 vp9_wb_write_literal(wb, lf->sharpness_level, 3); | 691 vp9_wb_write_literal(wb, lf->sharpness_level, 3); |
690 | 692 |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 first_part_size = write_compressed_header(cpi, data); | 1216 first_part_size = write_compressed_header(cpi, data); |
1215 data += first_part_size; | 1217 data += first_part_size; |
1216 // TODO(jbb): Figure out what to do if first_part_size > 16 bits. | 1218 // TODO(jbb): Figure out what to do if first_part_size > 16 bits. |
1217 vp9_wb_write_literal(&saved_wb, (int)first_part_size, 16); | 1219 vp9_wb_write_literal(&saved_wb, (int)first_part_size, 16); |
1218 | 1220 |
1219 data += encode_tiles(cpi, data); | 1221 data += encode_tiles(cpi, data); |
1220 | 1222 |
1221 *size = data - dest; | 1223 *size = data - dest; |
1222 } | 1224 } |
1223 | 1225 |
OLD | NEW |