OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 |
11 #include <math.h> | 11 #include <math.h> |
12 | 12 |
13 #include "vp9/encoder/vp9_vaq.h" | 13 #include "vp9/encoder/vp9_vaq.h" |
14 | 14 |
15 #include "vp9/common/vp9_seg_common.h" | 15 #include "vp9/common/vp9_seg_common.h" |
16 | 16 |
17 #include "vp9/encoder/vp9_ratectrl.h" | 17 #include "vp9/encoder/vp9_ratectrl.h" |
18 #include "vp9/encoder/vp9_rdopt.h" | 18 #include "vp9/encoder/vp9_rdopt.h" |
19 #include "vp9/encoder/vp9_segmentation.h" | 19 #include "vp9/encoder/vp9_segmentation.h" |
20 #include "vp9/common/vp9_systemdependent.h" | 20 #include "vp9/common/vp9_systemdependent.h" |
21 | 21 |
22 #define ENERGY_MIN (-3) | 22 #define ENERGY_MIN (-1) |
23 #define ENERGY_MAX (3) | 23 #define ENERGY_MAX (1) |
24 #define ENERGY_SPAN (ENERGY_MAX - ENERGY_MIN + 1) | 24 #define ENERGY_SPAN (ENERGY_MAX - ENERGY_MIN + 1) |
25 #define ENERGY_IN_BOUNDS(energy)\ | 25 #define ENERGY_IN_BOUNDS(energy)\ |
26 assert((energy) >= ENERGY_MIN && (energy) <= ENERGY_MAX) | 26 assert((energy) >= ENERGY_MIN && (energy) <= ENERGY_MAX) |
27 | 27 |
28 static double q_ratio[MAX_SEGMENTS] = { 1, 1, 1, 1, 1, 1, 1, 1 }; | 28 static double q_ratio[MAX_SEGMENTS] = { 1, 1, 1, 1, 1, 1, 1, 1 }; |
29 static double rdmult_ratio[MAX_SEGMENTS] = { 1, 1, 1, 1, 1, 1, 1, 1 }; | 29 static double rdmult_ratio[MAX_SEGMENTS] = { 1, 1, 1, 1, 1, 1, 1, 1 }; |
30 static int segment_id[MAX_SEGMENTS] = { 5, 3, 1, 0, 2, 4, 6, 7 }; | 30 static int segment_id[MAX_SEGMENTS] = { 5, 3, 1, 0, 2, 4, 6, 7 }; |
31 | 31 |
32 #define Q_RATIO(i) q_ratio[(i) - ENERGY_MIN] | 32 #define Q_RATIO(i) q_ratio[(i) - ENERGY_MIN] |
33 #define RDMULT_RATIO(i) rdmult_ratio[(i) - ENERGY_MIN] | 33 #define RDMULT_RATIO(i) rdmult_ratio[(i) - ENERGY_MIN] |
(...skipping 24 matching lines...) Expand all Loading... |
58 } | 58 } |
59 | 59 |
60 void vp9_vaq_init() { | 60 void vp9_vaq_init() { |
61 int i; | 61 int i; |
62 double base_ratio; | 62 double base_ratio; |
63 | 63 |
64 assert(ENERGY_SPAN <= MAX_SEGMENTS); | 64 assert(ENERGY_SPAN <= MAX_SEGMENTS); |
65 | 65 |
66 vp9_clear_system_state(); // __asm emms; | 66 vp9_clear_system_state(); // __asm emms; |
67 | 67 |
68 base_ratio = 1.8; | 68 base_ratio = 1.5; |
69 | 69 |
70 for (i = ENERGY_MIN; i <= ENERGY_MAX; i++) { | 70 for (i = ENERGY_MIN; i <= ENERGY_MAX; i++) { |
71 Q_RATIO(i) = pow(base_ratio, i/3.0); | 71 Q_RATIO(i) = pow(base_ratio, i/3.0); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 void vp9_vaq_frame_setup(VP9_COMP *cpi) { | 75 void vp9_vaq_frame_setup(VP9_COMP *cpi) { |
76 VP9_COMMON *cm = &cpi->common; | 76 VP9_COMMON *cm = &cpi->common; |
77 struct segmentation *seg = &cm->seg; | 77 struct segmentation *seg = &cm->seg; |
78 int base_q = vp9_convert_qindex_to_q(cm->base_qindex); | 78 int base_q = vp9_convert_qindex_to_q(cm->base_qindex); |
79 int base_rdmult = vp9_compute_rd_mult(cpi, cm->base_qindex + | 79 int base_rdmult = vp9_compute_rd_mult(cpi, cm->base_qindex + |
80 cm->y_dc_delta_q); | 80 cm->y_dc_delta_q); |
81 int i; | 81 int i; |
82 | 82 |
83 vp9_enable_segmentation((VP9_PTR)cpi); | 83 if (cm->frame_type == KEY_FRAME || |
84 vp9_clearall_segfeatures(seg); | 84 cpi->refresh_alt_ref_frame || |
| 85 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) { |
| 86 vp9_enable_segmentation((VP9_PTR)cpi); |
| 87 vp9_clearall_segfeatures(seg); |
85 | 88 |
86 seg->abs_delta = SEGMENT_DELTADATA; | 89 seg->abs_delta = SEGMENT_DELTADATA; |
87 | 90 |
88 vp9_clear_system_state(); // __asm emms; | 91 vp9_clear_system_state(); // __asm emms; |
89 | 92 |
90 for (i = ENERGY_MIN; i <= ENERGY_MAX; i++) { | 93 for (i = ENERGY_MIN; i <= ENERGY_MAX; i++) { |
91 int qindex_delta, segment_rdmult; | 94 int qindex_delta, segment_rdmult; |
92 | 95 |
93 if (Q_RATIO(i) == 1) { | 96 if (Q_RATIO(i) == 1) { |
94 // No need to enable SEG_LVL_ALT_Q for this segment | 97 // No need to enable SEG_LVL_ALT_Q for this segment |
95 RDMULT_RATIO(i) = 1; | 98 RDMULT_RATIO(i) = 1; |
96 continue; | 99 continue; |
| 100 } |
| 101 |
| 102 qindex_delta = vp9_compute_qdelta(cpi, base_q, base_q * Q_RATIO(i)); |
| 103 vp9_set_segdata(seg, SEGMENT_ID(i), SEG_LVL_ALT_Q, qindex_delta); |
| 104 vp9_enable_segfeature(seg, SEGMENT_ID(i), SEG_LVL_ALT_Q); |
| 105 |
| 106 segment_rdmult = vp9_compute_rd_mult(cpi, cm->base_qindex + qindex_delta + |
| 107 cm->y_dc_delta_q); |
| 108 |
| 109 RDMULT_RATIO(i) = (double) segment_rdmult / base_rdmult; |
97 } | 110 } |
98 | |
99 qindex_delta = vp9_compute_qdelta(cpi, base_q, base_q * Q_RATIO(i)); | |
100 vp9_set_segdata(seg, SEGMENT_ID(i), SEG_LVL_ALT_Q, qindex_delta); | |
101 vp9_enable_segfeature(seg, SEGMENT_ID(i), SEG_LVL_ALT_Q); | |
102 | |
103 segment_rdmult = vp9_compute_rd_mult(cpi, cm->base_qindex + qindex_delta + | |
104 cm->y_dc_delta_q); | |
105 | |
106 RDMULT_RATIO(i) = (double) segment_rdmult / base_rdmult; | |
107 } | 111 } |
108 } | 112 } |
109 | 113 |
110 | 114 |
111 static unsigned int block_variance(VP9_COMP *cpi, MACROBLOCK *x, | 115 static unsigned int block_variance(VP9_COMP *cpi, MACROBLOCK *x, |
112 BLOCK_SIZE bs) { | 116 BLOCK_SIZE bs) { |
113 MACROBLOCKD *xd = &x->e_mbd; | 117 MACROBLOCKD *xd = &x->e_mbd; |
114 unsigned int var, sse; | 118 unsigned int var, sse; |
115 int right_overflow = (xd->mb_to_right_edge < 0) ? | 119 int right_overflow = (xd->mb_to_right_edge < 0) ? |
116 ((-xd->mb_to_right_edge) >> 3) : 0; | 120 ((-xd->mb_to_right_edge) >> 3) : 0; |
(...skipping 21 matching lines...) Expand all Loading... |
138 unsigned int var = block_variance(cpi, x, bs); | 142 unsigned int var = block_variance(cpi, x, bs); |
139 | 143 |
140 vp9_clear_system_state(); // __asm emms; | 144 vp9_clear_system_state(); // __asm emms; |
141 | 145 |
142 // if (var <= 1000) | 146 // if (var <= 1000) |
143 // return 0; | 147 // return 0; |
144 | 148 |
145 energy = 0.9*(logf(var + 1) - 10.0); | 149 energy = 0.9*(logf(var + 1) - 10.0); |
146 return clamp(round(energy), ENERGY_MIN, ENERGY_MAX); | 150 return clamp(round(energy), ENERGY_MIN, ENERGY_MAX); |
147 } | 151 } |
OLD | NEW |