1 use nihav_codec_support::codecs::{MV, ZERO_MV};
2 use super::mb::{Coeffs, InterMB};
3 //use super::super::vpcommon::VPMBType;
5 // todo replace with an approximation formula
6 const AVG_NITS_PER_MB_INTRA: [u32; 64] = [
7 143, 146, 148, 150, 154, 163, 169, 177,
8 185, 193, 206, 218, 232, 238, 242, 246,
9 250, 260, 265, 270, 275, 283, 290, 297,
10 304, 319, 327, 343, 358, 368, 381, 393,
11 405, 417, 432, 445, 460, 476, 501, 520,
12 543, 564, 591, 617, 645, 678, 711, 746,
13 786, 833, 892, 966, 1031, 1102, 1187, 1281,
14 1395, 1539, 1711, 1938, 2247, 2655, 3314, 4625
16 const AVG_NITS_PER_MB_INTER: [u32; 64] = [
17 112, 112, 112, 112, 110, 111, 111, 112,
18 112, 113, 112, 118, 121, 117, 118, 118,
19 119, 118, 118, 119, 120, 122, 123, 124,
20 126, 126, 128, 132, 138, 141, 139, 141,
21 148, 151, 152, 155, 158, 162, 172, 177,
22 183, 189, 195, 203, 210, 220, 231, 243,
23 256, 272, 289, 313, 337, 363, 396, 435,
24 481, 539, 613, 710, 864, 1079, 1430, 2225
26 const AVG_NITS_PER_MB_INTRA_HUFF: [u32; 64] = [
27 176, 179, 181, 184, 188, 198, 205, 213,
28 223, 233, 247, 260, 276, 283, 288, 292,
29 297, 307, 313, 318, 324, 334, 341, 349,
30 357, 374, 383, 401, 417, 429, 441, 455,
31 469, 482, 499, 513, 530, 547, 572, 594,
32 621, 644, 673, 703, 734, 771, 807, 847,
33 893, 948, 1016, 1097, 1168, 1244, 1335, 1436,
34 1555, 1708, 1890, 2130, 2461, 2897, 3604, 5014
36 const AVG_NITS_PER_MB_INTER_HUFF: [u32; 64] = [
37 126, 126, 126, 126, 125, 125, 126, 127,
38 127, 129, 127, 134, 137, 134, 134, 135,
39 136, 135, 136, 137, 138, 141, 142, 143,
40 145, 146, 147, 152, 160, 163, 161, 164,
41 171, 174, 176, 180, 183, 188, 199, 206,
42 212, 219, 227, 236, 244, 255, 268, 281,
43 296, 315, 334, 362, 389, 419, 456, 500,
44 550, 613, 695, 799, 971, 1205, 1581, 2437
47 // todo replace with an approximation formula
48 const HDR_SIZES: [(u32, u32); 64] = [
49 (5867, 797), (5971, 802), (5975, 798), (5986, 814),
50 (6152, 802), (6269, 821), (6457, 827), (6620, 855),
51 (6865, 865), (6852, 878), (7103, 885), (7295, 924),
52 (7658, 952), (7710, 950), (7851, 959), (8119, 963),
53 (8119, 962), (8292, 914), (8238, 920), (8260, 949),
54 (8174, 943), (8515, 952), (8625, 976), (8784, 979),
55 (8687, 987), (8853, 1007), (8934, 998), (9270, 1013),
56 (9524, 1082), (9595, 1117), (9889, 1060), (10187, 1070),
57 (10241, 1143), (10527, 1164), (10691, 1151), (10694, 1188),
58 (10959, 1132), (11092, 1168), (11197, 1237), (11443, 1267),
59 (11573, 1295), (11856, 1309), (12165, 1340), (12299, 1364),
60 (12767, 1344), (13108, 1373), (13262, 1407), (13497, 1420),
61 (14019, 1458), (14442, 1525), (14935, 1574), (15155, 1626),
62 (15682, 1691), (15936, 1754), (16394, 1859), (16953, 1944),
63 (17407, 2078), (18143, 2195), (18850, 2339), (19677, 2525),
64 (20546, 2786), (21228, 3093), (22549, 3469), (24164, 4144)
67 pub fn estimate_frame_size(intra: bool, huffman: bool, q: usize, mb_w: usize, mb_h: usize) -> usize {
68 let hdr_nits = if intra { HDR_SIZES[q].0 } else { HDR_SIZES[q].1 } as usize;
69 let avg_mb_nits = match (huffman, intra) {
70 (false, true) => AVG_NITS_PER_MB_INTRA[q],
71 (false, false) => AVG_NITS_PER_MB_INTER[q],
72 (true, true) => AVG_NITS_PER_MB_INTRA_HUFF[q],
73 (true, false) => AVG_NITS_PER_MB_INTER_HUFF[q],
75 (hdr_nits + avg_mb_nits * mb_w * mb_h + 7) >> 3
78 pub fn estimate_mv_nits(mv: MV) -> u32 {
79 (mv.x.abs() + mv.y.abs()).min(32) as u32
82 // todo make an approximation
83 const NITS_PER_BLOCK: [[u32; 65]; 16] = [
85 0, 42, 103, 150, 197, 245, 290, 332, 362, 399, 438, 485, 516, 555, 568, 615, 645, 704, 752, 775, 829, 807, 850, 847, 847, 424, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938, 938
87 0, 44, 103, 151, 198, 245, 292, 340, 373, 405, 452, 498, 527, 570, 604, 638, 658, 697, 727, 764, 807, 842, 887, 986, 893, 985, 1048, 1018, 1018, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013, 1013
89 0, 47, 105, 154, 200, 246, 295, 342, 380, 419, 458, 498, 547, 585, 626, 664, 693, 734, 772, 809, 842, 853, 864, 920, 955, 981, 1031, 1045, 1096, 1152, 1184, 1188, 1206, 1338, 1270, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175, 1175
91 0, 49, 105, 155, 203, 248, 294, 342, 383, 416, 464, 510, 544, 595, 620, 668, 714, 747, 773, 824, 865, 889, 919, 934, 969, 1029, 1010, 1063, 1088, 1158, 1175, 1204, 1207, 1303, 1283, 1358, 1512, 1405, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337, 1337
93 0, 50, 106, 156, 203, 252, 297, 345, 387, 423, 463, 509, 552, 594, 627, 668, 722, 758, 788, 824, 870, 898, 936, 963, 983, 1019, 1023, 1100, 1101, 1140, 1199, 1206, 1240, 1278, 1301, 1368, 1405, 1365, 1445, 1436, 1483, 1562, 1562, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620
95 1, 51, 107, 156, 204, 252, 298, 347, 391, 424, 465, 509, 553, 591, 634, 685, 709, 747, 805, 826, 881, 914, 937, 997, 1023, 1024, 1056, 1091, 1108, 1145, 1214, 1207, 1246, 1260, 1332, 1400, 1391, 1426, 1486, 1552, 1482, 1573, 1626, 1610, 1610, 1692, 1692, 1692, 1692, 1692, 1692, 1692, 1692, 1692, 1692, 1692, 1692, 1692, 1692, 1692, 1692, 1692, 1692, 1692, 1692
97 1, 53, 109, 158, 205, 253, 301, 352, 397, 425, 470, 505, 557, 595, 642, 682, 720, 755, 805, 849, 878, 930, 964, 995, 1034, 1072, 1093, 1142, 1180, 1194, 1219, 1243, 1286, 1318, 1325, 1379, 1403, 1471, 1477, 1473, 1554, 1585, 1593, 1646, 1677, 1692, 1763, 1825, 1817, 1817, 1817, 1817, 1817, 1817, 1817, 1817, 1817, 1817, 1817, 1817, 1817, 1817, 1817, 1817, 1817
99 1, 54, 111, 159, 206, 255, 305, 355, 406, 428, 472, 516, 555, 593, 636, 688, 730, 765, 807, 842, 892, 933, 987, 1001, 1050, 1097, 1111, 1167, 1175, 1223, 1255, 1294, 1297, 1342, 1361, 1404, 1408, 1471, 1495, 1560, 1553, 1611, 1635, 1692, 1783, 1695, 1765, 1764, 1906, 1906, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018
101 1, 55, 113, 160, 209, 255, 306, 357, 408, 435, 477, 521, 557, 598, 641, 685, 730, 773, 814, 844, 889, 940, 982, 1008, 1065, 1102, 1124, 1188, 1228, 1251, 1287, 1297, 1350, 1399, 1380, 1436, 1484, 1514, 1537, 1590, 1599, 1642, 1634, 1726, 1762, 1755, 1799, 1862, 1919, 2086, 1712, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984
103 1, 56, 116, 164, 211, 259, 307, 359, 414, 437, 481, 525, 564, 608, 645, 685, 734, 769, 808, 858, 906, 943, 987, 1000, 1058, 1101, 1145, 1183, 1211, 1274, 1274, 1357, 1384, 1412, 1469, 1454, 1505, 1543, 1563, 1617, 1639, 1667, 1681, 1762, 1770, 1797, 1869, 1853, 1909, 1978, 2077, 2034, 1967, 2139, 2139, 2139, 2139, 2139, 2139, 2139, 2139, 2139, 2139, 2139, 2139
105 1, 59, 118, 166, 213, 261, 309, 360, 416, 437, 483, 524, 570, 611, 651, 686, 732, 768, 806, 844, 895, 938, 983, 1025, 1071, 1103, 1149, 1193, 1226, 1258, 1312, 1340, 1405, 1425, 1479, 1547, 1555, 1588, 1612, 1641, 1662, 1723, 1739, 1797, 1841, 1854, 1888, 1879, 1947, 2025, 2065, 2104, 2158, 2077, 2380, 2177, 2336, 2078, 2078, 2078, 2078, 2078, 2078, 2078, 2078
107 1, 61, 120, 170, 219, 265, 314, 366, 425, 439, 483, 528, 573, 615, 656, 693, 737, 772, 807, 852, 897, 929, 976, 1008, 1053, 1111, 1140, 1192, 1219, 1279, 1314, 1356, 1387, 1449, 1484, 1513, 1552, 1592, 1673, 1704, 1773, 1784, 1809, 1843, 1903, 1902, 1962, 2002, 2014, 2054, 2109, 2161, 2148, 2198, 2235, 2353, 2360, 2511, 2282, 2282, 2282, 2282, 2282, 2282, 2282
109 2, 65, 123, 173, 225, 273, 322, 373, 438, 448, 488, 533, 580, 616, 661, 703, 739, 779, 819, 855, 897, 943, 983, 1013, 1040, 1086, 1132, 1167, 1217, 1258, 1299, 1345, 1391, 1452, 1474, 1526, 1574, 1602, 1646, 1721, 1764, 1803, 1825, 1921, 1919, 2030, 2049, 2067, 2134, 2152, 2209, 2225, 2274, 2299, 2375, 2379, 2374, 2462, 2536, 2584, 2822, 2822, 2822, 2822, 2822
111 2, 74, 126, 177, 230, 284, 332, 386, 454, 462, 507, 542, 592, 630, 673, 717, 753, 799, 841, 874, 913, 955, 996, 1031, 1073, 1103, 1138, 1172, 1219, 1249, 1300, 1325, 1383, 1428, 1446, 1504, 1550, 1585, 1636, 1702, 1728, 1784, 1841, 1905, 1934, 1978, 2055, 2130, 2165, 2231, 2291, 2417, 2405, 2494, 2491, 2525, 2587, 2626, 2658, 2658, 2708, 2713, 2667, 2867, 2867
113 4, 88, 137, 193, 244, 302, 353, 416, 495, 490, 534, 579, 615, 663, 716, 757, 792, 833, 884, 918, 962, 1006, 1058, 1087, 1125, 1169, 1203, 1258, 1286, 1326, 1365, 1405, 1437, 1477, 1520, 1554, 1597, 1642, 1664, 1709, 1759, 1800, 1842, 1894, 1941, 2002, 2062, 2124, 2138, 2225, 2310, 2377, 2448, 2584, 2628, 2731, 2824, 2846, 2960, 3016, 3147, 3099, 3197, 3107, 3107
115 18, 145, 182, 239, 297, 360, 415, 485, 584, 579, 638, 684, 737, 782, 834, 878, 924, 967, 1016, 1062, 1111, 1145, 1206, 1258, 1302, 1357, 1388, 1460, 1493, 1538, 1577, 1619, 1684, 1732, 1770, 1823, 1879, 1909, 1959, 2022, 2053, 2113, 2176, 2207, 2272, 2316, 2367, 2428, 2479, 2548, 2622, 2671, 2748, 2813, 2894, 2984, 3064, 3153, 3258, 3392, 3507, 3669, 3870, 4082, 4255
119 pub fn estimate_intra_mb_nits(mb: &Coeffs, q: usize) -> u32 {
121 for blk in mb.iter() {
123 for &el in blk.iter() {
128 count += NITS_PER_BLOCK[q >> 2][nz];
133 pub fn estimate_inter_mb_nits(mb: &InterMB, q: usize, fourmv: bool) -> u32 {
135 for blk in mb.residue.coeffs.iter() {
137 for &el in blk.iter() {
142 count += NITS_PER_BLOCK[q >> 2][nz];
145 if mb.mv[3] != ZERO_MV {
146 count += estimate_mv_nits(mb.mv[3]);
149 count += 4 * 2 * u32::from(super::models::PROB_BITS[128]);
150 for &mv in mb.mv.iter() {
152 count += estimate_mv_nits(mv);
159 /*pub fn estimate_mb_hdr_size(mb_type: VPMBType) -> u32 {
161 VPMBType::Intra => 60,
162 VPMBType::InterFourMV => 34,
163 VPMBType::InterNoMV => 3,
164 VPMBType::InterMV | VPMBType::InterNearest | VPMBType::InterNear => 20,