annotate h264_cavlc.c @ 10948:c80f0dfbf47d libavcodec

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