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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 static void update_coef_probs_common(vp9_writer* const bc, VP9_COMP *cpi, | 513 static void update_coef_probs_common(vp9_writer* const bc, VP9_COMP *cpi, |
514 TX_SIZE tx_size, | 514 TX_SIZE tx_size, |
515 vp9_coeff_stats *frame_branch_ct, | 515 vp9_coeff_stats *frame_branch_ct, |
516 vp9_coeff_probs_model *new_coef_probs) { | 516 vp9_coeff_probs_model *new_coef_probs) { |
517 vp9_coeff_probs_model *old_coef_probs = cpi->common.fc.coef_probs[tx_size]; | 517 vp9_coeff_probs_model *old_coef_probs = cpi->common.fc.coef_probs[tx_size]; |
518 const vp9_prob upd = DIFF_UPDATE_PROB; | 518 const vp9_prob upd = DIFF_UPDATE_PROB; |
519 const int entropy_nodes_update = UNCONSTRAINED_NODES; | 519 const int entropy_nodes_update = UNCONSTRAINED_NODES; |
520 int i, j, k, l, t; | 520 int i, j, k, l, t; |
521 switch (cpi->sf.use_fast_coef_updates) { | 521 switch (cpi->sf.use_fast_coef_updates) { |
522 case TWO_LOOP: { | 522 case TWO_LOOP: { |
523 /* dry run to see if there is any udpate at all needed */ | 523 /* dry run to see if there is any update at all needed */ |
524 int savings = 0; | 524 int savings = 0; |
525 int update[2] = {0, 0}; | 525 int update[2] = {0, 0}; |
526 for (i = 0; i < PLANE_TYPES; ++i) { | 526 for (i = 0; i < PLANE_TYPES; ++i) { |
527 for (j = 0; j < REF_TYPES; ++j) { | 527 for (j = 0; j < REF_TYPES; ++j) { |
528 for (k = 0; k < COEF_BANDS; ++k) { | 528 for (k = 0; k < COEF_BANDS; ++k) { |
529 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { | 529 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { |
530 for (t = 0; t < entropy_nodes_update; ++t) { | 530 for (t = 0; t < entropy_nodes_update; ++t) { |
531 vp9_prob newp = new_coef_probs[i][j][k][l][t]; | 531 vp9_prob newp = new_coef_probs[i][j][k][l][t]; |
532 const vp9_prob oldp = old_coef_probs[i][j][k][l][t]; | 532 const vp9_prob oldp = old_coef_probs[i][j][k][l][t]; |
533 int s; | 533 int s; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 } | 732 } |
733 | 733 |
734 static void encode_quantization(VP9_COMMON *cm, | 734 static void encode_quantization(VP9_COMMON *cm, |
735 struct vp9_write_bit_buffer *wb) { | 735 struct vp9_write_bit_buffer *wb) { |
736 vp9_wb_write_literal(wb, cm->base_qindex, QINDEX_BITS); | 736 vp9_wb_write_literal(wb, cm->base_qindex, QINDEX_BITS); |
737 write_delta_q(wb, cm->y_dc_delta_q); | 737 write_delta_q(wb, cm->y_dc_delta_q); |
738 write_delta_q(wb, cm->uv_dc_delta_q); | 738 write_delta_q(wb, cm->uv_dc_delta_q); |
739 write_delta_q(wb, cm->uv_ac_delta_q); | 739 write_delta_q(wb, cm->uv_ac_delta_q); |
740 } | 740 } |
741 | 741 |
742 | |
743 static void encode_segmentation(VP9_COMP *cpi, | 742 static void encode_segmentation(VP9_COMP *cpi, |
744 struct vp9_write_bit_buffer *wb) { | 743 struct vp9_write_bit_buffer *wb) { |
745 int i, j; | 744 int i, j; |
746 | 745 |
747 struct segmentation *seg = &cpi->common.seg; | 746 struct segmentation *seg = &cpi->common.seg; |
748 | 747 |
749 vp9_wb_write_bit(wb, seg->enabled); | 748 vp9_wb_write_bit(wb, seg->enabled); |
750 if (!seg->enabled) | 749 if (!seg->enabled) |
751 return; | 750 return; |
752 | 751 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 vp9_wb_write_bit(wb, data < 0); | 794 vp9_wb_write_bit(wb, data < 0); |
796 } else { | 795 } else { |
797 encode_unsigned_max(wb, data, data_max); | 796 encode_unsigned_max(wb, data, data_max); |
798 } | 797 } |
799 } | 798 } |
800 } | 799 } |
801 } | 800 } |
802 } | 801 } |
803 } | 802 } |
804 | 803 |
805 | |
806 static void encode_txfm_probs(VP9_COMMON *cm, vp9_writer *w) { | 804 static void encode_txfm_probs(VP9_COMMON *cm, vp9_writer *w) { |
807 // Mode | 805 // Mode |
808 vp9_write_literal(w, MIN(cm->tx_mode, ALLOW_32X32), 2); | 806 vp9_write_literal(w, MIN(cm->tx_mode, ALLOW_32X32), 2); |
809 if (cm->tx_mode >= ALLOW_32X32) | 807 if (cm->tx_mode >= ALLOW_32X32) |
810 vp9_write_bit(w, cm->tx_mode == TX_MODE_SELECT); | 808 vp9_write_bit(w, cm->tx_mode == TX_MODE_SELECT); |
811 | 809 |
812 // Probabilities | 810 // Probabilities |
813 if (cm->tx_mode == TX_MODE_SELECT) { | 811 if (cm->tx_mode == TX_MODE_SELECT) { |
814 int i, j; | 812 int i, j; |
815 unsigned int ct_8x8p[TX_SIZES - 3][2]; | 813 unsigned int ct_8x8p[TX_SIZES - 3][2]; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 if (cm->log2_tile_cols < max_log2_tile_cols) | 881 if (cm->log2_tile_cols < max_log2_tile_cols) |
884 vp9_wb_write_bit(wb, 0); | 882 vp9_wb_write_bit(wb, 0); |
885 | 883 |
886 // rows | 884 // rows |
887 vp9_wb_write_bit(wb, cm->log2_tile_rows != 0); | 885 vp9_wb_write_bit(wb, cm->log2_tile_rows != 0); |
888 if (cm->log2_tile_rows != 0) | 886 if (cm->log2_tile_rows != 0) |
889 vp9_wb_write_bit(wb, cm->log2_tile_rows != 1); | 887 vp9_wb_write_bit(wb, cm->log2_tile_rows != 1); |
890 } | 888 } |
891 | 889 |
892 static int get_refresh_mask(VP9_COMP *cpi) { | 890 static int get_refresh_mask(VP9_COMP *cpi) { |
893 if (!cpi->multi_arf_allowed && cpi->refresh_golden_frame && | 891 if (!cpi->multi_arf_allowed && cpi->refresh_golden_frame && |
894 cpi->rc.is_src_frame_alt_ref && !cpi->use_svc) { | 892 cpi->rc.is_src_frame_alt_ref && !cpi->use_svc) { |
895 // Preserve the previously existing golden frame and update the frame in | 893 // Preserve the previously existing golden frame and update the frame in |
896 // the alt ref slot instead. This is highly specific to the use of | 894 // the alt ref slot instead. This is highly specific to the use of |
897 // alt-ref as a forward reference, and this needs to be generalized as | 895 // alt-ref as a forward reference, and this needs to be generalized as |
898 // other uses are implemented (like RTC/temporal scaling) | 896 // other uses are implemented (like RTC/temporal scaling) |
899 // | 897 // |
900 // gld_fb_idx and alt_fb_idx need to be swapped for future frames, but | 898 // gld_fb_idx and alt_fb_idx need to be swapped for future frames, but |
901 // that happens in vp9_encoder.c:update_reference_frames() so that it can | 899 // that happens in vp9_encoder.c:update_reference_frames() so that it can |
902 // be done outside of the recode loop. | 900 // be done outside of the recode loop. |
903 return (cpi->refresh_last_frame << cpi->lst_fb_idx) | | 901 return (cpi->refresh_last_frame << cpi->lst_fb_idx) | |
904 (cpi->refresh_golden_frame << cpi->alt_fb_idx); | 902 (cpi->refresh_golden_frame << cpi->alt_fb_idx); |
905 } else { | 903 } else { |
906 int arf_idx = cpi->alt_fb_idx; | 904 int arf_idx = cpi->alt_fb_idx; |
907 if ((cpi->pass == 2) && cpi->multi_arf_allowed) { | 905 if ((cpi->pass == 2) && cpi->multi_arf_allowed) { |
908 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; | 906 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
909 arf_idx = gf_group->arf_update_idx[gf_group->index]; | 907 arf_idx = gf_group->arf_update_idx[gf_group->index]; |
910 } | |
911 return (cpi->refresh_last_frame << cpi->lst_fb_idx) | | |
912 (cpi->refresh_golden_frame << cpi->gld_fb_idx) | | |
913 (cpi->refresh_alt_ref_frame << arf_idx); | |
914 } | 908 } |
| 909 return (cpi->refresh_last_frame << cpi->lst_fb_idx) | |
| 910 (cpi->refresh_golden_frame << cpi->gld_fb_idx) | |
| 911 (cpi->refresh_alt_ref_frame << arf_idx); |
| 912 } |
915 } | 913 } |
916 | 914 |
917 static size_t encode_tiles(VP9_COMP *cpi, uint8_t *data_ptr) { | 915 static size_t encode_tiles(VP9_COMP *cpi, uint8_t *data_ptr) { |
918 VP9_COMMON *const cm = &cpi->common; | 916 VP9_COMMON *const cm = &cpi->common; |
919 vp9_writer residual_bc; | 917 vp9_writer residual_bc; |
920 | 918 |
921 int tile_row, tile_col; | 919 int tile_row, tile_col; |
922 TOKENEXTRA *tok[4][1 << 6], *tok_end; | 920 TOKENEXTRA *tok[4][1 << 6], *tok_end; |
923 size_t total_size = 0; | 921 size_t total_size = 0; |
924 const int tile_cols = 1 << cm->log2_tile_cols; | 922 const int tile_cols = 1 << cm->log2_tile_cols; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 if (cm->profile > PROFILE_1) { | 1059 if (cm->profile > PROFILE_1) { |
1062 assert(cm->bit_depth > BITS_8); | 1060 assert(cm->bit_depth > BITS_8); |
1063 vp9_wb_write_bit(wb, cm->bit_depth - BITS_10); | 1061 vp9_wb_write_bit(wb, cm->bit_depth - BITS_10); |
1064 } | 1062 } |
1065 vp9_wb_write_literal(wb, cs, 3); | 1063 vp9_wb_write_literal(wb, cs, 3); |
1066 if (cs != SRGB) { | 1064 if (cs != SRGB) { |
1067 vp9_wb_write_bit(wb, 0); // 0: [16, 235] (i.e. xvYCC), 1: [0, 255] | 1065 vp9_wb_write_bit(wb, 0); // 0: [16, 235] (i.e. xvYCC), 1: [0, 255] |
1068 if (cm->profile == PROFILE_1 || cm->profile == PROFILE_3) { | 1066 if (cm->profile == PROFILE_1 || cm->profile == PROFILE_3) { |
1069 vp9_wb_write_bit(wb, cm->subsampling_x); | 1067 vp9_wb_write_bit(wb, cm->subsampling_x); |
1070 vp9_wb_write_bit(wb, cm->subsampling_y); | 1068 vp9_wb_write_bit(wb, cm->subsampling_y); |
1071 vp9_wb_write_bit(wb, 0); // has extra plane | 1069 vp9_wb_write_bit(wb, 0); // unused |
1072 } | 1070 } |
1073 } else { | 1071 } else { |
1074 assert(cm->profile == PROFILE_1 || cm->profile == PROFILE_3); | 1072 assert(cm->profile == PROFILE_1 || cm->profile == PROFILE_3); |
1075 vp9_wb_write_bit(wb, 0); // has extra plane | 1073 vp9_wb_write_bit(wb, 0); // unused |
1076 } | 1074 } |
1077 | 1075 |
1078 write_frame_size(cm, wb); | 1076 write_frame_size(cm, wb); |
1079 } else { | 1077 } else { |
1080 if (!cm->show_frame) | 1078 if (!cm->show_frame) |
1081 vp9_wb_write_bit(wb, cm->intra_only); | 1079 vp9_wb_write_bit(wb, cm->intra_only); |
1082 | 1080 |
1083 if (!cm->error_resilient_mode) | 1081 if (!cm->error_resilient_mode) |
1084 vp9_wb_write_literal(wb, cm->reset_frame_context, 2); | 1082 vp9_wb_write_literal(wb, cm->reset_frame_context, 2); |
1085 | 1083 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 | 1214 |
1217 first_part_size = write_compressed_header(cpi, data); | 1215 first_part_size = write_compressed_header(cpi, data); |
1218 data += first_part_size; | 1216 data += first_part_size; |
1219 // TODO(jbb): Figure out what to do if first_part_size > 16 bits. | 1217 // TODO(jbb): Figure out what to do if first_part_size > 16 bits. |
1220 vp9_wb_write_literal(&saved_wb, (int)first_part_size, 16); | 1218 vp9_wb_write_literal(&saved_wb, (int)first_part_size, 16); |
1221 | 1219 |
1222 data += encode_tiles(cpi, data); | 1220 data += encode_tiles(cpi, data); |
1223 | 1221 |
1224 *size = data - dest; | 1222 *size = data - dest; |
1225 } | 1223 } |
1226 | |
OLD | NEW |