1 /*****************************************************************************
2 * vpar_blocks.c : blocks parsing
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
28 #include <sys/types.h> /* on BSD, uio.h needs types.h */
29 #include <sys/uio.h> /* "input.h" */
30 #include <string.h> /* memset */
39 #include "debug.h" /* XXX?? temporaire, requis par netlist.h */
42 #include "input_netlist.h"
43 #include "decoder_fifo.h"
45 #include "video_output.h"
47 #include "vdec_idct.h"
48 #include "video_decoder.h"
49 #include "vdec_motion.h"
51 #include "vpar_blocks.h"
52 #include "vpar_headers.h"
53 #include "vpar_synchro.h"
54 #include "video_parser.h"
55 #include "video_fifo.h"
58 * Welcome to vpar_blocks.c ! Here's where the heavy processor-critical parsing
59 * task is done. This file is divided in several parts :
60 * - Initialization of the lookup tables
61 * - Decoding of coded blocks
62 * - Decoding of motion vectors
63 * - Decoding of the other macroblock structures
64 * - Picture data parsing management (slices and error handling)
65 * It's a pretty long file. Good luck and have a nice day.
70 * Initialization tables
73 /* Table for coded_block_pattern resolution */
74 static lookup_t pl_coded_pattern[512] =
75 { {MB_ERROR, 0}, {0, 9}, {39, 9}, {27, 9}, {59, 9}, {55, 9}, {47, 9}, {31, 9},
76 {58, 8}, {58, 8}, {54, 8}, {54, 8}, {46, 8}, {46, 8}, {30, 8}, {30, 8},
77 {57, 8}, {57, 8}, {53, 8}, {53, 8}, {45, 8}, {45, 8}, {29, 8}, {29, 8},
78 {38, 8}, {38, 8}, {26, 8}, {26, 8}, {37, 8}, {37, 8}, {25, 8}, {25, 8},
79 {43, 8}, {43, 8}, {23, 8}, {23, 8}, {51, 8}, {51, 8}, {15, 8}, {15, 8},
80 {42, 8}, {42, 8}, {22, 8}, {22, 8}, {50, 8}, {50, 8}, {14, 8}, {14, 8},
81 {41, 8}, {41, 8}, {21, 8}, {21, 8}, {49, 8}, {49, 8}, {13, 8}, {13, 8},
82 {35, 8}, {35, 8}, {19, 8}, {19, 8}, {11, 8}, {11, 8}, {7, 8}, {7, 8},
83 {34, 7}, {34, 7}, {34, 7}, {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7},
84 {10, 7}, {10, 7}, {10, 7}, {10, 7}, {6, 7}, {6, 7}, {6, 7}, {6, 7},
85 {33, 7}, {33, 7}, {33, 7}, {33, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
86 {9, 7}, {9, 7}, {9, 7}, {9, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7},
87 {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6},
88 {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6},
89 {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6},
90 {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6},
91 {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5},
92 {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5},
93 {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5},
94 {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5},
95 {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5},
96 {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5},
97 {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5},
98 {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5},
99 {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5},
100 {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5},
101 {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5},
102 {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5},
103 {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5},
104 {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5},
105 {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5},
106 {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5},
107 {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5},
108 {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5},
109 {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5},
110 {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5},
111 {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5},
112 {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5},
113 {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
114 {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
115 {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
116 {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
117 {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
118 {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
119 {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
120 {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
121 {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
122 {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
123 {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4},
124 {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4},
125 {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4},
126 {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4},
127 {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
128 {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
129 {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
130 {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
131 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
132 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
133 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
134 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
135 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
136 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
137 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
138 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3} };
140 /* Tables for dc DCT coefficients
141 * Tables are cut in two parts to reduce memory occupation
144 /* Table B-12, dct_dc_size_luminance, codes 00XXX ... 11110 */
146 static lookup_t pl_dct_dc_lum_init_table_1[32] =
147 { {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
148 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
149 {0, 3}, {0, 3}, {0, 3}, {0, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
150 {4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5}, {MB_ERROR, 0}
153 static lookup_t ppl_dct_dc_init_table_1[2][32] =
154 { { {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
155 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
156 {0, 3}, {0, 3}, {0, 3}, {0, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
157 {4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5}, {MB_ERROR, 0}},
158 { {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
159 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
160 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
161 {3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5}, {MB_ERROR, 0}
165 /* Table B-12, dct_dc_size_luminance, codes 111110xxx ... 111111111 */
167 static lookup_t pl_dct_dc_lum_init_table_2[32] =
168 { {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6},
169 {8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10,9}, {11,9},
170 {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
171 {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
172 {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
173 {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}
176 static lookup_t ppl_dct_dc_init_table_2[2][32] =
177 { { {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6},
178 {8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10,9}, {11,9},
179 {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
180 {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
181 {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
182 {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}},
183 { {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
184 {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
185 {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7},
186 {8, 8}, {8, 8}, {8, 8}, {8, 8}, {9, 9}, {9, 9}, {10,10}, {11,10}
190 /* Table B-13, dct_dc_size_chrominance, codes 00xxx ... 11110 */
191 static lookup_t pl_dct_dc_chrom_init_table_1[32] =
192 { {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
193 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
194 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
195 {3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5}, {MB_ERROR, 0}
199 /* Table B-13, dct_dc_size_chrominance, codes 111110xxxx ... 1111111111 */
200 static lookup_t pl_dct_dc_chrom_init_table_2[32] =
201 { {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
202 {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
203 {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7},
204 {8, 8}, {8, 8}, {8, 8}, {8, 8}, {9, 9}, {9, 9}, {10,10}, {11,10}
208 /* Tables for ac DCT coefficients. There are cut in many parts to save space */
209 /* Table B-14, DCT coefficients table zero,
210 * codes 0100 ... 1xxx (used for first (DC) coefficient)
212 static dct_lookup_t pl_DCT_tab_dc[12] =
214 {0,2,4}, {2,1,4}, {1,1,3}, {1,1,3},
215 {0,1,1}, {0,1,1}, {0,1,1}, {0,1,1},
216 {0,1,1}, {0,1,1}, {0,1,1}, {0,1,1}
219 /* Table B-14, DCT coefficients table zero,
220 * codes 0100 ... 1xxx (used for all other coefficients)
222 static dct_lookup_t pl_DCT_tab_ac[12] =
224 {0,2,4}, {2,1,4}, {1,1,3}, {1,1,3},
225 {DCT_EOB,0,2}, {DCT_EOB,0,2}, {DCT_EOB,0,2}, {DCT_EOB,0,2}, /* EOB */
226 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}
229 /* Table B-14, DCT coefficients table zero,
230 * codes 000001xx ... 00111xxx
232 static dct_lookup_t pl_DCT_tab0[60] =
234 {DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6},
236 {2,2,7}, {2,2,7}, {9,1,7}, {9,1,7},
237 {0,4,7}, {0,4,7}, {8,1,7}, {8,1,7},
238 {7,1,6}, {7,1,6}, {7,1,6}, {7,1,6},
239 {6,1,6}, {6,1,6}, {6,1,6}, {6,1,6},
240 {1,2,6}, {1,2,6}, {1,2,6}, {1,2,6},
241 {5,1,6}, {5,1,6}, {5,1,6}, {5,1,6},
242 {13,1,8}, {0,6,8}, {12,1,8}, {11,1,8},
243 {3,2,8}, {1,3,8}, {0,5,8}, {10,1,8},
244 {0,3,5}, {0,3,5}, {0,3,5}, {0,3,5},
245 {0,3,5}, {0,3,5}, {0,3,5}, {0,3,5},
246 {4,1,5}, {4,1,5}, {4,1,5}, {4,1,5},
247 {4,1,5}, {4,1,5}, {4,1,5}, {4,1,5},
248 {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5},
249 {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5}
252 /* Table B-15, DCT coefficients table one,
253 * codes 000001xx ... 11111111
255 static dct_lookup_t pl_DCT_tab0a[252] =
257 {65,0,6}, {65,0,6}, {65,0,6}, {65,0,6}, /* Escape */
258 {7,1,7}, {7,1,7}, {8,1,7}, {8,1,7},
259 {6,1,7}, {6,1,7}, {2,2,7}, {2,2,7},
260 {0,7,6}, {0,7,6}, {0,7,6}, {0,7,6},
261 {0,6,6}, {0,6,6}, {0,6,6}, {0,6,6},
262 {4,1,6}, {4,1,6}, {4,1,6}, {4,1,6},
263 {5,1,6}, {5,1,6}, {5,1,6}, {5,1,6},
264 {1,5,8}, {11,1,8}, {0,11,8}, {0,10,8},
265 {13,1,8}, {12,1,8}, {3,2,8}, {1,4,8},
266 {2,1,5}, {2,1,5}, {2,1,5}, {2,1,5},
267 {2,1,5}, {2,1,5}, {2,1,5}, {2,1,5},
268 {1,2,5}, {1,2,5}, {1,2,5}, {1,2,5},
269 {1,2,5}, {1,2,5}, {1,2,5}, {1,2,5},
270 {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5},
271 {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5},
272 {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
273 {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
274 {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
275 {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
276 {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
277 {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
278 {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
279 {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
280 {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4}, /* EOB */
281 {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4},
282 {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4},
283 {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4},
284 {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
285 {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
286 {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
287 {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
288 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
289 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
290 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
291 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
292 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
293 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
294 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
295 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
296 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
297 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
298 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
299 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
300 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
301 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
302 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
303 {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
304 {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
305 {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
306 {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
307 {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
308 {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
309 {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
310 {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
311 {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
312 {0,4,5}, {0,4,5}, {0,4,5}, {0,4,5},
313 {0,4,5}, {0,4,5}, {0,4,5}, {0,4,5},
314 {0,5,5}, {0,5,5}, {0,5,5}, {0,5,5},
315 {0,5,5}, {0,5,5}, {0,5,5}, {0,5,5},
316 {9,1,7}, {9,1,7}, {1,3,7}, {1,3,7},
317 {10,1,7}, {10,1,7}, {0,8,7}, {0,8,7},
318 {0,9,7}, {0,9,7}, {0,12,8}, {0,13,8},
319 {2,3,8}, {4,2,8}, {0,14,8}, {0,15,8}
322 /* Table B-14, DCT coefficients table zero,
323 * codes 0000001000 ... 0000001111
325 static dct_lookup_t pl_DCT_tab1[8] =
327 {16,1,10}, {5,2,10}, {0,7,10}, {2,3,10},
328 {1,4,10}, {15,1,10}, {14,1,10}, {4,2,10}
331 /* Table B-15, DCT coefficients table one,
332 * codes 000000100x ... 000000111x
334 static dct_lookup_t pl_DCT_tab1a[8] =
336 {5,2,9}, {5,2,9}, {14,1,9}, {14,1,9},
337 {2,4,10}, {16,1,10}, {15,1,9}, {15,1,9}
340 /* Table B-14/15, DCT coefficients table zero / one,
341 * codes 000000010000 ... 000000011111
343 static dct_lookup_t pl_DCT_tab2[16] =
345 {0,11,12}, {8,2,12}, {4,3,12}, {0,10,12},
346 {2,4,12}, {7,2,12}, {21,1,12}, {20,1,12},
347 {0,9,12}, {19,1,12}, {18,1,12}, {1,5,12},
348 {3,3,12}, {0,8,12}, {6,2,12}, {17,1,12}
351 /* Table B-14/15, DCT coefficients table zero / one,
352 * codes 0000000010000 ... 0000000011111
354 static dct_lookup_t pl_DCT_tab3[16] =
356 {10,2,13}, {9,2,13}, {5,3,13}, {3,4,13},
357 {2,5,13}, {1,7,13}, {1,6,13}, {0,15,13},
358 {0,14,13}, {0,13,13}, {0,12,13}, {26,1,13},
359 {25,1,13}, {24,1,13}, {23,1,13}, {22,1,13}
362 /* Table B-14/15, DCT coefficients table zero / one,
363 * codes 00000000010000 ... 00000000011111
365 static dct_lookup_t pl_DCT_tab4[16] =
367 {0,31,14}, {0,30,14}, {0,29,14}, {0,28,14},
368 {0,27,14}, {0,26,14}, {0,25,14}, {0,24,14},
369 {0,23,14}, {0,22,14}, {0,21,14}, {0,20,14},
370 {0,19,14}, {0,18,14}, {0,17,14}, {0,16,14}
373 /* Table B-14/15, DCT coefficients table zero / one,
374 * codes 000000000010000 ... 000000000011111
376 static dct_lookup_t pl_DCT_tab5[16] =
378 {0,40,15}, {0,39,15}, {0,38,15}, {0,37,15},
379 {0,36,15}, {0,35,15}, {0,34,15}, {0,33,15},
380 {0,32,15}, {1,14,15}, {1,13,15}, {1,12,15},
381 {1,11,15}, {1,10,15}, {1,9,15}, {1,8,15}
384 /* Table B-14/15, DCT coefficients table zero / one,
385 * codes 0000000000010000 ... 0000000000011111
387 static dct_lookup_t pl_DCT_tab6[16] =
389 {1,18,16}, {1,17,16}, {1,16,16}, {1,15,16},
390 {6,3,16}, {16,2,16}, {15,2,16}, {14,2,16},
391 {13,2,16}, {12,2,16}, {11,2,16}, {31,1,16},
392 {30,1,16}, {29,1,16}, {28,1,16}, {27,1,16}
395 /* Pointers on tables of dct coefficients */
396 static dct_lookup_t * ppl_dct_tab1[2] = { pl_DCT_tab_ac, pl_DCT_tab0a };
398 static dct_lookup_t * ppl_dct_tab2[2] = { pl_DCT_tab_ac, pl_DCT_tab_dc };
401 /* Lookup Table for the chromatic component */
402 static int pi_cc_index[12] = { 0, 0, 0, 0, 1, 2, 1, 2, 1, 2 };
406 * Initialization of lookup tables
409 /*****************************************************************************
410 * vpar_InitCrop : Initialize the crop table for saturation
411 * (ISO/IEC 13818-2 section 7.4.3)
412 *****************************************************************************/
413 #if defined(MPEG2_COMPLIANT) && !defined(VDEC_DFT)
414 void vpar_InitCrop( vpar_thread_t * p_vpar )
418 p_vpar->pi_crop = p_vpar->pi_crop_buf + 4096;
420 for( i_dummy = -4096; i_dummy < -2048; i_dummy++ )
422 p_vpar->pi_crop[i_dummy] = -2048;
424 for( ; i_dummy < 2047; i_dummy++ )
426 p_vpar->pi_crop[i_dummy] = i_dummy;
428 for( ; i_dummy < 4095; i_dummy++ )
430 p_vpar->pi_crop[i_dummy] = 2047;
435 /*****************************************************************************
436 * vpar_InitMbAddrInc : Initialize the lookup table for mb_addr_inc
437 *****************************************************************************/
439 /* Function for filling up the lookup table for mb_addr_inc */
440 static void FillMbAddrIncTable( vpar_thread_t * p_vpar,
441 int i_start, int i_end, int i_step,
442 int * pi_value, int i_length )
445 for( i_pos = i_start ; i_pos < i_end ; i_pos += i_step )
447 for( i_offset = 0 ; i_offset < i_step ; i_offset ++ )
449 p_vpar->pl_mb_addr_inc[i_pos + i_offset].i_value = * pi_value;
450 p_vpar->pl_mb_addr_inc[i_pos + i_offset].i_length = i_length;
456 /* Function that initialize the table using the last one */
457 void vpar_InitMbAddrInc( vpar_thread_t * p_vpar )
462 for( i_dummy = 0 ; i_dummy < 8 ; i_dummy++ )
464 p_vpar->pl_mb_addr_inc[i_dummy].i_value = MB_ERROR;
465 p_vpar->pl_mb_addr_inc[i_dummy].i_length = 0;
468 p_vpar->pl_mb_addr_inc[8].i_value = MB_ADDRINC_ESCAPE;
469 p_vpar->pl_mb_addr_inc[8].i_length = 11;
471 for( i_dummy = 9 ; i_dummy < 15 ; i_dummy ++ )
473 p_vpar->pl_mb_addr_inc[i_dummy].i_value = MB_ERROR;
474 p_vpar->pl_mb_addr_inc[i_dummy].i_length = 0;
477 p_vpar->pl_mb_addr_inc[15].i_value = MB_ADDRINC_STUFFING;
478 p_vpar->pl_mb_addr_inc[15].i_length = 11;
480 for( i_dummy = 16; i_dummy < 24; i_dummy++ )
482 p_vpar->pl_mb_addr_inc[i_dummy].i_value = MB_ERROR;
483 p_vpar->pl_mb_addr_inc[i_dummy].i_length = 0;
488 FillMbAddrIncTable( p_vpar, 24, 36, 1, &i_value, 11 );
489 FillMbAddrIncTable( p_vpar, 36, 48, 2, &i_value, 10 );
490 FillMbAddrIncTable( p_vpar, 48, 96, 8, &i_value, 8 );
491 FillMbAddrIncTable( p_vpar, 96, 128, 16, &i_value, 7 );
492 FillMbAddrIncTable( p_vpar, 128, 256, 64, &i_value, 5 );
493 FillMbAddrIncTable( p_vpar, 256, 512, 128, &i_value, 4 );
494 FillMbAddrIncTable( p_vpar, 512, 1024, 256, &i_value, 3 );
495 FillMbAddrIncTable( p_vpar, 1024, 2048, 1024, &i_value, 1 );
498 /*****************************************************************************
499 * vpar_Init*MBType : Initialize lookup table for the Macroblock type
500 *****************************************************************************/
502 /* Fonction for filling up the tables */
503 static void FillMBType( vpar_thread_t * p_vpar,
512 for( i_dummy = i_start ; i_dummy < i_end ; i_dummy++ )
514 p_vpar->ppl_mb_type[i_mb_type][i_dummy].i_value = i_value;
515 p_vpar->ppl_mb_type[i_mb_type][i_dummy].i_length = i_length;
519 /* Fonction that fills the table for P MB_Type */
520 void vpar_InitPMBType( vpar_thread_t * p_vpar )
522 FillMBType( p_vpar, 0, 32, 64, MB_MOTION_FORWARD|MB_PATTERN, 1 );
523 FillMBType( p_vpar, 0, 16, 32, MB_PATTERN, 2 );
524 FillMBType( p_vpar, 0, 8, 16, MB_MOTION_FORWARD, 3 );
525 FillMBType( p_vpar, 0, 6, 8, MB_INTRA, 5 );
526 FillMBType( p_vpar, 0, 4, 6, MB_QUANT|MB_MOTION_FORWARD|MB_PATTERN, 5 );
527 FillMBType( p_vpar, 0, 2, 4, MB_QUANT|MB_PATTERN, 5 );
528 p_vpar->ppl_mb_type[0][1].i_value = MB_QUANT|MB_INTRA;
529 p_vpar->ppl_mb_type[0][1].i_length = 6;
530 p_vpar->ppl_mb_type[0][0].i_value = MB_ERROR;
531 p_vpar->ppl_mb_type[0][0].i_length = 0;
534 /* Fonction that fills the table for B MB_Type */
535 void vpar_InitBMBType( vpar_thread_t * p_vpar )
537 FillMBType( p_vpar, 1, 48, 64, MB_MOTION_FORWARD
538 |MB_MOTION_BACKWARD|MB_PATTERN, 2 );
539 FillMBType( p_vpar, 1, 32, 48, MB_MOTION_FORWARD|MB_MOTION_BACKWARD, 2 );
540 FillMBType( p_vpar, 1, 24, 32, MB_MOTION_BACKWARD|MB_PATTERN, 3 );
541 FillMBType( p_vpar, 1, 16, 24, MB_MOTION_BACKWARD, 3 );
542 FillMBType( p_vpar, 1, 12, 16, MB_MOTION_FORWARD|MB_PATTERN, 4 );
543 FillMBType( p_vpar, 1, 8, 12, MB_MOTION_FORWARD, 4 );
544 FillMBType( p_vpar, 1, 6, 8, MB_INTRA, 5 );
545 FillMBType( p_vpar, 1, 4, 6, MB_QUANT|MB_MOTION_FORWARD
546 |MB_MOTION_BACKWARD|MB_PATTERN, 5 );
547 p_vpar->ppl_mb_type[1][3].i_value = MB_QUANT|MB_MOTION_FORWARD|MB_PATTERN;
548 p_vpar->ppl_mb_type[1][3].i_length = 6;
549 p_vpar->ppl_mb_type[1][2].i_value = MB_QUANT|MB_MOTION_BACKWARD|MB_PATTERN;
550 p_vpar->ppl_mb_type[1][2].i_length = 6;
551 p_vpar->ppl_mb_type[1][1].i_value = MB_QUANT|MB_INTRA;
552 p_vpar->ppl_mb_type[1][1].i_length = 6;
553 p_vpar->ppl_mb_type[1][0].i_value =MB_ERROR;
554 p_vpar->ppl_mb_type[1][0].i_length = 0;
558 /*****************************************************************************
559 * vpar_InitDCTTables : Initialize tables giving the length of the dct
560 * coefficient from the vlc code
561 *****************************************************************************/
563 /* First fonction for filling the table */
564 static void FillDCTTable( dct_lookup_t * p_tab_dest, dct_lookup_t * p_tab_src,
565 int i_step, int i_nb_elem, int i_offset )
567 int i_dummy, i_dummy2;
569 for( i_dummy=0 ; i_dummy < i_nb_elem ; i_dummy++ )
571 for( i_dummy2=0 ; i_dummy2 < i_step ; i_dummy2++ )
573 p_tab_dest[(i_dummy+i_offset)*i_step+i_dummy2] = p_tab_src[i_dummy];
579 /* Fonction that actually fills the table or create the pointers */
580 void vpar_InitDCTTables( vpar_thread_t * p_vpar )
582 /* Tables are cut in two parts to reduce memory occupation */
583 p_vpar->pppl_dct_dc_size[0][0] = pl_dct_dc_lum_init_table_1;
584 p_vpar->pppl_dct_dc_size[0][1] = pl_dct_dc_lum_init_table_2;
585 p_vpar->pppl_dct_dc_size[1][0] = pl_dct_dc_chrom_init_table_1;
586 p_vpar->pppl_dct_dc_size[1][1] = pl_dct_dc_chrom_init_table_2;
588 /* XXX?? MB_ERROR is replaced by 0 because if we use -1 we
589 * can block in DecodeMPEG2Intra and others */
590 memset( p_vpar->ppl_dct_coef[0], 0, 16 );
591 memset( p_vpar->ppl_dct_coef[1], 0, 16 );
593 /* For table B14 & B15, we have a pointer to tables */
594 /* We fill the table thanks to the fonction defined above */
595 FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab0, 256, 60, 4 );
596 FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab1, 64, 8, 8 );
597 FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab2, 16, 16, 16 );
598 FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab3, 8, 16, 16 );
599 FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab4, 4, 16, 16 );
600 FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab5, 2, 16, 16 );
601 FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab6, 1, 16, 16 );
603 FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab0a, 256, 60, 4 );
604 FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab1a, 64, 8, 8 );
605 FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab2, 16, 16, 16 );
606 FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab3, 8, 16, 16 );
607 FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab4, 4, 16, 16 );
608 FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab5, 2, 16, 16 );
609 FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab6, 1, 16, 16 );
617 /*****************************************************************************
618 * DecodeMPEG1NonIntra : decode MPEG-1 non-intra blocks
619 *****************************************************************************/
620 static __inline__ void DecodeMPEG1NonIntra( vpar_thread_t * p_vpar,
621 macroblock_t * p_mb, int i_b,
622 int i_chroma_format )
637 /* Give the chromatic component (0, 1, 2) */
638 i_cc = pi_cc_index[i_b];
640 /* Determine whether it is luminance or not (chrominance) */
641 b_chroma = ( i_cc + 1 ) >> 1;
643 /* There should be no D picture in non-intra blocks */
644 if( p_vpar->picture.i_coding_type == D_CODING_TYPE )
645 intf_ErrMsg("vpar error : D-picture in non intra block\n");
647 /* Decoding of the AC coefficients */
653 for( i_parse = 0; !p_vpar->b_die; i_parse++ )
655 i_code = ShowBits( &p_vpar->bit_stream, 16 );
656 if( i_code >= 16384 )
658 b_dc = !((i_parse + 62)/63);
659 i_run = ppl_dct_tab2[b_dc][(i_code>>12)-4].i_run;
660 i_level = ppl_dct_tab2[b_dc][(i_code>>12)-4].i_level;
661 i_length = ppl_dct_tab2[b_dc][(i_code>>12)-4].i_length;
665 i_run = p_vpar->ppl_dct_coef[0][i_code].i_run;
666 i_length = p_vpar->ppl_dct_coef[0][i_code].i_length;
667 i_level = p_vpar->ppl_dct_coef[0][i_code].i_level;
670 RemoveBits( &p_vpar->bit_stream, i_length );
675 i_run = GetBits( &p_vpar->bit_stream, 6 );
676 i_level = GetBits( &p_vpar->bit_stream, 8 );
678 i_level = GetBits( &p_vpar->bit_stream, 8 );
679 else if (i_level == 128)
680 i_level = GetBits( &p_vpar->bit_stream, 8 ) - 256;
681 else if (i_level > 128)
690 /* The MMX IDCT has a precision problem with non-intra
692 p_mb->ppi_blocks[i_b][0] += 4;
696 p_mb->pf_idct[i_b] = vdec_SparseIDCT;
697 p_mb->pi_sparse_pos[i_b] = i_coef;
701 p_mb->pf_idct[i_b] = vdec_IDCT;
707 b_sign = GetBits( &p_vpar->bit_stream, 1 );
718 i_pos = pi_scan[p_vpar->picture.b_alternate_scan][i_parse];
719 i_level = ( ((i_level << 1) + 1) * p_vpar->mb.i_quantizer_scale
720 * p_vpar->sequence.nonintra_quant.pi_matrix[i_pos] ) >> 4;
721 p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
724 intf_ErrMsg("vpar error: DCT coeff (non-intra) is out of bounds\n");
725 p_vpar->picture.b_error = 1;
728 /*****************************************************************************
729 * DecodeMPEG1Intra : decode MPEG-1 intra blocks
730 *****************************************************************************/
731 static __inline__ void DecodeMPEG1Intra( vpar_thread_t * p_vpar,
732 macroblock_t * p_mb, int i_b ,
733 int i_chroma_format )
749 /* Give the chromatic component (0, 1, 2) */
750 i_cc = pi_cc_index[i_b];
752 /* Determine whether it is luminance or not (chrominance) */
753 b_chroma = ( i_cc + 1 ) >> 1;
756 i_code = ShowBits(&p_vpar->bit_stream, 5);
760 i_dct_dc_size = ppl_dct_dc_init_table_1[b_chroma][i_code].i_value;
761 i_length = ppl_dct_dc_init_table_1[b_chroma][i_code].i_length;
762 RemoveBits( &p_vpar->bit_stream, i_length);
766 i_code = ShowBits(&p_vpar->bit_stream, (9+b_chroma)) - (0x1f0 * (b_chroma + 1));
767 i_dct_dc_size = ppl_dct_dc_init_table_2[b_chroma][i_code].i_value;
768 i_length = ppl_dct_dc_init_table_2[b_chroma][i_code].i_length;
769 RemoveBits( &p_vpar->bit_stream, i_length);
772 if (i_dct_dc_size == 0)
776 i_dct_dc_diff = GetBits( &p_vpar->bit_stream, i_dct_dc_size);
777 if ((i_dct_dc_diff & (1<<(i_dct_dc_size-1))) == 0)
778 i_dct_dc_diff -= (1<<i_dct_dc_size) - 1;
781 /* Read the actual code with the good length */
782 p_vpar->mb.pi_dc_dct_pred[i_cc] += i_dct_dc_diff;
784 p_mb->ppi_blocks[i_b][0] = p_vpar->mb.pi_dc_dct_pred[i_cc];
786 i_nc = ( p_vpar->mb.pi_dc_dct_pred[i_cc] != 0 );
789 if( p_vpar->picture.i_coding_type == D_CODING_TYPE )
791 /* Remove end_of_macroblock (always 1, prevents startcode emulation)
792 * ISO/IEC 11172-2 section 2.4.2.7 and 2.4.3.6 */
793 RemoveBits( &p_vpar->bit_stream, 1 );
794 /* D pictures do not have AC coefficients */
799 /* Decoding of the AC coefficients */
804 for( i_parse = 1; !p_vpar->b_die/*i_parse < 64*/; i_parse++ )
806 i_code = ShowBits( &p_vpar->bit_stream, 16 );
807 /* We use 2 main tables for the coefficients */
808 if( i_code >= 16384 )
810 i_run = ppl_dct_tab1[0][(i_code>>12)-4].i_run;
811 i_level = ppl_dct_tab1[0][(i_code>>12)-4].i_level;
812 i_length = ppl_dct_tab1[0][(i_code>>12)-4].i_length;
816 i_run = p_vpar->ppl_dct_coef[0][i_code].i_run;
817 i_length = p_vpar->ppl_dct_coef[0][i_code].i_length;
818 i_level = p_vpar->ppl_dct_coef[0][i_code].i_level;
821 RemoveBits( &p_vpar->bit_stream, i_length );
826 i_run = GetBits( &p_vpar->bit_stream, 6 );
827 i_level = GetBits( &p_vpar->bit_stream, 8 );
829 i_level = GetBits( &p_vpar->bit_stream, 8 );
830 else if (i_level == 128)
831 i_level = GetBits( &p_vpar->bit_stream, 8 ) - 256;
832 else if (i_level > 128)
838 p_mb->pf_idct[i_b] = vdec_SparseIDCT;
839 p_mb->pi_sparse_pos[i_b] = i_coef;
843 p_mb->pf_idct[i_b] = vdec_IDCT;
849 b_sign = GetBits( &p_vpar->bit_stream, 1 );
852 /* Prepare the next block */
859 /* We have an error in the stream */
863 /* Determine the position of the block in the frame */
864 i_pos = pi_scan[p_vpar->picture.b_alternate_scan][i_parse];
865 i_level = ( i_level *
866 p_vpar->mb.i_quantizer_scale *
867 p_vpar->sequence.intra_quant.pi_matrix[i_pos] ) >> 3;
868 p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
871 intf_ErrMsg("vpar error: DCT coeff (intra) is out of bounds\n");
872 p_vpar->picture.b_error = 1;
875 /*****************************************************************************
876 * DecodeMPEG2NonIntra : decode MPEG-2 non-intra blocks
877 *****************************************************************************/
878 static __inline__ void DecodeMPEG2NonIntra( vpar_thread_t * p_vpar,
879 macroblock_t * p_mb, int i_b,
880 int i_chroma_format )
896 /* Give the chromatic component (0, 1, 2) */
897 i_cc = pi_cc_index[i_b];
899 /* Determine whether it is luminance or not (chrominance) */
900 b_chroma = ( i_cc + 1 ) >> 1;
902 /* Give a pointer to the quantization matrices for intra blocks */
903 if( (i_chroma_format == CHROMA_420) || (!b_chroma) )
905 pi_quant = p_vpar->sequence.nonintra_quant.pi_matrix;
909 pi_quant = p_vpar->sequence.chroma_nonintra_quant.pi_matrix;
912 /* Decoding of the AC coefficients */
916 for( i_parse = 0; !p_vpar->b_die; i_parse++ )
918 i_code = ShowBits( &p_vpar->bit_stream, 16 );
919 if( i_code >= 16384 )
921 b_dc = (i_parse == 0);
922 i_run = ppl_dct_tab2[b_dc][(i_code>>12)-4].i_run;
923 i_level = ppl_dct_tab2[b_dc][(i_code>>12)-4].i_level;
924 i_length = ppl_dct_tab2[b_dc][(i_code>>12)-4].i_length;
928 i_run = p_vpar->ppl_dct_coef[0][i_code].i_run;
929 i_length = p_vpar->ppl_dct_coef[0][i_code].i_length;
930 i_level = p_vpar->ppl_dct_coef[0][i_code].i_level;
934 RemoveBits( &p_vpar->bit_stream, i_length );
939 i_run = GetBits( &p_vpar->bit_stream, 6 );
940 i_level = GetBits( &p_vpar->bit_stream, 12 );
941 i_level = (b_sign = ( i_level > 2047 )) ? 4096 - i_level
946 /* The MMX IDCT has a precision problem with non-intra
948 p_mb->ppi_blocks[i_b][0] += 4;
952 p_mb->pf_idct[i_b] = vdec_SparseIDCT;
953 p_mb->pi_sparse_pos[i_b] = i_coef;
957 p_mb->pf_idct[i_b] = vdec_IDCT;
963 b_sign = GetBits( &p_vpar->bit_stream, 1 );
974 i_pos = pi_scan[p_vpar->picture.b_alternate_scan][i_parse];
975 i_level = ( ((i_level << 1) + 1) * p_vpar->mb.i_quantizer_scale
976 * pi_quant[i_pos] ) >> 5;
977 p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
980 intf_ErrMsg("vpar error: DCT coeff (non-intra) is out of bounds\n");
981 p_vpar->picture.b_error = 1;
984 /*****************************************************************************
985 * DecodeMPEG2Intra : decode MPEG-2 intra blocks
986 *****************************************************************************/
987 static __inline__ void DecodeMPEG2Intra( vpar_thread_t * p_vpar,
988 macroblock_t * p_mb, int i_b,
989 int i_chroma_format )
1002 boolean_t b_vlc_intra;
1007 /* Give the chromatic component (0, 1, 2) */
1008 i_cc = pi_cc_index[i_b];
1010 /* Determine whether it is luminance or not (chrominance) */
1011 b_chroma = ( i_cc + 1 ) >> 1;
1013 /* Give a pointer to the quantization matrices for intra blocks */
1014 if( (i_chroma_format == CHROMA_420) || (!b_chroma) )
1016 pi_quant = p_vpar->sequence.intra_quant.pi_matrix;
1020 pi_quant = p_vpar->sequence.chroma_intra_quant.pi_matrix;
1024 i_code = ShowBits(&p_vpar->bit_stream, 5);
1028 i_dct_dc_size = ppl_dct_dc_init_table_1[b_chroma][i_code].i_value;
1029 i_length = ppl_dct_dc_init_table_1[b_chroma][i_code].i_length;
1030 RemoveBits( &p_vpar->bit_stream, i_length);
1034 i_code = ShowBits(&p_vpar->bit_stream, (9+b_chroma)) - (0x1f0 * (b_chroma + 1));
1035 i_dct_dc_size = ppl_dct_dc_init_table_2[b_chroma][i_code].i_value;
1036 i_length = ppl_dct_dc_init_table_2[b_chroma][i_code].i_length;
1037 RemoveBits( &p_vpar->bit_stream, i_length);
1040 if (i_dct_dc_size == 0)
1044 i_dct_dc_diff = GetBits( &p_vpar->bit_stream, i_dct_dc_size);
1045 if ((i_dct_dc_diff & (1<<(i_dct_dc_size-1))) == 0)
1046 i_dct_dc_diff -= (1<<i_dct_dc_size) - 1;
1049 /* Read the actual code with the good length */
1050 p_vpar->mb.pi_dc_dct_pred[i_cc] += i_dct_dc_diff;
1052 p_mb->ppi_blocks[i_b][0] = ( p_vpar->mb.pi_dc_dct_pred[i_cc] <<
1053 ( 3 - p_vpar->picture.i_intra_dc_precision ) );
1055 i_nc = ( p_vpar->mb.pi_dc_dct_pred[i_cc] != 0 );
1058 /* Decoding of the AC coefficients */
1061 b_vlc_intra = p_vpar->picture.b_intra_vlc_format;
1062 for( i_parse = 1; !p_vpar->b_die/*i_parse < 64*/; i_parse++ )
1064 i_code = ShowBits( &p_vpar->bit_stream, 16 );
1065 /* We use 2 main tables for the coefficients */
1066 if( i_code >= 16384 )
1068 i_run = ppl_dct_tab1[b_vlc_intra][(i_code>>(12-(4*b_vlc_intra)))-4].i_run;
1069 i_level = ppl_dct_tab1[b_vlc_intra][(i_code>>(12-(4*b_vlc_intra)))-4].i_level;
1070 i_length = ppl_dct_tab1[b_vlc_intra][(i_code>>(12-(4*b_vlc_intra)))-4].i_length;
1074 i_run = p_vpar->ppl_dct_coef[b_vlc_intra][i_code].i_run;
1075 i_length = p_vpar->ppl_dct_coef[b_vlc_intra][i_code].i_length;
1076 i_level = p_vpar->ppl_dct_coef[b_vlc_intra][i_code].i_level;
1079 RemoveBits( &p_vpar->bit_stream, i_length );
1084 i_run = GetBits( &p_vpar->bit_stream, 6 );
1085 i_level = GetBits( &p_vpar->bit_stream, 12 );
1086 i_level = (b_sign = ( i_level > 2047 )) ? 4096 - i_level
1092 p_mb->pf_idct[i_b] = vdec_SparseIDCT;
1093 p_mb->pi_sparse_pos[i_b] = i_coef;
1097 p_mb->pf_idct[i_b] = vdec_IDCT;
1103 b_sign = GetBits( &p_vpar->bit_stream, 1 );
1106 /* Prepare the next block */
1113 /* We have an error in the stream */
1117 /* Determine the position of the block in the frame */
1118 i_pos = pi_scan[p_vpar->picture.b_alternate_scan][i_parse];
1119 i_level = ( i_level *
1120 p_vpar->mb.i_quantizer_scale *
1121 pi_quant[i_pos] ) >> 4;
1122 p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
1125 intf_ErrMsg("vpar error: DCT coeff (intra) is out of bounds\n");
1126 p_vpar->picture.b_error = 1;
1134 /****************************************************************************
1135 * MotionCode : Parse the next motion code
1136 ****************************************************************************/
1137 static __inline__ int MotionCode( vpar_thread_t * p_vpar )
1140 static lookup_t pl_mv_tab0[8] =
1141 { {-1,0}, {3,3}, {2,2}, {2,2}, {1,1}, {1,1}, {1,1}, {1,1} };
1142 /* Table B-10, motion_code, codes 0000011 ... 000011x */
1143 static lookup_t pl_mv_tab1[8] =
1144 { {-1,0}, {-1,0}, {-1,0}, {7,6}, {6,6}, {5,6}, {4,5}, {4,5} };
1145 /* Table B-10, motion_code, codes 0000001100 ... 000001011x */
1146 static lookup_t pl_mv_tab2[12] = {
1147 {16,9}, {15,9}, {14,9}, {13,9},
1148 {12,9}, {11,9}, {10,8}, {10,8},
1149 {9,8}, {9,8}, {8,8}, {8,8} };
1151 if( GetBits( &p_vpar->bit_stream, 1 ) )
1155 if( (i_code = ShowBits( &p_vpar->bit_stream, 9) ) >= 64 )
1158 RemoveBits( &p_vpar->bit_stream, pl_mv_tab0[i_code].i_length );
1159 return( GetBits( &p_vpar->bit_stream, 1 ) ?
1160 -pl_mv_tab0[i_code].i_value : pl_mv_tab0[i_code].i_value );
1166 RemoveBits( &p_vpar->bit_stream, pl_mv_tab1[i_code].i_length );
1167 return( GetBits( &p_vpar->bit_stream, 1 ) ?
1168 -pl_mv_tab1[i_code].i_value : pl_mv_tab1[i_code].i_value );
1171 if( (i_code -= 12) < 0 )
1173 p_vpar->picture.b_error = 1;
1174 intf_DbgMsg( "vpar debug: Invalid motion_vector code\n" );
1178 RemoveBits( &p_vpar->bit_stream, pl_mv_tab2[i_code].i_length );
1179 return( GetBits( &p_vpar->bit_stream, 1 ) ?
1180 -pl_mv_tab2[i_code].i_value : pl_mv_tab2[i_code].i_value );
1183 /****************************************************************************
1184 * DecodeMotionVector : Decode a motion_vector
1185 ****************************************************************************/
1186 static __inline__ void DecodeMotionVector( int * pi_prediction, int i_r_size,
1187 int i_motion_code, int i_motion_residual, int i_full_pel )
1189 int i_limit, i_vector;
1191 /* ISO/IEC 13818-1 section 7.6.3.1 */
1192 i_limit = 16 << i_r_size;
1193 i_vector = *pi_prediction >> i_full_pel;
1195 if( i_motion_code > 0 )
1197 i_vector += ((i_motion_code-1) << i_r_size) + i_motion_residual + 1;
1198 if( i_vector >= i_limit )
1199 i_vector -= i_limit + i_limit;
1201 else if( i_motion_code < 0 )
1203 i_vector -= ((-i_motion_code-1) << i_r_size) + i_motion_residual + 1;
1204 if( i_vector < -i_limit )
1205 i_vector += i_limit + i_limit;
1207 *pi_prediction = i_vector << i_full_pel;
1210 /****************************************************************************
1211 * MotionVector : Parse the next motion_vector field
1212 ****************************************************************************/
1213 static __inline__ void MotionVector( vpar_thread_t * p_vpar,
1214 macroblock_t * p_mb, int i_r,
1215 int i_s, int i_full_pel, int i_structure )
1217 int i_motion_code, i_motion_residual;
1219 int pi_dm_vector[2];
1221 i_r_size = p_vpar->picture.ppi_f_code[i_s][0] - 1;
1222 i_motion_code = MotionCode( p_vpar );
1223 i_motion_residual = (i_r_size != 0 && i_motion_code != 0) ?
1224 GetBits( &p_vpar->bit_stream, i_r_size) : 0;
1225 DecodeMotionVector( &p_vpar->mb.pppi_pmv[i_r][i_s][0], i_r_size,
1226 i_motion_code, i_motion_residual, i_full_pel );
1227 p_mb->pppi_motion_vectors[i_r][i_s][0] = p_vpar->mb.pppi_pmv[i_r][i_s][0];
1229 if( p_vpar->mb.b_dmv )
1231 if( GetBits(&p_vpar->bit_stream, 1) )
1233 pi_dm_vector[0] = GetBits( &p_vpar->bit_stream, 1 ) ? -1 : 1;
1237 pi_dm_vector[0] = 0;
1241 i_r_size = p_vpar->picture.ppi_f_code[i_s][1]-1;
1242 i_motion_code = MotionCode( p_vpar );
1243 i_motion_residual = (i_r_size != 0 && i_motion_code != 0) ?
1244 GetBits( &p_vpar->bit_stream, i_r_size) : 0;
1247 if( (p_vpar->mb.i_mv_format == MOTION_FIELD)
1248 && (i_structure == FRAME_STRUCTURE) )
1250 p_vpar->mb.pppi_pmv[i_r][i_s][1] >>= 1;
1253 DecodeMotionVector( &p_vpar->mb.pppi_pmv[i_r][i_s][1], i_r_size,
1254 i_motion_code, i_motion_residual, i_full_pel );
1256 if( (p_vpar->mb.i_mv_format == MOTION_FIELD)
1257 && (i_structure == FRAME_STRUCTURE) )
1258 p_vpar->mb.pppi_pmv[i_r][i_s][1] <<= 1;
1260 p_mb->pppi_motion_vectors[i_r][i_s][1] = p_vpar->mb.pppi_pmv[i_r][i_s][1];
1262 if( p_vpar->mb.b_dmv )
1264 if( GetBits(&p_vpar->bit_stream, 1) )
1266 pi_dm_vector[1] = GetBits( &p_vpar->bit_stream, 1 ) ? -1 : 1;
1270 pi_dm_vector[1] = 0;
1273 /* Dual Prime Arithmetic (ISO/IEC 13818-2 section 7.6.3.6). */
1275 #define i_mv_x p_mb->pppi_motion_vectors[0][0][0]
1276 if( i_structure == FRAME_STRUCTURE )
1278 #define i_mv_y (p_mb->pppi_motion_vectors[0][0][1] << 1)
1279 if( p_vpar->picture.b_top_field_first )
1281 /* vector for prediction of top field from bottom field */
1282 p_mb->ppi_dmv[0][0] = ((i_mv_x + (i_mv_x > 0)) >> 1) + pi_dm_vector[0];
1283 p_mb->ppi_dmv[0][1] = ((i_mv_y + (i_mv_y > 0)) >> 1) + pi_dm_vector[1] - 1;
1285 /* vector for prediction of bottom field from top field */
1286 p_mb->ppi_dmv[1][0] = ((3*i_mv_x + (i_mv_x > 0)) >> 1) + pi_dm_vector[0];
1287 p_mb->ppi_dmv[1][1] = ((3*i_mv_y + (i_mv_y > 0)) >> 1) + pi_dm_vector[1] + 1;
1291 /* vector for prediction of top field from bottom field */
1292 p_mb->ppi_dmv[0][0] = ((3*i_mv_x + (i_mv_x > 0)) >> 1) + pi_dm_vector[0];
1293 p_mb->ppi_dmv[0][1] = ((3*i_mv_y + (i_mv_y > 0)) >> 1) + pi_dm_vector[1] - 1;
1295 /* vector for prediction of bottom field from top field */
1296 p_mb->ppi_dmv[1][0] = ((i_mv_x + (i_mv_x > 0)) >> 1) + pi_dm_vector[0];
1297 p_mb->ppi_dmv[1][1] = ((i_mv_y + (i_mv_y > 0)) >> 1) + pi_dm_vector[1] + 1;
1303 #define i_mv_y p_mb->pppi_motion_vectors[0][0][1]
1304 /* vector for prediction from field of opposite 'parity' */
1305 p_mb->ppi_dmv[0][0] = ((i_mv_x + (i_mv_x > 0)) >> 1) + pi_dm_vector[0];
1306 p_mb->ppi_dmv[0][1] = ((i_mv_y + (i_mv_y > 0)) >> 1) + pi_dm_vector[1];
1308 /* correct for vertical field shift */
1309 if( p_vpar->picture.i_structure == TOP_FIELD )
1310 p_mb->ppi_dmv[0][1]--;
1312 p_mb->ppi_dmv[0][1]++;
1319 /*****************************************************************************
1320 * DecodeMVMPEG1 : Parse the next MPEG-1 motion vectors
1321 *****************************************************************************/
1322 static void DecodeMVMPEG1( vpar_thread_t * p_vpar,
1323 macroblock_t * p_mb, int i_s, int i_structure )
1325 MotionVector( p_vpar, p_mb, 0, i_s,
1326 p_vpar->picture.pb_full_pel_vector[i_s], i_structure );
1329 /*****************************************************************************
1330 * DecodeMVMPEG2 : Parse the next MPEG-2 motion_vectors field
1331 *****************************************************************************/
1332 static void DecodeMVMPEG2( vpar_thread_t * p_vpar,
1333 macroblock_t * p_mb, int i_s, int i_structure )
1335 if( p_vpar->mb.i_mv_count == 1 )
1337 if( p_vpar->mb.i_mv_format == MOTION_FIELD && !p_vpar->mb.b_dmv )
1339 p_mb->ppi_field_select[0][i_s] = p_mb->ppi_field_select[1][i_s]
1340 = GetBits( &p_vpar->bit_stream, 1 );
1342 MotionVector( p_vpar, p_mb, 0, i_s, 0, i_structure );
1343 p_vpar->mb.pppi_pmv[1][i_s][0] = p_vpar->mb.pppi_pmv[0][i_s][0];
1344 p_vpar->mb.pppi_pmv[1][i_s][1] = p_vpar->mb.pppi_pmv[0][i_s][1];
1345 p_mb->pppi_motion_vectors[1][i_s][0] = p_vpar->mb.pppi_pmv[0][i_s][0];
1346 p_mb->pppi_motion_vectors[1][i_s][1] = p_vpar->mb.pppi_pmv[0][i_s][1];
1350 p_mb->ppi_field_select[0][i_s] = GetBits( &p_vpar->bit_stream, 1 );
1351 MotionVector( p_vpar, p_mb, 0, i_s, 0, i_structure );
1352 p_mb->ppi_field_select[1][i_s] = GetBits( &p_vpar->bit_stream, 1 );
1353 MotionVector( p_vpar, p_mb, 1, i_s, 0, i_structure );
1359 * Macroblock information structures
1362 /*****************************************************************************
1363 * MacroblockAddressIncrement : Get the macroblock_address_increment field
1364 *****************************************************************************/
1365 static int MacroblockAddressIncrement( vpar_thread_t * p_vpar )
1368 /* Index in the lookup table mb_addr_inc */
1369 int i_index = ShowBits( &p_vpar->bit_stream, 11 );
1371 /* Test the presence of the escape character */
1372 while( i_index == 8 )
1374 RemoveBits( &p_vpar->bit_stream, 11 );
1376 i_index = ShowBits( &p_vpar->bit_stream, 11 );
1379 /* Affect the value from the lookup table */
1380 i_addr_inc += p_vpar->pl_mb_addr_inc[i_index].i_value;
1382 /* Dump the good number of bits */
1383 RemoveBits( &p_vpar->bit_stream, p_vpar->pl_mb_addr_inc[i_index].i_length );
1388 /*****************************************************************************
1389 * IMBType : macroblock_type in I pictures
1390 *****************************************************************************/
1391 static __inline__ int IMBType( vpar_thread_t * p_vpar )
1393 /* Take two bits for testing */
1394 int i_type = ShowBits( &p_vpar->bit_stream, 2 );
1396 /* Lookup table for macroblock_type */
1397 static lookup_t pl_mb_Itype[4] = { {MB_ERROR, 0},
1398 {MB_QUANT|MB_INTRA, 2},
1401 /* Dump the good number of bits */
1402 RemoveBits( &p_vpar->bit_stream, pl_mb_Itype[i_type].i_length );
1403 return pl_mb_Itype[i_type].i_value;
1406 /*****************************************************************************
1407 * PMBType : macroblock_type in P pictures
1408 *****************************************************************************/
1409 static __inline__ int PMBType( vpar_thread_t * p_vpar )
1411 /* Testing on 6 bits */
1412 int i_type = ShowBits( &p_vpar->bit_stream, 6 );
1414 /* Dump the good number of bits */
1415 RemoveBits( &p_vpar->bit_stream, p_vpar->ppl_mb_type[0][i_type].i_length );
1416 /* return the value from the lookup table for P type */
1417 return p_vpar->ppl_mb_type[0][i_type].i_value;
1420 /*****************************************************************************
1421 * BMBType : macroblock_type in B pictures
1422 *****************************************************************************/
1423 static __inline__ int BMBType( vpar_thread_t * p_vpar )
1425 /* Testing on 6 bits */
1426 int i_type = ShowBits( &p_vpar->bit_stream, 6 );
1428 /* Dump the good number of bits */
1429 RemoveBits( &p_vpar->bit_stream, p_vpar->ppl_mb_type[1][i_type].i_length );
1431 /* return the value from the lookup table for B type */
1432 return p_vpar->ppl_mb_type[1][i_type].i_value;
1435 /*****************************************************************************
1436 * DMBType : macroblock_type in D pictures
1437 *****************************************************************************/
1438 static __inline__ int DMBType( vpar_thread_t * p_vpar )
1440 return GetBits( &p_vpar->bit_stream, 1 );
1443 /*****************************************************************************
1444 * CodedPattern420 : coded_block_pattern with 4:2:0 chroma
1445 *****************************************************************************/
1446 static __inline__ int CodedPattern420( vpar_thread_t * p_vpar )
1448 /* Take the max 9 bits length vlc code for testing */
1449 int i_vlc = ShowBits( &p_vpar->bit_stream, 9 );
1451 /* Trash the good number of bits read in the lookup table */
1452 RemoveBits( &p_vpar->bit_stream, pl_coded_pattern[i_vlc].i_length );
1454 /* return the value from the vlc table */
1455 return pl_coded_pattern[i_vlc].i_value;
1458 /*****************************************************************************
1459 * CodedPattern422 : coded_block_pattern with 4:2:2 chroma
1460 *****************************************************************************/
1461 static __inline__ int CodedPattern422( vpar_thread_t * p_vpar )
1463 int i_vlc = ShowBits( &p_vpar->bit_stream, 9 );
1465 RemoveBits( &p_vpar->bit_stream, pl_coded_pattern[i_vlc].i_length );
1467 /* Supplementary 2 bits long code for 4:2:2 format */
1468 return pl_coded_pattern[i_vlc].i_value |
1469 (GetBits( &p_vpar->bit_stream, 2 ) << 6);
1472 /*****************************************************************************
1473 * CodedPattern444 : coded_block_pattern with 4:4:4 chroma
1474 *****************************************************************************/
1475 static __inline__ int CodedPattern444( vpar_thread_t * p_vpar )
1477 int i_vlc = ShowBits( &p_vpar->bit_stream, 9 );
1479 RemoveBits( &p_vpar->bit_stream, pl_coded_pattern[i_vlc].i_length );
1481 return pl_coded_pattern[i_vlc].i_value |
1482 (GetBits( &p_vpar->bit_stream, 6 ) << 6);
1485 /*****************************************************************************
1486 * InitMacroblock : Initialize macroblock values
1487 *****************************************************************************/
1488 static __inline__ void InitMacroblock( vpar_thread_t * p_vpar,
1489 macroblock_t * p_mb, int i_coding_type,
1490 int i_chroma_format,
1492 boolean_t b_second_field )
1494 p_mb->i_chroma_nb_blocks = 1 << i_chroma_format;
1495 p_mb->p_picture = p_vpar->picture.p_picture;
1497 if( i_coding_type == B_CODING_TYPE )
1498 p_mb->p_backward = p_vpar->sequence.p_backward;
1500 p_mb->p_backward = NULL;
1501 if( (i_coding_type == P_CODING_TYPE) || (i_coding_type == B_CODING_TYPE) )
1502 p_mb->p_forward = p_vpar->sequence.p_forward;
1504 p_mb->p_forward = NULL;
1506 p_mb->i_l_x = p_vpar->mb.i_l_x;
1507 p_mb->i_c_x = p_vpar->mb.i_c_x;
1508 p_mb->i_motion_l_y = p_vpar->mb.i_l_y;
1509 p_mb->i_motion_c_y = p_vpar->mb.i_c_y;
1510 if( (p_mb->b_motion_field = (i_structure == BOTTOM_FIELD)) )
1512 p_mb->i_motion_l_y--;
1513 p_mb->i_motion_c_y--;
1515 p_mb->i_addb_l_stride = (p_mb->i_l_stride = p_vpar->picture.i_l_stride) - 8;
1516 p_mb->i_addb_c_stride = (p_mb->i_c_stride = p_vpar->picture.i_c_stride) - 8;
1517 p_mb->b_P_second = ( b_second_field && i_coding_type == P_CODING_TYPE );
1520 /*****************************************************************************
1521 * UpdateContext : Update the p_vpar contextual values
1522 *****************************************************************************/
1523 static __inline__ void UpdateContext( vpar_thread_t * p_vpar, int i_structure )
1525 /* Update macroblock real position. */
1526 p_vpar->mb.i_l_x += 16;
1527 p_vpar->mb.i_l_y += (p_vpar->mb.i_l_x / p_vpar->sequence.i_width)
1528 * (2 - (i_structure == FRAME_STRUCTURE)) * 16;
1529 p_vpar->mb.i_l_x %= p_vpar->sequence.i_width;
1531 p_vpar->mb.i_c_x += p_vpar->sequence.i_chroma_mb_width;
1532 p_vpar->mb.i_c_y += (p_vpar->mb.i_c_x / p_vpar->sequence.i_chroma_width)
1533 * (2 - (i_structure == FRAME_STRUCTURE))
1534 * p_vpar->sequence.i_chroma_mb_height;
1535 p_vpar->mb.i_c_x %= p_vpar->sequence.i_chroma_width;
1538 /*****************************************************************************
1539 * SkippedMacroblock : Generate a skipped macroblock with NULL motion vector
1540 *****************************************************************************/
1541 static __inline__ void SkippedMacroblock( vpar_thread_t * p_vpar, int i_mb,
1542 int i_mb_base, int i_coding_type,
1543 int i_chroma_format,
1545 boolean_t b_second_field )
1547 macroblock_t * p_mb;
1549 static f_motion_t pf_motion_skipped[4][4] =
1551 {NULL, NULL, NULL, NULL},
1552 {NULL, vdec_MotionFieldField420, vdec_MotionFieldField420,
1553 vdec_MotionFrameFrame420},
1554 {NULL, vdec_MotionFieldField422, vdec_MotionFieldField422,
1555 vdec_MotionFrameFrame422},
1556 {NULL, vdec_MotionFieldField444, vdec_MotionFieldField444,
1557 vdec_MotionFrameFrame444},
1560 if( i_coding_type == I_CODING_TYPE )
1562 intf_DbgMsg("vpar error: skipped macroblock in I-picture\n");
1563 p_vpar->picture.b_error = 1;
1567 if( (p_mb = vpar_NewMacroblock( &p_vpar->vfifo )) == NULL )
1573 p_vpar->picture.pp_mb[i_mb_base + i_mb] = p_mb;
1576 InitMacroblock( p_vpar, p_mb, i_coding_type, i_chroma_format,
1577 i_structure, b_second_field );
1579 /* Motion type is picture structure. */
1580 p_mb->pf_motion = pf_motion_skipped[i_chroma_format]
1582 p_mb->i_mb_type = MB_MOTION_FORWARD;
1583 p_mb->i_coded_block_pattern = 0;
1584 memset( p_mb->pppi_motion_vectors, 0, 8*sizeof(int) );
1586 /* Set the field we use for motion compensation */
1587 p_mb->ppi_field_select[0][0] = p_mb->ppi_field_select[0][1]
1588 = ( i_structure == BOTTOM_FIELD );
1590 UpdateContext( p_vpar, i_structure );
1593 /* Decode the macroblock NOW ! */
1594 vdec_DecodeMacroblock( p_vpar->pp_vdec[0], p_mb );
1598 /*****************************************************************************
1599 * MacroblockModes : Get the macroblock_modes structure
1600 *****************************************************************************/
1601 static __inline__ void MacroblockModes( vpar_thread_t * p_vpar,
1602 macroblock_t * p_mb,
1603 int i_chroma_format,
1607 static int ppi_mv_count[2][4] = { {0, 1, 2, 1}, {0, 2, 1, 1} };
1608 static int ppi_mv_format[2][4] = { {0, 1, 1, 1}, {0, 1, 2, 1} };
1610 /* Get macroblock_type. */
1611 switch( i_coding_type )
1614 p_mb->i_mb_type = PMBType( p_vpar );
1617 p_mb->i_mb_type = BMBType( p_vpar );
1620 p_mb->i_mb_type = IMBType( p_vpar );
1623 p_mb->i_mb_type = DMBType( p_vpar );
1626 /* SCALABILITY : warning, we don't know if spatial_temporal_weight_code
1627 * has to be dropped, take care if you use scalable streams. */
1628 /* RemoveBits( &p_vpar->bit_stream, 2 ); */
1630 if( (i_coding_type == P_CODING_TYPE || i_coding_type == B_CODING_TYPE)
1631 && (p_mb->i_mb_type & (MB_MOTION_FORWARD | MB_MOTION_BACKWARD)) )
1633 if( !(i_structure == FRAME_STRUCTURE
1634 && p_vpar->picture.b_frame_pred_frame_dct) )
1636 p_vpar->mb.i_motion_type = GetBits( &p_vpar->bit_stream, 2 );
1640 p_vpar->mb.i_motion_type = MOTION_FRAME;
1644 p_vpar->mb.i_mv_count = ppi_mv_count[i_structure == FRAME_STRUCTURE]
1645 [p_vpar->mb.i_motion_type];
1646 p_vpar->mb.i_mv_format = ppi_mv_format[i_structure == FRAME_STRUCTURE]
1647 [p_vpar->mb.i_motion_type];
1648 p_vpar->mb.b_dmv = p_vpar->mb.i_motion_type == MOTION_DMV;
1651 p_vpar->mb.b_dct_type = 0;
1652 if( (i_structure == FRAME_STRUCTURE) &&
1653 (!p_vpar->picture.b_frame_pred_frame_dct) &&
1654 (p_mb->i_mb_type & (MB_PATTERN|MB_INTRA)) )
1656 if( (p_vpar->mb.b_dct_type = GetBits( &p_vpar->bit_stream, 1 )) )
1658 /* The DCT is coded on fields. Jump one line between each
1660 p_mb->i_addb_l_stride <<= 1;
1661 p_mb->i_addb_l_stride += 8;
1662 /* With CHROMA_420, the DCT is necessarily frame-coded. */
1663 if( i_chroma_format != CHROMA_420 )
1665 p_mb->i_addb_c_stride <<= 1;
1666 p_mb->i_addb_c_stride += 8;
1672 /*****************************************************************************
1673 * ParseMacroblock : Parse the next macroblock
1674 *****************************************************************************/
1675 #define PARSEERROR \
1676 if( p_vpar->picture.b_error ) \
1678 /* Mark this block as skipped (better than green blocks), and \
1679 * go to the next slice. */ \
1680 (*pi_mb_address)--; \
1681 vpar_DestroyMacroblock( &p_vpar->vfifo, p_mb ); \
1685 #define PARSEBLOCKS( MPEG1FUNC, MPEG2FUNC ) \
1687 i_mask = 1 << (3 + (1 << i_chroma_format)); \
1690 p_data1 = p_mb->p_picture->p_y \
1691 + p_mb->i_l_x + p_vpar->mb.i_l_y*(p_vpar->sequence.i_width); \
1693 for( i_b = 0 ; i_b < 4 ; i_b++, i_mask >>= 1 ) \
1695 if( p_mb->i_coded_block_pattern & i_mask ) \
1697 memset( p_mb->ppi_blocks[i_b], 0, 64*sizeof(dctelem_t) ); \
1699 MPEG2FUNC( p_vpar, p_mb, i_b, i_chroma_format ); \
1701 MPEG1FUNC( p_vpar, p_mb, i_b, i_chroma_format ); \
1703 /* Calculate block coordinates. */ \
1704 p_mb->p_data[i_b] = p_data1 \
1705 + pi_y[p_vpar->mb.b_dct_type][i_b] \
1706 * p_vpar->picture.i_l_stride \
1714 p_data1 = p_mb->p_picture->p_u \
1716 + p_vpar->mb.i_c_y \
1717 * (p_vpar->sequence.i_chroma_width); \
1718 p_data2 = p_mb->p_picture->p_v \
1720 + p_vpar->mb.i_c_y \
1721 * (p_vpar->sequence.i_chroma_width); \
1723 for( i_b = 4; i_b < 4 + (1 << i_chroma_format); \
1724 i_b++, i_mask >>= 1 ) \
1726 yuv_data_t * pp_data[2] = {p_data1, p_data2}; \
1728 if( p_mb->i_coded_block_pattern & i_mask ) \
1730 memset( p_mb->ppi_blocks[i_b], 0, 64*sizeof(dctelem_t) ); \
1732 MPEG2FUNC( p_vpar, p_mb, i_b, i_chroma_format ); \
1734 MPEG1FUNC( p_vpar, p_mb, i_b, i_chroma_format ); \
1736 /* Calculate block coordinates. */ \
1737 p_mb->p_data[i_b] = pp_data[i_b & 1] \
1738 + pi_y[p_vpar->mb.b_dct_type][i_b] \
1739 * p_vpar->picture.i_c_stride \
1747 static __inline__ void ParseMacroblock(
1748 vpar_thread_t * p_vpar,
1749 int * pi_mb_address, /* previous address to be
1750 * used for mb_addr_incr */
1751 int i_mb_previous, /* actual previous mb */
1752 int i_mb_base, /* non-zero if field structure */
1753 /* The following parameters are explicit in
1754 * optimized routines : */
1755 boolean_t b_mpeg2, /* you know what ? */
1756 int i_coding_type, /* I, P, B or D */
1757 int i_chroma_format, /* 4:2:0, 4:2:2 or 4:4:4 */
1758 int i_structure, /* T(OP), B(OTTOM) or F(RAME) */
1759 boolean_t b_second_field ) /* second field of a
1762 static f_motion_t pppf_motion[4][2][4] =
1764 { {NULL, NULL, NULL, NULL},
1765 {NULL, NULL, NULL, NULL}
1767 { {NULL, vdec_MotionFieldField420, vdec_MotionField16x8420,
1768 vdec_MotionFieldDMV420},
1769 {NULL, vdec_MotionFrameField420, vdec_MotionFrameFrame420,
1770 vdec_MotionFrameDMV420}
1772 { {NULL, vdec_MotionFieldField422, vdec_MotionField16x8422,
1773 vdec_MotionFieldDMV422},
1774 {NULL, vdec_MotionFrameField422, vdec_MotionFrameFrame422,
1775 vdec_MotionFrameDMV422}
1777 { {NULL, vdec_MotionFieldField444, vdec_MotionField16x8444,
1778 vdec_MotionFieldDMV444},
1779 {NULL, vdec_MotionFrameField444, vdec_MotionFrameFrame444,
1780 vdec_MotionFrameDMV444}
1783 static int pi_x[12] = {0,8,0,8,0,0,0,0,8,8,8,8};
1784 static int pi_y[2][12] = { {0,0,8,8,0,0,8,8,0,0,8,8},
1785 {0,0,1,1,0,0,1,1,0,0,1,1} };
1786 int i_mb, i_b, i_mask;
1788 macroblock_t * p_mb;
1789 yuv_data_t * p_data1;
1790 yuv_data_t * p_data2;
1792 i_inc = MacroblockAddressIncrement( p_vpar );
1793 *pi_mb_address += i_inc;
1797 intf_ErrMsg( "vpar error: bad address increment (%d)\n", i_inc );
1798 p_vpar->picture.b_error = 1;
1802 if( *pi_mb_address - i_mb_previous - 1 )
1804 /* Skipped macroblock (ISO/IEC 13818-2 7.6.6). */
1806 /* Reset DC predictors (7.2.1). */
1807 p_vpar->mb.pi_dc_dct_pred[0] = p_vpar->mb.pi_dc_dct_pred[1]
1808 = p_vpar->mb.pi_dc_dct_pred[2]
1809 = 1 << (7 + p_vpar->picture.i_intra_dc_precision);
1811 if( i_coding_type == P_CODING_TYPE )
1813 /* Reset motion vector predictors (ISO/IEC 13818-2 7.6.3.4). */
1814 memset( p_vpar->mb.pppi_pmv, 0, 8*sizeof(int) );
1817 for( i_mb = i_mb_previous + 1; i_mb < *pi_mb_address; i_mb++ )
1819 SkippedMacroblock( p_vpar, i_mb, i_mb_base, i_coding_type,
1820 i_chroma_format, i_structure, b_second_field );
1824 /* Get a macroblock structure. */
1825 if( (p_mb = vpar_NewMacroblock( &p_vpar->vfifo )) == NULL )
1831 p_vpar->picture.pp_mb[i_mb_base + *pi_mb_address] = p_mb;
1834 InitMacroblock( p_vpar, p_mb, i_coding_type, i_chroma_format,
1835 i_structure, b_second_field );
1837 /* Parse off macroblock_modes structure. */
1838 MacroblockModes( p_vpar, p_mb, i_chroma_format, i_coding_type,
1841 if( p_mb->i_mb_type & MB_QUANT )
1843 LoadQuantizerScale( p_vpar );
1846 if( (i_coding_type == P_CODING_TYPE || i_coding_type == B_CODING_TYPE)
1847 && (p_mb->i_mb_type & MB_MOTION_FORWARD) )
1850 DecodeMVMPEG2( p_vpar, p_mb, 0, i_structure );
1852 DecodeMVMPEG1( p_vpar, p_mb, 0, i_structure );
1856 if( (i_coding_type == B_CODING_TYPE)
1857 && (p_mb->i_mb_type & MB_MOTION_BACKWARD) )
1860 DecodeMVMPEG2( p_vpar, p_mb, 1, i_structure );
1862 DecodeMVMPEG1( p_vpar, p_mb, 1, i_structure );
1866 if( i_coding_type == P_CODING_TYPE
1867 && !(p_mb->i_mb_type & (MB_MOTION_FORWARD|MB_INTRA)) )
1869 /* Special No-MC macroblock in P pictures (7.6.3.5). */
1870 p_mb->i_mb_type |= MB_MOTION_FORWARD;
1871 memset( p_vpar->mb.pppi_pmv, 0, 8*sizeof(int) );
1872 memset( p_mb->pppi_motion_vectors, 0, 8*sizeof(int) );
1873 p_vpar->mb.i_motion_type = 1 + (i_structure == FRAME_STRUCTURE);
1874 p_mb->ppi_field_select[0][0] = (i_structure == BOTTOM_FIELD);
1877 if( (i_coding_type != I_CODING_TYPE) && !(p_mb->i_mb_type & MB_INTRA) )
1879 /* Reset DC predictors (7.2.1). */
1880 p_vpar->mb.pi_dc_dct_pred[0] = p_vpar->mb.pi_dc_dct_pred[1]
1881 = p_vpar->mb.pi_dc_dct_pred[2]
1882 = 1 << (7 + p_vpar->picture.i_intra_dc_precision);
1884 /* Motion function pointer. */
1885 p_mb->pf_motion = pppf_motion[i_chroma_format]
1886 [i_structure == FRAME_STRUCTURE]
1887 [p_vpar->mb.i_motion_type];
1889 if( p_mb->i_mb_type & MB_PATTERN )
1891 switch( i_chroma_format )
1894 p_mb->i_coded_block_pattern = CodedPattern420( p_vpar );
1897 p_mb->i_coded_block_pattern = CodedPattern422( p_vpar );
1900 p_mb->i_coded_block_pattern = CodedPattern444( p_vpar );
1905 p_mb->i_coded_block_pattern = 0;
1909 * Effectively decode blocks.
1911 PARSEBLOCKS( DecodeMPEG1NonIntra, DecodeMPEG2NonIntra )
1915 if( !p_vpar->picture.b_concealment_mv )
1917 /* Reset MV predictors. */
1918 memset( p_vpar->mb.pppi_pmv, 0, 8*sizeof(int) );
1923 DecodeMVMPEG2( p_vpar, p_mb, 0, i_structure );
1925 DecodeMVMPEG1( p_vpar, p_mb, 0, i_structure );
1926 RemoveBits( &p_vpar->bit_stream, 1 );
1929 if( p_mb->i_mb_type & MB_PATTERN )
1931 switch( i_chroma_format )
1934 p_mb->i_coded_block_pattern = CodedPattern420( p_vpar );
1937 p_mb->i_coded_block_pattern = CodedPattern422( p_vpar );
1940 p_mb->i_coded_block_pattern = CodedPattern444( p_vpar );
1945 p_mb->i_coded_block_pattern =
1946 (1 << (4 + (1 << i_chroma_format))) - 1;
1950 * Effectively decode blocks.
1952 PARSEBLOCKS( DecodeMPEG1Intra, DecodeMPEG2Intra )
1955 if( !p_vpar->picture.b_error )
1957 UpdateContext( p_vpar, i_structure );
1959 /* Decode the macroblock NOW ! */
1960 vdec_DecodeMacroblock( p_vpar->pp_vdec[0], p_mb );
1965 /* Mark this block as skipped (better than green blocks), and go
1966 * to the next slice. */
1968 vpar_DestroyMacroblock( &p_vpar->vfifo, p_mb );
1973 * Picture data parsing management
1976 /*****************************************************************************
1977 * ParseMacroblockVWXYZ : Parse the next macroblock ; specific functions
1978 *****************************************************************************
1981 * X = chroma format ?
1983 * Z = second field ?
1984 *****************************************************************************/
1985 void ParseMacroblockGENERIC( vpar_thread_t * p_vpar, int * pi_mb_address,
1986 int i_mb_previous, int i_mb_base,
1987 boolean_t b_mpeg2, int i_coding_type,
1988 int i_chroma_format, int i_structure,
1989 boolean_t b_second_field )
1991 ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
1992 b_mpeg2, i_coding_type, i_chroma_format,
1993 i_structure, b_second_field );
1996 #if (VPAR_OPTIM_LEVEL > 0)
1997 /* Optimizations for frame pictures */
1998 void ParseMacroblock2I420F0( vpar_thread_t * p_vpar, int * pi_mb_address, int i_mb_previous, int i_mb_base,
1999 boolean_t b_mpeg2, int i_coding_type,
2000 int i_chroma_format, int i_structure,
2001 boolean_t b_second_field )
2003 ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
2004 1, I_CODING_TYPE, CHROMA_420,
2005 FRAME_STRUCTURE, 0 );
2008 void ParseMacroblock2P420F0( vpar_thread_t * p_vpar, int * pi_mb_address, int i_mb_previous, int i_mb_base,
2009 boolean_t b_mpeg2, int i_coding_type,
2010 int i_chroma_format, int i_structure,
2011 boolean_t b_second_field )
2013 ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
2014 1, P_CODING_TYPE, CHROMA_420,
2015 FRAME_STRUCTURE, 0 );
2018 void ParseMacroblock2B420F0( vpar_thread_t * p_vpar, int * pi_mb_address, int i_mb_previous, int i_mb_base,
2019 boolean_t b_mpeg2, int i_coding_type,
2020 int i_chroma_format, int i_structure,
2021 boolean_t b_second_field )
2023 ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
2024 1, B_CODING_TYPE, CHROMA_420,
2025 FRAME_STRUCTURE, 0 );
2029 #if (VPAR_OPTIM_LEVEL > 1)
2030 /* Optimizations for field pictures */
2031 void ParseMacroblock2I420TZ( vpar_thread_t * p_vpar, int * pi_mb_address, int i_mb_previous, int i_mb_base,
2032 boolean_t b_mpeg2, int i_coding_type,
2033 int i_chroma_format, int i_structure,
2034 boolean_t b_second_field )
2036 ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
2037 1, I_CODING_TYPE, CHROMA_420,
2038 TOP_FIELD, (p_vpar->picture.i_structure !=
2039 p_vpar->picture.i_current_structure) );
2042 void ParseMacroblock2P420TZ( vpar_thread_t * p_vpar, int * pi_mb_address, int i_mb_previous, int i_mb_base,
2043 boolean_t b_mpeg2, int i_coding_type,
2044 int i_chroma_format, int i_structure,
2045 boolean_t b_second_field )
2047 ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
2048 1, P_CODING_TYPE, CHROMA_420,
2049 TOP_FIELD, (p_vpar->picture.i_structure !=
2050 p_vpar->picture.i_current_structure) );
2053 void ParseMacroblock2B420TZ( vpar_thread_t * p_vpar, int * pi_mb_address, int i_mb_previous, int i_mb_base,
2054 boolean_t b_mpeg2, int i_coding_type,
2055 int i_chroma_format, int i_structure,
2056 boolean_t b_second_field )
2058 ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
2059 1, B_CODING_TYPE, CHROMA_420,
2060 TOP_FIELD, (p_vpar->picture.i_structure !=
2061 p_vpar->picture.i_current_structure) );
2064 void ParseMacroblock2I420BZ( vpar_thread_t * p_vpar, int * pi_mb_address, int i_mb_previous, int i_mb_base,
2065 boolean_t b_mpeg2, int i_coding_type,
2066 int i_chroma_format, int i_structure,
2067 boolean_t b_second_field )
2069 ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
2070 1, I_CODING_TYPE, CHROMA_420,
2071 BOTTOM_FIELD, (p_vpar->picture.i_structure !=
2072 p_vpar->picture.i_current_structure) );
2075 void ParseMacroblock2P420BZ( vpar_thread_t * p_vpar, int * pi_mb_address, int i_mb_previous, int i_mb_base,
2076 boolean_t b_mpeg2, int i_coding_type,
2077 int i_chroma_format, int i_structure,
2078 boolean_t b_second_field )
2080 ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
2081 1, P_CODING_TYPE, CHROMA_420,
2082 BOTTOM_FIELD, (p_vpar->picture.i_structure !=
2083 p_vpar->picture.i_current_structure) );
2086 void ParseMacroblock2B420BZ( vpar_thread_t * p_vpar, int * pi_mb_address, int i_mb_previous, int i_mb_base,
2087 boolean_t b_mpeg2, int i_coding_type,
2088 int i_chroma_format, int i_structure,
2089 boolean_t b_second_field )
2091 ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
2092 1, B_CODING_TYPE, CHROMA_420,
2093 BOTTOM_FIELD, (p_vpar->picture.i_structure !=
2094 p_vpar->picture.i_current_structure) );
2098 /*****************************************************************************
2099 * SliceHeader : Parse the next slice structure
2100 *****************************************************************************/
2101 typedef void (*f_parse_mb_t)( vpar_thread_t * p_vpar, int * pi_mb_address, int i_mb_previous, int i_mb_base,
2102 boolean_t b_mpeg2, int i_coding_type,
2103 int i_chroma_format, int i_structure,
2104 boolean_t b_second_field );
2106 static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
2107 int * pi_mb_address, int i_mb_base,
2108 u32 i_vert_code, boolean_t b_high,
2109 boolean_t b_dp_scalable,
2110 boolean_t b_mpeg2, int i_coding_type,
2111 int i_chroma_format, int i_structure,
2112 boolean_t b_second_field )
2114 static f_parse_mb_t ppf_parse_mb[4][4] =
2117 NULL, NULL, NULL, NULL
2121 #if (VPAR_OPTIM_LEVEL > 1)
2122 NULL, ParseMacroblock2I420TZ, ParseMacroblock2P420TZ,
2123 ParseMacroblock2B420TZ
2125 NULL, ParseMacroblockGENERIC, ParseMacroblockGENERIC,
2126 ParseMacroblockGENERIC
2131 #if (VPAR_OPTIM_LEVEL > 1)
2132 NULL, ParseMacroblock2I420BZ, ParseMacroblock2P420BZ,
2133 ParseMacroblock2B420BZ
2135 NULL, ParseMacroblockGENERIC, ParseMacroblockGENERIC,
2136 ParseMacroblockGENERIC
2141 #if (VPAR_OPTIM_LEVEL > 0)
2142 NULL, ParseMacroblock2I420F0, ParseMacroblock2P420F0,
2143 ParseMacroblock2B420F0
2145 NULL, ParseMacroblockGENERIC, ParseMacroblockGENERIC,
2146 ParseMacroblockGENERIC
2151 int i_mb_address_save = *pi_mb_address;
2153 p_vpar->picture.b_error = 0;
2157 /* Picture with more than 2800 lines. */
2158 i_vert_code += GetBits( &p_vpar->bit_stream, 3 ) << 7;
2162 /* DATA_PARTITIONING scalability. */
2163 RemoveBits( &p_vpar->bit_stream, 7 ); /* priority_breakpoint */
2166 LoadQuantizerScale( p_vpar );
2168 if( GetBits( &p_vpar->bit_stream, 1 ) )
2170 /* intra_slice, slice_id */
2171 RemoveBits( &p_vpar->bit_stream, 8 );
2172 /* extra_information_slice */
2173 while( GetBits( &p_vpar->bit_stream, 1 ) )
2175 RemoveBits( &p_vpar->bit_stream, 8 );
2178 *pi_mb_address = (i_vert_code - 1)*p_vpar->sequence.i_mb_width;
2180 if( *pi_mb_address < i_mb_address_save )
2182 intf_ErrMsg( "vpar error: slices do not follow, maybe a PES has been trashed\n" );
2183 p_vpar->picture.b_error = 1;
2187 /* Reset DC coefficients predictors (ISO/IEC 13818-2 7.2.1). */
2188 p_vpar->mb.pi_dc_dct_pred[0] = p_vpar->mb.pi_dc_dct_pred[1]
2189 = p_vpar->mb.pi_dc_dct_pred[2]
2190 = 1 << (7 + p_vpar->picture.i_intra_dc_precision);
2192 /* Reset motion vector predictors (ISO/IEC 13818-2 7.6.3.4). */
2193 memset( p_vpar->mb.pppi_pmv, 0, 8*sizeof(int) );
2197 if( i_mb_address_save >= p_vpar->sequence.i_mb_size )
2199 p_vpar->picture.b_error = 1;
2203 if( p_vpar->sequence.i_chroma_format != CHROMA_420
2204 || !p_vpar->sequence.b_mpeg2 || p_vpar->sequence.i_height > 2800
2205 || p_vpar->sequence.i_scalable_mode == SC_DP )
2207 /* Weird stream. Use the slower generic function. */
2208 ParseMacroblockGENERIC( p_vpar, pi_mb_address, i_mb_address_save,
2209 i_mb_base, b_mpeg2, i_coding_type,
2210 i_chroma_format, i_structure,
2215 /* Try to find an optimized function. */
2216 if( ppf_parse_mb[i_structure]
2217 [p_vpar->picture.i_coding_type] == NULL )
2219 intf_ErrMsg( "vpar error: bad ppf_parse_mb function pointer (struct:%d, coding type:%d)\n",
2220 i_structure, i_coding_type );
2224 ppf_parse_mb[i_structure][i_coding_type]
2225 ( p_vpar, pi_mb_address, i_mb_address_save,
2226 i_mb_base, b_mpeg2, i_coding_type,
2227 i_chroma_format, i_structure,
2232 i_mb_address_save = *pi_mb_address;
2233 if( p_vpar->picture.b_error )
2238 while( ShowBits( &p_vpar->bit_stream, 23 ) && !p_vpar->b_die );
2239 NextStartCode( p_vpar );
2242 /*****************************************************************************
2243 * PictureData : Parse off all macroblocks (ISO/IEC 13818-2 6.2.3.7)
2244 *****************************************************************************/
2245 void vpar_PictureData( vpar_thread_t * p_vpar, int i_mb_base )
2247 int i_mb_address = 0;
2250 NextStartCode( p_vpar );
2251 while( ((p_vpar->picture.i_coding_type != I_CODING_TYPE
2252 && p_vpar->picture.i_coding_type != D_CODING_TYPE)
2253 || !p_vpar->picture.b_error)
2254 && i_mb_address < (p_vpar->sequence.i_mb_size
2255 >> (p_vpar->picture.i_structure != FRAME_STRUCTURE))
2258 if( ((i_dummy = ShowBits( &p_vpar->bit_stream, 32 ))
2259 < SLICE_START_CODE_MIN) ||
2260 (i_dummy > SLICE_START_CODE_MAX) )
2262 intf_DbgMsg("vpar debug: premature end of picture\n");
2263 p_vpar->picture.b_error = 1;
2266 RemoveBits32( &p_vpar->bit_stream );
2268 /* Decode slice data. */
2269 SliceHeader( p_vpar, &i_mb_address, i_mb_base, i_dummy & 255,
2270 (p_vpar->sequence.i_height > 2800),
2271 (p_vpar->sequence.i_scalable_mode == SC_DP),
2272 p_vpar->sequence.b_mpeg2, p_vpar->picture.i_coding_type,
2273 p_vpar->sequence.i_chroma_format,
2274 p_vpar->picture.i_structure,
2275 (p_vpar->picture.i_structure !=
2276 p_vpar->picture.i_current_structure) );
2279 /* Try to recover from error. If we missed less than half the
2280 * number of macroblocks of the picture, mark the missed ones
2282 if( (p_vpar->picture.i_coding_type == P_CODING_TYPE
2283 || p_vpar->picture.i_coding_type == B_CODING_TYPE)
2284 && p_vpar->picture.b_error &&
2285 ( (i_mb_address-i_mb_base) > (p_vpar->sequence.i_mb_size >> 1)
2286 || (p_vpar->picture.i_structure != FRAME_STRUCTURE
2287 && (i_mb_address-i_mb_base) > (p_vpar->sequence.i_mb_size >> 2) ) ) )
2291 p_vpar->picture.b_error = 0;
2292 for( i_mb = i_mb_address + 1;
2293 i_mb < (p_vpar->sequence.i_mb_size
2294 << (p_vpar->picture.i_structure != FRAME_STRUCTURE));
2297 SkippedMacroblock( p_vpar, i_mb, i_mb_base,
2298 p_vpar->picture.i_coding_type,
2299 p_vpar->sequence.i_chroma_format,
2300 p_vpar->picture.i_structure,
2301 (p_vpar->picture.i_structure !=
2302 p_vpar->picture.i_current_structure) );