annotate h264_cavlc.c @ 10920:d7e7c2d42732 libavcodec

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