OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "media/filters/vp9_uncompressed_header_parser.h" | |
6 | |
7 #include "base/logging.h" | |
8 | |
9 namespace media { | |
10 | |
11 namespace { | |
12 | |
13 // 10.5 Default probability tables | |
14 Vp9FrameContext kVp9DefaultFrameContext = { | |
15 .tx_probs_8x8 = {{100}, {66}}, | |
16 .tx_probs_16x16 = {{20, 152}, {15, 101}}, | |
17 .tx_probs_32x32 = {{3, 136, 37}, {5, 52, 13}}, | |
18 .coef_probs = | |
19 {// 4x4 | |
20 {{{{{195, 29, 183}, {84, 49, 136}, {8, 42, 71}}, | |
21 {{31, 107, 169}, | |
22 {35, 99, 159}, | |
23 {17, 82, 140}, | |
24 {8, 66, 114}, | |
25 {2, 44, 76}, | |
26 {1, 19, 32}}, | |
27 {{40, 132, 201}, | |
28 {29, 114, 187}, | |
29 {13, 91, 157}, | |
30 {7, 75, 127}, | |
31 {3, 58, 95}, | |
32 {1, 28, 47}}, | |
33 {{69, 142, 221}, | |
34 {42, 122, 201}, | |
35 {15, 91, 159}, | |
36 {6, 67, 121}, | |
37 {1, 42, 77}, | |
38 {1, 17, 31}}, | |
39 {{102, 148, 228}, | |
40 {67, 117, 204}, | |
41 {17, 82, 154}, | |
42 {6, 59, 114}, | |
43 {2, 39, 75}, | |
44 {1, 15, 29}}, | |
45 {{156, 57, 233}, | |
46 {119, 57, 212}, | |
47 {58, 48, 163}, | |
48 {29, 40, 124}, | |
49 {12, 30, 81}, | |
50 {3, 12, 31}}}, | |
51 {{{191, 107, 226}, {124, 117, 204}, {25, 99, 155}}, | |
52 {{29, 148, 210}, | |
53 {37, 126, 194}, | |
54 {8, 93, 157}, | |
55 {2, 68, 118}, | |
56 {1, 39, 69}, | |
57 {1, 17, 33}}, | |
58 {{41, 151, 213}, | |
59 {27, 123, 193}, | |
60 {3, 82, 144}, | |
61 {1, 58, 105}, | |
62 {1, 32, 60}, | |
63 {1, 13, 26}}, | |
64 {{59, 159, 220}, | |
65 {23, 126, 198}, | |
66 {4, 88, 151}, | |
67 {1, 66, 114}, | |
68 {1, 38, 71}, | |
69 {1, 18, 34}}, | |
70 {{114, 136, 232}, | |
71 {51, 114, 207}, | |
72 {11, 83, 155}, | |
73 {3, 56, 105}, | |
74 {1, 33, 65}, | |
75 {1, 17, 34}}, | |
76 {{149, 65, 234}, | |
77 {121, 57, 215}, | |
78 {61, 49, 166}, | |
79 {28, 36, 114}, | |
80 {12, 25, 76}, | |
81 {3, 16, 42}}}}, | |
82 {{{{214, 49, 220}, {132, 63, 188}, {42, 65, 137}}, | |
83 {{85, 137, 221}, | |
84 {104, 131, 216}, | |
85 {49, 111, 192}, | |
86 {21, 87, 155}, | |
87 {2, 49, 87}, | |
88 {1, 16, 28}}, | |
89 {{89, 163, 230}, | |
90 {90, 137, 220}, | |
91 {29, 100, 183}, | |
92 {10, 70, 135}, | |
93 {2, 42, 81}, | |
94 {1, 17, 33}}, | |
95 {{108, 167, 237}, | |
96 {55, 133, 222}, | |
97 {15, 97, 179}, | |
98 {4, 72, 135}, | |
99 {1, 45, 85}, | |
100 {1, 19, 38}}, | |
101 {{124, 146, 240}, | |
102 {66, 124, 224}, | |
103 {17, 88, 175}, | |
104 {4, 58, 122}, | |
105 {1, 36, 75}, | |
106 {1, 18, 37}}, | |
107 {{141, 79, 241}, | |
108 {126, 70, 227}, | |
109 {66, 58, 182}, | |
110 {30, 44, 136}, | |
111 {12, 34, 96}, | |
112 {2, 20, 47}}}, | |
113 {{{229, 99, 249}, {143, 111, 235}, {46, 109, 192}}, | |
114 {{82, 158, 236}, | |
115 {94, 146, 224}, | |
116 {25, 117, 191}, | |
117 {9, 87, 149}, | |
118 {3, 56, 99}, | |
119 {1, 33, 57}}, | |
120 {{83, 167, 237}, | |
121 {68, 145, 222}, | |
122 {10, 103, 177}, | |
123 {2, 72, 131}, | |
124 {1, 41, 79}, | |
125 {1, 20, 39}}, | |
126 {{99, 167, 239}, | |
127 {47, 141, 224}, | |
128 {10, 104, 178}, | |
129 {2, 73, 133}, | |
130 {1, 44, 85}, | |
131 {1, 22, 47}}, | |
132 {{127, 145, 243}, | |
133 {71, 129, 228}, | |
134 {17, 93, 177}, | |
135 {3, 61, 124}, | |
136 {1, 41, 84}, | |
137 {1, 21, 52}}, | |
138 {{157, 78, 244}, | |
139 {140, 72, 231}, | |
140 {69, 58, 184}, | |
141 {31, 44, 137}, | |
142 {14, 38, 105}, | |
143 {8, 23, 61}}}}}, | |
144 // 8x8 | |
145 {{{{{125, 34, 187}, {52, 41, 133}, {6, 31, 56}}, | |
146 {{37, 109, 153}, | |
147 {51, 102, 147}, | |
148 {23, 87, 128}, | |
149 {8, 67, 101}, | |
150 {1, 41, 63}, | |
151 {1, 19, 29}}, | |
152 {{31, 154, 185}, | |
153 {17, 127, 175}, | |
154 {6, 96, 145}, | |
155 {2, 73, 114}, | |
156 {1, 51, 82}, | |
157 {1, 28, 45}}, | |
158 {{23, 163, 200}, | |
159 {10, 131, 185}, | |
160 {2, 93, 148}, | |
161 {1, 67, 111}, | |
162 {1, 41, 69}, | |
163 {1, 14, 24}}, | |
164 {{29, 176, 217}, | |
165 {12, 145, 201}, | |
166 {3, 101, 156}, | |
167 {1, 69, 111}, | |
168 {1, 39, 63}, | |
169 {1, 14, 23}}, | |
170 {{57, 192, 233}, | |
171 {25, 154, 215}, | |
172 {6, 109, 167}, | |
173 {3, 78, 118}, | |
174 {1, 48, 69}, | |
175 {1, 21, 29}}}, | |
176 {{{202, 105, 245}, {108, 106, 216}, {18, 90, 144}}, | |
177 {{33, 172, 219}, | |
178 {64, 149, 206}, | |
179 {14, 117, 177}, | |
180 {5, 90, 141}, | |
181 {2, 61, 95}, | |
182 {1, 37, 57}}, | |
183 {{33, 179, 220}, | |
184 {11, 140, 198}, | |
185 {1, 89, 148}, | |
186 {1, 60, 104}, | |
187 {1, 33, 57}, | |
188 {1, 12, 21}}, | |
189 {{30, 181, 221}, | |
190 {8, 141, 198}, | |
191 {1, 87, 145}, | |
192 {1, 58, 100}, | |
193 {1, 31, 55}, | |
194 {1, 12, 20}}, | |
195 {{32, 186, 224}, | |
196 {7, 142, 198}, | |
197 {1, 86, 143}, | |
198 {1, 58, 100}, | |
199 {1, 31, 55}, | |
200 {1, 12, 22}}, | |
201 {{57, 192, 227}, | |
202 {20, 143, 204}, | |
203 {3, 96, 154}, | |
204 {1, 68, 112}, | |
205 {1, 42, 69}, | |
206 {1, 19, 32}}}}, | |
207 {{{{212, 35, 215}, {113, 47, 169}, {29, 48, 105}}, | |
208 {{74, 129, 203}, | |
209 {106, 120, 203}, | |
210 {49, 107, 178}, | |
211 {19, 84, 144}, | |
212 {4, 50, 84}, | |
213 {1, 15, 25}}, | |
214 {{71, 172, 217}, | |
215 {44, 141, 209}, | |
216 {15, 102, 173}, | |
217 {6, 76, 133}, | |
218 {2, 51, 89}, | |
219 {1, 24, 42}}, | |
220 {{64, 185, 231}, | |
221 {31, 148, 216}, | |
222 {8, 103, 175}, | |
223 {3, 74, 131}, | |
224 {1, 46, 81}, | |
225 {1, 18, 30}}, | |
226 {{65, 196, 235}, | |
227 {25, 157, 221}, | |
228 {5, 105, 174}, | |
229 {1, 67, 120}, | |
230 {1, 38, 69}, | |
231 {1, 15, 30}}, | |
232 {{65, 204, 238}, | |
233 {30, 156, 224}, | |
234 {7, 107, 177}, | |
235 {2, 70, 124}, | |
236 {1, 42, 73}, | |
237 {1, 18, 34}}}, | |
238 {{{225, 86, 251}, {144, 104, 235}, {42, 99, 181}}, | |
239 {{85, 175, 239}, | |
240 {112, 165, 229}, | |
241 {29, 136, 200}, | |
242 {12, 103, 162}, | |
243 {6, 77, 123}, | |
244 {2, 53, 84}}, | |
245 {{75, 183, 239}, | |
246 {30, 155, 221}, | |
247 {3, 106, 171}, | |
248 {1, 74, 128}, | |
249 {1, 44, 76}, | |
250 {1, 17, 28}}, | |
251 {{73, 185, 240}, | |
252 {27, 159, 222}, | |
253 {2, 107, 172}, | |
254 {1, 75, 127}, | |
255 {1, 42, 73}, | |
256 {1, 17, 29}}, | |
257 {{62, 190, 238}, | |
258 {21, 159, 222}, | |
259 {2, 107, 172}, | |
260 {1, 72, 122}, | |
261 {1, 40, 71}, | |
262 {1, 18, 32}}, | |
263 {{61, 199, 240}, | |
264 {27, 161, 226}, | |
265 {4, 113, 180}, | |
266 {1, 76, 129}, | |
267 {1, 46, 80}, | |
268 {1, 23, 41}}}}}, | |
269 // 16x16 | |
270 {{{{{7, 27, 153}, {5, 30, 95}, {1, 16, 30}}, | |
271 {{50, 75, 127}, | |
272 {57, 75, 124}, | |
273 {27, 67, 108}, | |
274 {10, 54, 86}, | |
275 {1, 33, 52}, | |
276 {1, 12, 18}}, | |
277 {{43, 125, 151}, | |
278 {26, 108, 148}, | |
279 {7, 83, 122}, | |
280 {2, 59, 89}, | |
281 {1, 38, 60}, | |
282 {1, 17, 27}}, | |
283 {{23, 144, 163}, | |
284 {13, 112, 154}, | |
285 {2, 75, 117}, | |
286 {1, 50, 81}, | |
287 {1, 31, 51}, | |
288 {1, 14, 23}}, | |
289 {{18, 162, 185}, | |
290 {6, 123, 171}, | |
291 {1, 78, 125}, | |
292 {1, 51, 86}, | |
293 {1, 31, 54}, | |
294 {1, 14, 23}}, | |
295 {{15, 199, 227}, | |
296 {3, 150, 204}, | |
297 {1, 91, 146}, | |
298 {1, 55, 95}, | |
299 {1, 30, 53}, | |
300 {1, 11, 20}}}, | |
301 {{{19, 55, 240}, {19, 59, 196}, {3, 52, 105}}, | |
302 {{41, 166, 207}, | |
303 {104, 153, 199}, | |
304 {31, 123, 181}, | |
305 {14, 101, 152}, | |
306 {5, 72, 106}, | |
307 {1, 36, 52}}, | |
308 {{35, 176, 211}, | |
309 {12, 131, 190}, | |
310 {2, 88, 144}, | |
311 {1, 60, 101}, | |
312 {1, 36, 60}, | |
313 {1, 16, 28}}, | |
314 {{28, 183, 213}, | |
315 {8, 134, 191}, | |
316 {1, 86, 142}, | |
317 {1, 56, 96}, | |
318 {1, 30, 53}, | |
319 {1, 12, 20}}, | |
320 {{20, 190, 215}, | |
321 {4, 135, 192}, | |
322 {1, 84, 139}, | |
323 {1, 53, 91}, | |
324 {1, 28, 49}, | |
325 {1, 11, 20}}, | |
326 {{13, 196, 216}, | |
327 {2, 137, 192}, | |
328 {1, 86, 143}, | |
329 {1, 57, 99}, | |
330 {1, 32, 56}, | |
331 {1, 13, 24}}}}, | |
332 {{{{211, 29, 217}, {96, 47, 156}, {22, 43, 87}}, | |
333 {{78, 120, 193}, | |
334 {111, 116, 186}, | |
335 {46, 102, 164}, | |
336 {15, 80, 128}, | |
337 {2, 49, 76}, | |
338 {1, 18, 28}}, | |
339 {{71, 161, 203}, | |
340 {42, 132, 192}, | |
341 {10, 98, 150}, | |
342 {3, 69, 109}, | |
343 {1, 44, 70}, | |
344 {1, 18, 29}}, | |
345 {{57, 186, 211}, | |
346 {30, 140, 196}, | |
347 {4, 93, 146}, | |
348 {1, 62, 102}, | |
349 {1, 38, 65}, | |
350 {1, 16, 27}}, | |
351 {{47, 199, 217}, | |
352 {14, 145, 196}, | |
353 {1, 88, 142}, | |
354 {1, 57, 98}, | |
355 {1, 36, 62}, | |
356 {1, 15, 26}}, | |
357 {{26, 219, 229}, | |
358 {5, 155, 207}, | |
359 {1, 94, 151}, | |
360 {1, 60, 104}, | |
361 {1, 36, 62}, | |
362 {1, 16, 28}}}, | |
363 {{{233, 29, 248}, {146, 47, 220}, {43, 52, 140}}, | |
364 {{100, 163, 232}, | |
365 {179, 161, 222}, | |
366 {63, 142, 204}, | |
367 {37, 113, 174}, | |
368 {26, 89, 137}, | |
369 {18, 68, 97}}, | |
370 {{85, 181, 230}, | |
371 {32, 146, 209}, | |
372 {7, 100, 164}, | |
373 {3, 71, 121}, | |
374 {1, 45, 77}, | |
375 {1, 18, 30}}, | |
376 {{65, 187, 230}, | |
377 {20, 148, 207}, | |
378 {2, 97, 159}, | |
379 {1, 68, 116}, | |
380 {1, 40, 70}, | |
381 {1, 14, 29}}, | |
382 {{40, 194, 227}, | |
383 {8, 147, 204}, | |
384 {1, 94, 155}, | |
385 {1, 65, 112}, | |
386 {1, 39, 66}, | |
387 {1, 14, 26}}, | |
388 {{16, 208, 228}, | |
389 {3, 151, 207}, | |
390 {1, 98, 160}, | |
391 {1, 67, 117}, | |
392 {1, 41, 74}, | |
393 {1, 17, 31}}}}}, | |
394 // 32x32 | |
395 {{{{{17, 38, 140}, {7, 34, 80}, {1, 17, 29}}, | |
396 {{37, 75, 128}, | |
397 {41, 76, 128}, | |
398 {26, 66, 116}, | |
399 {12, 52, 94}, | |
400 {2, 32, 55}, | |
401 {1, 10, 16}}, | |
402 {{50, 127, 154}, | |
403 {37, 109, 152}, | |
404 {16, 82, 121}, | |
405 {5, 59, 85}, | |
406 {1, 35, 54}, | |
407 {1, 13, 20}}, | |
408 {{40, 142, 167}, | |
409 {17, 110, 157}, | |
410 {2, 71, 112}, | |
411 {1, 44, 72}, | |
412 {1, 27, 45}, | |
413 {1, 11, 17}}, | |
414 {{30, 175, 188}, | |
415 {9, 124, 169}, | |
416 {1, 74, 116}, | |
417 {1, 48, 78}, | |
418 {1, 30, 49}, | |
419 {1, 11, 18}}, | |
420 {{10, 222, 223}, | |
421 {2, 150, 194}, | |
422 {1, 83, 128}, | |
423 {1, 48, 79}, | |
424 {1, 27, 45}, | |
425 {1, 11, 17}}}, | |
426 {{{36, 41, 235}, {29, 36, 193}, {10, 27, 111}}, | |
427 {{85, 165, 222}, | |
428 {177, 162, 215}, | |
429 {110, 135, 195}, | |
430 {57, 113, 168}, | |
431 {23, 83, 120}, | |
432 {10, 49, 61}}, | |
433 {{85, 190, 223}, | |
434 {36, 139, 200}, | |
435 {5, 90, 146}, | |
436 {1, 60, 103}, | |
437 {1, 38, 65}, | |
438 {1, 18, 30}}, | |
439 {{72, 202, 223}, | |
440 {23, 141, 199}, | |
441 {2, 86, 140}, | |
442 {1, 56, 97}, | |
443 {1, 36, 61}, | |
444 {1, 16, 27}}, | |
445 {{55, 218, 225}, | |
446 {13, 145, 200}, | |
447 {1, 86, 141}, | |
448 {1, 57, 99}, | |
449 {1, 35, 61}, | |
450 {1, 13, 22}}, | |
451 {{15, 235, 212}, | |
452 {1, 132, 184}, | |
453 {1, 84, 139}, | |
454 {1, 57, 97}, | |
455 {1, 34, 56}, | |
456 {1, 14, 23}}}}, | |
457 {{{{181, 21, 201}, {61, 37, 123}, {10, 38, 71}}, | |
458 {{47, 106, 172}, | |
459 {95, 104, 173}, | |
460 {42, 93, 159}, | |
461 {18, 77, 131}, | |
462 {4, 50, 81}, | |
463 {1, 17, 23}}, | |
464 {{62, 147, 199}, | |
465 {44, 130, 189}, | |
466 {28, 102, 154}, | |
467 {18, 75, 115}, | |
468 {2, 44, 65}, | |
469 {1, 12, 19}}, | |
470 {{55, 153, 210}, | |
471 {24, 130, 194}, | |
472 {3, 93, 146}, | |
473 {1, 61, 97}, | |
474 {1, 31, 50}, | |
475 {1, 10, 16}}, | |
476 {{49, 186, 223}, | |
477 {17, 148, 204}, | |
478 {1, 96, 142}, | |
479 {1, 53, 83}, | |
480 {1, 26, 44}, | |
481 {1, 11, 17}}, | |
482 {{13, 217, 212}, | |
483 {2, 136, 180}, | |
484 {1, 78, 124}, | |
485 {1, 50, 83}, | |
486 {1, 29, 49}, | |
487 {1, 14, 23}}}, | |
488 {{{197, 13, 247}, {82, 17, 222}, {25, 17, 162}}, | |
489 {{126, 186, 247}, | |
490 {234, 191, 243}, | |
491 {176, 177, 234}, | |
492 {104, 158, 220}, | |
493 {66, 128, 186}, | |
494 {55, 90, 137}}, | |
495 {{111, 197, 242}, | |
496 {46, 158, 219}, | |
497 {9, 104, 171}, | |
498 {2, 65, 125}, | |
499 {1, 44, 80}, | |
500 {1, 17, 91}}, | |
501 {{104, 208, 245}, | |
502 {39, 168, 224}, | |
503 {3, 109, 162}, | |
504 {1, 79, 124}, | |
505 {1, 50, 102}, | |
506 {1, 43, 102}}, | |
507 {{84, 220, 246}, | |
508 {31, 177, 231}, | |
509 {2, 115, 180}, | |
510 {1, 79, 134}, | |
511 {1, 55, 77}, | |
512 {1, 60, 79}}, | |
513 {{43, 243, 240}, | |
514 {8, 180, 217}, | |
515 {1, 115, 166}, | |
516 {1, 84, 121}, | |
517 {1, 51, 67}, | |
518 {1, 16, 6}}}}}}, | |
519 .skip_prob = {192, 128, 64}, | |
520 .inter_mode_probs = {{2, 173, 34}, | |
521 {7, 145, 85}, | |
522 {7, 166, 63}, | |
523 {7, 94, 66}, | |
524 {8, 64, 46}, | |
525 {17, 81, 31}, | |
526 {25, 29, 30}}, | |
527 .interp_filter_probs = {{235, 162}, {36, 255}, {34, 3}, {149, 144}}, | |
528 .is_inter_prob = {9, 102, 187, 225}, | |
529 .comp_mode_prob = {239, 183, 119, 96, 41}, | |
530 .single_ref_prob = {{33, 16}, {77, 74}, {142, 142}, {172, 170}, {238, 247}}, | |
531 .comp_ref_prob = {50, 126, 123, 221, 226}, | |
532 .y_mode_probs = {{65, 32, 18, 144, 162, 194, 41, 51, 98}, | |
533 {132, 68, 18, 165, 217, 196, 45, 40, 78}, | |
534 {173, 80, 19, 176, 240, 193, 64, 35, 46}, | |
535 {221, 135, 38, 194, 248, 121, 96, 85, 29}}, | |
536 .uv_mode_probs = {{120, 7, 76, 176, 208, 126, 28, 54, 103}, | |
537 {48, 12, 154, 155, 139, 90, 34, 117, 119}, | |
538 {67, 6, 25, 204, 243, 158, 13, 21, 96}, | |
539 {97, 5, 44, 131, 176, 139, 48, 68, 97}, | |
540 {83, 5, 42, 156, 111, 152, 26, 49, 152}, | |
541 {80, 5, 58, 178, 74, 83, 33, 62, 145}, | |
542 {86, 5, 32, 154, 192, 168, 14, 22, 163}, | |
543 {85, 5, 32, 156, 216, 148, 19, 29, 73}, | |
544 {77, 7, 64, 116, 132, 122, 37, 126, 120}, | |
545 {101, 21, 107, 181, 192, 103, 19, 67, 125}}, | |
546 .partition_probs = {{199, 122, 141}, | |
547 {147, 63, 159}, | |
548 {148, 133, 118}, | |
549 {121, 104, 114}, | |
550 {174, 73, 87}, | |
551 {92, 41, 83}, | |
552 {82, 99, 50}, | |
553 {53, 39, 39}, | |
554 {177, 58, 59}, | |
555 {68, 26, 63}, | |
556 {52, 79, 25}, | |
557 {17, 14, 12}, | |
558 {222, 34, 30}, | |
559 {72, 16, 44}, | |
560 {58, 32, 12}, | |
561 {10, 7, 6}}, | |
562 .mv_joint_probs = {32, 64, 96}, | |
563 .mv_sign_prob = {128, 128}, | |
564 .mv_class_probs = {{224, 144, 192, 168, 192, 176, 192, 198, 198, 245}, | |
565 {216, 128, 176, 160, 176, 176, 192, 198, 198, 208}}, | |
566 .mv_class0_bit_prob = {216, 208}, | |
567 .mv_bits_prob = {{136, 140, 148, 160, 176, 192, 224, 234, 234, 240}, | |
568 {136, 140, 148, 160, 176, 192, 224, 234, 234, 240}}, | |
569 .mv_class0_fr_probs = {{{128, 128, 64}, {96, 112, 64}}, | |
570 {{128, 128, 64}, {96, 112, 64}}}, | |
571 .mv_fr_probs = {{64, 96, 64}, {64, 96, 64}}, | |
572 .mv_class0_hp_prob = {160, 160}, | |
573 .mv_hp_prob = {128, 128}, | |
574 }; | |
575 | |
576 // Helper function for Vp9Parser::ReadTileInfo. Defined as | |
577 // calc_min_log2_tile_cols in spec 6.2.14 Tile size calculation. | |
578 int GetMinLog2TileCols(int sb64_cols) { | |
579 const int kMaxTileWidthB64 = 64; | |
580 int min_log2 = 0; | |
581 while ((kMaxTileWidthB64 << min_log2) < sb64_cols) | |
582 min_log2++; | |
583 return min_log2; | |
584 } | |
585 | |
586 // Helper function for Vp9Parser::ReadTileInfo. Defined as | |
587 // calc_max_log2_tile_cols in spec 6.2.14 Tile size calculation. | |
588 int GetMaxLog2TileCols(int sb64_cols) { | |
589 const int kMinTileWidthB64 = 4; | |
590 int max_log2 = 1; | |
591 while ((sb64_cols >> max_log2) >= kMinTileWidthB64) | |
592 max_log2++; | |
593 return max_log2 - 1; | |
594 } | |
595 | |
596 } // namespace | |
597 | |
598 Vp9UncompressedHeaderParser::Vp9UncompressedHeaderParser( | |
599 Vp9Parser::Context* context) | |
600 : context_(context) {} | |
601 | |
602 uint8_t Vp9UncompressedHeaderParser::ReadProfile() { | |
603 uint8_t profile = 0; | |
604 | |
605 // LSB first. | |
606 if (reader_.ReadBool()) | |
607 profile |= 1; | |
608 if (reader_.ReadBool()) | |
609 profile |= 2; | |
610 if (profile > 2 && reader_.ReadBool()) | |
611 profile += 1; | |
612 return profile; | |
613 } | |
614 | |
615 // 6.2.1 Frame sync syntax | |
616 bool Vp9UncompressedHeaderParser::VerifySyncCode() { | |
617 const int kSyncCode = 0x498342; | |
618 if (reader_.ReadLiteral(8 * 3) != kSyncCode) { | |
619 DVLOG(1) << "Invalid frame sync code"; | |
620 return false; | |
621 } | |
622 return true; | |
623 } | |
624 | |
625 // 6.2.2 Color config syntax | |
626 bool Vp9UncompressedHeaderParser::ReadColorConfig(Vp9FrameHeader* fhdr) { | |
627 if (fhdr->profile == 2 || fhdr->profile == 3) { | |
628 fhdr->bit_depth = reader_.ReadBool() ? 12 : 10; | |
629 } else { | |
630 fhdr->bit_depth = 8; | |
631 } | |
632 | |
633 fhdr->color_space = static_cast<Vp9ColorSpace>(reader_.ReadLiteral(3)); | |
634 if (fhdr->color_space != Vp9ColorSpace::SRGB) { | |
635 fhdr->color_range = reader_.ReadBool(); | |
636 if (fhdr->profile == 1 || fhdr->profile == 3) { | |
637 fhdr->subsampling_x = reader_.ReadBool() ? 1 : 0; | |
638 fhdr->subsampling_y = reader_.ReadBool() ? 1 : 0; | |
639 if (fhdr->subsampling_x == 1 && fhdr->subsampling_y == 1) { | |
640 DVLOG(1) << "4:2:0 color not supported in profile 1 or 3"; | |
641 return false; | |
642 } | |
643 bool reserved = reader_.ReadBool(); | |
644 if (reserved) { | |
645 DVLOG(1) << "reserved bit set"; | |
646 return false; | |
647 } | |
648 } else { | |
649 fhdr->subsampling_x = fhdr->subsampling_y = 1; | |
650 } | |
651 } else { | |
652 fhdr->color_range = true; | |
653 if (fhdr->profile == 1 || fhdr->profile == 3) { | |
654 fhdr->subsampling_x = fhdr->subsampling_y = 0; | |
655 | |
656 bool reserved = reader_.ReadBool(); | |
657 if (reserved) { | |
658 DVLOG(1) << "reserved bit set"; | |
659 return false; | |
660 } | |
661 } else { | |
662 DVLOG(1) << "4:4:4 color not supported in profile 0 or 2"; | |
663 return false; | |
664 } | |
665 } | |
666 | |
667 return true; | |
668 } | |
669 | |
670 // 6.2.3 Frame size syntax | |
671 void Vp9UncompressedHeaderParser::ReadFrameSize(Vp9FrameHeader* fhdr) { | |
672 fhdr->frame_width = reader_.ReadLiteral(16) + 1; | |
673 fhdr->frame_height = reader_.ReadLiteral(16) + 1; | |
674 } | |
675 | |
676 // 6.2.4 Render size syntax | |
677 void Vp9UncompressedHeaderParser::ReadRenderSize(Vp9FrameHeader* fhdr) { | |
678 if (reader_.ReadBool()) { | |
679 fhdr->render_width = reader_.ReadLiteral(16) + 1; | |
680 fhdr->render_height = reader_.ReadLiteral(16) + 1; | |
681 } else { | |
682 fhdr->render_width = fhdr->frame_width; | |
683 fhdr->render_height = fhdr->frame_height; | |
684 } | |
685 } | |
686 | |
687 // 6.2.5 Frame size with refs syntax | |
688 bool Vp9UncompressedHeaderParser::ReadFrameSizeFromRefs(Vp9FrameHeader* fhdr) { | |
689 bool found_ref = false; | |
690 for (const auto& idx : fhdr->ref_frame_idx) { | |
691 found_ref = reader_.ReadBool(); | |
692 if (found_ref) { | |
693 const Vp9Parser::ReferenceSlot& ref = context_->ref_slots[idx]; | |
694 DCHECK(ref.initialized); | |
695 fhdr->frame_width = ref.frame_width; | |
696 fhdr->frame_height = ref.frame_height; | |
697 | |
698 const unsigned kMaxDimension = 1u << 16; | |
699 DCHECK_LE(fhdr->frame_width, kMaxDimension); | |
700 DCHECK_LE(fhdr->frame_height, kMaxDimension); | |
701 break; | |
702 } | |
703 } | |
704 | |
705 if (!found_ref) | |
706 ReadFrameSize(fhdr); | |
707 | |
708 // 7.2.5 Frame size with refs semantics | |
709 bool has_valid_ref_frame = false; | |
710 for (const auto& idx : fhdr->ref_frame_idx) { | |
711 const Vp9Parser::ReferenceSlot& ref = context_->ref_slots[idx]; | |
712 if (2 * fhdr->frame_width >= ref.frame_width && | |
713 2 * fhdr->frame_height >= ref.frame_height && | |
714 fhdr->frame_width <= 16 * ref.frame_width && | |
715 fhdr->frame_height <= 16 * ref.frame_height) { | |
716 has_valid_ref_frame = true; | |
717 break; | |
718 } | |
719 } | |
720 if (!has_valid_ref_frame) { | |
721 DVLOG(1) << "There should be at least one reference frame meeting " | |
722 << "size conditions."; | |
723 return false; | |
724 } | |
725 | |
726 ReadRenderSize(fhdr); | |
727 return true; | |
728 } | |
729 | |
730 // 6.2.7 Interpolation filter syntax | |
731 Vp9InterpolationFilter Vp9UncompressedHeaderParser::ReadInterpolationFilter() { | |
732 if (reader_.ReadBool()) | |
733 return Vp9InterpolationFilter::SWITCHABLE; | |
734 | |
735 // The mapping table for next two bits. | |
736 const Vp9InterpolationFilter table[] = { | |
737 Vp9InterpolationFilter::EIGHTTAP_SMOOTH, Vp9InterpolationFilter::EIGHTTAP, | |
738 Vp9InterpolationFilter::EIGHTTAP_SHARP, Vp9InterpolationFilter::BILINEAR, | |
739 }; | |
740 return table[reader_.ReadLiteral(2)]; | |
741 } | |
742 | |
743 void Vp9UncompressedHeaderParser::SetupPastIndependence(Vp9FrameHeader* fhdr) { | |
744 memset(&context_->segmentation, 0, sizeof(context_->segmentation)); | |
745 ResetLoopfilter(); | |
746 fhdr->frame_context = kVp9DefaultFrameContext; | |
747 DCHECK(Vp9FrameContextManager::IsValidFrameContext(fhdr->frame_context)); | |
748 } | |
749 | |
750 // 6.2.8 Loop filter params syntax | |
751 void Vp9UncompressedHeaderParser::ReadLoopFilterParams() { | |
752 Vp9LoopFilterParams& loop_filter = context_->loop_filter; | |
753 | |
754 loop_filter.level = reader_.ReadLiteral(6); | |
755 loop_filter.sharpness = reader_.ReadLiteral(3); | |
756 loop_filter.delta_update = false; | |
757 | |
758 loop_filter.delta_enabled = reader_.ReadBool(); | |
759 if (loop_filter.delta_enabled) { | |
760 loop_filter.delta_update = reader_.ReadBool(); | |
761 if (loop_filter.delta_update) { | |
762 for (size_t i = 0; i < Vp9FrameType::VP9_FRAME_MAX; i++) { | |
763 loop_filter.update_ref_deltas[i] = reader_.ReadBool(); | |
764 if (loop_filter.update_ref_deltas[i]) | |
765 loop_filter.ref_deltas[i] = reader_.ReadSignedLiteral(6); | |
766 } | |
767 | |
768 for (size_t i = 0; i < Vp9LoopFilterParams::kNumModeDeltas; i++) { | |
769 loop_filter.update_mode_deltas[i] = reader_.ReadBool(); | |
770 if (loop_filter.update_mode_deltas[i]) | |
771 loop_filter.mode_deltas[i] = reader_.ReadLiteral(6); | |
772 } | |
773 } | |
774 } | |
775 } | |
776 | |
777 // 6.2.9 Quantization params syntax | |
778 void Vp9UncompressedHeaderParser::ReadQuantizationParams( | |
779 Vp9QuantizationParams* quants) { | |
780 quants->base_q_idx = reader_.ReadLiteral(8); | |
781 | |
782 quants->delta_q_y_dc = ReadDeltaQ(); | |
783 quants->delta_q_uv_dc = ReadDeltaQ(); | |
784 quants->delta_q_uv_ac = ReadDeltaQ(); | |
785 } | |
786 | |
787 // 6.2.10 Delta quantizer syntax | |
788 int8_t Vp9UncompressedHeaderParser::ReadDeltaQ() { | |
789 if (reader_.ReadBool()) | |
790 return reader_.ReadSignedLiteral(4); | |
791 return 0; | |
792 } | |
793 | |
794 // 6.2.11 Segmentation params syntax | |
795 bool Vp9UncompressedHeaderParser::ReadSegmentationParams() { | |
796 Vp9SegmentationParams& segmentation = context_->segmentation; | |
797 segmentation.update_map = false; | |
798 segmentation.update_data = false; | |
799 | |
800 segmentation.enabled = reader_.ReadBool(); | |
801 if (!segmentation.enabled) | |
802 return true; | |
803 | |
804 segmentation.update_map = reader_.ReadBool(); | |
805 if (segmentation.update_map) { | |
806 for (auto& tree_prob : segmentation.tree_probs) { | |
807 tree_prob = ReadProb(); | |
808 } | |
809 | |
810 segmentation.temporal_update = reader_.ReadBool(); | |
811 for (auto& pred_prob : segmentation.pred_probs) { | |
812 pred_prob = segmentation.temporal_update ? ReadProb() : kVp9MaxProb; | |
813 } | |
814 } | |
815 | |
816 segmentation.update_data = reader_.ReadBool(); | |
817 if (segmentation.update_data) { | |
818 segmentation.abs_or_delta_update = reader_.ReadBool(); | |
819 | |
820 const int kFeatureDataBits[] = {8, 6, 2, 0}; | |
821 const bool kFeatureDataSigned[] = {true, true, false, false}; | |
822 | |
823 for (size_t i = 0; i < Vp9SegmentationParams::kNumSegments; i++) { | |
824 for (size_t j = 0; j < Vp9SegmentationParams::SEG_LVL_MAX; j++) { | |
825 int16_t data = 0; | |
826 segmentation.feature_enabled[i][j] = reader_.ReadBool(); | |
827 if (segmentation.feature_enabled[i][j]) { | |
828 data = reader_.ReadLiteral(kFeatureDataBits[j]); | |
829 if (kFeatureDataSigned[j]) | |
830 if (reader_.ReadBool()) { | |
831 // 7.2.9 | |
832 if (segmentation.abs_or_delta_update) { | |
833 DVLOG(1) << "feature_sign should be 0" | |
834 << " if abs_or_delta_update is 1"; | |
835 return false; | |
836 } | |
837 data = -data; | |
838 } | |
839 } | |
840 segmentation.feature_data[i][j] = data; | |
841 } | |
842 } | |
843 } | |
844 return true; | |
845 } | |
846 | |
847 // 6.2.12 Probability syntax | |
848 uint8_t Vp9UncompressedHeaderParser::ReadProb() { | |
849 return reader_.ReadBool() ? reader_.ReadLiteral(8) : kVp9MaxProb; | |
850 } | |
851 | |
852 // 6.2.13 Tile info syntax | |
853 bool Vp9UncompressedHeaderParser::ReadTileInfo(Vp9FrameHeader* fhdr) { | |
854 int sb64_cols = (fhdr->frame_width + 63) / 64; | |
855 | |
856 int min_log2_tile_cols = GetMinLog2TileCols(sb64_cols); | |
857 int max_log2_tile_cols = GetMaxLog2TileCols(sb64_cols); | |
858 | |
859 int max_ones = max_log2_tile_cols - min_log2_tile_cols; | |
860 fhdr->tile_cols_log2 = min_log2_tile_cols; | |
861 while (max_ones-- && reader_.ReadBool()) | |
862 fhdr->tile_cols_log2++; | |
863 | |
864 fhdr->tile_rows_log2 = reader_.ReadBool() ? 1 : 0; | |
865 if (fhdr->tile_rows_log2 > 0 && reader_.ReadBool()) | |
866 fhdr->tile_rows_log2++; | |
867 | |
868 // 7.2.11 Tile info semantics | |
869 if (fhdr->tile_cols_log2 > 6) { | |
870 VLOG(1) << "tile_cols_log2 should be <= 6"; | |
Pawel Osciak
2016/08/05 10:09:39
s/VLOG/DVLOG/?
kcwu
2016/08/05 11:38:48
Done.
| |
871 return false; | |
872 } | |
873 | |
874 return true; | |
875 } | |
876 | |
877 void Vp9UncompressedHeaderParser::ResetLoopfilter() { | |
878 Vp9LoopFilterParams& loop_filter = context_->loop_filter; | |
879 | |
880 loop_filter.delta_enabled = true; | |
881 loop_filter.delta_update = true; | |
882 | |
883 loop_filter.ref_deltas[VP9_FRAME_INTRA] = 1; | |
884 loop_filter.ref_deltas[VP9_FRAME_LAST] = 0; | |
885 loop_filter.ref_deltas[VP9_FRAME_GOLDEN] = -1; | |
886 loop_filter.ref_deltas[VP9_FRAME_ALTREF] = -1; | |
887 | |
888 memset(loop_filter.mode_deltas, 0, sizeof(loop_filter.mode_deltas)); | |
889 } | |
890 | |
891 // 6.2 Uncompressed header syntax | |
892 bool Vp9UncompressedHeaderParser::Parse(const uint8_t* stream, | |
893 off_t frame_size, | |
894 Vp9FrameHeader* fhdr) { | |
895 DVLOG(2) << "Vp9UncompressedHeaderParser::Parse"; | |
896 reader_.Initialize(stream, frame_size); | |
897 | |
898 fhdr->data = stream; | |
899 fhdr->frame_size = frame_size; | |
900 | |
901 // frame marker | |
902 if (reader_.ReadLiteral(2) != 0x2) { | |
903 DVLOG(1) << "frame marker shall be equal to 2"; | |
904 return false; | |
905 } | |
906 | |
907 fhdr->profile = ReadProfile(); | |
908 if (fhdr->profile >= kVp9MaxProfile) { | |
909 DVLOG(1) << "Unsupported bitstream profile"; | |
910 return false; | |
911 } | |
912 | |
913 fhdr->show_existing_frame = reader_.ReadBool(); | |
914 if (fhdr->show_existing_frame) { | |
915 fhdr->frame_to_show_map_idx = reader_.ReadLiteral(3); | |
916 fhdr->show_frame = true; | |
917 | |
918 if (!reader_.ConsumeTrailingBits()) { | |
919 DVLOG(1) << "trailing bits are not zero"; | |
920 return false; | |
921 } | |
922 if (!reader_.IsValid()) { | |
923 DVLOG(1) << "parser reads beyond the end of buffer"; | |
924 return false; | |
925 } | |
926 fhdr->uncompressed_header_size = reader_.GetBytesRead(); | |
927 fhdr->header_size_in_bytes = 0; | |
928 return true; | |
929 } | |
930 | |
931 fhdr->frame_type = static_cast<Vp9FrameHeader::FrameType>(reader_.ReadBool()); | |
932 fhdr->show_frame = reader_.ReadBool(); | |
933 fhdr->error_resilient_mode = reader_.ReadBool(); | |
934 | |
935 if (fhdr->IsKeyframe()) { | |
936 if (!VerifySyncCode()) | |
937 return false; | |
938 | |
939 if (!ReadColorConfig(fhdr)) | |
940 return false; | |
941 | |
942 ReadFrameSize(fhdr); | |
943 ReadRenderSize(fhdr); | |
944 fhdr->refresh_frame_flags = 0xff; | |
945 } else { | |
946 if (!fhdr->show_frame) | |
947 fhdr->intra_only = reader_.ReadBool(); | |
948 | |
949 if (!fhdr->error_resilient_mode) | |
950 fhdr->reset_frame_context = reader_.ReadLiteral(2); | |
951 | |
952 if (fhdr->intra_only) { | |
953 if (!VerifySyncCode()) | |
954 return false; | |
955 | |
956 if (fhdr->profile > 0) { | |
957 if (!ReadColorConfig(fhdr)) | |
958 return false; | |
959 } else { | |
960 fhdr->bit_depth = 8; | |
961 fhdr->color_space = Vp9ColorSpace::BT_601; | |
962 fhdr->subsampling_x = fhdr->subsampling_y = 1; | |
963 } | |
964 | |
965 fhdr->refresh_frame_flags = reader_.ReadLiteral(8); | |
966 | |
967 ReadFrameSize(fhdr); | |
968 ReadRenderSize(fhdr); | |
969 } else { | |
970 fhdr->refresh_frame_flags = reader_.ReadLiteral(8); | |
971 | |
972 static_assert(arraysize(fhdr->ref_frame_sign_bias) >= | |
973 Vp9FrameType::VP9_FRAME_LAST + kVp9NumRefsPerFrame, | |
974 "ref_frame_sign_bias is not big enough"); | |
975 for (size_t i = 0; i < kVp9NumRefsPerFrame; i++) { | |
976 fhdr->ref_frame_idx[i] = reader_.ReadLiteral(kVp9NumRefFramesLog2); | |
977 fhdr->ref_frame_sign_bias[Vp9FrameType::VP9_FRAME_LAST + i] = | |
978 reader_.ReadBool(); | |
979 | |
980 // 8.2 Frame order constraints | |
981 // ref_frame_idx[i] refers to an earlier decoded frame. | |
982 const Vp9Parser::ReferenceSlot& ref = | |
983 context_->ref_slots[fhdr->ref_frame_idx[i]]; | |
984 if (!ref.initialized) { | |
985 DVLOG(1) << "ref_frame_idx[" << i | |
986 << "]=" << static_cast<int>(fhdr->ref_frame_idx[i]) | |
987 << " refers to unused frame"; | |
988 return false; | |
989 } | |
990 | |
991 // 7.2 Uncompressed header semantics | |
992 // the selected reference frames match the current frame in bit depth, | |
993 // profile, chroma subsampling, and color space. | |
994 // TODO(kcwu): how about color_range? | |
Pawel Osciak
2016/08/05 10:09:39
Do we want to leave this TODO?
kcwu
2016/08/05 11:38:48
removed
| |
995 if (ref.profile != fhdr->profile) { | |
996 DVLOG(1) << "profile of referenced frame mismatch"; | |
997 return false; | |
998 } | |
999 if (i == 0) { | |
1000 // Some fields are not specified for inter-frame in header, so copy | |
Pawel Osciak
2016/08/05 10:09:39
s/Some/Below/
kcwu
2016/08/05 11:38:48
Done.
| |
1001 // them from referenced frame. | |
1002 fhdr->bit_depth = ref.bit_depth; | |
1003 fhdr->color_space = ref.color_space; | |
1004 fhdr->subsampling_x = ref.subsampling_x; | |
1005 fhdr->subsampling_y = ref.subsampling_y; | |
1006 } else { | |
1007 if (fhdr->bit_depth != ref.bit_depth) { | |
1008 DVLOG(1) << "bit_depth of referenced frame mismatch"; | |
1009 return false; | |
1010 } | |
1011 if (fhdr->color_space != ref.color_space) { | |
1012 DVLOG(1) << "color_space of referenced frame mismatch"; | |
1013 return false; | |
1014 } | |
1015 if (fhdr->subsampling_x != ref.subsampling_x || | |
1016 fhdr->subsampling_y != ref.subsampling_y) { | |
1017 DVLOG(1) << "chroma subsampling of referenced frame mismatch"; | |
1018 return false; | |
1019 } | |
1020 } | |
1021 } | |
1022 | |
1023 if (!ReadFrameSizeFromRefs(fhdr)) | |
1024 return false; | |
1025 | |
1026 fhdr->allow_high_precision_mv = reader_.ReadBool(); | |
1027 fhdr->interpolation_filter = ReadInterpolationFilter(); | |
1028 } | |
1029 } | |
1030 | |
1031 if (fhdr->error_resilient_mode) { | |
1032 fhdr->refresh_frame_context = false; | |
1033 fhdr->frame_parallel_decoding_mode = true; | |
1034 } else { | |
1035 fhdr->refresh_frame_context = reader_.ReadBool(); | |
1036 fhdr->frame_parallel_decoding_mode = reader_.ReadBool(); | |
1037 } | |
1038 | |
1039 fhdr->frame_context_idx_backup = fhdr->frame_context_idx = | |
1040 reader_.ReadLiteral(2); | |
1041 | |
1042 if (fhdr->IsIntra()) { | |
1043 SetupPastIndependence(fhdr); | |
1044 if (fhdr->IsKeyframe() || fhdr->error_resilient_mode || | |
1045 fhdr->reset_frame_context == 3) { | |
1046 for (auto& frame_context_manage : context_->frame_context_managers) | |
1047 frame_context_manage.Update(fhdr->frame_context); | |
1048 } else if (fhdr->reset_frame_context == 2) { | |
1049 DCHECK_LT(fhdr->frame_context_idx, | |
1050 arraysize(context_->frame_context_managers)); | |
Pawel Osciak
2016/08/05 10:09:39
maybe static assert on (arraysize() == 1 << 2)?
kcwu
2016/08/05 11:38:48
Do you mean "== 1 << 2" literally? It looks ugly.
Pawel Osciak
2016/08/08 08:13:37
Anything is ok, my point being this could perhaps
kcwu
2016/08/09 04:29:43
I don't like magic number and prefer to keep it as
kcwu
2016/08/09 07:56:03
I changed to use static_assert.
| |
1051 context_->frame_context_managers[fhdr->frame_context_idx].Update( | |
1052 fhdr->frame_context); | |
1053 } | |
1054 fhdr->frame_context_idx = 0; | |
1055 } | |
1056 | |
1057 ReadLoopFilterParams(); | |
1058 ReadQuantizationParams(&fhdr->quant_params); | |
1059 if (!ReadSegmentationParams()) | |
1060 return false; | |
1061 | |
1062 if (!ReadTileInfo(fhdr)) | |
1063 return false; | |
1064 | |
1065 fhdr->header_size_in_bytes = reader_.ReadLiteral(16); | |
1066 if (fhdr->header_size_in_bytes == 0) { | |
1067 DVLOG(1) << "invalid header size"; | |
1068 return false; | |
1069 } | |
1070 | |
1071 if (!reader_.ConsumeTrailingBits()) { | |
1072 DVLOG(1) << "trailing bits are not zero"; | |
1073 return false; | |
1074 } | |
1075 if (!reader_.IsValid()) { | |
1076 DVLOG(1) << "parser reads beyond the end of buffer"; | |
1077 return false; | |
1078 } | |
1079 fhdr->uncompressed_header_size = reader_.GetBytesRead(); | |
1080 | |
1081 return true; | |
1082 } | |
1083 | |
1084 } // namespace media | |
OLD | NEW |