annotate h264_cavlc.c @ 11321:e0feb5fa4e97 libavcodec

Make the following functions static (and remove ff_), they are only used inside libxvidff.c: ff_xvid_encode_init(), ff_xvid_encode_frame(), ff_xvid_encode_close()
author cehoyos
date Sun, 28 Feb 2010 18:57:18 +0000
parents 5e583a785508
children c4c8c8c426eb
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;
10991
cf7a9b5c4064 1 cpu cycle faster suffix_length calculation.
michael
parents: 10959
diff changeset
411 int suffix_length = total_coeff > 10 & trailing_ones < 3;
10866
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{
10993
3932fd1a1c25 Optimize level_code computation, 6cpu cycles speedup.
michael
parents: 10991
diff changeset
444 level_code += ((level_code>>31)|1) & -(trailing_ones < 3);
10866
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
445
10994
2179ea01df62 Simplify suffix_length computation, same speed.
michael
parents: 10993
diff changeset
446 suffix_length = 1 + (level_code + 3U > 6U);
10866
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
447 level[trailing_ones]= level_code;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
448 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
449
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
450 //remaining coefficients have suffix_length > 0
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
451 for(i=trailing_ones+1;i<total_coeff;i++) {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
452 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
453 int bitsi= show_bits(gb, LEVEL_TAB_BITS);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
454 level_code= cavlc_level_tab[suffix_length][bitsi][0];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
455
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
456 skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
457 if(level_code >= 100){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
458 prefix= level_code - 100;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
459 if(prefix == LEVEL_TAB_BITS){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
460 prefix += get_level_prefix(gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
461 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
462 if(prefix<15){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
463 level_code = (prefix<<suffix_length) + get_bits(gb, suffix_length);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
464 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
465 level_code = (15<<suffix_length) + get_bits(gb, prefix-3);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
466 if(prefix>=16)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
467 level_code += (1<<(prefix-3))-4096;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
468 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
469 mask= -(level_code&1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
470 level_code= (((2+level_code)>>1) ^ mask) - mask;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
471 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
472 level[i]= level_code;
10995
5352afcd6748 Optimize suffix_length computation, 1 cpu cycle speedup.
michael
parents: 10994
diff changeset
473 suffix_length+= suffix_limit[suffix_length] + level_code > 2U*suffix_limit[suffix_length];
10866
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
474 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
475 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
476
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
477 if(total_coeff == max_coeff)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
478 zeros_left=0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
479 else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
480 if(n == CHROMA_DC_BLOCK_INDEX)
10996
26f9c146ef2a a[b-1] -> (a-1)[b].
michael
parents: 10995
diff changeset
481 zeros_left= get_vlc2(gb, (chroma_dc_total_zeros_vlc-1)[ total_coeff ].table, CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);
10866
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
482 else
10996
26f9c146ef2a a[b-1] -> (a-1)[b].
michael
parents: 10995
diff changeset
483 zeros_left= get_vlc2(gb, (total_zeros_vlc-1)[ total_coeff ].table, TOTAL_ZEROS_VLC_BITS, 1);
10866
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
484 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
485
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
486 coeff_num = zeros_left + total_coeff - 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
487 j = scantable[coeff_num];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
488 if(n > 24){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
489 block[j] = level[0];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
490 for(i=1;i<total_coeff;i++) {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
491 if(zeros_left <= 0)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
492 run_before = 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
493 else if(zeros_left < 7){
10996
26f9c146ef2a a[b-1] -> (a-1)[b].
michael
parents: 10995
diff changeset
494 run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1);
10866
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
495 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
496 run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
497 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
498 zeros_left -= run_before;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
499 coeff_num -= 1 + run_before;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
500 j= scantable[ coeff_num ];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
501
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
502 block[j]= level[i];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
503 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
504 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
505 block[j] = (level[0] * qmul[j] + 32)>>6;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
506 for(i=1;i<total_coeff;i++) {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
507 if(zeros_left <= 0)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
508 run_before = 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
509 else if(zeros_left < 7){
10996
26f9c146ef2a a[b-1] -> (a-1)[b].
michael
parents: 10995
diff changeset
510 run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1);
10866
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
511 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
512 run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
513 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
514 zeros_left -= run_before;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
515 coeff_num -= 1 + run_before;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
516 j= scantable[ coeff_num ];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
517
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
518 block[j]= (level[i] * qmul[j] + 32)>>6;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
519 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
520 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
521
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
522 if(zeros_left<0){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
523 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
524 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
525 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
526
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
527 return 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
528 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
529
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
530 int ff_h264_decode_mb_cavlc(H264Context *h){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
531 MpegEncContext * const s = &h->s;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
532 int mb_xy;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
533 int partition_count;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
534 unsigned int mb_type, cbp;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
535 int dct8x8_allowed= h->pps.transform_8x8_mode;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
536
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
537 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
538
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
539 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
540 cbp = 0; /* avoid warning. FIXME: find a solution without slowing
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
541 down the code */
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
542 if(h->slice_type_nos != FF_I_TYPE){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
543 if(s->mb_skip_run==-1)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
544 s->mb_skip_run= get_ue_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
545
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
546 if (s->mb_skip_run--) {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
547 if(FRAME_MBAFF && (s->mb_y&1) == 0){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
548 if(s->mb_skip_run==0)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
549 h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
550 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
551 decode_mb_skip(h);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
552 return 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
553 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
554 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
555 if(FRAME_MBAFF){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
556 if( (s->mb_y&1) == 0 )
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
557 h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
558 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
559
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
560 h->prev_mb_skipped= 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
561
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
562 mb_type= get_ue_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
563 if(h->slice_type_nos == FF_B_TYPE){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
564 if(mb_type < 23){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
565 partition_count= b_mb_type_info[mb_type].partition_count;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
566 mb_type= b_mb_type_info[mb_type].type;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
567 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
568 mb_type -= 23;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
569 goto decode_intra_mb;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
570 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
571 }else if(h->slice_type_nos == FF_P_TYPE){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
572 if(mb_type < 5){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
573 partition_count= p_mb_type_info[mb_type].partition_count;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
574 mb_type= p_mb_type_info[mb_type].type;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
575 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
576 mb_type -= 5;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
577 goto decode_intra_mb;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
578 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
579 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
580 assert(h->slice_type_nos == FF_I_TYPE);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
581 if(h->slice_type == FF_SI_TYPE && mb_type)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
582 mb_type--;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
583 decode_intra_mb:
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
584 if(mb_type > 25){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
585 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
586 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
587 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
588 partition_count=0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
589 cbp= i_mb_type_info[mb_type].cbp;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
590 h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
591 mb_type= i_mb_type_info[mb_type].type;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
592 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
593
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
594 if(MB_FIELD)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
595 mb_type |= MB_TYPE_INTERLACED;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
596
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
597 h->slice_table[ mb_xy ]= h->slice_num;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
598
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
599 if(IS_INTRA_PCM(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
600 unsigned int x;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
601
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
602 // We assume these blocks are very rare so we do not optimize it.
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
603 align_get_bits(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
604
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
605 // 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
606 for(x=0; x < (CHROMA ? 384 : 256); x++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
607 ((uint8_t*)h->mb)[x]= get_bits(&s->gb, 8);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
608 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
609
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
610 // In deblocking, the quantizer is 0
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
611 s->current_picture.qscale_table[mb_xy]= 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
612 // All coeffs are present
10906
1b5fba731e24 Rearchitecturing the stiched up goose part 1
michael
parents: 10893
diff changeset
613 memset(h->non_zero_count[mb_xy], 16, 32);
10866
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
614
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
615 s->current_picture.mb_type[mb_xy]= mb_type;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
616 return 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
617 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
618
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
619 if(MB_MBAFF){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
620 h->ref_count[0] <<= 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
621 h->ref_count[1] <<= 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
622 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
623
11183
d1a855cb0a0c Split setting neighboring MBs from fill_decode_caches()
michael
parents: 10999
diff changeset
624 fill_decode_neighbors(h, mb_type);
10907
2d82b73b12ef Split fill_caches() between filter and decoder.
michael
parents: 10906
diff changeset
625 fill_decode_caches(h, mb_type);
10866
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
626
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
627 //mb_pred
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
628 if(IS_INTRA(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
629 int pred_mode;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
630 // init_top_left_availability(h);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
631 if(IS_INTRA4x4(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
632 int i;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
633 int di = 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
634 if(dct8x8_allowed && get_bits1(&s->gb)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
635 mb_type |= MB_TYPE_8x8DCT;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
636 di = 4;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
637 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
638
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
639 // fill_intra4x4_pred_table(h);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
640 for(i=0; i<16; i+=di){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
641 int mode= pred_intra_mode(h, i);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
642
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
643 if(!get_bits1(&s->gb)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
644 const int rem_mode= get_bits(&s->gb, 3);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
645 mode = rem_mode + (rem_mode >= mode);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
646 }
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(di==4)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
649 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
650 else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
651 h->intra4x4_pred_mode_cache[ scan8[i] ] = mode;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
652 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
653 ff_h264_write_back_intra_pred_mode(h);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
654 if( ff_h264_check_intra4x4_pred_mode(h) < 0)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
655 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
656 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
657 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
658 if(h->intra16x16_pred_mode < 0)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
659 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
660 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
661 if(CHROMA){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
662 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
663 if(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 h->chroma_pred_mode= pred_mode;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
666 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
667 }else if(partition_count==4){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
668 int i, j, sub_partition_count[4], list, ref[2][4];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
669
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
670 if(h->slice_type_nos == FF_B_TYPE){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
671 for(i=0; i<4; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
672 h->sub_mb_type[i]= get_ue_golomb_31(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
673 if(h->sub_mb_type[i] >=13){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
674 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
675 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
676 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
677 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
678 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
679 }
10946
5a23fa01dec1 Merge multiple IS_* macro uses where possible.
michael
parents: 10929
diff changeset
680 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
681 ff_h264_pred_direct_motion(h, &mb_type);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
682 h->ref_cache[0][scan8[4]] =
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
683 h->ref_cache[1][scan8[4]] =
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
684 h->ref_cache[0][scan8[12]] =
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
685 h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
686 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
687 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
688 assert(h->slice_type_nos == FF_P_TYPE); //FIXME SP correct ?
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
689 for(i=0; i<4; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
690 h->sub_mb_type[i]= get_ue_golomb_31(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
691 if(h->sub_mb_type[i] >=4){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
692 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
693 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
694 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
695 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
696 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
697 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
698 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
699
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
700 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
701 int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
702 for(i=0; i<4; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
703 if(IS_DIRECT(h->sub_mb_type[i])) continue;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
704 if(IS_DIR(h->sub_mb_type[i], 0, list)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
705 unsigned int tmp;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
706 if(ref_count == 1){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
707 tmp= 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
708 }else if(ref_count == 2){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
709 tmp= get_bits1(&s->gb)^1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
710 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
711 tmp= get_ue_golomb_31(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
712 if(tmp>=ref_count){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
713 av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
714 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
715 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
716 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
717 ref[list][i]= tmp;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
718 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
719 //FIXME
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
720 ref[list][i] = -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
721 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
722 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
723 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
724
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
725 if(dct8x8_allowed)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
726 dct8x8_allowed = get_dct8x8_allowed(h);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
727
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
728 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
729 for(i=0; i<4; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
730 if(IS_DIRECT(h->sub_mb_type[i])) {
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
731 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
732 continue;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
733 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
734 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
735 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
736
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
737 if(IS_DIR(h->sub_mb_type[i], 0, list)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
738 const int sub_mb_type= h->sub_mb_type[i];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
739 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
740 for(j=0; j<sub_partition_count[i]; j++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
741 int mx, my;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
742 const int index= 4*i + block_width*j;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
743 int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
744 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
745 mx += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
746 my += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
747 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
748
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
749 if(IS_SUB_8X8(sub_mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
750 mv_cache[ 1 ][0]=
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
751 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
752 mv_cache[ 1 ][1]=
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
753 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
754 }else if(IS_SUB_8X4(sub_mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
755 mv_cache[ 1 ][0]= mx;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
756 mv_cache[ 1 ][1]= my;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
757 }else if(IS_SUB_4X8(sub_mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
758 mv_cache[ 8 ][0]= mx;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
759 mv_cache[ 8 ][1]= my;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
760 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
761 mv_cache[ 0 ][0]= mx;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
762 mv_cache[ 0 ][1]= my;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
763 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
764 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
765 uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
766 p[0] = p[1]=
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
767 p[8] = p[9]= 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
768 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
769 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
770 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
771 }else if(IS_DIRECT(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
772 ff_h264_pred_direct_motion(h, &mb_type);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
773 dct8x8_allowed &= h->sps.direct_8x8_inference_flag;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
774 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
775 int list, mx, my, i;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
776 //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
777 if(IS_16X16(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
778 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
779 unsigned int val;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
780 if(IS_DIR(mb_type, 0, list)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
781 if(h->ref_count[list]==1){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
782 val= 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
783 }else if(h->ref_count[list]==2){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
784 val= get_bits1(&s->gb)^1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
785 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
786 val= get_ue_golomb_31(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
787 if(val >= h->ref_count[list]){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
788 av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
789 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
790 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
791 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
792 }else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
793 val= LIST_NOT_USED&0xFF;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
794 fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 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 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
797 unsigned int val;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
798 if(IS_DIR(mb_type, 0, list)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
799 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
800 mx += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
801 my += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
802 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
803
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
804 val= pack16to32(mx,my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
805 }else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
806 val=0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
807 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, val, 4);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
808 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
809 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
810 else if(IS_16X8(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
811 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
812 for(i=0; i<2; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
813 unsigned int val;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
814 if(IS_DIR(mb_type, i, list)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
815 if(h->ref_count[list] == 1){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
816 val= 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
817 }else if(h->ref_count[list] == 2){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
818 val= get_bits1(&s->gb)^1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
819 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
820 val= get_ue_golomb_31(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
821 if(val >= h->ref_count[list]){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
822 av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
823 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
824 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
825 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
826 }else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
827 val= LIST_NOT_USED&0xFF;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
828 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
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 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
832 for(i=0; i<2; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
833 unsigned int val;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
834 if(IS_DIR(mb_type, i, list)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
835 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
836 mx += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
837 my += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
838 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
839
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
840 val= pack16to32(mx,my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
841 }else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
842 val=0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
843 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
844 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
845 }
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 assert(IS_8X16(mb_type));
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
848 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
849 for(i=0; i<2; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
850 unsigned int val;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
851 if(IS_DIR(mb_type, i, list)){ //FIXME optimize
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
852 if(h->ref_count[list]==1){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
853 val= 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
854 }else if(h->ref_count[list]==2){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
855 val= get_bits1(&s->gb)^1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
856 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
857 val= get_ue_golomb_31(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
858 if(val >= h->ref_count[list]){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
859 av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
860 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
861 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
862 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
863 }else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
864 val= LIST_NOT_USED&0xFF;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
865 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
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 for(list=0; list<h->list_count; list++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
869 for(i=0; i<2; i++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
870 unsigned int val;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
871 if(IS_DIR(mb_type, i, list)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
872 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
873 mx += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
874 my += get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
875 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
876
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
877 val= pack16to32(mx,my);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
878 }else
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
879 val=0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
880 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
881 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
882 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
883 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
884 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
885
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
886 if(IS_INTER(mb_type))
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
887 write_back_motion(h, mb_type);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
888
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
889 if(!IS_INTRA16x16(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
890 cbp= get_ue_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
891 if(cbp > 47){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
892 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
893 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
894 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
895
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
896 if(CHROMA){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
897 if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp[cbp];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
898 else cbp= golomb_to_inter_cbp [cbp];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
899 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
900 if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
901 else cbp= golomb_to_inter_cbp_gray[cbp];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
902 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
903 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
904
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
905 if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){
10999
7cfb7bb6e554 Branchless setting of MB_TYPE_8x8DCT.
michael
parents: 10998
diff changeset
906 mb_type |= MB_TYPE_8x8DCT*get_bits1(&s->gb);
10866
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
907 }
10920
d7e7c2d42732 filter_mb_fast needs cbp_table to be set.
michael
parents: 10907
diff changeset
908 h->cbp=
d7e7c2d42732 filter_mb_fast needs cbp_table to be set.
michael
parents: 10907
diff changeset
909 h->cbp_table[mb_xy]= cbp;
10866
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
910 s->current_picture.mb_type[mb_xy]= mb_type;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
911
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
912 if(cbp || IS_INTRA16x16(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
913 int i8x8, i4x4, chroma_idx;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
914 int dquant;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
915 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
916 const uint8_t *scan, *scan8x8, *dc_scan;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
917
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
918 if(IS_INTERLACED(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
919 scan8x8= s->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
920 scan= s->qscale ? h->field_scan : h->field_scan_q0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
921 dc_scan= luma_dc_field_scan;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
922 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
923 scan8x8= s->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
924 scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
925 dc_scan= luma_dc_zigzag_scan;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
926 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
927
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
928 dquant= get_se_golomb(&s->gb);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
929
10959
d5320d1acaee Move dquant check into qscale overflow check.
michael
parents: 10946
diff changeset
930 s->qscale += dquant;
10866
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
931
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
932 if(((unsigned)s->qscale) > 51){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
933 if(s->qscale<0) s->qscale+= 52;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
934 else s->qscale-= 52;
10959
d5320d1acaee Move dquant check into qscale overflow check.
michael
parents: 10946
diff changeset
935 if(((unsigned)s->qscale) > 51){
d5320d1acaee Move dquant check into qscale overflow check.
michael
parents: 10946
diff changeset
936 av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y);
d5320d1acaee Move dquant check into qscale overflow check.
michael
parents: 10946
diff changeset
937 return -1;
d5320d1acaee Move dquant check into qscale overflow check.
michael
parents: 10946
diff changeset
938 }
10866
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
939 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
940
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
941 h->chroma_qp[0]= get_chroma_qp(h, 0, s->qscale);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
942 h->chroma_qp[1]= get_chroma_qp(h, 1, s->qscale);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
943 if(IS_INTRA16x16(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
944 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
945 return -1; //FIXME continue if partitioned and other return -1 too
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
946 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
947
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
948 assert((cbp&15) == 0 || (cbp&15) == 15);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
949
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
950 if(cbp&15){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
951 for(i8x8=0; i8x8<4; i8x8++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
952 for(i4x4=0; i4x4<4; i4x4++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
953 const int index= i4x4 + 4*i8x8;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
954 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
955 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
956 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
957 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
958 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
959 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
960 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
961 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
962 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
963 for(i8x8=0; i8x8<4; i8x8++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
964 if(cbp & (1<<i8x8)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
965 if(IS_8x8DCT(mb_type)){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
966 DCTELEM *buf = &h->mb[64*i8x8];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
967 uint8_t *nnz;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
968 for(i4x4=0; i4x4<4; i4x4++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
969 if( decode_residual(h, gb, buf, i4x4+4*i8x8, scan8x8+16*i4x4,
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
970 h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 16) <0 )
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
971 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
972 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
973 nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
974 nnz[0] += nnz[1] + nnz[8] + nnz[9];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
975 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
976 for(i4x4=0; i4x4<4; i4x4++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
977 const int index= i4x4 + 4*i8x8;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
978
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
979 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
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 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
983 }
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 uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
986 nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
987 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
988 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
989 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
990
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
991 if(cbp&0x30){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
992 for(chroma_idx=0; chroma_idx<2; chroma_idx++)
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
993 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
994 return -1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
995 }
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 if(cbp&0x20){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
999 for(chroma_idx=0; chroma_idx<2; chroma_idx++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1000 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
1001 for(i4x4=0; i4x4<4; i4x4++){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1002 const int index= 16 + 4*chroma_idx + i4x4;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1003 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
1004 return -1;
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 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1008 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1009 uint8_t * const nnz= &h->non_zero_count_cache[0];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1010 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
1011 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
1012 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1013 }else{
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1014 uint8_t * const nnz= &h->non_zero_count_cache[0];
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1015 fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1016 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
1017 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
1018 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1019 s->current_picture.qscale_table[mb_xy]= s->qscale;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1020 write_back_non_zero_count(h);
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1021
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1022 if(MB_MBAFF){
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1023 h->ref_count[0] >>= 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1024 h->ref_count[1] >>= 1;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1025 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1026
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1027 return 0;
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1028 }
d26e9b4d2ca1 Split cavlc out of h264.c.
michael
parents:
diff changeset
1029