| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 int enumerator = frame_type == KEY_FRAME ? 4000000 : 2500000; | 64 int enumerator = frame_type == KEY_FRAME ? 4000000 : 2500000; |
| 65 | 65 |
| 66 // q based adjustment to baseline enumerator | 66 // q based adjustment to baseline enumerator |
| 67 enumerator += (int)(enumerator * q) >> 12; | 67 enumerator += (int)(enumerator * q) >> 12; |
| 68 return (int)(0.5 + (enumerator * correction_factor / q)); | 68 return (int)(0.5 + (enumerator * correction_factor / q)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void vp9_save_coding_context(VP9_COMP *cpi) { | 71 void vp9_save_coding_context(VP9_COMP *cpi) { |
| 72 CODING_CONTEXT *const cc = &cpi->coding_context; | 72 CODING_CONTEXT *const cc = &cpi->coding_context; |
| 73 VP9_COMMON *cm = &cpi->common; | 73 VP9_COMMON *cm = &cpi->common; |
| 74 MACROBLOCKD *xd = &cpi->mb.e_mbd; | |
| 75 | 74 |
| 76 // Stores a snapshot of key state variables which can subsequently be | 75 // Stores a snapshot of key state variables which can subsequently be |
| 77 // restored with a call to vp9_restore_coding_context. These functions are | 76 // restored with a call to vp9_restore_coding_context. These functions are |
| 78 // intended for use in a re-code loop in vp9_compress_frame where the | 77 // intended for use in a re-code loop in vp9_compress_frame where the |
| 79 // quantizer value is adjusted between loop iterations. | 78 // quantizer value is adjusted between loop iterations. |
| 80 | 79 |
| 81 cc->nmvc = cm->fc.nmvc; | 80 cc->nmvc = cm->fc.nmvc; |
| 82 vp9_copy(cc->nmvjointcost, cpi->mb.nmvjointcost); | 81 vp9_copy(cc->nmvjointcost, cpi->mb.nmvjointcost); |
| 83 vp9_copy(cc->nmvcosts, cpi->mb.nmvcosts); | 82 vp9_copy(cc->nmvcosts, cpi->mb.nmvcosts); |
| 84 vp9_copy(cc->nmvcosts_hp, cpi->mb.nmvcosts_hp); | 83 vp9_copy(cc->nmvcosts_hp, cpi->mb.nmvcosts_hp); |
| 85 | 84 |
| 86 vp9_copy(cc->inter_mode_probs, cm->fc.inter_mode_probs); | 85 vp9_copy(cc->inter_mode_probs, cm->fc.inter_mode_probs); |
| 87 | 86 |
| 88 vp9_copy(cc->y_mode_prob, cm->fc.y_mode_prob); | 87 vp9_copy(cc->y_mode_prob, cm->fc.y_mode_prob); |
| 89 vp9_copy(cc->uv_mode_prob, cm->fc.uv_mode_prob); | 88 vp9_copy(cc->uv_mode_prob, cm->fc.uv_mode_prob); |
| 90 vp9_copy(cc->partition_prob, cm->fc.partition_prob); | 89 vp9_copy(cc->partition_prob, cm->fc.partition_prob); |
| 91 | 90 |
| 92 vp9_copy(cc->segment_pred_probs, xd->seg.pred_probs); | 91 vp9_copy(cc->segment_pred_probs, cm->seg.pred_probs); |
| 93 | 92 |
| 94 vp9_copy(cc->intra_inter_prob, cm->fc.intra_inter_prob); | 93 vp9_copy(cc->intra_inter_prob, cm->fc.intra_inter_prob); |
| 95 vp9_copy(cc->comp_inter_prob, cm->fc.comp_inter_prob); | 94 vp9_copy(cc->comp_inter_prob, cm->fc.comp_inter_prob); |
| 96 vp9_copy(cc->single_ref_prob, cm->fc.single_ref_prob); | 95 vp9_copy(cc->single_ref_prob, cm->fc.single_ref_prob); |
| 97 vp9_copy(cc->comp_ref_prob, cm->fc.comp_ref_prob); | 96 vp9_copy(cc->comp_ref_prob, cm->fc.comp_ref_prob); |
| 98 | 97 |
| 99 vpx_memcpy(cpi->coding_context.last_frame_seg_map_copy, | 98 vpx_memcpy(cpi->coding_context.last_frame_seg_map_copy, |
| 100 cm->last_frame_seg_map, (cm->mi_rows * cm->mi_cols)); | 99 cm->last_frame_seg_map, (cm->mi_rows * cm->mi_cols)); |
| 101 | 100 |
| 102 vp9_copy(cc->last_ref_lf_deltas, xd->lf.last_ref_deltas); | 101 vp9_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas); |
| 103 vp9_copy(cc->last_mode_lf_deltas, xd->lf.last_mode_deltas); | 102 vp9_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas); |
| 104 | 103 |
| 105 vp9_copy(cc->coef_probs, cm->fc.coef_probs); | 104 vp9_copy(cc->coef_probs, cm->fc.coef_probs); |
| 106 vp9_copy(cc->switchable_interp_prob, cm->fc.switchable_interp_prob); | 105 vp9_copy(cc->switchable_interp_prob, cm->fc.switchable_interp_prob); |
| 107 cc->tx_probs = cm->fc.tx_probs; | 106 cc->tx_probs = cm->fc.tx_probs; |
| 108 vp9_copy(cc->mbskip_probs, cm->fc.mbskip_probs); | 107 vp9_copy(cc->mbskip_probs, cm->fc.mbskip_probs); |
| 109 } | 108 } |
| 110 | 109 |
| 111 void vp9_restore_coding_context(VP9_COMP *cpi) { | 110 void vp9_restore_coding_context(VP9_COMP *cpi) { |
| 112 CODING_CONTEXT *const cc = &cpi->coding_context; | 111 CODING_CONTEXT *const cc = &cpi->coding_context; |
| 113 VP9_COMMON *cm = &cpi->common; | 112 VP9_COMMON *cm = &cpi->common; |
| 114 MACROBLOCKD *xd = &cpi->mb.e_mbd; | |
| 115 | 113 |
| 116 // Restore key state variables to the snapshot state stored in the | 114 // Restore key state variables to the snapshot state stored in the |
| 117 // previous call to vp9_save_coding_context. | 115 // previous call to vp9_save_coding_context. |
| 118 | 116 |
| 119 cm->fc.nmvc = cc->nmvc; | 117 cm->fc.nmvc = cc->nmvc; |
| 120 vp9_copy(cpi->mb.nmvjointcost, cc->nmvjointcost); | 118 vp9_copy(cpi->mb.nmvjointcost, cc->nmvjointcost); |
| 121 vp9_copy(cpi->mb.nmvcosts, cc->nmvcosts); | 119 vp9_copy(cpi->mb.nmvcosts, cc->nmvcosts); |
| 122 vp9_copy(cpi->mb.nmvcosts_hp, cc->nmvcosts_hp); | 120 vp9_copy(cpi->mb.nmvcosts_hp, cc->nmvcosts_hp); |
| 123 | 121 |
| 124 vp9_copy(cm->fc.inter_mode_probs, cc->inter_mode_probs); | 122 vp9_copy(cm->fc.inter_mode_probs, cc->inter_mode_probs); |
| 125 | 123 |
| 126 vp9_copy(cm->fc.y_mode_prob, cc->y_mode_prob); | 124 vp9_copy(cm->fc.y_mode_prob, cc->y_mode_prob); |
| 127 vp9_copy(cm->fc.uv_mode_prob, cc->uv_mode_prob); | 125 vp9_copy(cm->fc.uv_mode_prob, cc->uv_mode_prob); |
| 128 vp9_copy(cm->fc.partition_prob, cc->partition_prob); | 126 vp9_copy(cm->fc.partition_prob, cc->partition_prob); |
| 129 | 127 |
| 130 vp9_copy(xd->seg.pred_probs, cc->segment_pred_probs); | 128 vp9_copy(cm->seg.pred_probs, cc->segment_pred_probs); |
| 131 | 129 |
| 132 vp9_copy(cm->fc.intra_inter_prob, cc->intra_inter_prob); | 130 vp9_copy(cm->fc.intra_inter_prob, cc->intra_inter_prob); |
| 133 vp9_copy(cm->fc.comp_inter_prob, cc->comp_inter_prob); | 131 vp9_copy(cm->fc.comp_inter_prob, cc->comp_inter_prob); |
| 134 vp9_copy(cm->fc.single_ref_prob, cc->single_ref_prob); | 132 vp9_copy(cm->fc.single_ref_prob, cc->single_ref_prob); |
| 135 vp9_copy(cm->fc.comp_ref_prob, cc->comp_ref_prob); | 133 vp9_copy(cm->fc.comp_ref_prob, cc->comp_ref_prob); |
| 136 | 134 |
| 137 vpx_memcpy(cm->last_frame_seg_map, | 135 vpx_memcpy(cm->last_frame_seg_map, |
| 138 cpi->coding_context.last_frame_seg_map_copy, | 136 cpi->coding_context.last_frame_seg_map_copy, |
| 139 (cm->mi_rows * cm->mi_cols)); | 137 (cm->mi_rows * cm->mi_cols)); |
| 140 | 138 |
| 141 vp9_copy(xd->lf.last_ref_deltas, cc->last_ref_lf_deltas); | 139 vp9_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas); |
| 142 vp9_copy(xd->lf.last_mode_deltas, cc->last_mode_lf_deltas); | 140 vp9_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas); |
| 143 | 141 |
| 144 vp9_copy(cm->fc.coef_probs, cc->coef_probs); | 142 vp9_copy(cm->fc.coef_probs, cc->coef_probs); |
| 145 vp9_copy(cm->fc.switchable_interp_prob, cc->switchable_interp_prob); | 143 vp9_copy(cm->fc.switchable_interp_prob, cc->switchable_interp_prob); |
| 146 cm->fc.tx_probs = cc->tx_probs; | 144 cm->fc.tx_probs = cc->tx_probs; |
| 147 vp9_copy(cm->fc.mbskip_probs, cc->mbskip_probs); | 145 vp9_copy(cm->fc.mbskip_probs, cc->mbskip_probs); |
| 148 } | 146 } |
| 149 | 147 |
| 150 void vp9_setup_key_frame(VP9_COMP *cpi) { | 148 void vp9_setup_key_frame(VP9_COMP *cpi) { |
| 151 VP9_COMMON *cm = &cpi->common; | 149 VP9_COMMON *cm = &cpi->common; |
| 152 MACROBLOCKD *xd = &cpi->mb.e_mbd; | |
| 153 | 150 |
| 154 vp9_setup_past_independence(cm, xd); | 151 vp9_setup_past_independence(cm); |
| 155 | 152 |
| 156 // interval before next GF | 153 // interval before next GF |
| 157 cpi->frames_till_gf_update_due = cpi->baseline_gf_interval; | 154 cpi->frames_till_gf_update_due = cpi->baseline_gf_interval; |
| 158 /* All buffers are implicitly updated on key frames. */ | 155 /* All buffers are implicitly updated on key frames. */ |
| 159 cpi->refresh_golden_frame = 1; | 156 cpi->refresh_golden_frame = 1; |
| 160 cpi->refresh_alt_ref_frame = 1; | 157 cpi->refresh_alt_ref_frame = 1; |
| 161 } | 158 } |
| 162 | 159 |
| 163 void vp9_setup_inter_frame(VP9_COMP *cpi) { | 160 void vp9_setup_inter_frame(VP9_COMP *cpi) { |
| 164 VP9_COMMON *cm = &cpi->common; | 161 VP9_COMMON *cm = &cpi->common; |
| 165 MACROBLOCKD *xd = &cpi->mb.e_mbd; | |
| 166 if (cm->error_resilient_mode || cm->intra_only) | 162 if (cm->error_resilient_mode || cm->intra_only) |
| 167 vp9_setup_past_independence(cm, xd); | 163 vp9_setup_past_independence(cm); |
| 168 | 164 |
| 169 assert(cm->frame_context_idx < NUM_FRAME_CONTEXTS); | 165 assert(cm->frame_context_idx < NUM_FRAME_CONTEXTS); |
| 170 cm->fc = cm->frame_contexts[cm->frame_context_idx]; | 166 cm->fc = cm->frame_contexts[cm->frame_context_idx]; |
| 171 } | 167 } |
| 172 | 168 |
| 173 static int estimate_bits_at_q(int frame_kind, int q, int mbs, | 169 static int estimate_bits_at_q(int frame_kind, int q, int mbs, |
| 174 double correction_factor) { | 170 double correction_factor) { |
| 175 const int bpm = (int)(vp9_bits_per_mb(frame_kind, q, correction_factor)); | 171 const int bpm = (int)(vp9_bits_per_mb(frame_kind, q, correction_factor)); |
| 176 | 172 |
| 177 // Attempt to retain reasonable accuracy without overflow. The cutoff is | 173 // Attempt to retain reasonable accuracy without overflow. The cutoff is |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 int vp9_pick_frame_size(VP9_COMP *cpi) { | 494 int vp9_pick_frame_size(VP9_COMP *cpi) { |
| 499 VP9_COMMON *cm = &cpi->common; | 495 VP9_COMMON *cm = &cpi->common; |
| 500 | 496 |
| 501 if (cm->frame_type == KEY_FRAME) | 497 if (cm->frame_type == KEY_FRAME) |
| 502 calc_iframe_target_size(cpi); | 498 calc_iframe_target_size(cpi); |
| 503 else | 499 else |
| 504 calc_pframe_target_size(cpi); | 500 calc_pframe_target_size(cpi); |
| 505 | 501 |
| 506 return 1; | 502 return 1; |
| 507 } | 503 } |
| OLD | NEW |