Extended quantizer range for high bitdepth

These changes allow 10 and 12 bit depth streams
to encode at higher quality by using a finer
quantizer.  Category 6 tokens now transmit 18
extra bits instead of 14 in order to be able to
encode the greater range of output coefficients.

The extended quantizer range is only used when
configured with the following options:
--enable-vp9-high
--enable-high-transforms
--enable-high-quant

Change-Id: I58d2981676d67b65cc022e98cf443603d38ba6ff
This commit is contained in:
Peter de Rivaz
2014-06-16 14:52:37 +01:00
parent 20e745e8e4
commit 8ca39ede47
33 changed files with 1060 additions and 235 deletions

1
configure vendored
View File

@@ -271,6 +271,7 @@ EXPERIMENT_LIST="
multiple_arf
spatial_svc
high_transforms
high_quant
"
CONFIG_LIST="
external_build

View File

@@ -55,8 +55,12 @@ typedef struct {
// indexed by token value
extern const vp9_extra_bit vp9_extra_bits[ENTROPY_TOKENS];
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
extern const vp9_extra_bit vp9_extra_bits_high[ENTROPY_TOKENS];
#endif
#define DCT_MAX_VALUE 16384
#define DCT_MAX_VALUE_HIGH 262144
/* Coefficients are predicted via a 3-dimensional probability table. */

View File

@@ -25,7 +25,7 @@ static INLINE tran_low_t clamp_high(tran_high_t value, tran_low_t low,
static INLINE tran_low_t clip_pixel_bps_high(tran_high_t dest,
tran_high_t trans, int bps) {
#if CONFIG_HIGH_TRANSFORMS
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
switch (bps) {
default:
return clamp_high(dest + trans, 0, 255);

View File

@@ -33,7 +33,7 @@ extern "C" {
#define pair_set_epi16(a, b) \
_mm_set_epi16(b, a, b, a, b, a, b, a)
#if CONFIG_HIGH_TRANSFORMS
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
typedef int64_t tran_high_t;
typedef int32_t tran_low_t;
#else

View File

@@ -66,10 +66,10 @@ typedef struct {
typedef struct VP9Common {
struct vpx_internal_error_info error;
DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE_MAX][8]);
DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE_MAX][8]);
#if CONFIG_ALPHA
DECLARE_ALIGNED(16, int16_t, a_dequant[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, a_dequant[QINDEX_RANGE_MAX][8]);
#endif
COLOR_SPACE color_space;

View File

@@ -48,6 +48,105 @@ static const int16_t dc_qlookup[QINDEX_RANGE] = {
1022, 1058, 1098, 1139, 1184, 1232, 1282, 1336,
};
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
static const int16_t dc_qlookup_10[QINDEX_RANGE_10] = {
4, 8, 8, 9, 10, 11, 12, 13,
13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 22, 23, 24, 25, 26, 27,
28, 29, 30, 30, 31, 32, 33, 34,
35, 36, 37, 38, 38, 39, 40, 41,
42, 43, 44, 45, 45, 46, 47, 48,
49, 50, 51, 52, 53, 53, 54, 55,
56, 57, 58, 59, 60, 60, 61, 62,
63, 64, 65, 66, 67, 67, 68, 69,
70, 71, 72, 73, 74, 74, 75, 76,
77, 78, 79, 80, 81, 81, 82, 83,
84, 85, 86, 87, 88, 88, 89, 90,
92, 94, 95, 97, 99, 101, 102, 104,
106, 107, 109, 111, 113, 114, 116, 118,
119, 121, 123, 125, 126, 128, 130, 131,
133, 136, 138, 141, 143, 146, 148, 151,
153, 156, 159, 161, 164, 166, 169, 171,
174, 176, 180, 183, 186, 190, 193, 196,
199, 203, 206, 209, 213, 216, 219, 223,
227, 232, 236, 240, 244, 248, 252, 256,
260, 265, 270, 274, 279, 284, 289, 294,
298, 303, 309, 314, 320, 325, 331, 336,
341, 348, 354, 360, 366, 372, 378, 385,
392, 399, 406, 413, 419, 427, 434, 442,
449, 456, 464, 473, 481, 489, 496, 505,
514, 522, 531, 540, 549, 558, 567, 577,
587, 596, 606, 616, 626, 637, 647, 658,
669, 680, 691, 702, 714, 725, 737, 749,
761, 773, 785, 798, 811, 824, 836, 850,
863, 877, 890, 904, 918, 933, 947, 962,
976, 992, 1007, 1022, 1037, 1053, 1069, 1085,
1101, 1117, 1133, 1150, 1167, 1184, 1201, 1219,
1236, 1254, 1272, 1291, 1309, 1328, 1347, 1366,
1385, 1405, 1425, 1445, 1465, 1486, 1507, 1528,
1550, 1572, 1595, 1618, 1641, 1664, 1689, 1713,
1738, 1764, 1790, 1816, 1844, 1872, 1901, 1930,
1961, 1992, 2025, 2058, 2093, 2129, 2166, 2205,
2245, 2287, 2330, 2376, 2423, 2473, 2526, 2580,
2638, 2699, 2763, 2830, 2902, 2976, 3055, 3139,
3228, 3322, 3423, 3529, 3641, 3761, 3889, 4024,
4169, 4323, 4488, 4663, 4850, 5049, 5262, 5489,
};
static const int16_t dc_qlookup_12[QINDEX_RANGE_12] = {
4, 8, 8, 9, 10, 11, 12, 13,
13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 40, 41,
42, 43, 44, 45, 46, 47, 48, 48,
49, 50, 51, 52, 53, 54, 55, 56,
57, 57, 58, 59, 60, 61, 62, 63,
64, 65, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 74, 75, 76, 77,
78, 79, 80, 81, 82, 82, 83, 84,
85, 86, 87, 88, 89, 90, 90, 91,
93, 95, 97, 99, 100, 102, 104, 106,
107, 109, 111, 113, 115, 116, 118, 120,
122, 123, 125, 127, 129, 131, 132, 134,
136, 139, 141, 144, 147, 149, 152, 154,
157, 160, 162, 165, 168, 170, 173, 176,
178, 181, 185, 188, 192, 195, 199, 202,
206, 209, 213, 216, 220, 223, 227, 231,
236, 240, 244, 249, 253, 258, 262, 266,
271, 276, 281, 287, 292, 297, 302, 307,
313, 318, 324, 330, 336, 342, 348, 354,
361, 367, 374, 381, 388, 395, 402, 410,
418, 425, 433, 441, 449, 457, 466, 474,
483, 491, 501, 510, 520, 529, 538, 549,
559, 569, 579, 590, 601, 612, 623, 635,
647, 659, 670, 683, 695, 708, 721, 735,
748, 762, 776, 790, 805, 820, 835, 851,
866, 882, 898, 915, 932, 949, 966, 984,
1002, 1020, 1039, 1058, 1078, 1098, 1118, 1138,
1159, 1180, 1202, 1224, 1246, 1269, 1292, 1315,
1339, 1363, 1388, 1412, 1438, 1464, 1490, 1517,
1544, 1572, 1600, 1628, 1658, 1687, 1717, 1747,
1778, 1809, 1841, 1873, 1906, 1940, 1974, 2008,
2043, 2079, 2115, 2152, 2190, 2228, 2266, 2305,
2344, 2384, 2425, 2466, 2508, 2550, 2593, 2637,
2681, 2726, 2771, 2817, 2864, 2911, 2959, 3007,
3057, 3106, 3157, 3208, 3260, 3312, 3366, 3419,
3474, 3529, 3585, 3641, 3699, 3756, 3815, 3874,
3934, 3995, 4056, 4118, 4181, 4244, 4308, 4373,
4439, 4505, 4572, 4640, 4709, 4778, 4848, 4919,
4991, 5064, 5137, 5212, 5287, 5363, 5440, 5518,
5597, 5677, 5758, 5840, 5923, 6008, 6093, 6180,
6268, 6358, 6449, 6542, 6636, 6732, 6831, 6931,
7033, 7138, 7245, 7355, 7467, 7583, 7702, 7824,
7949, 8079, 8213, 8352, 8496, 8645, 8800, 8960,
9128, 9303, 9485, 9675, 9875, 10083, 10303, 10533,
10775, 11030, 11299, 11583, 11883, 12200, 12536, 12891,
13269, 13668, 14093, 14545, 15024, 15535, 16078, 16657,
17273, 17930, 18632, 19380, 20179, 21032, 21943,
};
#endif
static const int16_t ac_qlookup[QINDEX_RANGE] = {
4, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22,
@@ -83,6 +182,105 @@ static const int16_t ac_qlookup[QINDEX_RANGE] = {
1597, 1628, 1660, 1692, 1725, 1759, 1793, 1828,
};
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
static const int16_t ac_qlookup_10[QINDEX_RANGE_10] = {
4, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62,
63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 76, 77, 78,
79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102,
104, 106, 108, 110, 112, 114, 116, 118,
120, 122, 124, 126, 128, 130, 132, 134,
136, 138, 140, 142, 144, 146, 148, 150,
152, 155, 158, 161, 164, 167, 170, 173,
176, 179, 182, 185, 188, 191, 194, 197,
200, 203, 207, 211, 215, 219, 223, 227,
231, 235, 239, 243, 247, 251, 255, 260,
265, 270, 275, 280, 285, 290, 295, 300,
305, 311, 317, 323, 329, 335, 341, 347,
353, 359, 366, 373, 380, 387, 394, 401,
408, 416, 424, 432, 440, 448, 456, 465,
474, 483, 492, 501, 510, 520, 530, 540,
550, 560, 571, 582, 593, 604, 615, 627,
639, 651, 663, 676, 689, 702, 715, 729,
743, 757, 771, 786, 801, 816, 832, 848,
864, 881, 898, 915, 933, 951, 969, 988,
1007, 1026, 1046, 1066, 1087, 1108, 1129, 1151,
1173, 1196, 1219, 1243, 1267, 1292, 1317, 1343,
1369, 1396, 1423, 1451, 1479, 1508, 1537, 1567,
1597, 1628, 1660, 1692, 1725, 1759, 1793, 1828,
1864, 1900, 1937, 1975, 2014, 2053, 2093, 2134,
2176, 2218, 2261, 2305, 2350, 2396, 2443, 2491,
2540, 2590, 2641, 2693, 2746, 2800, 2855, 2911,
2968, 3026, 3085, 3145, 3207, 3270, 3334, 3399,
3466, 3534, 3603, 3674, 3746, 3819, 3894, 3970,
4048, 4127, 4208, 4291, 4375, 4461, 4549, 4638,
4729, 4822, 4917, 5014, 5113, 5213, 5315, 5419,
5526, 5635, 5746, 5859, 5974, 6091, 6211, 6333,
6458, 6585, 6715, 6847, 6982, 7119, 7259, 7402,
};
static const int16_t ac_qlookup_12[QINDEX_RANGE_12] = {
4, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62,
63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 76, 77, 78,
79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102,
104, 106, 108, 110, 112, 114, 116, 118,
120, 122, 124, 126, 128, 130, 132, 134,
136, 138, 140, 142, 144, 146, 148, 150,
152, 155, 158, 161, 164, 167, 170, 173,
176, 179, 182, 185, 188, 191, 194, 197,
200, 203, 207, 211, 215, 219, 223, 227,
231, 235, 239, 243, 247, 251, 255, 260,
265, 270, 275, 280, 285, 290, 295, 300,
305, 311, 317, 323, 329, 335, 341, 347,
353, 359, 366, 373, 380, 387, 394, 401,
408, 416, 424, 432, 440, 448, 456, 465,
474, 483, 492, 501, 510, 520, 530, 540,
550, 560, 571, 582, 593, 604, 615, 627,
639, 651, 663, 676, 689, 702, 715, 729,
743, 757, 771, 786, 801, 816, 832, 848,
864, 881, 898, 915, 933, 951, 969, 988,
1007, 1026, 1046, 1066, 1087, 1108, 1129, 1151,
1173, 1196, 1219, 1243, 1267, 1292, 1317, 1343,
1369, 1396, 1423, 1451, 1479, 1508, 1537, 1567,
1597, 1628, 1660, 1692, 1725, 1759, 1793, 1828,
1864, 1900, 1937, 1975, 2014, 2053, 2093, 2134,
2176, 2218, 2261, 2305, 2350, 2396, 2443, 2491,
2540, 2590, 2641, 2693, 2746, 2800, 2855, 2911,
2968, 3026, 3085, 3145, 3207, 3270, 3334, 3399,
3466, 3534, 3603, 3674, 3746, 3819, 3894, 3970,
4048, 4127, 4208, 4291, 4375, 4461, 4549, 4638,
4729, 4822, 4917, 5014, 5113, 5213, 5315, 5419,
5526, 5635, 5746, 5859, 5974, 6091, 6211, 6333,
6458, 6585, 6715, 6847, 6982, 7119, 7259, 7402,
7548, 7697, 7849, 8004, 8162, 8323, 8487, 8654,
8824, 8998, 9175, 9356, 9540, 9728, 9920, 10115,
10314, 10517, 10724, 10935, 11150, 11370, 11594, 11822,
12055, 12293, 12535, 12782, 13034, 13291, 13553, 13820,
14092, 14370, 14653, 14942, 15237, 15537, 15843, 16155,
16474, 16799, 17130, 17468, 17812, 18163, 18521, 18886,
19258, 19638, 20025, 20420, 20823, 21234, 21653, 22080,
22516, 22960, 23413, 23875, 24346, 24826, 25316, 25815,
26324, 26843, 27373, 27913, 28464, 29026, 29599,
};
#endif
void vp9_init_quant_tables(void) { }
#else
static int16_t dc_qlookup[QINDEX_RANGE];
@@ -122,15 +320,27 @@ void vp9_init_quant_tables() {
#endif
int16_t vp9_dc_quant(int qindex, int delta, vpx_bit_depth_t bit_depth) {
#if CONFIG_HIGH_TRANSFORMS
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
switch (bit_depth) {
case VPX_BITS_8:
return dc_qlookup[clamp(qindex + delta, 0, MAXQ)];
case VPX_BITS_10:
return dc_qlookup_10[clamp(qindex + delta, 0, MAXQ_10)];
case VPX_BITS_12:
return dc_qlookup_12[clamp(qindex + delta, 0, MAXQ_12)];
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#elif CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
switch (bit_depth) {
case VPX_BITS_8:
return dc_qlookup[clamp(qindex + delta, 0, MAXQ)];
case VPX_BITS_10:
return dc_qlookup[clamp(qindex + delta, 0, MAXQ)] << 2;
case VPX_BITS_12:
return dc_qlookup[clamp(qindex + delta, 0, MAXQ)] << 4;
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#else
(void) bit_depth;
@@ -139,15 +349,27 @@ int16_t vp9_dc_quant(int qindex, int delta, vpx_bit_depth_t bit_depth) {
}
int16_t vp9_ac_quant(int qindex, int delta, vpx_bit_depth_t bit_depth) {
#if CONFIG_HIGH_TRANSFORMS
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
switch (bit_depth) {
case VPX_BITS_8:
return ac_qlookup[clamp(qindex + delta, 0, MAXQ)];
case VPX_BITS_10:
return ac_qlookup_10[clamp(qindex + delta, 0, MAXQ_10)];
case VPX_BITS_12:
return ac_qlookup_12[clamp(qindex + delta, 0, MAXQ_12)];
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#elif CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
switch (bit_depth) {
case VPX_BITS_8:
return ac_qlookup[clamp(qindex + delta, 0, MAXQ)];
case VPX_BITS_10:
return ac_qlookup[clamp(qindex + delta, 0, MAXQ)] << 2;
case VPX_BITS_12:
return ac_qlookup[clamp(qindex + delta, 0, MAXQ)] << 4;
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#else
(void) bit_depth;
@@ -155,16 +377,69 @@ int16_t vp9_ac_quant(int qindex, int delta, vpx_bit_depth_t bit_depth) {
#endif
}
int vp9_get_qindex(const struct segmentation *seg, int segment_id,
int base_qindex) {
int base_qindex, vpx_bit_depth_t bit_depth) {
if (vp9_segfeature_active(seg, segment_id, SEG_LVL_ALT_Q)) {
const int data = vp9_get_segdata(seg, segment_id, SEG_LVL_ALT_Q);
const int seg_qindex = seg->abs_delta == SEGMENT_ABSDATA ?
data : base_qindex + data;
return clamp(seg_qindex, 0, MAXQ);
return clamp(seg_qindex, 0, vp9_get_maxq(bit_depth));
} else {
return base_qindex;
}
}
int vp9_get_maxq(vpx_bit_depth_t bit_depth) {
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
switch (bit_depth) {
case VPX_BITS_8:
return MAXQ;
case VPX_BITS_10:
return MAXQ_10;
case VPX_BITS_12:
return MAXQ_12;
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#else
(void) bit_depth;
return MAXQ;
#endif
}
int vp9_get_qindex_range(vpx_bit_depth_t bit_depth) {
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
switch (bit_depth) {
case VPX_BITS_8:
return QINDEX_RANGE;
case VPX_BITS_10:
return QINDEX_RANGE_10;
case VPX_BITS_12:
return QINDEX_RANGE_12;
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#else
(void) bit_depth;
return QINDEX_RANGE;
#endif
}
int vp9_get_qindex_bits(vpx_bit_depth_t bit_depth) {
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
switch (bit_depth) {
case VPX_BITS_8:
return QINDEX_BITS;
case VPX_BITS_10:
return QINDEX_BITS_10;
case VPX_BITS_12:
return QINDEX_BITS_12;
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#else
(void) bit_depth;
return QINDEX_BITS;
#endif
}

View File

@@ -20,8 +20,20 @@ extern "C" {
#define MINQ 0
#define MAXQ 255
#define MAXQ_10 327
#define MAXQ_12 398
#define QINDEX_RANGE (MAXQ - MINQ + 1)
#define QINDEX_RANGE_10 (MAXQ_10 - MINQ + 1)
#define QINDEX_RANGE_12 (MAXQ_12 - MINQ + 1)
#define QINDEX_BITS 8
#define QINDEX_BITS_10 9
#define QINDEX_BITS_12 9
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
#define QINDEX_RANGE_MAX QINDEX_RANGE_12
#else
#define QINDEX_RANGE_MAX QINDEX_RANGE
#endif
void vp9_init_quant_tables();
@@ -29,7 +41,13 @@ int16_t vp9_dc_quant(int qindex, int delta, vpx_bit_depth_t bit_depth);
int16_t vp9_ac_quant(int qindex, int delta, vpx_bit_depth_t bit_depth);
int vp9_get_qindex(const struct segmentation *seg, int segment_id,
int base_qindex);
int base_qindex, vpx_bit_depth_t bit_depth);
int vp9_get_maxq(vpx_bit_depth_t bit_depth);
int vp9_get_qindex_range(vpx_bit_depth_t bit_depth);
int vp9_get_qindex_bits(vpx_bit_depth_t bit_depth);
#ifdef __cplusplus
} // extern "C"

View File

@@ -332,7 +332,7 @@ $vp9_convolve8_avg_vert_neon_asm=vp9_convolve8_avg_vert_neon;
#
# dct
#
if (vpx_config("CONFIG_HIGH_TRANSFORMS") eq "yes") {
if (vpx_config("CONFIG_VP9_HIGH") eq "yes" && vpx_config("CONFIG_HIGH_TRANSFORMS") eq "yes") {
add_proto qw/void vp9_idct4x4_1_add/, "const tran_low_t *input, uint8_t *dest, int dest_stride";
specialize qw/vp9_idct4x4_1_add/;
@@ -1060,7 +1060,7 @@ specialize qw/vp9_get_mb_ss mmx sse2/;
add_proto qw/void vp9_subtract_block/, "int rows, int cols, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride";
specialize qw/vp9_subtract_block/, "$sse2_x86inc";
if (vpx_config("CONFIG_HIGH_TRANSFORMS") eq "yes") {
if (vpx_config("CONFIG_VP9_HIGH") eq "yes" && vpx_config("CONFIG_HIGH_TRANSFORMS") eq "yes") {
add_proto qw/int64_t vp9_block_error/, "const tran_low_t *coeff, const tran_low_t *dqcoeff, intptr_t block_size, int64_t *ssz";
specialize qw/vp9_block_error avx2/;
@@ -1092,7 +1092,7 @@ if (vpx_config("CONFIG_INTERNAL_STATS") eq "yes") {
}
# fdct functions
if (vpx_config("CONFIG_HIGH_TRANSFORMS") eq "yes") {
if (vpx_config("CONFIG_VP9_HIGH") eq "yes" && vpx_config("CONFIG_HIGH_TRANSFORMS") eq "yes") {
add_proto qw/void vp9_fht4x4/, "const int16_t *input, tran_low_t *output, int stride, int tx_type";
specialize qw/vp9_fht4x4/;

View File

@@ -15,11 +15,20 @@
#include "vp9/common/vp9_seg_common.h"
#include "vp9/common/vp9_quant_common.h"
static const int seg_feature_data_signed[SEG_LVL_MAX] = { 1, 1, 0, 0 };
static const int seg_feature_data_max[SEG_LVL_MAX] = {
MAXQ, MAX_LOOP_FILTER, 3, 0 };
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
static const int seg_feature_data_max_10[SEG_LVL_MAX] = {
MAXQ_10, MAX_LOOP_FILTER, 3, 0 };
static const int seg_feature_data_max_12[SEG_LVL_MAX] = {
MAXQ_12, MAX_LOOP_FILTER, 3, 0 };
#endif
// These functions provide access to new segment level features.
// Eventually these function may be "optimized out" but for the moment,
// the coding mechanism is still subject to change so these provide a
@@ -41,8 +50,23 @@ void vp9_enable_segfeature(struct segmentation *seg, int segment_id,
seg->feature_mask[segment_id] |= 1 << feature_id;
}
int vp9_seg_feature_data_max(SEG_LVL_FEATURES feature_id) {
int vp9_seg_feature_data_max(SEG_LVL_FEATURES feature_id,
vpx_bit_depth_t bit_depth) {
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
switch (bit_depth) {
case VPX_BITS_8:
return seg_feature_data_max[feature_id];
case VPX_BITS_10:
return seg_feature_data_max_10[feature_id];
case VPX_BITS_12:
return seg_feature_data_max_12[feature_id];
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#else
(void) bit_depth;
return seg_feature_data_max[feature_id];
#endif
}
int vp9_is_segfeature_signed(SEG_LVL_FEATURES feature_id) {
@@ -50,11 +74,13 @@ int vp9_is_segfeature_signed(SEG_LVL_FEATURES feature_id) {
}
void vp9_set_segdata(struct segmentation *seg, int segment_id,
SEG_LVL_FEATURES feature_id, int seg_data) {
assert(seg_data <= seg_feature_data_max[feature_id]);
SEG_LVL_FEATURES feature_id, int seg_data,
vpx_bit_depth_t bit_depth) {
const int data_max = vp9_seg_feature_data_max(feature_id, bit_depth);
assert(seg_data <= data_max);
if (seg_data < 0) {
assert(seg_feature_data_signed[feature_id]);
assert(-seg_data <= seg_feature_data_max[feature_id]);
assert(-seg_data <= data_max);
}
seg->feature_data[segment_id][feature_id] = seg_data;

View File

@@ -11,6 +11,8 @@
#ifndef VP9_COMMON_VP9_SEG_COMMON_H_
#define VP9_COMMON_VP9_SEG_COMMON_H_
#include "vpx/vpx_codec.h"
#include "vp9/common/vp9_prob.h"
#ifdef __cplusplus
@@ -59,14 +61,16 @@ void vp9_enable_segfeature(struct segmentation *seg,
int segment_id,
SEG_LVL_FEATURES feature_id);
int vp9_seg_feature_data_max(SEG_LVL_FEATURES feature_id);
int vp9_seg_feature_data_max(SEG_LVL_FEATURES feature_id,
vpx_bit_depth_t bit_depth);
int vp9_is_segfeature_signed(SEG_LVL_FEATURES feature_id);
void vp9_set_segdata(struct segmentation *seg,
int segment_id,
SEG_LVL_FEATURES feature_id,
int seg_data);
int seg_data,
vpx_bit_depth_t bit_depth);
int vp9_get_segdata(const struct segmentation *seg,
int segment_id,

View File

@@ -400,7 +400,8 @@ static void decode_block(VP9_COMMON *const cm, MACROBLOCKD *const xd,
} else {
if (cm->seg.enabled)
setup_plane_dequants(cm, xd, vp9_get_qindex(&cm->seg, mbmi->segment_id,
cm->base_qindex));
cm->base_qindex,
cm->bit_depth));
}
if (!is_inter_block(mbmi)) {
@@ -541,7 +542,8 @@ static void read_coef_probs(FRAME_CONTEXT *fc, TX_MODE tx_mode,
}
static void setup_segmentation(struct segmentation *seg,
struct vp9_read_bit_buffer *rb) {
struct vp9_read_bit_buffer *rb,
vpx_bit_depth_t bit_depth) {
int i, j;
seg->update_map = 0;
@@ -582,11 +584,12 @@ static void setup_segmentation(struct segmentation *seg,
const int feature_enabled = vp9_rb_read_bit(rb);
if (feature_enabled) {
vp9_enable_segfeature(seg, i, j);
data = decode_unsigned_max(rb, vp9_seg_feature_data_max(j));
data = decode_unsigned_max(rb, vp9_seg_feature_data_max(j,
bit_depth));
if (vp9_is_segfeature_signed(j))
data = vp9_rb_read_bit(rb) ? -data : data;
}
vp9_set_segdata(seg, i, j, data);
vp9_set_segdata(seg, i, j, data, bit_depth);
}
}
}
@@ -628,7 +631,7 @@ static void setup_quantization(VP9_COMMON *const cm, MACROBLOCKD *const xd,
struct vp9_read_bit_buffer *rb) {
int update = 0;
cm->base_qindex = vp9_rb_read_literal(rb, QINDEX_BITS);
cm->base_qindex = vp9_rb_read_literal(rb, vp9_get_qindex_bits(cm->bit_depth));
update |= read_delta_q(rb, &cm->y_dc_delta_q);
update |= read_delta_q(rb, &cm->uv_dc_delta_q);
update |= read_delta_q(rb, &cm->uv_ac_delta_q);
@@ -1265,7 +1268,7 @@ static size_t read_uncompressed_header(VP9Decoder *pbi,
setup_loopfilter(&cm->lf, rb);
setup_quantization(cm, &pbi->mb, rb);
setup_segmentation(&cm->seg, rb);
setup_segmentation(&cm->seg, rb, cm->bit_depth);
setup_tile_info(cm, rb);
sz = vp9_rb_read_literal(rb, 16);
@@ -1331,8 +1334,9 @@ static int read_compressed_header(VP9Decoder *pbi, const uint8_t *data,
void vp9_init_dequantizer(VP9_COMMON *cm) {
int q;
int range = vp9_get_qindex_range(cm->bit_depth);
for (q = 0; q < QINDEX_RANGE; q++) {
for (q = 0; q < range; q++) {
cm->y_dequant[q][0] = vp9_dc_quant(q, cm->y_dc_delta_q, cm->bit_depth);
cm->y_dequant[q][1] = vp9_ac_quant(q, 0, cm->bit_depth);

View File

@@ -8,6 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "./vpx_config.h"
#include "vpx_mem/vpx_mem.h"
#include "vpx_ports/mem.h"
@@ -58,6 +60,13 @@ static const vp9_prob cat6_prob[15] = {
254, 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129, 0
};
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
static const vp9_prob cat6_prob_high[19] = {
254, 254, 254, 254, 254, 254, 254, 252, 249,
243, 230, 196, 177, 153, 140, 133, 130, 129, 0
};
#endif
#define INCREMENT_COUNT(token) \
do { \
if (!cm->frame_parallel_decoding_mode) \
@@ -98,11 +107,21 @@ static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd, PLANE_TYPE type,
counts->eob_branch[tx_size][type][ref];
uint8_t token_cache[32 * 32];
const uint8_t *cat6;
const uint8_t *cat6_ptr;
const uint8_t *band_translate = get_band_translate(tx_size);
const int dq_shift = (tx_size == TX_32X32);
int v;
int16_t dqv = dq[0];
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
if (cm->use_high)
cat6_ptr = cat6_prob_high;
else
cat6_ptr = cat6_prob;
#else
cat6_ptr = cat6_prob;
#endif
while (c < max_eob) {
int val;
band = *band_translate++;
@@ -184,7 +203,8 @@ static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd, PLANE_TYPE type,
WRITE_COEF_CONTINUE(val, CATEGORY5_TOKEN);
}
val = 0;
cat6 = cat6_prob;
cat6 = cat6_ptr;
while (*cat6)
val = (val << 1) | vp9_read(r, *cat6++);
val += CAT6_MIN_VAL;

View File

@@ -49,9 +49,10 @@ void vp9_setup_in_frame_q_adj(VP9_COMP *cpi) {
for (segment = 1; segment < 2; segment++) {
const int qindex_delta =
vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type, cm->base_qindex,
in_frame_q_adj_ratio[segment]);
in_frame_q_adj_ratio[segment],
cm->bit_depth);
vp9_enable_segfeature(seg, segment, SEG_LVL_ALT_Q);
vp9_set_segdata(seg, segment, SEG_LVL_ALT_Q, qindex_delta);
vp9_set_segdata(seg, segment, SEG_LVL_ALT_Q, qindex_delta, cm->bit_depth);
}
}
}

View File

@@ -201,7 +201,7 @@ void vp9_cyclic_refresh_setup(VP9_COMP *const cpi) {
// Rate target ratio to set q delta.
const float rate_ratio_qdelta = 2.0;
const double q = vp9_convert_qindex_to_q(cm->base_qindex);
const double q = vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth);
vp9_clear_system_state();
// Some of these parameters may be set via codec-control function later.
cr->max_sbs_perframe = 10;
@@ -243,17 +243,18 @@ void vp9_cyclic_refresh_setup(VP9_COMP *const cpi) {
// Set the q delta for segment 1.
qindex_delta = vp9_compute_qdelta_by_rate(rc, cm->frame_type,
cm->base_qindex,
rate_ratio_qdelta);
rate_ratio_qdelta, cm->bit_depth);
// TODO(marpan): Incorporate the actual-vs-target rate over/undershoot from
// previous encoded frame.
if (-qindex_delta > cr->max_qdelta_perc * cm->base_qindex / 100)
qindex_delta = -cr->max_qdelta_perc * cm->base_qindex / 100;
// Compute rd-mult for segment 1.
qindex2 = clamp(cm->base_qindex + cm->y_dc_delta_q + qindex_delta, 0, MAXQ);
qindex2 = clamp(cm->base_qindex + cm->y_dc_delta_q + qindex_delta, 0,
vp9_get_maxq(cm->bit_depth));
cr->rdmult = vp9_compute_rd_mult(cpi, qindex2);
vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qindex_delta);
vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qindex_delta, cm->bit_depth);
sb_cols = (cm->mi_cols + MI_BLOCK_SIZE - 1) / MI_BLOCK_SIZE;
sb_rows = (cm->mi_rows + MI_BLOCK_SIZE - 1) / MI_BLOCK_SIZE;

View File

@@ -79,7 +79,7 @@ void vp9_vaq_init() {
void vp9_vaq_frame_setup(VP9_COMP *cpi) {
VP9_COMMON *cm = &cpi->common;
struct segmentation *seg = &cm->seg;
const double base_q = vp9_convert_qindex_to_q(cm->base_qindex);
const double base_q = vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth);
const int base_rdmult = vp9_compute_rd_mult(cpi, cm->base_qindex +
cm->y_dc_delta_q);
int i;
@@ -103,8 +103,10 @@ void vp9_vaq_frame_setup(VP9_COMP *cpi) {
continue;
}
qindex_delta = vp9_compute_qdelta(&cpi->rc, base_q, base_q * Q_RATIO(i));
vp9_set_segdata(seg, SEGMENT_ID(i), SEG_LVL_ALT_Q, qindex_delta);
qindex_delta = vp9_compute_qdelta(&cpi->rc, base_q, base_q * Q_RATIO(i),
cm->bit_depth);
vp9_set_segdata(seg, SEGMENT_ID(i), SEG_LVL_ALT_Q, qindex_delta,
cm->bit_depth);
vp9_enable_segfeature(seg, SEGMENT_ID(i), SEG_LVL_ALT_Q);
segment_rdmult = vp9_compute_rd_mult(cpi, cm->base_qindex + qindex_delta +

View File

@@ -12,6 +12,8 @@
#include <stdio.h>
#include <limits.h>
#include "./vpx_config.h"
#include "vpx/vpx_encoder.h"
#include "vpx_mem/vpx_mem.h"
#include "vpx_ports/mem_ops.h"
@@ -121,16 +123,22 @@ static void update_switchable_interp_probs(VP9_COMMON *cm, vp9_writer *w) {
}
static void pack_mb_tokens(vp9_writer *w,
TOKENEXTRA **tp, const TOKENEXTRA *stop) {
TOKENEXTRA **tp, const TOKENEXTRA *stop,
BITSTREAM_PROFILE profile) {
TOKENEXTRA *p = *tp;
while (p < stop && p->token != EOSB_TOKEN) {
const int t = p->token;
const struct vp9_token *const a = &vp9_coef_encodings[t];
const vp9_extra_bit *const b = &vp9_extra_bits[t];
int i = 0;
int v = a->value;
int n = a->len;
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
const vp9_extra_bit *const b = profile > PROFILE_1 ?
&vp9_extra_bits_high[t] : &vp9_extra_bits[t];
#else
const vp9_extra_bit *const b = &vp9_extra_bits[t];
#endif
/* skip one or two nodes */
if (p->skip_eob_node) {
@@ -388,7 +396,7 @@ static void write_modes_b(VP9_COMP *cpi, const TileInfo *const tile,
}
assert(*tok < tok_end);
pack_mb_tokens(w, tok, tok_end);
pack_mb_tokens(w, tok, tok_end, cm->profile);
}
static void write_partition(VP9_COMMON *cm, MACROBLOCKD *xd,
@@ -733,7 +741,7 @@ static void write_delta_q(struct vp9_write_bit_buffer *wb, int delta_q) {
static void encode_quantization(VP9_COMMON *cm,
struct vp9_write_bit_buffer *wb) {
vp9_wb_write_literal(wb, cm->base_qindex, QINDEX_BITS);
vp9_wb_write_literal(wb, cm->base_qindex, vp9_get_qindex_bits(cm->bit_depth));
write_delta_q(wb, cm->y_dc_delta_q);
write_delta_q(wb, cm->uv_dc_delta_q);
write_delta_q(wb, cm->uv_ac_delta_q);
@@ -788,7 +796,8 @@ static void encode_segmentation(VP9_COMP *cpi,
vp9_wb_write_bit(wb, active);
if (active) {
const int data = vp9_get_segdata(seg, i, j);
const int data_max = vp9_seg_feature_data_max(j);
const int data_max = vp9_seg_feature_data_max(j,
cpi->common.bit_depth);
if (vp9_is_segfeature_signed(j)) {
encode_unsigned_max(wb, abs(data), data_max);

View File

@@ -1368,8 +1368,10 @@ static void set_source_var_based_partition(VP9_COMP *cpi,
d16[j].sum >>= 4;
break;
case VPX_BITS_8:
default:
break;
default:
assert(0 && "cm->bit_depth should be VPX_BITS_8, "
"VPX_BITS_10 or VPX_BITS_12");
}
} else {
get_sse_sum_16x16(src + b_offset, src_stride,

View File

@@ -60,7 +60,7 @@ void vp9_high_subtract_block_c(int rows, int cols,
int r, c;
uint16_t *src = CONVERT_TO_SHORTPTR(src8);
uint16_t *pred = CONVERT_TO_SHORTPTR(pred8);
#if CONFIG_HIGH_TRANSFORMS
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
(void) bps;
#else
int shift = bps - 8;
@@ -69,7 +69,7 @@ void vp9_high_subtract_block_c(int rows, int cols,
for (r = 0; r < rows; r++) {
for (c = 0; c < cols; c++) {
#if CONFIG_HIGH_TRANSFORMS
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
diff[c] = src[c] - pred[c];
#else
diff[c] = (src[c] - pred[c] + rnd) >> shift;
@@ -163,6 +163,8 @@ static int optimize_b(MACROBLOCK *mb, int plane, int block,
int64_t rd_cost0, rd_cost1;
int rate0, rate1, error0, error1, t0, t1;
int best, band, pt, i, final_eob;
const TOKENVALUE *dct_value_tokens;
const int16_t *dct_value_cost;
assert((!type && !plane) || (type && plane));
assert(eob <= default_eob);
@@ -179,9 +181,22 @@ static int optimize_b(MACROBLOCK *mb, int plane, int block,
tokens[eob][0].qc = 0;
tokens[eob][1] = tokens[eob][0];
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
if (xd->bps > 8) {
dct_value_tokens = vp9_dct_value_tokens_high_ptr;
dct_value_cost = vp9_dct_value_cost_high_ptr;
} else {
dct_value_tokens = vp9_dct_value_tokens_ptr;
dct_value_cost = vp9_dct_value_cost_ptr;
}
#else
dct_value_tokens = vp9_dct_value_tokens_ptr;
dct_value_cost = vp9_dct_value_cost_ptr;
#endif
for (i = 0; i < eob; i++)
token_cache[scan[i]] =
vp9_pt_energy_class[vp9_dct_value_tokens_ptr[qcoeff[scan[i]]].token];
vp9_pt_energy_class[dct_value_tokens[qcoeff[scan[i]]].token];
for (i = eob; i-- > 0;) {
int base_bits, d2, dx;
@@ -195,7 +210,7 @@ static int optimize_b(MACROBLOCK *mb, int plane, int block,
/* Evaluate the first possibility for this state. */
rate0 = tokens[next][0].rate;
rate1 = tokens[next][1].rate;
t0 = (vp9_dct_value_tokens_ptr + x)->token;
t0 = (dct_value_tokens + x)->token;
/* Consider both possible successor states. */
if (next < default_eob) {
band = band_translate[i + 1];
@@ -208,9 +223,9 @@ static int optimize_b(MACROBLOCK *mb, int plane, int block,
UPDATE_RD_COST();
/* And pick the best. */
best = rd_cost1 < rd_cost0;
base_bits = vp9_dct_value_cost_ptr[x];
base_bits = dct_value_cost[x];
dx = mul * (dqcoeff[rc] - coeff[rc]);
#if CONFIG_HIGH_TRANSFORMS && CONFIG_VP9_HIGH
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
if (xd->cur_buf->flags & YV12_FLAG_HIGH) {
dx >>= xd->bps - 8;
}
@@ -247,7 +262,7 @@ static int optimize_b(MACROBLOCK *mb, int plane, int block,
t0 = tokens[next][0].token == EOB_TOKEN ? EOB_TOKEN : ZERO_TOKEN;
t1 = tokens[next][1].token == EOB_TOKEN ? EOB_TOKEN : ZERO_TOKEN;
} else {
t0 = t1 = (vp9_dct_value_tokens_ptr + x)->token;
t0 = t1 = (dct_value_tokens + x)->token;
}
if (next < default_eob) {
band = band_translate[i + 1];
@@ -266,10 +281,10 @@ static int optimize_b(MACROBLOCK *mb, int plane, int block,
UPDATE_RD_COST();
/* And pick the best. */
best = rd_cost1 < rd_cost0;
base_bits = vp9_dct_value_cost_ptr[x];
base_bits = dct_value_cost[x];
if (shortcut) {
#if CONFIG_HIGH_TRANSFORMS && CONFIG_VP9_HIGH
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
if (xd->cur_buf->flags & YV12_FLAG_HIGH) {
dx -= ((dequant_ptr[rc != 0] >> (xd->bps - 8)) + sz) ^ sz;
} else {

View File

@@ -289,9 +289,10 @@ static void configure_static_seg_features(VP9_COMP *cpi) {
seg->update_map = 1;
seg->update_data = 1;
qi_delta = vp9_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875);
vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2);
vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
qi_delta = vp9_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875,
cm->bit_depth);
vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2, cm->bit_depth);
vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2, cm->bit_depth);
vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
@@ -310,16 +311,18 @@ static void configure_static_seg_features(VP9_COMP *cpi) {
seg->update_data = 1;
seg->abs_delta = SEGMENT_DELTADATA;
qi_delta = vp9_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125);
vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2);
qi_delta = vp9_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125,
cm->bit_depth);
vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2, cm->bit_depth);
vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2, cm->bit_depth);
vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
// Segment coding disabled for compred testing
if (high_q || (cpi->static_mb_pct == 100)) {
vp9_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
vp9_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME,
cm->bit_depth);
vp9_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME);
vp9_enable_segfeature(seg, 1, SEG_LVL_SKIP);
}
@@ -347,9 +350,9 @@ static void configure_static_seg_features(VP9_COMP *cpi) {
// All mbs should use ALTREF_FRAME
vp9_clear_segdata(seg, 0, SEG_LVL_REF_FRAME);
vp9_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME);
vp9_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME, cm->bit_depth);
vp9_clear_segdata(seg, 1, SEG_LVL_REF_FRAME);
vp9_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
vp9_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME, cm->bit_depth);
// Skip all MBs if high Q (0,0 mv and skip coeffs)
if (high_q) {
@@ -1005,7 +1008,7 @@ static void high_set_var_fns(VP9_COMP *const cpi) {
VP9_COMMON *const cm = &cpi->common;
if (cm->use_high) {
switch (cm->bit_depth) {
default:
case VPX_BITS_8:
HIGH_BFP(BLOCK_32X16, vp9_high_sad32x16_bits8,
vp9_high_sad32x16_avg_bits8,
vp9_high_variance32x16,
@@ -1331,6 +1334,9 @@ static void high_set_var_fns(VP9_COMP *const cpi) {
vp9_high_sad4x4x8_bits12,
vp9_high_sad4x4x4d_bits12)
break;
default:
assert(0 && "cm->bit_depth should be VPX_BITS_8, "
"VPX_BITS_10 or VPX_BITS_12");
}
}
}
@@ -2214,16 +2220,17 @@ static void scale_and_extend_frame(const YV12_BUFFER_CONFIG *src,
vp8_yv12_extend_frame_borders_c(dst);
}
static int find_fp_qindex() {
static int find_fp_qindex(vpx_bit_depth_t bit_depth) {
int i;
int range = vp9_get_qindex_range(bit_depth);
for (i = 0; i < QINDEX_RANGE; i++) {
if (vp9_convert_qindex_to_q(i) >= 30.0) {
for (i = 0; i < range; i++) {
if (vp9_convert_qindex_to_q(i, bit_depth) >= 30.0) {
break;
}
}
if (i == QINDEX_RANGE)
if (i == range)
i--;
return i;
@@ -3130,7 +3137,7 @@ static void Pass1Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest,
(void) frame_flags;
vp9_rc_get_first_pass_params(cpi);
vp9_set_quantizer(&cpi->common, find_fp_qindex());
vp9_set_quantizer(&cpi->common, find_fp_qindex(cpi->common.bit_depth));
vp9_first_pass(cpi);
}
@@ -3778,7 +3785,6 @@ int vp9_high_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b,
assert((a->flags & YV12_FLAG_HIGH) != 0);
assert((b->flags & YV12_FLAG_HIGH) != 0);
switch (bit_depth) {
default:
case VPX_BITS_8:
high_variance(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride,
a->y_crop_width, a->y_crop_height, &sse, &sum);
@@ -3791,9 +3797,9 @@ int vp9_high_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b,
high_12_variance(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride,
a->y_crop_width, a->y_crop_height, &sse, &sum);
return (int) sse;
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
assert(0);
}
#endif

View File

@@ -72,8 +72,8 @@ static void swap_yv12(YV12_BUFFER_CONFIG *a, YV12_BUFFER_CONFIG *b) {
*b = temp;
}
static int gfboost_qadjust(int qindex) {
const double q = vp9_convert_qindex_to_q(qindex);
static int gfboost_qadjust(int qindex, vpx_bit_depth_t bit_depth) {
const double q = vp9_convert_qindex_to_q(qindex, bit_depth);
return (int)((0.00000828 * q * q * q) +
(-0.0055 * q * q) +
(1.32 * q) + 79.3);
@@ -338,6 +338,9 @@ static double high_simple_weight(const YV12_BUFFER_CONFIG *buf,
int shift;
uint16_t *row16 = CONVERT_TO_SHORTPTR(row);
switch (bit_depth) {
case VPX_BITS_8:
shift = 0;
break;
case VPX_BITS_10:
shift = 2;
break;
@@ -345,8 +348,7 @@ static double high_simple_weight(const YV12_BUFFER_CONFIG *buf,
shift = 4;
break;
default:
shift = 0;
break;
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
for (i = 0; i < h; ++i) {
@@ -699,6 +701,8 @@ void vp9_first_pass(VP9_COMP *cpi) {
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
if (cm->use_high) {
switch (cm->bit_depth) {
case VPX_BITS_8:
break;
case VPX_BITS_10:
this_error >>= 4;
break;
@@ -706,7 +710,8 @@ void vp9_first_pass(VP9_COMP *cpi) {
this_error >>= 8;
break;
default:
break;
assert(0 && "cm->bit_depth should be VPX_BITS_8, "
"VPX_BITS_10 or VPX_BITS_12");
}
}
#endif
@@ -1024,12 +1029,13 @@ static double calc_correction_factor(double err_per_mb,
double err_divisor,
double pt_low,
double pt_high,
int q) {
int q,
vpx_bit_depth_t bit_depth) {
const double error_term = err_per_mb / err_divisor;
// Adjustment based on actual quantizer to power term.
const double power_term = MIN(vp9_convert_qindex_to_q(q) * 0.0125 + pt_low,
pt_high);
const double power_term = MIN(vp9_convert_qindex_to_q(q, bit_depth)
* 0.0125 + pt_low, pt_high);
// Calculate correction factor.
if (power_term < 1.0)
@@ -1066,9 +1072,11 @@ static int get_twopass_worst_quality(const VP9_COMP *cpi,
const double factor =
calc_correction_factor(err_per_mb, ERR_DIVISOR,
is_svc_upper_layer ? SVC_FACTOR_PT_LOW :
FACTOR_PT_LOW, FACTOR_PT_HIGH, q);
FACTOR_PT_LOW, FACTOR_PT_HIGH, q,
cpi->common.bit_depth);
const int bits_per_mb = vp9_rc_bits_per_mb(INTER_FRAME, q,
factor * speed_term);
factor * speed_term,
cpi->common.bit_depth);
if (bits_per_mb <= target_norm_bits_per_mb)
break;
}
@@ -1721,7 +1729,8 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// interval to spread the cost of the GF.
//
active_max_gf_interval =
12 + ((int)vp9_convert_qindex_to_q(rc->last_q[INTER_FRAME]) >> 5);
12 + ((int)vp9_convert_qindex_to_q(rc->last_q[INTER_FRAME],
cpi->common.bit_depth) >> 5);
if (active_max_gf_interval > rc->max_gf_interval)
active_max_gf_interval = rc->max_gf_interval;
@@ -1907,7 +1916,8 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// Calculate the extra bits to be used for boosted frame(s)
{
int q = rc->last_q[INTER_FRAME];
int boost = (rc->gfu_boost * gfboost_qadjust(q)) / 100;
int boost = (rc->gfu_boost *
gfboost_qadjust(q, cpi->common.bit_depth)) / 100;
// Set max and minimum boost and hence minimum allocation.
boost = clamp(boost, 125, (rc->baseline_gf_interval + 1) * 200);
@@ -2342,7 +2352,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
section_target_bandwidth);
twopass->active_worst_quality = tmp_q;
rc->ni_av_qi = tmp_q;
rc->avg_q = vp9_convert_qindex_to_q(tmp_q);
rc->avg_q = vp9_convert_qindex_to_q(tmp_q, cm->bit_depth);
}
vp9_zero(this_frame);
if (EOF == input_stats(twopass, &this_frame))

View File

@@ -154,10 +154,28 @@ void vp9_pick_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi,
if (method == LPF_PICK_FROM_Q) {
const int min_filter_level = 0;
const int max_filter_level = get_max_filter_level(cpi);
const int q = vp9_ac_quant(cm->base_qindex, 0, VPX_BITS_8);
const int q = vp9_ac_quant(cm->base_qindex, 0, cm->bit_depth);
int filt_guess;
// These values were determined by linear fitting the result of the
// searched level, filt_guess = q * 0.316206 + 3.87252
int filt_guess = ROUND_POWER_OF_TWO(q * 20723 + 1015158, 18);
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
switch (cm->bit_depth) {
case VPX_BITS_8:
filt_guess = ROUND_POWER_OF_TWO(q * 20723 + 1015158, 18);
break;
case VPX_BITS_10:
filt_guess = ROUND_POWER_OF_TWO(q * 20723 + 4060632, 20);
break;
case VPX_BITS_12:
filt_guess = ROUND_POWER_OF_TWO(q * 20723 + 16242526, 22);
break;
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 "
"or VPX_BITS_12");
}
#else
filt_guess = ROUND_POWER_OF_TWO(q * 20723 + 1015158, 18);
#endif
if (cm->frame_type == KEY_FRAME)
filt_guess -= 4;
lf->filter_level = clamp(filt_guess, min_filter_level, max_filter_level);

View File

@@ -23,6 +23,7 @@
#include "vp9/common/vp9_reconintra.h"
#include "vp9/encoder/vp9_encoder.h"
#include "vp9/encoder/vp9_pickmode.h"
#include "vp9/encoder/vp9_ratectrl.h"
#include "vp9/encoder/vp9_rdopt.h"
@@ -172,7 +173,7 @@ static void model_rd_for_sb_y(VP9_COMP *cpi, BLOCK_SIZE bsize,
if ((sse >> 3) > var)
sse = var;
#if CONFIG_HIGH_TRANSFORMS && CONFIG_VP9_HIGH
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
if (xd->cur_buf->flags & YV12_FLAG_HIGH) {
vp9_model_rd_from_var_lapndz(var + sse,
1 << num_pels_log2_lookup[bsize],
@@ -219,8 +220,9 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
unsigned int sse_y = UINT_MAX;
VP9_COMMON *cm = &cpi->common;
int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q,
VPX_BITS_8);
int intra_cost_penalty = vp9_get_intra_cost_penalty(cm->base_qindex,
cm->y_dc_delta_q,
cm->bit_depth);
const int64_t inter_mode_thresh = RDCOST(x->rdmult, x->rddiv,
intra_cost_penalty, 0);
@@ -392,13 +394,13 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
// The encode_breakout input
const unsigned int min_thresh =
MIN(((unsigned int)x->encode_breakout << 4), max_thresh);
#if CONFIG_HIGH_TRANSFORMS && CONFIG_VP9_HIGH
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
const int shift = 2 * xd->bps - 16;
#endif
// Calculate threshold according to dequant value.
thresh_ac = (xd->plane[0].dequant[1] * xd->plane[0].dequant[1]) / 9;
#if CONFIG_HIGH_TRANSFORMS && CONFIG_VP9_HIGH
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
if (xd->cur_buf->flags & YV12_FLAG_HIGH) {
if (shift > 0)
thresh_ac = ROUND_POWER_OF_TWO(thresh_ac, shift);
@@ -410,7 +412,7 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
b_height_log2_lookup[bsize]);
thresh_dc = (xd->plane[0].dequant[0] * xd->plane[0].dequant[0] >> 6);
#if CONFIG_HIGH_TRANSFORMS && CONFIG_VP9_HIGH
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
if (xd->cur_buf->flags & YV12_FLAG_HIGH) {
if (shift > 0)
thresh_dc = ROUND_POWER_OF_TWO(thresh_dc, shift);
@@ -509,3 +511,22 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
return INT64_MAX;
}
int vp9_get_intra_cost_penalty(int qindex, int qdelta,
vpx_bit_depth_t bit_depth) {
const int q = vp9_dc_quant(qindex, qdelta, bit_depth);
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
switch (bit_depth) {
case VPX_BITS_8:
return 20 * q;
case VPX_BITS_10:
return 5 * q;
case VPX_BITS_12:
return ROUND_POWER_OF_TWO(5 * q, 2);
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#else
return 20 * q;
#endif
}

View File

@@ -24,6 +24,9 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
int64_t *returndistortion,
BLOCK_SIZE bsize);
int vp9_get_intra_cost_penalty(int qindex, int qdelta,
vpx_bit_depth_t bit_depth);
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -10,6 +10,8 @@
#include <math.h>
#include "./vpx_config.h"
#include "vpx_mem/vpx_mem.h"
#include "vp9/common/vp9_quant_common.h"
@@ -280,14 +282,33 @@ static void invert_quant(int16_t *quant, int16_t *shift, int d) {
*shift = 1 << (16 - l);
}
static int get_qzbin_factor(int q, vpx_bit_depth_t bit_depth) {
int quant = vp9_dc_quant(q, 0, bit_depth);
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
switch (bit_depth) {
case VPX_BITS_8:
return q == 0 ? 64 : (quant < 148 ? 84 : 80);
case VPX_BITS_10:
return q == 0 ? 64 : (quant < 592 ? 84 : 80);
case VPX_BITS_12:
return q == 0 ? 64 : (quant < 2368 ? 84 : 80);
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#else
return q == 0 ? 64 : (quant < 148 ? 84 : 80);
#endif
}
void vp9_init_quantizer(VP9_COMP *cpi) {
VP9_COMMON *const cm = &cpi->common;
QUANTS *const quants = &cpi->quants;
int i, q, quant;
int range = vp9_get_qindex_range(cm->bit_depth);
for (q = 0; q < range; q++) {
const int qzbin_factor = get_qzbin_factor(q, cm->bit_depth);
for (q = 0; q < QINDEX_RANGE; q++) {
const int qzbin_factor = q == 0 ? 64 :
(vp9_dc_quant(q, 0, VPX_BITS_8) < 148 ? 84 : 80);
const int qrounding_factor = q == 0 ? 64 : 48;
for (i = 0; i < 2; ++i) {
@@ -348,7 +369,8 @@ void vp9_init_plane_quantizers(VP9_COMP *cpi, MACROBLOCK *x) {
MACROBLOCKD *const xd = &x->e_mbd;
QUANTS *const quants = &cpi->quants;
const int segment_id = xd->mi[0]->mbmi.segment_id;
const int qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex);
const int qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex,
cm->bit_depth);
const int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q);
const int zbin = cpi->zbin_mode_boost;
int i;
@@ -428,15 +450,70 @@ static const int quantizer_to_qindex[] = {
224, 228, 232, 236, 240, 244, 249, 255,
};
int vp9_quantizer_to_qindex(int quantizer) {
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
static const int quantizer_to_qindex_10[] = {
0, 5, 10, 15, 20, 26, 31, 36,
41, 46, 52, 57, 62, 67, 72, 78,
83, 88, 93, 98, 104, 109, 114, 119,
124, 130, 135, 140, 145, 150, 156, 161,
166, 171, 176, 182, 187, 192, 197, 202,
208, 213, 218, 223, 228, 234, 239, 244,
249, 254, 260, 265, 270, 275, 280, 286,
291, 296, 301, 306, 312, 317, 322, 327,
};
static const int quantizer_to_qindex_12[] = {
0, 6, 12, 19, 25, 31, 38, 44,
50, 57, 63, 69, 76, 82, 88, 95,
101, 107, 114, 120, 126, 133, 139, 145,
152, 158, 164, 171, 177, 183, 190, 196,
202, 209, 215, 221, 228, 234, 240, 247,
253, 259, 266, 272, 278, 285, 291, 297,
304, 310, 316, 323, 329, 335, 342, 348,
354, 361, 367, 373, 380, 386, 392, 398,
};
#endif
int vp9_quantizer_to_qindex(int quantizer, vpx_bit_depth_t bit_depth) {
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
switch (bit_depth) {
case VPX_BITS_8:
return quantizer_to_qindex[quantizer];
case VPX_BITS_10:
return quantizer_to_qindex_10[quantizer];
case VPX_BITS_12:
return quantizer_to_qindex_12[quantizer];
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#else
(void) bit_depth;
return quantizer_to_qindex[quantizer];
#endif
}
int vp9_qindex_to_quantizer(int qindex) {
int vp9_qindex_to_quantizer(int qindex, vpx_bit_depth_t bit_depth) {
int quantizer;
const int *table = quantizer_to_qindex;
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
switch (bit_depth) {
case VPX_BITS_8:
break;
case VPX_BITS_10:
table = quantizer_to_qindex_10;
break;
case VPX_BITS_12:
table = quantizer_to_qindex_12;
break;
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#else
(void) bit_depth;
#endif
for (quantizer = 0; quantizer < 64; ++quantizer)
if (quantizer_to_qindex[quantizer] >= qindex)
if (table[quantizer] >= qindex)
return quantizer;
return 63;

View File

@@ -19,21 +19,21 @@ extern "C" {
#endif
typedef struct {
DECLARE_ALIGNED(16, int16_t, y_quant[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, y_quant_shift[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, y_zbin[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, y_round[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, y_quant[QINDEX_RANGE_MAX][8]);
DECLARE_ALIGNED(16, int16_t, y_quant_shift[QINDEX_RANGE_MAX][8]);
DECLARE_ALIGNED(16, int16_t, y_zbin[QINDEX_RANGE_MAX][8]);
DECLARE_ALIGNED(16, int16_t, y_round[QINDEX_RANGE_MAX][8]);
DECLARE_ALIGNED(16, int16_t, uv_quant[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, uv_quant_shift[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, uv_zbin[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, uv_round[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, uv_quant[QINDEX_RANGE_MAX][8]);
DECLARE_ALIGNED(16, int16_t, uv_quant_shift[QINDEX_RANGE_MAX][8]);
DECLARE_ALIGNED(16, int16_t, uv_zbin[QINDEX_RANGE_MAX][8]);
DECLARE_ALIGNED(16, int16_t, uv_round[QINDEX_RANGE_MAX][8]);
#if CONFIG_ALPHA
DECLARE_ALIGNED(16, int16_t, a_quant[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, a_quant_shift[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, a_zbin[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, a_round[QINDEX_RANGE][8]);
DECLARE_ALIGNED(16, int16_t, a_quant[QINDEX_RANGE_MAX][8]);
DECLARE_ALIGNED(16, int16_t, a_quant_shift[QINDEX_RANGE_MAX][8]);
DECLARE_ALIGNED(16, int16_t, a_zbin[QINDEX_RANGE_MAX][8]);
DECLARE_ALIGNED(16, int16_t, a_round[QINDEX_RANGE_MAX][8]);
#endif
} QUANTS;
@@ -53,9 +53,9 @@ void vp9_init_quantizer(struct VP9_COMP *cpi);
void vp9_set_quantizer(struct VP9Common *cm, int q);
int vp9_quantizer_to_qindex(int quantizer);
int vp9_quantizer_to_qindex(int quantizer, vpx_bit_depth_t bit_depth);
int vp9_qindex_to_quantizer(int qindex);
int vp9_qindex_to_quantizer(int qindex, vpx_bit_depth_t bit_depth);
#ifdef __cplusplus
} // extern "C"

View File

@@ -15,6 +15,8 @@
#include <stdlib.h>
#include <string.h>
#include "./vpx_config.h"
#include "vpx_mem/vpx_mem.h"
#include "vp9/common/vp9_alloccommon.h"
@@ -42,13 +44,52 @@
#define FRAME_OVERHEAD_BITS 200
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
#define ASSIGN_MINQ_TABLE(bit_depth, name) \
do { \
switch (bit_depth) { \
case VPX_BITS_8: \
name = name##_8; \
break; \
case VPX_BITS_10: \
name = name##_10; \
break; \
case VPX_BITS_12: \
name = name##_12; \
break; \
default: \
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10" \
" or VPX_BITS_12"); \
} \
} while (0)
#else
#define ASSIGN_MINQ_TABLE(bit_depth, name) \
do { \
name = name##_8; \
} while (0)
#endif
// Tables relating active max Q to active min Q
static int kf_low_motion_minq[QINDEX_RANGE];
static int kf_high_motion_minq[QINDEX_RANGE];
static int arfgf_low_motion_minq[QINDEX_RANGE];
static int arfgf_high_motion_minq[QINDEX_RANGE];
static int inter_minq[QINDEX_RANGE];
static int rtc_minq[QINDEX_RANGE];
static int kf_low_motion_minq_8[QINDEX_RANGE];
static int kf_high_motion_minq_8[QINDEX_RANGE];
static int arfgf_low_motion_minq_8[QINDEX_RANGE];
static int arfgf_high_motion_minq_8[QINDEX_RANGE];
static int inter_minq_8[QINDEX_RANGE];
static int rtc_minq_8[QINDEX_RANGE];
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
static int kf_low_motion_minq_10[QINDEX_RANGE_10];
static int kf_high_motion_minq_10[QINDEX_RANGE_10];
static int arfgf_low_motion_minq_10[QINDEX_RANGE_10];
static int arfgf_high_motion_minq_10[QINDEX_RANGE_10];
static int inter_minq_10[QINDEX_RANGE_10];
static int rtc_minq_10[QINDEX_RANGE_10];
static int kf_low_motion_minq_12[QINDEX_RANGE_12];
static int kf_high_motion_minq_12[QINDEX_RANGE_12];
static int arfgf_low_motion_minq_12[QINDEX_RANGE_12];
static int arfgf_high_motion_minq_12[QINDEX_RANGE_12];
static int inter_minq_12[QINDEX_RANGE_12];
static int rtc_minq_12[QINDEX_RANGE_12];
#endif
static int gf_high = 2000;
static int gf_low = 400;
static int kf_high = 5000;
@@ -58,8 +99,10 @@ static int kf_low = 400;
// formulaic approach to facilitate easier adjustment of the Q tables.
// The formulae were derived from computing a 3rd order polynomial best
// fit to the original data (after plotting real maxq vs minq (not q index))
static int get_minq_index(double maxq, double x3, double x2, double x1) {
static int get_minq_index(double maxq, double x3, double x2, double x1,
vpx_bit_depth_t bit_depth) {
int i;
int range = vp9_get_qindex_range(bit_depth);
const double minqtarget = MIN(((x3 * maxq + x2) * maxq + x1) * maxq,
maxq);
@@ -68,48 +111,79 @@ static int get_minq_index(double maxq, double x3, double x2, double x1) {
if (minqtarget <= 2.0)
return 0;
for (i = 0; i < QINDEX_RANGE; i++)
if (minqtarget <= vp9_convert_qindex_to_q(i))
for (i = 0; i < range; i++)
if (minqtarget <= vp9_convert_qindex_to_q(i, bit_depth))
return i;
return QINDEX_RANGE - 1;
return range - 1;
}
static void init_minq_luts(int *kf_low_m, int *kf_high_m,
int *arfgf_low, int *arfgf_high,
int *inter, int *rtc, vpx_bit_depth_t bit_depth) {
int i;
int range = vp9_get_qindex_range(bit_depth);
for (i = 0; i < range; i++) {
const double maxq = vp9_convert_qindex_to_q(i, bit_depth);
kf_low_m[i] = get_minq_index(maxq, 0.000001, -0.0004, 0.125, bit_depth);
kf_high_m[i] = get_minq_index(maxq, 0.000002, -0.0012, 0.50, bit_depth);
arfgf_low[i] = get_minq_index(maxq, 0.0000015, -0.0009, 0.30, bit_depth);
arfgf_high[i] = get_minq_index(maxq, 0.0000021, -0.00125, 0.50, bit_depth);
inter[i] = get_minq_index(maxq, 0.00000271, -0.00113, 0.90, bit_depth);
rtc[i] = get_minq_index(maxq, 0.00000271, -0.00113, 0.70, bit_depth);
}
}
void vp9_rc_init_minq_luts() {
int i;
for (i = 0; i < QINDEX_RANGE; i++) {
const double maxq = vp9_convert_qindex_to_q(i);
kf_low_motion_minq[i] = get_minq_index(maxq, 0.000001, -0.0004, 0.125);
kf_high_motion_minq[i] = get_minq_index(maxq, 0.000002, -0.0012, 0.50);
arfgf_low_motion_minq[i] = get_minq_index(maxq, 0.0000015, -0.0009, 0.30);
arfgf_high_motion_minq[i] = get_minq_index(maxq, 0.0000021, -0.00125, 0.50);
inter_minq[i] = get_minq_index(maxq, 0.00000271, -0.00113, 0.90);
rtc_minq[i] = get_minq_index(maxq, 0.00000271, -0.00113, 0.70);
}
init_minq_luts(kf_low_motion_minq_8, kf_high_motion_minq_8,
arfgf_low_motion_minq_8, arfgf_high_motion_minq_8,
inter_minq_8, rtc_minq_8, VPX_BITS_8);
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
init_minq_luts(kf_low_motion_minq_10, kf_high_motion_minq_10,
arfgf_low_motion_minq_10, arfgf_high_motion_minq_10,
inter_minq_10, rtc_minq_10, VPX_BITS_10);
init_minq_luts(kf_low_motion_minq_12, kf_high_motion_minq_12,
arfgf_low_motion_minq_12, arfgf_high_motion_minq_12,
inter_minq_12, rtc_minq_12, VPX_BITS_12);
#endif
}
// These functions use formulaic calculations to make playing with the
// quantizer tables easier. If necessary they can be replaced by lookup
// tables if and when things settle down in the experimental bitstream
double vp9_convert_qindex_to_q(int qindex) {
double vp9_convert_qindex_to_q(int qindex, vpx_bit_depth_t bit_depth) {
// Convert the index to a real Q value (scaled down to match old Q values)
return vp9_ac_quant(qindex, 0, VPX_BITS_8) / 4.0;
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
switch (bit_depth) {
case VPX_BITS_8:
return vp9_ac_quant(qindex, 0, bit_depth) / 4.0;
case VPX_BITS_10:
return vp9_ac_quant(qindex, 0, bit_depth) / 16.0;
case VPX_BITS_12:
return vp9_ac_quant(qindex, 0, bit_depth) / 64.0;
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#else
return vp9_ac_quant(qindex, 0, bit_depth) / 4.0;
#endif
}
int vp9_rc_bits_per_mb(FRAME_TYPE frame_type, int qindex,
double correction_factor) {
const double q = vp9_convert_qindex_to_q(qindex);
double correction_factor, vpx_bit_depth_t bit_depth) {
const double q = vp9_convert_qindex_to_q(qindex, bit_depth);
int enumerator = frame_type == KEY_FRAME ? 3300000 : 2250000;
// q based adjustment to baseline enumerator
enumerator += (int)(enumerator * q) >> 12;
return (int)(0.5 + (enumerator * correction_factor / q));
}
static int estimate_bits_at_q(FRAME_TYPE frame_type, int q, int mbs,
double correction_factor) {
const int bpm = (int)(vp9_rc_bits_per_mb(frame_type, q, correction_factor));
double correction_factor,
vpx_bit_depth_t bit_depth) {
const int bpm = (int)(vp9_rc_bits_per_mb(frame_type, q, correction_factor,
bit_depth));
return ((uint64_t)bpm * mbs) >> BPER_MB_NORMBITS;
}
@@ -230,7 +304,7 @@ void vp9_rc_init(const VP9EncoderConfig *oxcf, int pass, RATE_CONTROL *rc) {
rc->ni_frames = 0;
rc->tot_q = 0.0;
rc->avg_q = vp9_convert_qindex_to_q(oxcf->worst_allowed_q);
rc->avg_q = vp9_convert_qindex_to_q(oxcf->worst_allowed_q, oxcf->bit_depth);
rc->rate_correction_factor = 1.0;
rc->key_frame_rate_correction_factor = 1.0;
@@ -321,7 +395,8 @@ void vp9_rc_update_rate_correction_factors(VP9_COMP *cpi, int damp_var) {
// Stay in double to avoid int overflow when values are large
projected_size_based_on_q = estimate_bits_at_q(cm->frame_type,
cm->base_qindex, cm->MBs,
rate_correction_factor);
rate_correction_factor,
cm->bit_depth);
// Work out a size correction factor.
if (projected_size_based_on_q > 0)
correction_factor = (100 * cpi->rc.projected_frame_size) /
@@ -383,7 +458,8 @@ int vp9_rc_regulate_q(const VP9_COMP *cpi, int target_bits_per_frame,
do {
const int bits_per_mb_at_this_q = (int)vp9_rc_bits_per_mb(cm->frame_type, i,
correction_factor);
correction_factor,
cm->bit_depth);
if (bits_per_mb_at_this_q <= target_bits_per_mb) {
if ((target_bits_per_mb - bits_per_mb_at_this_q) <= last_error)
@@ -499,6 +575,17 @@ static int rc_pick_q_and_bounds_one_pass_cbr(const VP9_COMP *cpi,
int active_best_quality;
int active_worst_quality = calc_active_worst_quality_one_pass_cbr(cpi);
int q;
int *kf_low_motion_minq;
int *kf_high_motion_minq;
int *arfgf_low_motion_minq;
int *arfgf_high_motion_minq;
int *rtc_minq;
ASSIGN_MINQ_TABLE(cm->bit_depth, kf_low_motion_minq);
ASSIGN_MINQ_TABLE(cm->bit_depth, kf_high_motion_minq);
ASSIGN_MINQ_TABLE(cm->bit_depth, arfgf_low_motion_minq);
ASSIGN_MINQ_TABLE(cm->bit_depth, arfgf_high_motion_minq);
ASSIGN_MINQ_TABLE(cm->bit_depth, rtc_minq);
if (frame_is_intra_only(cm)) {
active_best_quality = rc->best_quality;
@@ -507,9 +594,10 @@ static int rc_pick_q_and_bounds_one_pass_cbr(const VP9_COMP *cpi,
// based on the ambient Q to reduce the risk of popping.
if (rc->this_key_frame_forced) {
int qindex = rc->last_boosted_qindex;
double last_boosted_q = vp9_convert_qindex_to_q(qindex);
double last_boosted_q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
int delta_qindex = vp9_compute_qdelta(rc, last_boosted_q,
(last_boosted_q * 0.75));
(last_boosted_q * 0.75),
cm->bit_depth);
active_best_quality = MAX(qindex + delta_qindex, rc->best_quality);
} else if (cm->current_video_frame > 0) {
// not first frame of one pass and kf_boost is set
@@ -529,9 +617,10 @@ static int rc_pick_q_and_bounds_one_pass_cbr(const VP9_COMP *cpi,
// Convert the adjustment factor to a qindex delta
// on active_best_quality.
q_val = vp9_convert_qindex_to_q(active_best_quality);
q_val = vp9_convert_qindex_to_q(active_best_quality, cm->bit_depth);
active_best_quality += vp9_compute_qdelta(rc, q_val,
q_val * q_adj_factor);
q_val * q_adj_factor,
cm->bit_depth);
}
} else if (!rc->is_src_frame_alt_ref &&
!cpi->use_svc &&
@@ -580,7 +669,8 @@ static int rc_pick_q_and_bounds_one_pass_cbr(const VP9_COMP *cpi,
int qdelta = 0;
vp9_clear_system_state();
qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
active_worst_quality, 2.0);
active_worst_quality, 2.0,
cm->bit_depth);
*top_index = active_worst_quality + qdelta;
*top_index = (*top_index > *bottom_index) ? *top_index : *bottom_index;
}
@@ -632,6 +722,22 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
int active_best_quality;
int active_worst_quality = calc_active_worst_quality_one_pass_vbr(cpi);
int q;
#if !CONFIG_MULTIPLE_ARF
int *kf_low_motion_minq;
int *kf_high_motion_minq;
#endif
int *arfgf_low_motion_minq;
int *arfgf_high_motion_minq;
int *inter_minq;
#if !CONFIG_MULTIPLE_ARF
ASSIGN_MINQ_TABLE(cm->bit_depth, kf_low_motion_minq);
ASSIGN_MINQ_TABLE(cm->bit_depth, kf_high_motion_minq);
#endif
ASSIGN_MINQ_TABLE(cm->bit_depth, arfgf_low_motion_minq);
ASSIGN_MINQ_TABLE(cm->bit_depth, arfgf_high_motion_minq);
ASSIGN_MINQ_TABLE(cm->bit_depth, inter_minq);
if (frame_is_intra_only(cm)) {
active_best_quality = rc->best_quality;
@@ -641,9 +747,10 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
// based on the ambient Q to reduce the risk of popping.
if (rc->this_key_frame_forced) {
int qindex = rc->last_boosted_qindex;
double last_boosted_q = vp9_convert_qindex_to_q(qindex);
double last_boosted_q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
int delta_qindex = vp9_compute_qdelta(rc, last_boosted_q,
last_boosted_q * 0.75);
last_boosted_q * 0.75,
cm->bit_depth);
active_best_quality = MAX(qindex + delta_qindex, rc->best_quality);
} else if (cm->current_video_frame > 0) {
// not first frame of one pass and kf_boost is set
@@ -663,16 +770,17 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
// Convert the adjustment factor to a qindex delta
// on active_best_quality.
q_val = vp9_convert_qindex_to_q(active_best_quality);
q_val = vp9_convert_qindex_to_q(active_best_quality, cm->bit_depth);
active_best_quality += vp9_compute_qdelta(rc, q_val,
q_val * q_adj_factor);
q_val * q_adj_factor,
cm->bit_depth);
}
#else
double current_q;
// Force the KF quantizer to be 30% of the active_worst_quality.
current_q = vp9_convert_qindex_to_q(active_worst_quality);
current_q = vp9_convert_qindex_to_q(active_worst_quality, cm->bit_depth);
active_best_quality = active_worst_quality
+ vp9_compute_qdelta(rc, current_q, current_q * 0.3);
+ vp9_compute_qdelta(rc, current_q, current_q * 0.3, cm->bit_depth);
#endif
} else if (!rc->is_src_frame_alt_ref &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
@@ -748,11 +856,13 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
!rc->this_key_frame_forced &&
!(cm->current_video_frame == 0)) {
qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
active_worst_quality, 2.0);
active_worst_quality, 2.0,
cm->bit_depth);
} else if (!rc->is_src_frame_alt_ref &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
active_worst_quality, 1.75);
active_worst_quality, 1.75,
cm->bit_depth);
}
*top_index = active_worst_quality + qdelta;
*top_index = (*top_index > *bottom_index) ? *top_index : *bottom_index;
@@ -780,12 +890,13 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
if (cpi->multi_arf_enabled && (cm->frame_type != KEY_FRAME) &&
cpi->oxcf.rc_mode != RC_MODE_CONSTANT_QUALITY) {
double new_q;
double current_q = vp9_convert_qindex_to_q(active_worst_quality);
double current_q = vp9_convert_qindex_to_q(active_worst_quality,
cm->bit_depth);
int level = cpi->this_frame_weight;
assert(level >= 0);
new_q = current_q * (1.0 - (0.2 * (cpi->max_arf_level - level)));
q = active_worst_quality +
vp9_compute_qdelta(rc, current_q, new_q);
vp9_compute_qdelta(rc, current_q, new_q, cm->bit_depth);
*bottom_index = q;
*top_index = q;
@@ -810,6 +921,21 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
int active_best_quality;
int active_worst_quality = cpi->twopass.active_worst_quality;
int q;
#if !CONFIG_MULTIPLE_ARF
int *kf_low_motion_minq;
int *kf_high_motion_minq;
#endif
int *arfgf_low_motion_minq;
int *arfgf_high_motion_minq;
int *inter_minq;
#if !CONFIG_MULTIPLE_ARF
ASSIGN_MINQ_TABLE(cm->bit_depth, kf_low_motion_minq);
ASSIGN_MINQ_TABLE(cm->bit_depth, kf_high_motion_minq);
#endif
ASSIGN_MINQ_TABLE(cm->bit_depth, arfgf_low_motion_minq);
ASSIGN_MINQ_TABLE(cm->bit_depth, arfgf_high_motion_minq);
ASSIGN_MINQ_TABLE(cm->bit_depth, inter_minq);
if (frame_is_intra_only(cm) || vp9_is_upper_layer_key_frame(cpi)) {
#if !CONFIG_MULTIPLE_ARF
@@ -818,9 +944,10 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
// based on the ambient Q to reduce the risk of popping.
if (rc->this_key_frame_forced) {
int qindex = rc->last_boosted_qindex;
double last_boosted_q = vp9_convert_qindex_to_q(qindex);
double last_boosted_q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
int delta_qindex = vp9_compute_qdelta(rc, last_boosted_q,
last_boosted_q * 0.75);
last_boosted_q * 0.75,
cm->bit_depth);
active_best_quality = MAX(qindex + delta_qindex, rc->best_quality);
} else {
// Not forced keyframe.
@@ -843,16 +970,17 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
// Convert the adjustment factor to a qindex delta
// on active_best_quality.
q_val = vp9_convert_qindex_to_q(active_best_quality);
q_val = vp9_convert_qindex_to_q(active_best_quality, cm->bit_depth);
active_best_quality += vp9_compute_qdelta(rc, q_val,
q_val * q_adj_factor);
q_val * q_adj_factor,
cm->bit_depth);
}
#else
double current_q;
// Force the KF quantizer to be 30% of the active_worst_quality.
current_q = vp9_convert_qindex_to_q(active_worst_quality);
current_q = vp9_convert_qindex_to_q(active_worst_quality, cm->bit_depth);
active_best_quality = active_worst_quality
+ vp9_compute_qdelta(rc, current_q, current_q * 0.3);
+ vp9_compute_qdelta(rc, current_q, current_q * 0.3, cm->bit_depth);
#endif
} else if (!rc->is_src_frame_alt_ref &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
@@ -924,12 +1052,14 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
if ((cm->frame_type == KEY_FRAME || vp9_is_upper_layer_key_frame(cpi)) &&
!rc->this_key_frame_forced) {
qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
active_worst_quality, 2.0);
active_worst_quality, 2.0,
cm->bit_depth);
} else if (!rc->is_src_frame_alt_ref &&
(oxcf->rc_mode != RC_MODE_CBR) &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
active_worst_quality, 1.75);
active_worst_quality, 1.75,
cm->bit_depth);
}
*top_index = active_worst_quality + qdelta;
*top_index = (*top_index > *bottom_index) ? *top_index : *bottom_index;
@@ -957,12 +1087,13 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
if (cpi->multi_arf_enabled && (cm->frame_type != KEY_FRAME) &&
cpi->oxcf.rc_mode != RC_MODE_CONSTANT_QUALITY) {
double new_q;
double current_q = vp9_convert_qindex_to_q(active_worst_quality);
double current_q = vp9_convert_qindex_to_q(active_worst_quality,
cm->bit_depth);
int level = cpi->this_frame_weight;
assert(level >= 0);
new_q = current_q * (1.0 - (0.2 * (cpi->max_arf_level - level)));
q = active_worst_quality +
vp9_compute_qdelta(rc, current_q, new_q);
vp9_compute_qdelta(rc, current_q, new_q, cm->bit_depth);
*bottom_index = q;
*top_index = q;
@@ -1098,7 +1229,7 @@ void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) {
rc->avg_frame_qindex[INTER_FRAME] =
ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[INTER_FRAME] + qindex, 2);
rc->ni_frames++;
rc->tot_q += vp9_convert_qindex_to_q(qindex);
rc->tot_q += vp9_convert_qindex_to_q(qindex, cm->bit_depth);
rc->avg_q = rc->tot_q / rc->ni_frames;
// Calculate the average Q for normal inter frames (not key or GFU frames).
rc->ni_tot_qi += qindex;
@@ -1347,7 +1478,8 @@ void vp9_rc_get_one_pass_cbr_params(VP9_COMP *cpi) {
rc->baseline_gf_interval = INT_MAX;
}
int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget) {
int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget,
vpx_bit_depth_t bit_depth) {
int start_index = rc->worst_quality;
int target_index = rc->worst_quality;
int i;
@@ -1355,14 +1487,14 @@ int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget) {
// Convert the average q value to an index.
for (i = rc->best_quality; i < rc->worst_quality; ++i) {
start_index = i;
if (vp9_convert_qindex_to_q(i) >= qstart)
if (vp9_convert_qindex_to_q(i, bit_depth) >= qstart)
break;
}
// Convert the q target to an index
for (i = rc->best_quality; i < rc->worst_quality; ++i) {
target_index = i;
if (vp9_convert_qindex_to_q(i) >= qtarget)
if (vp9_convert_qindex_to_q(i, bit_depth) >= qtarget)
break;
}
@@ -1370,12 +1502,14 @@ int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget) {
}
int vp9_compute_qdelta_by_rate(const RATE_CONTROL *rc, FRAME_TYPE frame_type,
int qindex, double rate_target_ratio) {
int qindex, double rate_target_ratio,
vpx_bit_depth_t bit_depth) {
int target_index = rc->worst_quality;
int i;
// Look up the current projected bits per block for the base index
const int base_bits_per_mb = vp9_rc_bits_per_mb(frame_type, qindex, 1.0);
const int base_bits_per_mb = vp9_rc_bits_per_mb(frame_type, qindex, 1.0,
bit_depth);
// Find the target bits per mb based on the base value and given ratio.
const int target_bits_per_mb = (int)(rate_target_ratio * base_bits_per_mb);
@@ -1383,7 +1517,7 @@ int vp9_compute_qdelta_by_rate(const RATE_CONTROL *rc, FRAME_TYPE frame_type,
// Convert the q target to an index
for (i = rc->best_quality; i < rc->worst_quality; ++i) {
target_index = i;
if (vp9_rc_bits_per_mb(frame_type, i, 1.0) <= target_bits_per_mb )
if (vp9_rc_bits_per_mb(frame_type, i, 1.0, bit_depth) <= target_bits_per_mb)
break;
}

View File

@@ -13,6 +13,7 @@
#define VP9_ENCODER_VP9_RATECTRL_H_
#include "vpx/vpx_integer.h"
#include "vpx/vpx_codec.h"
#include "vp9/common/vp9_blockd.h"
@@ -93,7 +94,7 @@ struct VP9EncoderConfig;
void vp9_rc_init(const struct VP9EncoderConfig *oxcf, int pass,
RATE_CONTROL *rc);
double vp9_convert_qindex_to_q(int qindex);
double vp9_convert_qindex_to_q(int qindex, vpx_bit_depth_t bit_depth);
void vp9_rc_init_minq_luts();
@@ -156,7 +157,7 @@ int vp9_rc_regulate_q(const struct VP9_COMP *cpi, int target_bits_per_frame,
// Estimates bits per mb for a given qindex and correction factor.
int vp9_rc_bits_per_mb(FRAME_TYPE frame_type, int qindex,
double correction_factor);
double correction_factor, vpx_bit_depth_t bit_depth);
// Clamping utilities for bitrate targets for iframes and pframes.
int vp9_rc_clamp_iframe_target_size(const struct VP9_COMP *const cpi,
@@ -169,12 +170,14 @@ void vp9_rc_set_frame_target(struct VP9_COMP *cpi, int target);
// Computes a q delta (in "q index" terms) to get from a starting q value
// to a target q value
int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget);
int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget,
vpx_bit_depth_t bit_depth);
// Computes a q delta (in "q index" terms) to get from a starting q value
// to a value that should equate to the given rate ratio.
int vp9_compute_qdelta_by_rate(const RATE_CONTROL *rc, FRAME_TYPE frame_type,
int qindex, double rate_target_ratio);
int qindex, double rate_target_ratio,
vpx_bit_depth_t bit_depth);
void vp9_rc_update_framerate(struct VP9_COMP *cpi);

View File

@@ -14,6 +14,7 @@
#include <stdio.h>
#include "./vp9_rtcd.h"
#include "./vpx_config.h"
#include "vpx_mem/vpx_mem.h"
@@ -34,6 +35,7 @@
#include "vp9/encoder/vp9_encodemv.h"
#include "vp9/encoder/vp9_encoder.h"
#include "vp9/encoder/vp9_mcomp.h"
#include "vp9/encoder/vp9_pickmode.h"
#include "vp9/encoder/vp9_quantize.h"
#include "vp9/encoder/vp9_ratectrl.h"
#include "vp9/encoder/vp9_rdopt.h"
@@ -201,26 +203,62 @@ static const uint8_t rd_iifactor[32] = {
// 3* dc_qlookup[Q]*dc_qlookup[Q];
/* values are now correlated to quantizer */
static int sad_per_bit16lut[QINDEX_RANGE];
static int sad_per_bit4lut[QINDEX_RANGE];
static int sad_per_bit16lut_8[QINDEX_RANGE];
static int sad_per_bit4lut_8[QINDEX_RANGE];
void vp9_init_me_luts() {
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
static int sad_per_bit16lut_10[QINDEX_RANGE_10];
static int sad_per_bit4lut_10[QINDEX_RANGE_10];
static int sad_per_bit16lut_12[QINDEX_RANGE_12];
static int sad_per_bit4lut_12[QINDEX_RANGE_12];
#endif
static void init_me_luts_bd(int *bit16lut, int *bit4lut, int range,
vpx_bit_depth_t bit_depth) {
int i;
// Initialize the sad lut tables using a formulaic calculation for now
// This is to make it easier to resolve the impact of experimental changes
// to the quantizer tables.
for (i = 0; i < QINDEX_RANGE; i++) {
const double q = vp9_convert_qindex_to_q(i);
sad_per_bit16lut[i] = (int)(0.0418 * q + 2.4107);
sad_per_bit4lut[i] = (int)(0.063 * q + 2.742);
for (i = 0; i < range; i++) {
const double q = vp9_convert_qindex_to_q(i, bit_depth);
bit16lut[i] = (int)(0.0418 * q + 2.4107);
bit4lut[i] = (int)(0.063 * q + 2.742);
}
}
void vp9_init_me_luts() {
init_me_luts_bd(sad_per_bit16lut_8, sad_per_bit4lut_8, QINDEX_RANGE,
VPX_BITS_8);
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
init_me_luts_bd(sad_per_bit16lut_10, sad_per_bit4lut_10, QINDEX_RANGE_10,
VPX_BITS_10);
init_me_luts_bd(sad_per_bit16lut_12, sad_per_bit4lut_12, QINDEX_RANGE_12,
VPX_BITS_12);
#endif
}
int vp9_compute_rd_mult(const VP9_COMP *cpi, int qindex) {
const int q = vp9_dc_quant(qindex, 0, VPX_BITS_8);
int rdmult;
const int64_t q = vp9_dc_quant(qindex, 0, cpi->common.bit_depth);
// TODO(debargha): Adjust the function below
int rdmult = 88 * q * q / 25;
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
switch (cpi->common.bit_depth) {
case VPX_BITS_8:
rdmult = 88 * q * q / 25;
break;
case VPX_BITS_10:
rdmult = ROUND_POWER_OF_TWO(88 * q * q / 25, 4);
break;
case VPX_BITS_12:
rdmult = ROUND_POWER_OF_TWO(88 * q * q / 25, 8);
break;
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#else
rdmult = 88 * q * q / 25;
#endif
if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME)) {
if (cpi->twopass.next_iiratio > 31)
rdmult += (rdmult * rd_iifactor[31]) >> 4;
@@ -230,16 +268,52 @@ int vp9_compute_rd_mult(const VP9_COMP *cpi, int qindex) {
return rdmult;
}
static int compute_rd_thresh_factor(int qindex) {
static int compute_rd_thresh_factor(int qindex, vpx_bit_depth_t bit_depth) {
double q;
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
switch (bit_depth) {
case VPX_BITS_8:
q = vp9_dc_quant(qindex, 0, VPX_BITS_8) / 4.0;
break;
case VPX_BITS_10:
q = vp9_dc_quant(qindex, 0, VPX_BITS_10) / 16.0;
break;
case VPX_BITS_12:
q = vp9_dc_quant(qindex, 0, VPX_BITS_12) / 64.0;
break;
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#else
(void) bit_depth;
q = vp9_dc_quant(qindex, 0, VPX_BITS_8) / 4.0;
#endif
// TODO(debargha): Adjust the function below
const int q = (int)(pow(vp9_dc_quant(qindex, 0, VPX_BITS_8) / 4.0,
RD_THRESH_POW) * 5.12);
return MAX(q, 8);
return MAX((int)(pow(q, RD_THRESH_POW) * 5.12), 8);
}
void vp9_initialize_me_consts(VP9_COMP *cpi, int qindex) {
cpi->mb.sadperbit16 = sad_per_bit16lut[qindex];
cpi->mb.sadperbit4 = sad_per_bit4lut[qindex];
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
switch (cpi->common.bit_depth) {
case VPX_BITS_8:
cpi->mb.sadperbit16 = sad_per_bit16lut_8[qindex];
cpi->mb.sadperbit4 = sad_per_bit4lut_8[qindex];
break;
case VPX_BITS_10:
cpi->mb.sadperbit16 = sad_per_bit16lut_10[qindex];
cpi->mb.sadperbit4 = sad_per_bit4lut_10[qindex];
break;
case VPX_BITS_12:
cpi->mb.sadperbit16 = sad_per_bit16lut_12[qindex];
cpi->mb.sadperbit4 = sad_per_bit4lut_12[qindex];
break;
default:
assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
}
#else
cpi->mb.sadperbit16 = sad_per_bit16lut_8[qindex];
cpi->mb.sadperbit4 = sad_per_bit4lut_8[qindex];
#endif
}
static void swap_block_ptr(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx,
@@ -271,10 +345,11 @@ static void set_block_thresholds(const VP9_COMMON *cm, RD_OPT *rd) {
int i, bsize, segment_id;
for (segment_id = 0; segment_id < MAX_SEGMENTS; ++segment_id) {
const int qindex = clamp(vp9_get_qindex(&cm->seg, segment_id,
cm->base_qindex) + cm->y_dc_delta_q,
0, MAXQ);
const int q = compute_rd_thresh_factor(qindex);
const int qindex = clamp(
vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex, cm->bit_depth) +
cm->y_dc_delta_q, 0, vp9_get_maxq(cm->bit_depth));
const int q = compute_rd_thresh_factor(qindex, cm->bit_depth);
for (bsize = 0; bsize < BLOCK_SIZES; ++bsize) {
// Threshold here seems unnecessarily harsh but fine given actual
@@ -495,7 +570,7 @@ static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize,
} else {
int rate;
int64_t dist;
#if CONFIG_HIGH_TRANSFORMS && CONFIG_VP9_HIGH
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
if (xd->cur_buf->flags & YV12_FLAG_HIGH) {
vp9_model_rd_from_var_lapndz(sse, 1 << num_pels_log2_lookup[bs],
pd->dequant[1] >> (xd->bps - 5),
@@ -554,7 +629,7 @@ static void model_rd_for_sb_y_tx(VP9_COMP *cpi, BLOCK_SIZE bsize,
&pd->dst.buf[j * pd->dst.stride + k], pd->dst.stride,
&sse);
// sse works better than var, since there is no dc prediction used
#if CONFIG_HIGH_TRANSFORMS && CONFIG_VP9_HIGH
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
if (xd->cur_buf->flags & YV12_FLAG_HIGH) {
vp9_model_rd_from_var_lapndz(sse, t * t,
pd->dequant[1] >> (xd->bps - 5),
@@ -646,10 +721,25 @@ static INLINE int cost_coeffs(MACROBLOCK *x,
uint8_t token_cache[32 * 32];
int pt = combine_entropy_contexts(*A, *L);
int c, cost;
const TOKENVALUE *dct_value_tokens;
const int16_t *dct_value_cost;
// Check for consistency of tx_size with mode info
assert(type == PLANE_TYPE_Y ? mbmi->tx_size == tx_size
: get_uv_tx_size(mbmi) == tx_size);
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
if (xd->bps > 8) {
dct_value_tokens = vp9_dct_value_tokens_high_ptr;
dct_value_cost = vp9_dct_value_cost_high_ptr;
} else {
dct_value_tokens = vp9_dct_value_tokens_ptr;
dct_value_cost = vp9_dct_value_cost_ptr;
}
#else
dct_value_tokens = vp9_dct_value_tokens_ptr;
dct_value_cost = vp9_dct_value_cost_ptr;
#endif
if (eob == 0) {
// single eob token
cost = token_costs[0][0][pt][EOB_TOKEN];
@@ -659,8 +749,8 @@ static INLINE int cost_coeffs(MACROBLOCK *x,
// dc token
int v = qcoeff[0];
int prev_t = vp9_dct_value_tokens_ptr[v].token;
cost = (*token_costs)[0][pt][prev_t] + vp9_dct_value_cost_ptr[v];
int prev_t = dct_value_tokens[v].token;
cost = (*token_costs)[0][pt][prev_t] + dct_value_cost[v];
token_cache[0] = vp9_pt_energy_class[prev_t];
++token_costs;
@@ -670,12 +760,12 @@ static INLINE int cost_coeffs(MACROBLOCK *x,
int t;
v = qcoeff[rc];
t = vp9_dct_value_tokens_ptr[v].token;
t = dct_value_tokens[v].token;
if (use_fast_coef_costing) {
cost += (*token_costs)[!prev_t][!prev_t][t] + vp9_dct_value_cost_ptr[v];
cost += (*token_costs)[!prev_t][!prev_t][t] + dct_value_cost[v];
} else {
pt = get_coef_context(nb, token_cache, c);
cost += (*token_costs)[!prev_t][pt][t] + vp9_dct_value_cost_ptr[v];
cost += (*token_costs)[!prev_t][pt][t] + dct_value_cost[v];
token_cache[rc] = vp9_pt_energy_class[t];
}
prev_t = t;
@@ -1235,7 +1325,7 @@ static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int ib,
ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4,
so->scan, so->neighbors,
cpi->sf.use_fast_coef_costing);
#if CONFIG_HIGH_TRANSFORMS
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
distortion += vp9_high_block_error(coeff,
BLOCK_OFFSET(pd->dqcoeff, block), 16, &unused,
xd->bps) >> 2;
@@ -3109,7 +3199,7 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
// Calculate threshold according to dequant value.
thresh_ac = (xd->plane[0].dequant[1] * xd->plane[0].dequant[1]) / 9;
#if CONFIG_HIGH_TRANSFORMS && CONFIG_VP9_HIGH
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
if (xd->cur_buf->flags & YV12_FLAG_HIGH) {
const int shift = 2 * xd->bps - 16;
if (shift > 0)
@@ -3132,7 +3222,7 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
unsigned int thresh_dc;
thresh_dc = (xd->plane[0].dequant[0] * xd->plane[0].dequant[0] >> 6);
#if CONFIG_HIGH_TRANSFORMS && CONFIG_VP9_HIGH
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
if (xd->cur_buf->flags & YV12_FLAG_HIGH) {
const int shift = 2 * xd->bps - 16;
if (shift > 0)
@@ -3349,8 +3439,9 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
int skip_uv[TX_SIZES];
PREDICTION_MODE mode_uv[TX_SIZES];
int64_t mode_distortions[MB_MODE_COUNT] = {-1};
int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q,
VPX_BITS_8);
int intra_cost_penalty = vp9_get_intra_cost_penalty(cm->base_qindex,
cm->y_dc_delta_q,
cm->bit_depth);
const int bws = num_8x8_blocks_wide_lookup[bsize] / 2;
const int bhs = num_8x8_blocks_high_lookup[bsize] / 2;
int best_skip2 = 0;
@@ -3754,7 +3845,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
int qstep = xd->plane[0].dequant[1];
// TODO(debargha): Enhance this by specializing for each mode_index
int scale = 4;
#if CONFIG_HIGH_TRANSFORMS && CONFIG_VP9_HIGH
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
if (xd->cur_buf->flags & YV12_FLAG_HIGH) {
qstep >>= (xd->bps - 8);
}
@@ -3961,8 +4052,9 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
int64_t dist_uv;
int skip_uv;
PREDICTION_MODE mode_uv = DC_PRED;
int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q,
VPX_BITS_8);
int intra_cost_penalty = vp9_get_intra_cost_penalty(cm->base_qindex,
cm->y_dc_delta_q,
cm->bit_depth);
int_mv seg_mvs[4][MAX_REF_FRAMES];
b_mode_info best_bmodes[4];
int best_skip2 = 0;
@@ -4418,7 +4510,7 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
int qstep = xd->plane[0].dequant[1];
// TODO(debargha): Enhance this by specializing for each mode_index
int scale = 4;
#if CONFIG_HIGH_TRANSFORMS && CONFIG_VP9_HIGH
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS
if (xd->cur_buf->flags & YV12_FLAG_HIGH) {
qstep >>= (xd->bps - 8);
}

View File

@@ -733,10 +733,10 @@ void vp9_configure_arnr_filter(VP9_COMP *cpi,
// Adjust the strength based on active max q
if (cpi->common.current_video_frame > 1)
q = ((int)vp9_convert_qindex_to_q(
cpi->rc.avg_frame_qindex[INTER_FRAME]));
cpi->rc.avg_frame_qindex[INTER_FRAME], cpi->common.bit_depth));
else
q = ((int)vp9_convert_qindex_to_q(
cpi->rc.avg_frame_qindex[KEY_FRAME]));
cpi->rc.avg_frame_qindex[KEY_FRAME], cpi->common.bit_depth));
if (q > 16) {
cpi->active_arnr_strength = cpi->oxcf.arnr_strength;
} else {

View File

@@ -13,6 +13,8 @@
#include <stdio.h>
#include <string.h>
#include "./vpx_config.h"
#include "vpx_mem/vpx_mem.h"
#include "vp9/common/vp9_entropy.h"
@@ -28,6 +30,14 @@ const TOKENVALUE *vp9_dct_value_tokens_ptr;
static int16_t dct_value_cost[DCT_MAX_VALUE * 2];
const int16_t *vp9_dct_value_cost_ptr;
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
static TOKENVALUE dct_value_tokens_high[DCT_MAX_VALUE_HIGH * 2];
const TOKENVALUE *vp9_dct_value_tokens_high_ptr;
static int16_t dct_value_cost_high[DCT_MAX_VALUE_HIGH * 2];
const int16_t *vp9_dct_value_cost_high_ptr;
#endif
// Array indices are identical to previously-existing CONTEXT_NODE indices
const vp9_tree_index vp9_coef_tree[TREE_SIZE(ENTROPY_TOKENS)] = {
-EOB_TOKEN, 2, // 0 = EOB
@@ -66,6 +76,14 @@ static const vp9_prob Pcat6[] = {
static vp9_tree_index cat1[2], cat2[4], cat3[6], cat4[8], cat5[10], cat6[28];
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
static const vp9_prob Pcat6_high[] = {
254, 254, 254, 254, 254, 254, 254, 252, 249,
243, 230, 196, 177, 153, 140, 133, 130, 129
};
static vp9_tree_index cat6_high[36];
#endif
static void init_bit_tree(vp9_tree_index *p, int n) {
int i = 0;
@@ -84,6 +102,9 @@ static void init_bit_trees() {
init_bit_tree(cat4, 4);
init_bit_tree(cat5, 5);
init_bit_tree(cat6, 14);
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
init_bit_tree(cat6_high, 18);
#endif
}
const vp9_extra_bit vp9_extra_bits[ENTROPY_TOKENS] = {
@@ -101,6 +122,23 @@ const vp9_extra_bit vp9_extra_bits[ENTROPY_TOKENS] = {
{0, 0, 0, 0} // EOB_TOKEN
};
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
const vp9_extra_bit vp9_extra_bits_high[ENTROPY_TOKENS] = {
{0, 0, 0, 0}, // ZERO_TOKEN
{0, 0, 0, 1}, // ONE_TOKEN
{0, 0, 0, 2}, // TWO_TOKEN
{0, 0, 0, 3}, // THREE_TOKEN
{0, 0, 0, 4}, // FOUR_TOKEN
{cat1, Pcat1, 1, 5}, // CATEGORY1_TOKEN
{cat2, Pcat2, 2, 7}, // CATEGORY2_TOKEN
{cat3, Pcat3, 3, 11}, // CATEGORY3_TOKEN
{cat4, Pcat4, 4, 19}, // CATEGORY4_TOKEN
{cat5, Pcat5, 5, 35}, // CATEGORY5_TOKEN
{cat6_high, Pcat6_high, 18, 67}, // CATEGORY6_TOKEN
{0, 0, 0, 0} // EOB_TOKEN
};
#endif
struct vp9_token vp9_coef_encodings[ENTROPY_TOKENS];
void vp9_coef_tree_initialize() {
@@ -108,11 +146,9 @@ void vp9_coef_tree_initialize() {
vp9_tokens_from_tree(vp9_coef_encodings, vp9_coef_tree);
}
void vp9_tokenize_initialize() {
TOKENVALUE *const t = dct_value_tokens + DCT_MAX_VALUE;
const vp9_extra_bit *const e = vp9_extra_bits;
int i = -DCT_MAX_VALUE;
static void tokenize_init_one(TOKENVALUE *t, const vp9_extra_bit *const e,
int16_t *value_cost, int max_value) {
int i = -max_value;
int sign = 1;
do {
@@ -139,7 +175,7 @@ void vp9_tokenize_initialize() {
// initialize the cost for extra bits for all possible coefficient value.
{
int cost = 0;
const vp9_extra_bit *p = &vp9_extra_bits[t[i].token];
const vp9_extra_bit *p = &e[t[i].token];
if (p->base_val) {
const int extra = t[i].extra;
@@ -149,13 +185,27 @@ void vp9_tokenize_initialize() {
cost += treed_cost(p->tree, p->prob, extra >> 1, length);
cost += vp9_cost_bit(vp9_prob_half, extra & 1); /* sign */
dct_value_cost[i + DCT_MAX_VALUE] = cost;
value_cost[i] = cost;
}
}
} while (++i < DCT_MAX_VALUE);
} while (++i < max_value);
}
void vp9_tokenize_initialize() {
vp9_dct_value_tokens_ptr = dct_value_tokens + DCT_MAX_VALUE;
vp9_dct_value_cost_ptr = dct_value_cost + DCT_MAX_VALUE;
tokenize_init_one(dct_value_tokens + DCT_MAX_VALUE, vp9_extra_bits,
dct_value_cost + DCT_MAX_VALUE, DCT_MAX_VALUE);
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
vp9_dct_value_tokens_high_ptr = dct_value_tokens_high + DCT_MAX_VALUE_HIGH;
vp9_dct_value_cost_high_ptr = dct_value_cost_high + DCT_MAX_VALUE_HIGH;
tokenize_init_one(dct_value_tokens_high + DCT_MAX_VALUE_HIGH,
vp9_extra_bits_high,
dct_value_cost_high + DCT_MAX_VALUE_HIGH,
DCT_MAX_VALUE_HIGH);
#endif
}
struct tokenize_b_args {
@@ -177,7 +227,7 @@ static void set_entropy_context_b(int plane, int block, BLOCK_SIZE plane_bsize,
}
static INLINE void add_token(TOKENEXTRA **t, const vp9_prob *context_tree,
int16_t extra, uint8_t token,
int32_t extra, uint8_t token,
uint8_t skip_eob_node,
unsigned int *counts) {
(*t)->token = token;
@@ -234,6 +284,7 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE plane_bsize,
cpi->common.counts.eob_branch[tx_size][type][ref];
const uint8_t *const band = get_band_translate(tx_size);
const int seg_eob = get_tx_eob(&cpi->common.seg, segment_id, tx_size);
const TOKENVALUE *dct_value_tokens;
int aoff, loff;
txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &aoff, &loff);
@@ -244,6 +295,15 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE plane_bsize,
scan = so->scan;
nb = so->neighbors;
c = 0;
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
if (cpi->common.profile > PROFILE_1) {
dct_value_tokens = vp9_dct_value_tokens_high_ptr;
} else {
dct_value_tokens = vp9_dct_value_tokens_ptr;
}
#else
dct_value_tokens = vp9_dct_value_tokens_ptr;
#endif
while (c < eob) {
int v = 0;
int skip_eob = 0;
@@ -260,16 +320,15 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE plane_bsize,
pt = get_coef_context(nb, token_cache, c);
v = qcoeff[scan[c]];
}
add_token(&t, coef_probs[band[c]][pt],
vp9_dct_value_tokens_ptr[v].extra,
(uint8_t)vp9_dct_value_tokens_ptr[v].token,
dct_value_tokens[v].extra,
(uint8_t)dct_value_tokens[v].token,
(uint8_t)skip_eob,
counts[band[c]][pt]);
eob_branch[band[c]][pt] += !skip_eob;
token_cache[scan[c]] =
vp9_pt_energy_class[vp9_dct_value_tokens_ptr[v].token];
vp9_pt_energy_class[dct_value_tokens[v].token];
++c;
pt = get_coef_context(nb, token_cache, c);
}

View File

@@ -26,12 +26,20 @@ void vp9_tokenize_initialize();
typedef struct {
int16_t token;
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
int32_t extra;
#else
int16_t extra;
#endif
} TOKENVALUE;
typedef struct {
const vp9_prob *context_tree;
int16_t extra;
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
int32_t extra;
#else
int16_t extra;
#endif
uint8_t token;
uint8_t skip_eob_node;
} TOKENEXTRA;
@@ -54,6 +62,11 @@ extern const int16_t *vp9_dct_value_cost_ptr;
*/
extern const TOKENVALUE *vp9_dct_value_tokens_ptr;
#if CONFIG_VP9_HIGH && CONFIG_HIGH_TRANSFORMS && CONFIG_HIGH_QUANT
extern const int16_t *vp9_dct_value_cost_high_ptr;
extern const TOKENVALUE *vp9_dct_value_tokens_high_ptr;
#endif
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -346,9 +346,12 @@ static vpx_codec_err_t set_encoder_config(
oxcf->target_bandwidth = cfg->rc_target_bitrate;
oxcf->rc_max_intra_bitrate_pct = extra_cfg->rc_max_intra_bitrate_pct;
oxcf->best_allowed_q = vp9_quantizer_to_qindex(cfg->rc_min_quantizer);
oxcf->worst_allowed_q = vp9_quantizer_to_qindex(cfg->rc_max_quantizer);
oxcf->cq_level = vp9_quantizer_to_qindex(extra_cfg->cq_level);
oxcf->best_allowed_q = vp9_quantizer_to_qindex(cfg->rc_min_quantizer,
oxcf->bit_depth);
oxcf->worst_allowed_q = vp9_quantizer_to_qindex(cfg->rc_max_quantizer,
oxcf->bit_depth);
oxcf->cq_level = vp9_quantizer_to_qindex(extra_cfg->cq_level,
oxcf->bit_depth);
oxcf->fixed_q = -1;
oxcf->under_shoot_pct = cfg->rc_undershoot_pct;
@@ -490,7 +493,8 @@ static vpx_codec_err_t ctrl_get_param(vpx_codec_alg_priv_t *ctx, int ctrl_id,
switch (ctrl_id) {
MAP(VP8E_GET_LAST_QUANTIZER, vp9_get_quantizer(ctx->cpi));
MAP(VP8E_GET_LAST_QUANTIZER_64,
vp9_qindex_to_quantizer(vp9_get_quantizer(ctx->cpi)));
vp9_qindex_to_quantizer(vp9_get_quantizer(ctx->cpi),
ctx->oxcf.bit_depth));
}
return VPX_CODEC_OK;

View File

@@ -986,6 +986,9 @@ int main_loop(int argc, const char **argv_) {
// Fallback to 8bit
bit_depth = VPX_BITS_8;
}
// Default to codec bit depth if output bit depth not set
if (!out_bit_depth)
out_bit_depth = bit_depth * 2 + 8;
if (out_bit_depth != 8 &&
out_bit_depth != bit_depth * 2 + 8) {
fprintf(stderr, "Does not support bit-depth conversion to: %d.\n",