annotate h264_cavlc.c @ 10868:13a84faba50d libavcodec

Move golomb_to_int*cbp tables back to h264_data.h as svq3.c used them. Yes i did compile&test, no svq3.c was not recompiled.
author michael
date Wed, 13 Jan 2010 02:17:16 +0000
parents d26e9b4d2ca1
children 2aafcafbe1f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10866
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1 /*
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
2 * H.26L/H.264/AVC/JVT/14496-10/... cavlc bitstream decoding
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
4 *
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
5 * This file is part of FFmpeg.
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
6 *
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
11 *
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
16 *
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
20 */
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
21
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
22 /**
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
23 * @file libavcodec/h264_cavlc.c
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
24 * H.264 / AVC / MPEG4 part10 cavlc bitstream decoding.
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
25 * @author Michael Niedermayer <michaelni@gmx.at>
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
26 */
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
27
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
28 #include "internal.h"
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
29 #include "avcodec.h"
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
30 #include "mpegvideo.h"
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
31 #include "h264.h"
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
32 #include "h264data.h" // FIXME FIXME FIXME
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
33 #include "h264_mvpred.h"
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
34 #include "golomb.h"
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
35
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
36 #if ARCH_X86
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
37 #include "x86/h264_i386.h"
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
38 #endif
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
39
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
40 //#undef NDEBUG
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
41 #include <assert.h>
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
42
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
43 static const uint8_t golomb_to_inter_cbp_gray[16]={
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
44 0, 1, 2, 4, 8, 3, 5,10,12,15, 7,11,13,14, 6, 9,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
45 };
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
46
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
47 static const uint8_t golomb_to_intra4x4_cbp_gray[16]={
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
48 15, 0, 7,11,13,14, 3, 5,10,12, 1, 2, 4, 8, 6, 9,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
49 };
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
50
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
51 static const uint8_t chroma_dc_coeff_token_len[4*5]={
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
52 2, 0, 0, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
53 6, 1, 0, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
54 6, 6, 3, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
55 6, 7, 7, 6,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
56 6, 8, 8, 7,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
57 };
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
58
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
59 static const uint8_t chroma_dc_coeff_token_bits[4*5]={
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
60 1, 0, 0, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
61 7, 1, 0, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
62 4, 6, 1, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
63 3, 3, 2, 5,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
64 2, 3, 2, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
65 };
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
66
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
67 static const uint8_t coeff_token_len[4][4*17]={
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
68 {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
69 1, 0, 0, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
70 6, 2, 0, 0, 8, 6, 3, 0, 9, 8, 7, 5, 10, 9, 8, 6,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
71 11,10, 9, 7, 13,11,10, 8, 13,13,11, 9, 13,13,13,10,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
72 14,14,13,11, 14,14,14,13, 15,15,14,14, 15,15,15,14,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
73 16,15,15,15, 16,16,16,15, 16,16,16,16, 16,16,16,16,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
74 },
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
75 {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
76 2, 0, 0, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
77 6, 2, 0, 0, 6, 5, 3, 0, 7, 6, 6, 4, 8, 6, 6, 4,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
78 8, 7, 7, 5, 9, 8, 8, 6, 11, 9, 9, 6, 11,11,11, 7,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
79 12,11,11, 9, 12,12,12,11, 12,12,12,11, 13,13,13,12,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
80 13,13,13,13, 13,14,13,13, 14,14,14,13, 14,14,14,14,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
81 },
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
82 {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
83 4, 0, 0, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
84 6, 4, 0, 0, 6, 5, 4, 0, 6, 5, 5, 4, 7, 5, 5, 4,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
85 7, 5, 5, 4, 7, 6, 6, 4, 7, 6, 6, 4, 8, 7, 7, 5,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
86 8, 8, 7, 6, 9, 8, 8, 7, 9, 9, 8, 8, 9, 9, 9, 8,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
87 10, 9, 9, 9, 10,10,10,10, 10,10,10,10, 10,10,10,10,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
88 },
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
89 {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
90 6, 0, 0, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
91 6, 6, 0, 0, 6, 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 6,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
92 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
93 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
94 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
95 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
96 };
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
97
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
98 static const uint8_t coeff_token_bits[4][4*17]={
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
99 {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
100 1, 0, 0, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
101 5, 1, 0, 0, 7, 4, 1, 0, 7, 6, 5, 3, 7, 6, 5, 3,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
102 7, 6, 5, 4, 15, 6, 5, 4, 11,14, 5, 4, 8,10,13, 4,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
103 15,14, 9, 4, 11,10,13,12, 15,14, 9,12, 11,10,13, 8,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
104 15, 1, 9,12, 11,14,13, 8, 7,10, 9,12, 4, 6, 5, 8,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
105 },
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
106 {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
107 3, 0, 0, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
108 11, 2, 0, 0, 7, 7, 3, 0, 7,10, 9, 5, 7, 6, 5, 4,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
109 4, 6, 5, 6, 7, 6, 5, 8, 15, 6, 5, 4, 11,14,13, 4,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
110 15,10, 9, 4, 11,14,13,12, 8,10, 9, 8, 15,14,13,12,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
111 11,10, 9,12, 7,11, 6, 8, 9, 8,10, 1, 7, 6, 5, 4,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
112 },
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
113 {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
114 15, 0, 0, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
115 15,14, 0, 0, 11,15,13, 0, 8,12,14,12, 15,10,11,11,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
116 11, 8, 9,10, 9,14,13, 9, 8,10, 9, 8, 15,14,13,13,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
117 11,14,10,12, 15,10,13,12, 11,14, 9,12, 8,10,13, 8,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
118 13, 7, 9,12, 9,12,11,10, 5, 8, 7, 6, 1, 4, 3, 2,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
119 },
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
120 {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
121 3, 0, 0, 0,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
122 0, 1, 0, 0, 4, 5, 6, 0, 8, 9,10,11, 12,13,14,15,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
123 16,17,18,19, 20,21,22,23, 24,25,26,27, 28,29,30,31,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
124 32,33,34,35, 36,37,38,39, 40,41,42,43, 44,45,46,47,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
125 48,49,50,51, 52,53,54,55, 56,57,58,59, 60,61,62,63,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
126 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
127 };
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
128
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
129 static const uint8_t total_zeros_len[16][16]= {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
130 {1,3,3,4,4,5,5,6,6,7,7,8,8,9,9,9},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
131 {3,3,3,3,3,4,4,4,4,5,5,6,6,6,6},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
132 {4,3,3,3,4,4,3,3,4,5,5,6,5,6},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
133 {5,3,4,4,3,3,3,4,3,4,5,5,5},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
134 {4,4,4,3,3,3,3,3,4,5,4,5},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
135 {6,5,3,3,3,3,3,3,4,3,6},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
136 {6,5,3,3,3,2,3,4,3,6},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
137 {6,4,5,3,2,2,3,3,6},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
138 {6,6,4,2,2,3,2,5},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
139 {5,5,3,2,2,2,4},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
140 {4,4,3,3,1,3},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
141 {4,4,2,1,3},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
142 {3,3,1,2},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
143 {2,2,1},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
144 {1,1},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
145 };
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
146
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
147 static const uint8_t total_zeros_bits[16][16]= {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
148 {1,3,2,3,2,3,2,3,2,3,2,3,2,3,2,1},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
149 {7,6,5,4,3,5,4,3,2,3,2,3,2,1,0},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
150 {5,7,6,5,4,3,4,3,2,3,2,1,1,0},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
151 {3,7,5,4,6,5,4,3,3,2,2,1,0},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
152 {5,4,3,7,6,5,4,3,2,1,1,0},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
153 {1,1,7,6,5,4,3,2,1,1,0},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
154 {1,1,5,4,3,3,2,1,1,0},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
155 {1,1,1,3,3,2,2,1,0},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
156 {1,0,1,3,2,1,1,1},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
157 {1,0,1,3,2,1,1},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
158 {0,1,1,2,1,3},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
159 {0,1,1,1,1},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
160 {0,1,1,1},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
161 {0,1,1},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
162 {0,1},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
163 };
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
164
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
165 static const uint8_t chroma_dc_total_zeros_len[3][4]= {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
166 { 1, 2, 3, 3,},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
167 { 1, 2, 2, 0,},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
168 { 1, 1, 0, 0,},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
169 };
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
170
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
171 static const uint8_t chroma_dc_total_zeros_bits[3][4]= {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
172 { 1, 1, 1, 0,},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
173 { 1, 1, 0, 0,},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
174 { 1, 0, 0, 0,},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
175 };
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
176
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
177 static const uint8_t run_len[7][16]={
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
178 {1,1},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
179 {1,2,2},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
180 {2,2,2,2},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
181 {2,2,2,3,3},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
182 {2,2,3,3,3,3},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
183 {2,3,3,3,3,3,3},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
184 {3,3,3,3,3,3,3,4,5,6,7,8,9,10,11},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
185 };
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
186
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
187 static const uint8_t run_bits[7][16]={
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
188 {1,0},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
189 {1,1,0},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
190 {3,2,1,0},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
191 {3,2,1,1,0},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
192 {3,2,3,2,1,0},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
193 {3,0,1,3,2,5,4},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
194 {7,6,5,4,3,2,1,1,1,1,1,1,1,1,1},
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
195 };
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
196
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
197 static VLC coeff_token_vlc[4];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
198 static VLC_TYPE coeff_token_vlc_tables[520+332+280+256][2];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
199 static const int coeff_token_vlc_tables_size[4]={520,332,280,256};
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
200
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
201 static VLC chroma_dc_coeff_token_vlc;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
202 static VLC_TYPE chroma_dc_coeff_token_vlc_table[256][2];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
203 static const int chroma_dc_coeff_token_vlc_table_size = 256;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
204
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
205 static VLC total_zeros_vlc[15];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
206 static VLC_TYPE total_zeros_vlc_tables[15][512][2];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
207 static const int total_zeros_vlc_tables_size = 512;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
208
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
209 static VLC chroma_dc_total_zeros_vlc[3];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
210 static VLC_TYPE chroma_dc_total_zeros_vlc_tables[3][8][2];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
211 static const int chroma_dc_total_zeros_vlc_tables_size = 8;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
212
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
213 static VLC run_vlc[6];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
214 static VLC_TYPE run_vlc_tables[6][8][2];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
215 static const int run_vlc_tables_size = 8;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
216
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
217 static VLC run7_vlc;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
218 static VLC_TYPE run7_vlc_table[96][2];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
219 static const int run7_vlc_table_size = 96;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
220
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
221 #define LEVEL_TAB_BITS 8
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
222 static int8_t cavlc_level_tab[7][1<<LEVEL_TAB_BITS][2];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
223
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
224
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
225 /**
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
226 * gets the predicted number of non-zero coefficients.
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
227 * @param n block index
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
228 */
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
229 static inline int pred_non_zero_count(H264Context *h, int n){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
230 const int index8= scan8[n];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
231 const int left= h->non_zero_count_cache[index8 - 1];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
232 const int top = h->non_zero_count_cache[index8 - 8];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
233 int i= left + top;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
234
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
235 if(i<64) i= (i+1)>>1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
236
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
237 tprintf(h->s.avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
238
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
239 return i&31;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
240 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
241
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
242 static av_cold void init_cavlc_level_tab(void){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
243 int suffix_length, mask;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
244 unsigned int i;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
245
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
246 for(suffix_length=0; suffix_length<7; suffix_length++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
247 for(i=0; i<(1<<LEVEL_TAB_BITS); i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
248 int prefix= LEVEL_TAB_BITS - av_log2(2*i);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
249 int level_code= (prefix<<suffix_length) + (i>>(LEVEL_TAB_BITS-prefix-1-suffix_length)) - (1<<suffix_length);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
250
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
251 mask= -(level_code&1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
252 level_code= (((2+level_code)>>1) ^ mask) - mask;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
253 if(prefix + 1 + suffix_length <= LEVEL_TAB_BITS){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
254 cavlc_level_tab[suffix_length][i][0]= level_code;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
255 cavlc_level_tab[suffix_length][i][1]= prefix + 1 + suffix_length;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
256 }else if(prefix + 1 <= LEVEL_TAB_BITS){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
257 cavlc_level_tab[suffix_length][i][0]= prefix+100;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
258 cavlc_level_tab[suffix_length][i][1]= prefix + 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
259 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
260 cavlc_level_tab[suffix_length][i][0]= LEVEL_TAB_BITS+100;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
261 cavlc_level_tab[suffix_length][i][1]= LEVEL_TAB_BITS;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
262 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
263 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
264 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
265 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
266
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
267 av_cold void ff_h264_decode_init_vlc(void){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
268 static int done = 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
269
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
270 if (!done) {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
271 int i;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
272 int offset;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
273 done = 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
274
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
275 chroma_dc_coeff_token_vlc.table = chroma_dc_coeff_token_vlc_table;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
276 chroma_dc_coeff_token_vlc.table_allocated = chroma_dc_coeff_token_vlc_table_size;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
277 init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
278 &chroma_dc_coeff_token_len [0], 1, 1,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
279 &chroma_dc_coeff_token_bits[0], 1, 1,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
280 INIT_VLC_USE_NEW_STATIC);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
281
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
282 offset = 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
283 for(i=0; i<4; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
284 coeff_token_vlc[i].table = coeff_token_vlc_tables+offset;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
285 coeff_token_vlc[i].table_allocated = coeff_token_vlc_tables_size[i];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
286 init_vlc(&coeff_token_vlc[i], COEFF_TOKEN_VLC_BITS, 4*17,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
287 &coeff_token_len [i][0], 1, 1,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
288 &coeff_token_bits[i][0], 1, 1,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
289 INIT_VLC_USE_NEW_STATIC);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
290 offset += coeff_token_vlc_tables_size[i];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
291 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
292 /*
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
293 * This is a one time safety check to make sure that
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
294 * the packed static coeff_token_vlc table sizes
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
295 * were initialized correctly.
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
296 */
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
297 assert(offset == FF_ARRAY_ELEMS(coeff_token_vlc_tables));
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
298
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
299 for(i=0; i<3; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
300 chroma_dc_total_zeros_vlc[i].table = chroma_dc_total_zeros_vlc_tables[i];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
301 chroma_dc_total_zeros_vlc[i].table_allocated = chroma_dc_total_zeros_vlc_tables_size;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
302 init_vlc(&chroma_dc_total_zeros_vlc[i],
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
303 CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
304 &chroma_dc_total_zeros_len [i][0], 1, 1,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
305 &chroma_dc_total_zeros_bits[i][0], 1, 1,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
306 INIT_VLC_USE_NEW_STATIC);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
307 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
308 for(i=0; i<15; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
309 total_zeros_vlc[i].table = total_zeros_vlc_tables[i];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
310 total_zeros_vlc[i].table_allocated = total_zeros_vlc_tables_size;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
311 init_vlc(&total_zeros_vlc[i],
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
312 TOTAL_ZEROS_VLC_BITS, 16,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
313 &total_zeros_len [i][0], 1, 1,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
314 &total_zeros_bits[i][0], 1, 1,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
315 INIT_VLC_USE_NEW_STATIC);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
316 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
317
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
318 for(i=0; i<6; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
319 run_vlc[i].table = run_vlc_tables[i];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
320 run_vlc[i].table_allocated = run_vlc_tables_size;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
321 init_vlc(&run_vlc[i],
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
322 RUN_VLC_BITS, 7,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
323 &run_len [i][0], 1, 1,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
324 &run_bits[i][0], 1, 1,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
325 INIT_VLC_USE_NEW_STATIC);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
326 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
327 run7_vlc.table = run7_vlc_table,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
328 run7_vlc.table_allocated = run7_vlc_table_size;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
329 init_vlc(&run7_vlc, RUN7_VLC_BITS, 16,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
330 &run_len [6][0], 1, 1,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
331 &run_bits[6][0], 1, 1,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
332 INIT_VLC_USE_NEW_STATIC);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
333
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
334 init_cavlc_level_tab();
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
335 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
336 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
337
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
338 /**
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
339 *
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
340 */
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
341 static inline int get_level_prefix(GetBitContext *gb){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
342 unsigned int buf;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
343 int log;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
344
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
345 OPEN_READER(re, gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
346 UPDATE_CACHE(re, gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
347 buf=GET_CACHE(re, gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
348
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
349 log= 32 - av_log2(buf);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
350 #ifdef TRACE
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
351 print_bin(buf>>(32-log), log);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
352 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d lpr @%5d in %s get_level_prefix\n", buf>>(32-log), log, log-1, get_bits_count(gb), __FILE__);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
353 #endif
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
354
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
355 LAST_SKIP_BITS(re, gb, log);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
356 CLOSE_READER(re, gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
357
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
358 return log-1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
359 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
360
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
361 /**
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
362 * decodes a residual block.
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
363 * @param n block index
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
364 * @param scantable scantable
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
365 * @param max_coeff number of coefficients in the block
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
366 * @return <0 if an error occurred
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
367 */
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
368 static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
369 MpegEncContext * const s = &h->s;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
370 static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3};
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
371 int level[16];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
372 int zeros_left, coeff_num, coeff_token, total_coeff, i, j, trailing_ones, run_before;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
373
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
374 //FIXME put trailing_onex into the context
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
375
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
376 if(n == CHROMA_DC_BLOCK_INDEX){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
377 coeff_token= get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
378 total_coeff= coeff_token>>2;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
379 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
380 if(n == LUMA_DC_BLOCK_INDEX){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
381 total_coeff= pred_non_zero_count(h, 0);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
382 coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
383 total_coeff= coeff_token>>2;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
384 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
385 total_coeff= pred_non_zero_count(h, n);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
386 coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
387 total_coeff= coeff_token>>2;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
388 h->non_zero_count_cache[ scan8[n] ]= total_coeff;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
389 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
390 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
391
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
392 //FIXME set last_non_zero?
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
393
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
394 if(total_coeff==0)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
395 return 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
396 if(total_coeff > (unsigned)max_coeff) {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
397 av_log(h->s.avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", s->mb_x, s->mb_y, total_coeff);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
398 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
399 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
400
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
401 trailing_ones= coeff_token&3;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
402 tprintf(h->s.avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
403 assert(total_coeff<=16);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
404
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
405 i = show_bits(gb, 3);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
406 skip_bits(gb, trailing_ones);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
407 level[0] = 1-((i&4)>>1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
408 level[1] = 1-((i&2) );
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
409 level[2] = 1-((i&1)<<1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
410
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
411 if(trailing_ones<total_coeff) {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
412 int mask, prefix;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
413 int suffix_length = total_coeff > 10 && trailing_ones < 3;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
414 int bitsi= show_bits(gb, LEVEL_TAB_BITS);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
415 int level_code= cavlc_level_tab[suffix_length][bitsi][0];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
416
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
417 skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
418 if(level_code >= 100){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
419 prefix= level_code - 100;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
420 if(prefix == LEVEL_TAB_BITS)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
421 prefix += get_level_prefix(gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
422
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
423 //first coefficient has suffix_length equal to 0 or 1
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
424 if(prefix<14){ //FIXME try to build a large unified VLC table for all this
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
425 if(suffix_length)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
426 level_code= (prefix<<1) + get_bits1(gb); //part
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
427 else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
428 level_code= prefix; //part
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
429 }else if(prefix==14){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
430 if(suffix_length)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
431 level_code= (prefix<<1) + get_bits1(gb); //part
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
432 else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
433 level_code= prefix + get_bits(gb, 4); //part
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
434 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
435 level_code= 30 + get_bits(gb, prefix-3); //part
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
436 if(prefix>=16)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
437 level_code += (1<<(prefix-3))-4096;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
438 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
439
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
440 if(trailing_ones < 3) level_code += 2;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
441
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
442 suffix_length = 2;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
443 mask= -(level_code&1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
444 level[trailing_ones]= (((2+level_code)>>1) ^ mask) - mask;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
445 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
446 if(trailing_ones < 3) level_code += (level_code>>31)|1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
447
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
448 suffix_length = 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
449 if(level_code + 3U > 6U)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
450 suffix_length++;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
451 level[trailing_ones]= level_code;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
452 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
453
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
454 //remaining coefficients have suffix_length > 0
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
455 for(i=trailing_ones+1;i<total_coeff;i++) {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
456 static const unsigned int suffix_limit[7] = {0,3,6,12,24,48,INT_MAX };
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
457 int bitsi= show_bits(gb, LEVEL_TAB_BITS);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
458 level_code= cavlc_level_tab[suffix_length][bitsi][0];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
459
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
460 skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
461 if(level_code >= 100){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
462 prefix= level_code - 100;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
463 if(prefix == LEVEL_TAB_BITS){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
464 prefix += get_level_prefix(gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
465 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
466 if(prefix<15){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
467 level_code = (prefix<<suffix_length) + get_bits(gb, suffix_length);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
468 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
469 level_code = (15<<suffix_length) + get_bits(gb, prefix-3);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
470 if(prefix>=16)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
471 level_code += (1<<(prefix-3))-4096;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
472 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
473 mask= -(level_code&1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
474 level_code= (((2+level_code)>>1) ^ mask) - mask;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
475 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
476 level[i]= level_code;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
477
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
478 if(suffix_limit[suffix_length] + level_code > 2U*suffix_limit[suffix_length])
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
479 suffix_length++;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
480 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
481 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
482
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
483 if(total_coeff == max_coeff)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
484 zeros_left=0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
485 else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
486 if(n == CHROMA_DC_BLOCK_INDEX)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
487 zeros_left= get_vlc2(gb, chroma_dc_total_zeros_vlc[ total_coeff-1 ].table, CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
488 else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
489 zeros_left= get_vlc2(gb, total_zeros_vlc[ total_coeff-1 ].table, TOTAL_ZEROS_VLC_BITS, 1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
490 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
491
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
492 coeff_num = zeros_left + total_coeff - 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
493 j = scantable[coeff_num];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
494 if(n > 24){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
495 block[j] = level[0];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
496 for(i=1;i<total_coeff;i++) {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
497 if(zeros_left <= 0)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
498 run_before = 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
499 else if(zeros_left < 7){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
500 run_before= get_vlc2(gb, run_vlc[zeros_left-1].table, RUN_VLC_BITS, 1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
501 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
502 run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
503 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
504 zeros_left -= run_before;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
505 coeff_num -= 1 + run_before;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
506 j= scantable[ coeff_num ];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
507
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
508 block[j]= level[i];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
509 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
510 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
511 block[j] = (level[0] * qmul[j] + 32)>>6;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
512 for(i=1;i<total_coeff;i++) {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
513 if(zeros_left <= 0)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
514 run_before = 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
515 else if(zeros_left < 7){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
516 run_before= get_vlc2(gb, run_vlc[zeros_left-1].table, RUN_VLC_BITS, 1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
517 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
518 run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
519 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
520 zeros_left -= run_before;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
521 coeff_num -= 1 + run_before;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
522 j= scantable[ coeff_num ];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
523
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
524 block[j]= (level[i] * qmul[j] + 32)>>6;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
525 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
526 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
527
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
528 if(zeros_left<0){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
529 av_log(h->s.avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
530 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
531 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
532
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
533 return 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
534 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
535
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
536 int ff_h264_decode_mb_cavlc(H264Context *h){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
537 MpegEncContext * const s = &h->s;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
538 int mb_xy;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
539 int partition_count;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
540 unsigned int mb_type, cbp;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
541 int dct8x8_allowed= h->pps.transform_8x8_mode;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
542
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
543 mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
544
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
545 tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
546 cbp = 0; /* avoid warning. FIXME: find a solution without slowing
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
547 down the code */
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
548 if(h->slice_type_nos != FF_I_TYPE){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
549 if(s->mb_skip_run==-1)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
550 s->mb_skip_run= get_ue_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
551
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
552 if (s->mb_skip_run--) {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
553 if(FRAME_MBAFF && (s->mb_y&1) == 0){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
554 if(s->mb_skip_run==0)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
555 h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
556 else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
557 predict_field_decoding_flag(h);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
558 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
559 decode_mb_skip(h);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
560 return 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
561 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
562 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
563 if(FRAME_MBAFF){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
564 if( (s->mb_y&1) == 0 )
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
565 h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
566 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
567
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
568 h->prev_mb_skipped= 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
569
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
570 mb_type= get_ue_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
571 if(h->slice_type_nos == FF_B_TYPE){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
572 if(mb_type < 23){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
573 partition_count= b_mb_type_info[mb_type].partition_count;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
574 mb_type= b_mb_type_info[mb_type].type;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
575 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
576 mb_type -= 23;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
577 goto decode_intra_mb;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
578 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
579 }else if(h->slice_type_nos == FF_P_TYPE){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
580 if(mb_type < 5){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
581 partition_count= p_mb_type_info[mb_type].partition_count;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
582 mb_type= p_mb_type_info[mb_type].type;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
583 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
584 mb_type -= 5;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
585 goto decode_intra_mb;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
586 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
587 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
588 assert(h->slice_type_nos == FF_I_TYPE);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
589 if(h->slice_type == FF_SI_TYPE && mb_type)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
590 mb_type--;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
591 decode_intra_mb:
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
592 if(mb_type > 25){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
593 av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_pict_type_char(h->slice_type), s->mb_x, s->mb_y);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
594 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
595 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
596 partition_count=0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
597 cbp= i_mb_type_info[mb_type].cbp;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
598 h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
599 mb_type= i_mb_type_info[mb_type].type;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
600 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
601
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
602 if(MB_FIELD)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
603 mb_type |= MB_TYPE_INTERLACED;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
604
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
605 h->slice_table[ mb_xy ]= h->slice_num;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
606
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
607 if(IS_INTRA_PCM(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
608 unsigned int x;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
609
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
610 // We assume these blocks are very rare so we do not optimize it.
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
611 align_get_bits(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
612
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
613 // The pixels are stored in the same order as levels in h->mb array.
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
614 for(x=0; x < (CHROMA ? 384 : 256); x++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
615 ((uint8_t*)h->mb)[x]= get_bits(&s->gb, 8);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
616 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
617
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
618 // In deblocking, the quantizer is 0
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
619 s->current_picture.qscale_table[mb_xy]= 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
620 // All coeffs are present
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
621 memset(h->non_zero_count[mb_xy], 16, 16);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
622
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
623 s->current_picture.mb_type[mb_xy]= mb_type;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
624 return 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
625 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
626
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
627 if(MB_MBAFF){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
628 h->ref_count[0] <<= 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
629 h->ref_count[1] <<= 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
630 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
631
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
632 fill_caches(h, mb_type, 0);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
633
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
634 //mb_pred
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
635 if(IS_INTRA(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
636 int pred_mode;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
637 // init_top_left_availability(h);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
638 if(IS_INTRA4x4(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
639 int i;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
640 int di = 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
641 if(dct8x8_allowed && get_bits1(&s->gb)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
642 mb_type |= MB_TYPE_8x8DCT;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
643 di = 4;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
644 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
645
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
646 // fill_intra4x4_pred_table(h);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
647 for(i=0; i<16; i+=di){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
648 int mode= pred_intra_mode(h, i);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
649
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
650 if(!get_bits1(&s->gb)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
651 const int rem_mode= get_bits(&s->gb, 3);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
652 mode = rem_mode + (rem_mode >= mode);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
653 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
654
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
655 if(di==4)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
656 fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 );
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
657 else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
658 h->intra4x4_pred_mode_cache[ scan8[i] ] = mode;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
659 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
660 ff_h264_write_back_intra_pred_mode(h);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
661 if( ff_h264_check_intra4x4_pred_mode(h) < 0)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
662 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
663 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
664 h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode(h, h->intra16x16_pred_mode);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
665 if(h->intra16x16_pred_mode < 0)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
666 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
667 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
668 if(CHROMA){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
669 pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&s->gb));
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
670 if(pred_mode < 0)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
671 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
672 h->chroma_pred_mode= pred_mode;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
673 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
674 }else if(partition_count==4){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
675 int i, j, sub_partition_count[4], list, ref[2][4];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
676
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
677 if(h->slice_type_nos == FF_B_TYPE){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
678 for(i=0; i<4; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
679 h->sub_mb_type[i]= get_ue_golomb_31(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
680 if(h->sub_mb_type[i] >=13){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
681 av_log(h->s.avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
682 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
683 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
684 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
685 h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
686 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
687 if( IS_DIRECT(h->sub_mb_type[0]) || IS_DIRECT(h->sub_mb_type[1])
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
688 || IS_DIRECT(h->sub_mb_type[2]) || IS_DIRECT(h->sub_mb_type[3])) {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
689 ff_h264_pred_direct_motion(h, &mb_type);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
690 h->ref_cache[0][scan8[4]] =
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
691 h->ref_cache[1][scan8[4]] =
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
692 h->ref_cache[0][scan8[12]] =
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
693 h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
694 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
695 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
696 assert(h->slice_type_nos == FF_P_TYPE); //FIXME SP correct ?
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
697 for(i=0; i<4; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
698 h->sub_mb_type[i]= get_ue_golomb_31(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
699 if(h->sub_mb_type[i] >=4){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
700 av_log(h->s.avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
701 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
702 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
703 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
704 h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
705 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
706 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
707
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
708 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
709 int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
710 for(i=0; i<4; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
711 if(IS_DIRECT(h->sub_mb_type[i])) continue;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
712 if(IS_DIR(h->sub_mb_type[i], 0, list)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
713 unsigned int tmp;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
714 if(ref_count == 1){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
715 tmp= 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
716 }else if(ref_count == 2){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
717 tmp= get_bits1(&s->gb)^1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
718 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
719 tmp= get_ue_golomb_31(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
720 if(tmp>=ref_count){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
721 av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
722 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
723 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
724 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
725 ref[list][i]= tmp;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
726 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
727 //FIXME
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
728 ref[list][i] = -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
729 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
730 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
731 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
732
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
733 if(dct8x8_allowed)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
734 dct8x8_allowed = get_dct8x8_allowed(h);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
735
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
736 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
737 for(i=0; i<4; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
738 if(IS_DIRECT(h->sub_mb_type[i])) {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
739 h->ref_cache[list][ scan8[4*i] ] = h->ref_cache[list][ scan8[4*i]+1 ];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
740 continue;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
741 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
742 h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]=
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
743 h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
744
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
745 if(IS_DIR(h->sub_mb_type[i], 0, list)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
746 const int sub_mb_type= h->sub_mb_type[i];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
747 const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
748 for(j=0; j<sub_partition_count[i]; j++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
749 int mx, my;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
750 const int index= 4*i + block_width*j;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
751 int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
752 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
753 mx += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
754 my += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
755 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
756
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
757 if(IS_SUB_8X8(sub_mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
758 mv_cache[ 1 ][0]=
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
759 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
760 mv_cache[ 1 ][1]=
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
761 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
762 }else if(IS_SUB_8X4(sub_mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
763 mv_cache[ 1 ][0]= mx;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
764 mv_cache[ 1 ][1]= my;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
765 }else if(IS_SUB_4X8(sub_mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
766 mv_cache[ 8 ][0]= mx;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
767 mv_cache[ 8 ][1]= my;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
768 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
769 mv_cache[ 0 ][0]= mx;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
770 mv_cache[ 0 ][1]= my;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
771 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
772 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
773 uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
774 p[0] = p[1]=
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
775 p[8] = p[9]= 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
776 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
777 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
778 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
779 }else if(IS_DIRECT(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
780 ff_h264_pred_direct_motion(h, &mb_type);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
781 dct8x8_allowed &= h->sps.direct_8x8_inference_flag;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
782 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
783 int list, mx, my, i;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
784 //FIXME we should set ref_idx_l? to 0 if we use that later ...
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
785 if(IS_16X16(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
786 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
787 unsigned int val;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
788 if(IS_DIR(mb_type, 0, list)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
789 if(h->ref_count[list]==1){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
790 val= 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
791 }else if(h->ref_count[list]==2){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
792 val= get_bits1(&s->gb)^1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
793 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
794 val= get_ue_golomb_31(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
795 if(val >= h->ref_count[list]){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
796 av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
797 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
798 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
799 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
800 }else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
801 val= LIST_NOT_USED&0xFF;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
802 fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
803 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
804 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
805 unsigned int val;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
806 if(IS_DIR(mb_type, 0, list)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
807 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
808 mx += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
809 my += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
810 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
811
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
812 val= pack16to32(mx,my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
813 }else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
814 val=0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
815 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, val, 4);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
816 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
817 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
818 else if(IS_16X8(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
819 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
820 for(i=0; i<2; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
821 unsigned int val;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
822 if(IS_DIR(mb_type, i, list)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
823 if(h->ref_count[list] == 1){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
824 val= 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
825 }else if(h->ref_count[list] == 2){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
826 val= get_bits1(&s->gb)^1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
827 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
828 val= get_ue_golomb_31(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
829 if(val >= h->ref_count[list]){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
830 av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
831 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
832 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
833 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
834 }else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
835 val= LIST_NOT_USED&0xFF;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
836 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
837 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
838 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
839 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
840 for(i=0; i<2; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
841 unsigned int val;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
842 if(IS_DIR(mb_type, i, list)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
843 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
844 mx += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
845 my += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
846 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
847
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
848 val= pack16to32(mx,my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
849 }else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
850 val=0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
851 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 4);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
852 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
853 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
854 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
855 assert(IS_8X16(mb_type));
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
856 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
857 for(i=0; i<2; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
858 unsigned int val;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
859 if(IS_DIR(mb_type, i, list)){ //FIXME optimize
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
860 if(h->ref_count[list]==1){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
861 val= 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
862 }else if(h->ref_count[list]==2){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
863 val= get_bits1(&s->gb)^1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
864 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
865 val= get_ue_golomb_31(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
866 if(val >= h->ref_count[list]){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
867 av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
868 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
869 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
870 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
871 }else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
872 val= LIST_NOT_USED&0xFF;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
873 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
874 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
875 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
876 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
877 for(i=0; i<2; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
878 unsigned int val;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
879 if(IS_DIR(mb_type, i, list)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
880 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
881 mx += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
882 my += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
883 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
884
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
885 val= pack16to32(mx,my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
886 }else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
887 val=0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
888 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 4);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
889 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
890 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
891 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
892 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
893
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
894 if(IS_INTER(mb_type))
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
895 write_back_motion(h, mb_type);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
896
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
897 if(!IS_INTRA16x16(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
898 cbp= get_ue_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
899 if(cbp > 47){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
900 av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
901 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
902 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
903
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
904 if(CHROMA){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
905 if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp[cbp];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
906 else cbp= golomb_to_inter_cbp [cbp];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
907 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
908 if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
909 else cbp= golomb_to_inter_cbp_gray[cbp];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
910 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
911 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
912 h->cbp = cbp;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
913
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
914 if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
915 if(get_bits1(&s->gb)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
916 mb_type |= MB_TYPE_8x8DCT;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
917 h->cbp_table[mb_xy]= cbp;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
918 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
919 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
920 s->current_picture.mb_type[mb_xy]= mb_type;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
921
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
922 if(cbp || IS_INTRA16x16(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
923 int i8x8, i4x4, chroma_idx;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
924 int dquant;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
925 GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
926 const uint8_t *scan, *scan8x8, *dc_scan;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
927
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
928 // fill_non_zero_count_cache(h);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
929
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
930 if(IS_INTERLACED(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
931 scan8x8= s->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
932 scan= s->qscale ? h->field_scan : h->field_scan_q0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
933 dc_scan= luma_dc_field_scan;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
934 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
935 scan8x8= s->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
936 scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
937 dc_scan= luma_dc_zigzag_scan;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
938 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
939
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
940 dquant= get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
941
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
942 if( dquant > 25 || dquant < -26 ){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
943 av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
944 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
945 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
946
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
947 s->qscale += dquant;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
948 if(((unsigned)s->qscale) > 51){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
949 if(s->qscale<0) s->qscale+= 52;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
950 else s->qscale-= 52;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
951 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
952
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
953 h->chroma_qp[0]= get_chroma_qp(h, 0, s->qscale);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
954 h->chroma_qp[1]= get_chroma_qp(h, 1, s->qscale);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
955 if(IS_INTRA16x16(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
956 if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, h->dequant4_coeff[0][s->qscale], 16) < 0){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
957 return -1; //FIXME continue if partitioned and other return -1 too
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
958 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
959
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
960 assert((cbp&15) == 0 || (cbp&15) == 15);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
961
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
962 if(cbp&15){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
963 for(i8x8=0; i8x8<4; i8x8++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
964 for(i4x4=0; i4x4<4; i4x4++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
965 const int index= i4x4 + 4*i8x8;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
966 if( decode_residual(h, h->intra_gb_ptr, h->mb + 16*index, index, scan + 1, h->dequant4_coeff[0][s->qscale], 15) < 0 ){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
967 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
968 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
969 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
970 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
971 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
972 fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
973 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
974 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
975 for(i8x8=0; i8x8<4; i8x8++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
976 if(cbp & (1<<i8x8)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
977 if(IS_8x8DCT(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
978 DCTELEM *buf = &h->mb[64*i8x8];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
979 uint8_t *nnz;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
980 for(i4x4=0; i4x4<4; i4x4++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
981 if( decode_residual(h, gb, buf, i4x4+4*i8x8, scan8x8+16*i4x4,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
982 h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 16) <0 )
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
983 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
984 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
985 nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
986 nnz[0] += nnz[1] + nnz[8] + nnz[9];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
987 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
988 for(i4x4=0; i4x4<4; i4x4++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
989 const int index= i4x4 + 4*i8x8;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
990
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
991 if( decode_residual(h, gb, h->mb + 16*index, index, scan, h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale], 16) <0 ){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
992 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
993 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
994 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
995 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
996 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
997 uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
998 nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
999 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1000 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1001 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1002
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1003 if(cbp&0x30){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1004 for(chroma_idx=0; chroma_idx<2; chroma_idx++)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1005 if( decode_residual(h, gb, h->mb + 256 + 16*4*chroma_idx, CHROMA_DC_BLOCK_INDEX, chroma_dc_scan, NULL, 4) < 0){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1006 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1007 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1008 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1009
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1010 if(cbp&0x20){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1011 for(chroma_idx=0; chroma_idx<2; chroma_idx++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1012 const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[chroma_idx]];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1013 for(i4x4=0; i4x4<4; i4x4++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1014 const int index= 16 + 4*chroma_idx + i4x4;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1015 if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, qmul, 15) < 0){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1016 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1017 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1018 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1019 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1020 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1021 uint8_t * const nnz= &h->non_zero_count_cache[0];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1022 nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] =
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1023 nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1024 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1025 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1026 uint8_t * const nnz= &h->non_zero_count_cache[0];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1027 fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1028 nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] =
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1029 nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1030 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1031 s->current_picture.qscale_table[mb_xy]= s->qscale;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1032 write_back_non_zero_count(h);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1033
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1034 if(MB_MBAFF){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1035 h->ref_count[0] >>= 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1036 h->ref_count[1] >>= 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1037 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1038
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1039 return 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1040 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1041