summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-12-07 13:00:31 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-12-07 13:00:31 +0000
commit2b5f979d75a3d1c85b498c87ba6ae4c98c3011bc (patch)
treed9c40aa330a2bd973794eca11c86d559549422ca
parent5886efabf5e4c96a8a96836d665aad935c727e31 (diff)
downloadrockbox-2b5f979d75a3d1c85b498c87ba6ae4c98c3011bc.tar.gz
rockbox-2b5f979d75a3d1c85b498c87ba6ae4c98c3011bc.zip
Reformat and code police (tabs, trailing whitespace, annoying overuse of parentheses, etc.) in libmpeg2 so I can stomach working on it. Don't call IDCT functions through pointers - I don't feel like extracting that change just for relevance sake.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15892 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/mpegplayer/decode.c490
-rw-r--r--apps/plugins/mpegplayer/header.c592
-rw-r--r--apps/plugins/mpegplayer/idct.c109
-rw-r--r--apps/plugins/mpegplayer/idct_arm.S12
-rw-r--r--apps/plugins/mpegplayer/idct_coldfire.S12
-rw-r--r--apps/plugins/mpegplayer/motion_comp.c4
-rw-r--r--apps/plugins/mpegplayer/mpeg2.h106
-rw-r--r--apps/plugins/mpegplayer/mpeg2_internal.h78
-rw-r--r--apps/plugins/mpegplayer/slice.c1453
-rw-r--r--apps/plugins/mpegplayer/vlc.h40
10 files changed, 1785 insertions, 1111 deletions
diff --git a/apps/plugins/mpegplayer/decode.c b/apps/plugins/mpegplayer/decode.c
index ca3d29a952..fac724c48c 100644
--- a/apps/plugins/mpegplayer/decode.c
+++ b/apps/plugins/mpegplayer/decode.c
@@ -33,9 +33,15 @@ extern struct plugin_api* rb;
33 33
34#define BUFFER_SIZE (1194 * 1024) 34#define BUFFER_SIZE (1194 * 1024)
35 35
36#ifdef CPU_COLDFIRE
37/* twice as large as on other targets because coldfire uses
38 * a secondary, transposed buffer for optimisation */
39static int16_t static_dct_block[128] IBSS_ATTR ATTR_ALIGN(16);
40#endif
41
36const mpeg2_info_t * mpeg2_info (mpeg2dec_t * mpeg2dec) 42const mpeg2_info_t * mpeg2_info (mpeg2dec_t * mpeg2dec)
37{ 43{
38 return &(mpeg2dec->info); 44 return &mpeg2dec->info;
39} 45}
40 46
41static inline int skip_chunk (mpeg2dec_t * mpeg2dec, int bytes) 47static inline int skip_chunk (mpeg2dec_t * mpeg2dec, int bytes)
@@ -46,27 +52,34 @@ static inline int skip_chunk (mpeg2dec_t * mpeg2dec, int bytes)
46 uint8_t byte; 52 uint8_t byte;
47 53
48 if (!bytes) 54 if (!bytes)
49 return 0; 55 return 0;
50 56
51 current = mpeg2dec->buf_start; 57 current = mpeg2dec->buf_start;
52 shift = mpeg2dec->shift; 58 shift = mpeg2dec->shift;
53 limit = current + bytes; 59 limit = current + bytes;
54 60
55 do { 61 do
56 byte = *current++; 62 {
57 if (shift == 0x00000100) { 63 byte = *current++;
58 int skipped; 64
65 if (shift == 0x00000100)
66 {
67 int skipped;
59 68
60 mpeg2dec->shift = 0xffffff00; 69 mpeg2dec->shift = 0xffffff00;
61 skipped = current - mpeg2dec->buf_start; 70 skipped = current - mpeg2dec->buf_start;
62 mpeg2dec->buf_start = current; 71 mpeg2dec->buf_start = current;
63 return skipped; 72
64 } 73 return skipped;
65 shift = (shift | byte) << 8; 74 }
66 } while (current < limit); 75
76 shift = (shift | byte) << 8;
77 }
78 while (current < limit);
67 79
68 mpeg2dec->shift = shift; 80 mpeg2dec->shift = shift;
69 mpeg2dec->buf_start = current; 81 mpeg2dec->buf_start = current;
82
70 return 0; 83 return 0;
71} 84}
72 85
@@ -79,27 +92,32 @@ static inline int copy_chunk (mpeg2dec_t * mpeg2dec, int bytes)
79 uint8_t byte; 92 uint8_t byte;
80 93
81 if (!bytes) 94 if (!bytes)
82 return 0; 95 return 0;
83 96
84 current = mpeg2dec->buf_start; 97 current = mpeg2dec->buf_start;
85 shift = mpeg2dec->shift; 98 shift = mpeg2dec->shift;
86 chunk_ptr = mpeg2dec->chunk_ptr; 99 chunk_ptr = mpeg2dec->chunk_ptr;
87 limit = current + bytes; 100 limit = current + bytes;
88 101
89 do { 102 do
90 byte = *current++; 103 {
91 if (shift == 0x00000100) { 104 byte = *current++;
92 int copied; 105
93 106 if (shift == 0x00000100)
94 mpeg2dec->shift = 0xffffff00; 107 {
95 mpeg2dec->chunk_ptr = chunk_ptr + 1; 108 int copied;
96 copied = current - mpeg2dec->buf_start; 109
97 mpeg2dec->buf_start = current; 110 mpeg2dec->shift = 0xffffff00;
98 return copied; 111 mpeg2dec->chunk_ptr = chunk_ptr + 1;
99 } 112 copied = current - mpeg2dec->buf_start;
100 shift = (shift | byte) << 8; 113 mpeg2dec->buf_start = current;
101 *chunk_ptr++ = byte; 114 return copied;
102 } while (current < limit); 115 }
116
117 shift = (shift | byte) << 8;
118 *chunk_ptr++ = byte;
119 }
120 while (current < limit);
103 121
104 mpeg2dec->shift = shift; 122 mpeg2dec->shift = shift;
105 mpeg2dec->buf_start = current; 123 mpeg2dec->buf_start = current;
@@ -123,26 +141,39 @@ static inline mpeg2_state_t seek_chunk (mpeg2dec_t * mpeg2dec)
123 141
124 size = mpeg2dec->buf_end - mpeg2dec->buf_start; 142 size = mpeg2dec->buf_end - mpeg2dec->buf_start;
125 skipped = skip_chunk (mpeg2dec, size); 143 skipped = skip_chunk (mpeg2dec, size);
126 if (!skipped) { 144
127 mpeg2dec->bytes_since_tag += size; 145 if (!skipped)
128 return STATE_BUFFER; 146 {
147 mpeg2dec->bytes_since_tag += size;
148 return STATE_BUFFER;
129 } 149 }
150
130 mpeg2dec->bytes_since_tag += skipped; 151 mpeg2dec->bytes_since_tag += skipped;
131 mpeg2dec->code = mpeg2dec->buf_start[-1]; 152 mpeg2dec->code = mpeg2dec->buf_start[-1];
153
132 return (mpeg2_state_t)-1; 154 return (mpeg2_state_t)-1;
133} 155}
134 156
135mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec) 157mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec)
136{ 158{
137 while (mpeg2dec->code != 0xb3 && 159 while (mpeg2dec->code != 0xb3 &&
138 ((mpeg2dec->code != 0xb7 && mpeg2dec->code != 0xb8 && 160 ((mpeg2dec->code != 0xb7 &&
139 mpeg2dec->code) || mpeg2dec->sequence.width == (unsigned)-1)) 161 mpeg2dec->code != 0xb8 &&
140 if (seek_chunk (mpeg2dec) == STATE_BUFFER) 162 mpeg2dec->code) ||
141 return STATE_BUFFER; 163 mpeg2dec->sequence.width == (unsigned)-1))
142 mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer; 164 {
165 if (seek_chunk (mpeg2dec) == STATE_BUFFER)
166 return STATE_BUFFER;
167 }
168
169 mpeg2dec->chunk_start =
170 mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
171
143 mpeg2dec->user_data_len = 0; 172 mpeg2dec->user_data_len = 0;
144 return (mpeg2dec->code ? mpeg2_parse_header (mpeg2dec) : 173
145 mpeg2_header_picture_start (mpeg2dec)); 174 return mpeg2dec->code ?
175 mpeg2_parse_header(mpeg2dec) :
176 mpeg2_header_picture_start(mpeg2dec);
146} 177}
147 178
148#define RECEIVED(code,state) (((state) << 8) + (code)) 179#define RECEIVED(code,state) (((state) << 8) + (code))
@@ -151,146 +182,187 @@ mpeg2_state_t mpeg2_parse (mpeg2dec_t * mpeg2dec)
151{ 182{
152 int size_buffer, size_chunk, copied; 183 int size_buffer, size_chunk, copied;
153 184
154 if (mpeg2dec->action) { 185 if (mpeg2dec->action)
155 mpeg2_state_t state; 186 {
187 mpeg2_state_t state;
156 188
157 state = mpeg2dec->action (mpeg2dec); 189 state = mpeg2dec->action (mpeg2dec);
158 if ((int)state >= 0) 190
159 return state; 191 if ((int)state >= 0)
192 return state;
160 } 193 }
161 194
162 while (1) { 195 while (1)
163 while ((unsigned) (mpeg2dec->code - mpeg2dec->first_decode_slice) < 196 {
164 mpeg2dec->nb_decode_slices) { 197 while ((unsigned) (mpeg2dec->code - mpeg2dec->first_decode_slice) <
165 size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start; 198 mpeg2dec->nb_decode_slices)
166 size_chunk = (mpeg2dec->chunk_buffer + BUFFER_SIZE - 199 {
167 mpeg2dec->chunk_ptr); 200 size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start;
168 if (size_buffer <= size_chunk) { 201 size_chunk = mpeg2dec->chunk_buffer + BUFFER_SIZE -
169 copied = copy_chunk (mpeg2dec, size_buffer); 202 mpeg2dec->chunk_ptr;
170 if (!copied) { 203
171 mpeg2dec->bytes_since_tag += size_buffer; 204 if (size_buffer <= size_chunk)
172 mpeg2dec->chunk_ptr += size_buffer; 205 {
173 return STATE_BUFFER; 206 copied = copy_chunk (mpeg2dec, size_buffer);
174 } 207
175 } else { 208 if (!copied)
176 copied = copy_chunk (mpeg2dec, size_chunk); 209 {
177 if (!copied) { 210 mpeg2dec->bytes_since_tag += size_buffer;
178 /* filled the chunk buffer without finding a start code */ 211 mpeg2dec->chunk_ptr += size_buffer;
179 mpeg2dec->bytes_since_tag += size_chunk; 212 return STATE_BUFFER;
180 mpeg2dec->action = seek_chunk; 213 }
181 return STATE_INVALID; 214 }
182 } 215 else
216 {
217 copied = copy_chunk (mpeg2dec, size_chunk);
218
219 if (!copied)
220 {
221 /* filled the chunk buffer without finding a start code */
222 mpeg2dec->bytes_since_tag += size_chunk;
223 mpeg2dec->action = seek_chunk;
224 return STATE_INVALID;
225 }
226 }
227
228 mpeg2dec->bytes_since_tag += copied;
229
230 mpeg2_slice (&mpeg2dec->decoder, mpeg2dec->code,
231 mpeg2dec->chunk_start);
232 mpeg2dec->code = mpeg2dec->buf_start[-1];
233 mpeg2dec->chunk_ptr = mpeg2dec->chunk_start;
183 } 234 }
184 mpeg2dec->bytes_since_tag += copied; 235
185 236 if ((unsigned) (mpeg2dec->code - 1) >= 0xb0 - 1)
186 mpeg2_slice (&(mpeg2dec->decoder), mpeg2dec->code, 237 break;
187 mpeg2dec->chunk_start); 238
188 mpeg2dec->code = mpeg2dec->buf_start[-1]; 239 if (seek_chunk (mpeg2dec) == STATE_BUFFER)
189 mpeg2dec->chunk_ptr = mpeg2dec->chunk_start; 240 return STATE_BUFFER;
190 }
191 if ((unsigned) (mpeg2dec->code - 1) >= 0xb0 - 1)
192 break;
193 if (seek_chunk (mpeg2dec) == STATE_BUFFER)
194 return STATE_BUFFER;
195 } 241 }
196 242
197 switch (mpeg2dec->code) { 243 switch (mpeg2dec->code)
244 {
198 case 0x00: 245 case 0x00:
199 mpeg2dec->action = mpeg2_header_picture_start; 246 mpeg2dec->action = mpeg2_header_picture_start;
200 return mpeg2dec->state; 247 return mpeg2dec->state;
201 case 0xb7: 248 case 0xb7:
202 mpeg2dec->action = mpeg2_header_end; 249 mpeg2dec->action = mpeg2_header_end;
203 break; 250 break;
204 case 0xb3: 251 case 0xb3:
205 case 0xb8: 252 case 0xb8:
206 mpeg2dec->action = mpeg2_parse_header; 253 mpeg2dec->action = mpeg2_parse_header;
207 break; 254 break;
208 default: 255 default:
209 mpeg2dec->action = seek_chunk; 256 mpeg2dec->action = seek_chunk;
210 return STATE_INVALID; 257 return STATE_INVALID;
211 } 258 }
259
212 return (mpeg2dec->state == STATE_SLICE) ? STATE_SLICE : STATE_INVALID; 260 return (mpeg2dec->state == STATE_SLICE) ? STATE_SLICE : STATE_INVALID;
213} 261}
214 262
215mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec) 263mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec)
216{ 264{
217 static int (* process_header[]) (mpeg2dec_t * mpeg2dec) = { 265 static int (* const process_header[9]) (mpeg2dec_t *) =
218 mpeg2_header_picture, mpeg2_header_extension, mpeg2_header_user_data, 266 {
219 mpeg2_header_sequence, NULL, NULL, NULL, NULL, mpeg2_header_gop 267 mpeg2_header_picture,
268 mpeg2_header_extension,
269 mpeg2_header_user_data,
270 mpeg2_header_sequence,
271 NULL,
272 NULL,
273 NULL,
274 NULL,
275 mpeg2_header_gop
220 }; 276 };
277
221 int size_buffer, size_chunk, copied; 278 int size_buffer, size_chunk, copied;
222 279
223 mpeg2dec->action = mpeg2_parse_header; 280 mpeg2dec->action = mpeg2_parse_header;
224 mpeg2dec->info.user_data = NULL; mpeg2dec->info.user_data_len = 0; 281 mpeg2dec->info.user_data = NULL;
225 while (1) { 282 mpeg2dec->info.user_data_len = 0;
226 size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start; 283
227 size_chunk = (mpeg2dec->chunk_buffer + BUFFER_SIZE - 284 while (1)
228 mpeg2dec->chunk_ptr); 285 {
229 if (size_buffer <= size_chunk) { 286 size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start;
230 copied = copy_chunk (mpeg2dec, size_buffer); 287 size_chunk = mpeg2dec->chunk_buffer + BUFFER_SIZE -
231 if (!copied) { 288 mpeg2dec->chunk_ptr;
232 mpeg2dec->bytes_since_tag += size_buffer; 289
233 mpeg2dec->chunk_ptr += size_buffer; 290 if (size_buffer <= size_chunk)
234 return STATE_BUFFER; 291 {
235 } 292 copied = copy_chunk (mpeg2dec, size_buffer);
236 } else { 293
237 copied = copy_chunk (mpeg2dec, size_chunk); 294 if (!copied)
238 if (!copied) { 295 {
239 /* filled the chunk buffer without finding a start code */ 296 mpeg2dec->bytes_since_tag += size_buffer;
240 mpeg2dec->bytes_since_tag += size_chunk; 297 mpeg2dec->chunk_ptr += size_buffer;
241 mpeg2dec->code = 0xb4; 298 return STATE_BUFFER;
242 mpeg2dec->action = mpeg2_seek_header; 299 }
243 return STATE_INVALID; 300 }
244 } 301 else
245 } 302 {
246 mpeg2dec->bytes_since_tag += copied; 303 copied = copy_chunk (mpeg2dec, size_chunk);
247 304
248 if (process_header[mpeg2dec->code & 0x0b] (mpeg2dec)) { 305 if (!copied)
249 mpeg2dec->code = mpeg2dec->buf_start[-1]; 306 {
250 mpeg2dec->action = mpeg2_seek_header; 307 /* filled the chunk buffer without finding a start code */
251 return STATE_INVALID; 308 mpeg2dec->bytes_since_tag += size_chunk;
252 } 309 mpeg2dec->code = 0xb4;
253 310 mpeg2dec->action = mpeg2_seek_header;
254 mpeg2dec->code = mpeg2dec->buf_start[-1]; 311 return STATE_INVALID;
255 switch (RECEIVED (mpeg2dec->code, mpeg2dec->state)) { 312 }
256 313 }
257 /* state transition after a sequence header */ 314
258 case RECEIVED (0x00, STATE_SEQUENCE): 315 mpeg2dec->bytes_since_tag += copied;
259 mpeg2dec->action = mpeg2_header_picture_start; 316
260 case RECEIVED (0xb8, STATE_SEQUENCE): 317 if (process_header[mpeg2dec->code & 0x0b] (mpeg2dec))
261 mpeg2_header_sequence_finalize (mpeg2dec); 318 {
262 break; 319 mpeg2dec->code = mpeg2dec->buf_start[-1];
263 320 mpeg2dec->action = mpeg2_seek_header;
264 /* other legal state transitions */ 321 return STATE_INVALID;
265 case RECEIVED (0x00, STATE_GOP): 322 }
266 mpeg2_header_gop_finalize (mpeg2dec); 323
267 mpeg2dec->action = mpeg2_header_picture_start; 324 mpeg2dec->code = mpeg2dec->buf_start[-1];
268 break; 325
269 case RECEIVED (0x01, STATE_PICTURE): 326 switch (RECEIVED (mpeg2dec->code, mpeg2dec->state))
270 case RECEIVED (0x01, STATE_PICTURE_2ND): 327 {
271 mpeg2_header_picture_finalize (mpeg2dec); 328 /* state transition after a sequence header */
272 mpeg2dec->action = mpeg2_header_slice_start; 329 case RECEIVED (0x00, STATE_SEQUENCE):
273 break; 330 mpeg2dec->action = mpeg2_header_picture_start;
274 331 case RECEIVED (0xb8, STATE_SEQUENCE):
275 /* legal headers within a given state */ 332 mpeg2_header_sequence_finalize (mpeg2dec);
276 case RECEIVED (0xb2, STATE_SEQUENCE): 333 break;
277 case RECEIVED (0xb2, STATE_GOP): 334
278 case RECEIVED (0xb2, STATE_PICTURE): 335 /* other legal state transitions */
279 case RECEIVED (0xb2, STATE_PICTURE_2ND): 336 case RECEIVED (0x00, STATE_GOP):
280 case RECEIVED (0xb5, STATE_SEQUENCE): 337 mpeg2_header_gop_finalize (mpeg2dec);
281 case RECEIVED (0xb5, STATE_PICTURE): 338 mpeg2dec->action = mpeg2_header_picture_start;
282 case RECEIVED (0xb5, STATE_PICTURE_2ND): 339 break;
283 mpeg2dec->chunk_ptr = mpeg2dec->chunk_start; 340 case RECEIVED (0x01, STATE_PICTURE):
284 continue; 341 case RECEIVED (0x01, STATE_PICTURE_2ND):
285 342 mpeg2_header_picture_finalize (mpeg2dec);
286 default: 343 mpeg2dec->action = mpeg2_header_slice_start;
287 mpeg2dec->action = mpeg2_seek_header; 344 break;
288 return STATE_INVALID; 345
289 } 346 /* legal headers within a given state */
290 347 case RECEIVED (0xb2, STATE_SEQUENCE):
291 mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer; 348 case RECEIVED (0xb2, STATE_GOP):
292 mpeg2dec->user_data_len = 0; 349 case RECEIVED (0xb2, STATE_PICTURE):
293 return mpeg2dec->state; 350 case RECEIVED (0xb2, STATE_PICTURE_2ND):
351 case RECEIVED (0xb5, STATE_SEQUENCE):
352 case RECEIVED (0xb5, STATE_PICTURE):
353 case RECEIVED (0xb5, STATE_PICTURE_2ND):
354 mpeg2dec->chunk_ptr = mpeg2dec->chunk_start;
355 continue;
356
357 default:
358 mpeg2dec->action = mpeg2_seek_header;
359 return STATE_INVALID;
360 }
361
362 mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
363 mpeg2dec->user_data_len = 0;
364
365 return mpeg2dec->state;
294 } 366 }
295} 367}
296 368
@@ -299,33 +371,42 @@ int mpeg2_convert (mpeg2dec_t * mpeg2dec, mpeg2_convert_t convert, void * arg)
299 mpeg2_convert_init_t convert_init; 371 mpeg2_convert_init_t convert_init;
300 int error; 372 int error;
301 373
302 error = convert (MPEG2_CONVERT_SET, NULL, &(mpeg2dec->sequence), 0, 374 error = convert (MPEG2_CONVERT_SET, NULL, &mpeg2dec->sequence, 0,
303 arg, &convert_init); 375 arg, &convert_init);
304 if (!error) { 376
305 mpeg2dec->convert = convert; 377 if (!error)
306 mpeg2dec->convert_arg = arg; 378 {
307 mpeg2dec->convert_id_size = convert_init.id_size; 379 mpeg2dec->convert = convert;
308 mpeg2dec->convert_stride = 0; 380 mpeg2dec->convert_arg = arg;
381 mpeg2dec->convert_id_size = convert_init.id_size;
382 mpeg2dec->convert_stride = 0;
309 } 383 }
384
310 return error; 385 return error;
311} 386}
312 387
313int mpeg2_stride (mpeg2dec_t * mpeg2dec, int stride) 388int mpeg2_stride (mpeg2dec_t * mpeg2dec, int stride)
314{ 389{
315 if (!mpeg2dec->convert) { 390 if (!mpeg2dec->convert)
316 if (stride < (int) mpeg2dec->sequence.width) 391 {
317 stride = mpeg2dec->sequence.width; 392 if (stride < (int) mpeg2dec->sequence.width)
318 mpeg2dec->decoder.stride_frame = stride; 393 stride = mpeg2dec->sequence.width;
319 } else { 394
320 mpeg2_convert_init_t convert_init; 395 mpeg2dec->decoder.stride_frame = stride;
321 396 }
322 stride = mpeg2dec->convert (MPEG2_CONVERT_STRIDE, NULL, 397 else
323 &(mpeg2dec->sequence), stride, 398 {
324 mpeg2dec->convert_arg, 399 mpeg2_convert_init_t convert_init;
325 &convert_init); 400
326 mpeg2dec->convert_id_size = convert_init.id_size; 401 stride = mpeg2dec->convert(MPEG2_CONVERT_STRIDE, NULL,
327 mpeg2dec->convert_stride = stride; 402 &mpeg2dec->sequence, stride,
403 mpeg2dec->convert_arg,
404 &convert_init);
405
406 mpeg2dec->convert_id_size = convert_init.id_size;
407 mpeg2dec->convert_stride = stride;
328 } 408 }
409
329 return stride; 410 return stride;
330} 411}
331 412
@@ -333,21 +414,29 @@ void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[3], void * id)
333{ 414{
334 mpeg2_fbuf_t * fbuf; 415 mpeg2_fbuf_t * fbuf;
335 416
336 if (mpeg2dec->custom_fbuf) { 417 if (mpeg2dec->custom_fbuf)
337 if (mpeg2dec->state == STATE_SEQUENCE) { 418 {
338 mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1]; 419 if (mpeg2dec->state == STATE_SEQUENCE)
339 mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0]; 420 {
340 } 421 mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1];
341 mpeg2_set_fbuf (mpeg2dec, (mpeg2dec->decoder.coding_type == 422 mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0];
342 PIC_FLAG_CODING_TYPE_B)); 423 }
343 fbuf = mpeg2dec->fbuf[0]; 424
344 } else { 425 mpeg2_set_fbuf (mpeg2dec, (mpeg2dec->decoder.coding_type ==
345 fbuf = &(mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index].fbuf); 426 PIC_FLAG_CODING_TYPE_B));
346 mpeg2dec->alloc_index_user = ++mpeg2dec->alloc_index; 427
428 fbuf = mpeg2dec->fbuf[0];
429 }
430 else
431 {
432 fbuf = &mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index].fbuf;
433 mpeg2dec->alloc_index_user = ++mpeg2dec->alloc_index;
347 } 434 }
435
348 fbuf->buf[0] = buf[0]; 436 fbuf->buf[0] = buf[0];
349 fbuf->buf[1] = buf[1]; 437 fbuf->buf[1] = buf[1];
350 fbuf->buf[2] = buf[2]; 438 fbuf->buf[2] = buf[2];
439
351 fbuf->id = id; 440 fbuf->id = id;
352} 441}
353 442
@@ -390,31 +479,26 @@ void mpeg2_reset (mpeg2dec_t * mpeg2dec, int full_reset)
390 mpeg2dec->state = STATE_INVALID; 479 mpeg2dec->state = STATE_INVALID;
391 mpeg2dec->first = 1; 480 mpeg2dec->first = 1;
392 481
393 mpeg2_reset_info(&(mpeg2dec->info)); 482 mpeg2_reset_info(&mpeg2dec->info);
394 mpeg2dec->info.gop = NULL; 483 mpeg2dec->info.gop = NULL;
395 mpeg2dec->info.user_data = NULL; 484 mpeg2dec->info.user_data = NULL;
396 mpeg2dec->info.user_data_len = 0; 485 mpeg2dec->info.user_data_len = 0;
397 if (full_reset) {
398 mpeg2dec->info.sequence = NULL;
399 mpeg2_header_state_init (mpeg2dec);
400 }
401 486
487 if (full_reset)
488 {
489 mpeg2dec->info.sequence = NULL;
490 mpeg2_header_state_init (mpeg2dec);
491 }
402} 492}
403 493
404#ifdef CPU_COLDFIRE
405/* twice as large as on other targets because coldfire uses
406 * a secondary, transposed buffer for optimisation */
407static int16_t static_dct_block[128] IBSS_ATTR ATTR_ALIGN(16);
408#endif
409
410mpeg2dec_t * mpeg2_init (void) 494mpeg2dec_t * mpeg2_init (void)
411{ 495{
412 mpeg2dec_t * mpeg2dec; 496 mpeg2dec_t * mpeg2dec;
413 497
414 mpeg2_idct_init (); 498 mpeg2_idct_init ();
415 499
416 mpeg2dec = (mpeg2dec_t *) mpeg2_malloc (sizeof (mpeg2dec_t), 500 mpeg2dec = (mpeg2dec_t *)mpeg2_malloc(sizeof (mpeg2dec_t),
417 MPEG2_ALLOC_MPEG2DEC); 501 MPEG2_ALLOC_MPEG2DEC);
418 if (mpeg2dec == NULL) 502 if (mpeg2dec == NULL)
419 return NULL; 503 return NULL;
420 504
@@ -425,8 +509,8 @@ mpeg2dec_t * mpeg2_init (void)
425 rb->memset (mpeg2dec->decoder.DCTblock, 0, 64 * sizeof (int16_t)); 509 rb->memset (mpeg2dec->decoder.DCTblock, 0, 64 * sizeof (int16_t));
426 rb->memset (mpeg2dec->quantizer_matrix, 0, 4 * 64 * sizeof (uint8_t)); 510 rb->memset (mpeg2dec->quantizer_matrix, 0, 4 * 64 * sizeof (uint8_t));
427 511
428 mpeg2dec->chunk_buffer = (uint8_t *) mpeg2_malloc (BUFFER_SIZE + 4, 512 mpeg2dec->chunk_buffer = (uint8_t *)mpeg2_malloc(BUFFER_SIZE + 4,
429 MPEG2_ALLOC_CHUNK); 513 MPEG2_ALLOC_CHUNK);
430 514
431 mpeg2dec->sequence.width = (unsigned)-1; 515 mpeg2dec->sequence.width = (unsigned)-1;
432 mpeg2_reset (mpeg2dec, 1); 516 mpeg2_reset (mpeg2dec, 1);
diff --git a/apps/plugins/mpegplayer/header.c b/apps/plugins/mpegplayer/header.c
index 664be4badb..52a301f8d8 100644
--- a/apps/plugins/mpegplayer/header.c
+++ b/apps/plugins/mpegplayer/header.c
@@ -40,7 +40,8 @@ extern struct plugin_api* rb;
40#define PIC_CODING_EXT 0x100 40#define PIC_CODING_EXT 0x100
41 41
42/* default intra quant matrix, in zig-zag order */ 42/* default intra quant matrix, in zig-zag order */
43static const uint8_t default_intra_quantizer_matrix[64] = { 43static const uint8_t default_intra_quantizer_matrix[64] =
44{
44 8, 45 8,
45 16, 16, 46 16, 16,
46 19, 16, 19, 47 19, 16, 19,
@@ -58,20 +59,30 @@ static const uint8_t default_intra_quantizer_matrix[64] = {
58 83 59 83
59}; 60};
60 61
61const uint8_t default_mpeg2_scan_norm[64] = { 62const uint8_t default_mpeg2_scan_norm[64] =
63{
62 /* Zig-Zag scan pattern */ 64 /* Zig-Zag scan pattern */
63 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 65 0, 1, 8, 16, 9, 2, 3, 10,
64 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 66 17, 24, 32, 25, 18, 11, 4, 5,
65 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, 67 12, 19, 26, 33, 40, 48, 41, 34,
66 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63 68 27, 20, 13, 6, 7, 14, 21, 28,
69 35, 42, 49, 56, 57, 50, 43, 36,
70 29, 22, 15, 23, 30, 37, 44, 51,
71 58, 59, 52, 45, 38, 31, 39, 46,
72 53, 60, 61, 54, 47, 55, 62, 63
67}; 73};
68 74
69const uint8_t default_mpeg2_scan_alt[64] = { 75const uint8_t default_mpeg2_scan_alt[64] =
76{
70 /* Alternate scan pattern */ 77 /* Alternate scan pattern */
71 0, 8, 16, 24, 1, 9, 2, 10, 17, 25, 32, 40, 48, 56, 57, 49, 78 0, 8, 16, 24, 1, 9, 2, 10,
72 41, 33, 26, 18, 3, 11, 4, 12, 19, 27, 34, 42, 50, 58, 35, 43, 79 17, 25, 32, 40, 48, 56, 57, 49,
73 51, 59, 20, 28, 5, 13, 6, 14, 21, 29, 36, 44, 52, 60, 37, 45, 80 41, 33, 26, 18, 3, 11, 4, 12,
74 53, 61, 22, 30, 7, 15, 23, 31, 38, 46, 54, 62, 39, 47, 55, 63 81 19, 27, 34, 42, 50, 58, 35, 43,
82 51, 59, 20, 28, 5, 13, 6, 14,
83 21, 29, 36, 44, 52, 60, 37, 45,
84 53, 61, 22, 30, 7, 15, 23, 31,
85 38, 46, 54, 62, 39, 47, 55, 63
75}; 86};
76 87
77uint8_t mpeg2_scan_norm[64] IDATA_ATTR; 88uint8_t mpeg2_scan_norm[64] IDATA_ATTR;
@@ -79,33 +90,49 @@ uint8_t mpeg2_scan_alt[64] IDATA_ATTR;
79 90
80void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec) 91void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec)
81{ 92{
82 if (mpeg2dec->sequence.width != (unsigned)-1) { 93 if (mpeg2dec->sequence.width != (unsigned)-1)
94 {
83 int i; 95 int i;
84 96
85 mpeg2dec->sequence.width = (unsigned)-1; 97 mpeg2dec->sequence.width = (unsigned)-1;
98
86 if (!mpeg2dec->custom_fbuf) 99 if (!mpeg2dec->custom_fbuf)
100 {
87 for (i = mpeg2dec->alloc_index_user; 101 for (i = mpeg2dec->alloc_index_user;
88 i < mpeg2dec->alloc_index; i++) { 102 i < mpeg2dec->alloc_index; i++)
89 mpeg2_free (mpeg2dec->fbuf_alloc[i].fbuf.buf[0]); 103 {
90 mpeg2_free (mpeg2dec->fbuf_alloc[i].fbuf.buf[1]); 104 mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[0]);
91 mpeg2_free (mpeg2dec->fbuf_alloc[i].fbuf.buf[2]); 105 mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[1]);
106 mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[2]);
92 } 107 }
108 }
109
93 if (mpeg2dec->convert_start) 110 if (mpeg2dec->convert_start)
94 for (i = 0; i < 3; i++) { 111 {
95 mpeg2_free (mpeg2dec->yuv_buf[i][0]); 112 for (i = 0; i < 3; i++)
96 mpeg2_free (mpeg2dec->yuv_buf[i][1]); 113 {
97 mpeg2_free (mpeg2dec->yuv_buf[i][2]); 114 mpeg2_free(mpeg2dec->yuv_buf[i][0]);
115 mpeg2_free(mpeg2dec->yuv_buf[i][1]);
116 mpeg2_free(mpeg2dec->yuv_buf[i][2]);
98 } 117 }
118 }
119
99 if (mpeg2dec->decoder.convert_id) 120 if (mpeg2dec->decoder.convert_id)
100 mpeg2_free (mpeg2dec->decoder.convert_id); 121 {
122 mpeg2_free(mpeg2dec->decoder.convert_id);
123 }
101 } 124 }
125
102 mpeg2dec->decoder.coding_type = I_TYPE; 126 mpeg2dec->decoder.coding_type = I_TYPE;
103 mpeg2dec->decoder.convert = NULL; 127 mpeg2dec->decoder.convert = NULL;
104 mpeg2dec->decoder.convert_id = NULL; 128 mpeg2dec->decoder.convert_id = NULL;
129
105 mpeg2dec->picture = mpeg2dec->pictures; 130 mpeg2dec->picture = mpeg2dec->pictures;
131
106 mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[0].fbuf; 132 mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[0].fbuf;
107 mpeg2dec->fbuf[1] = &mpeg2dec->fbuf_alloc[1].fbuf; 133 mpeg2dec->fbuf[1] = &mpeg2dec->fbuf_alloc[1].fbuf;
108 mpeg2dec->fbuf[2] = &mpeg2dec->fbuf_alloc[2].fbuf; 134 mpeg2dec->fbuf[2] = &mpeg2dec->fbuf_alloc[2].fbuf;
135
109 mpeg2dec->first = 1; 136 mpeg2dec->first = 1;
110 mpeg2dec->alloc_index = 0; 137 mpeg2dec->alloc_index = 0;
111 mpeg2dec->alloc_index_user = 0; 138 mpeg2dec->alloc_index_user = 0;
@@ -119,14 +146,21 @@ void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec)
119 146
120void mpeg2_reset_info (mpeg2_info_t * info) 147void mpeg2_reset_info (mpeg2_info_t * info)
121{ 148{
122 info->current_picture = info->current_picture_2nd = NULL; 149 info->current_picture =
123 info->display_picture = info->display_picture_2nd = NULL; 150 info->current_picture_2nd = NULL;
124 info->current_fbuf = info->display_fbuf = info->discard_fbuf = NULL; 151
152 info->display_picture =
153 info->display_picture_2nd = NULL;
154
155 info->current_fbuf =
156 info->display_fbuf =
157 info->discard_fbuf = NULL;
125} 158}
126 159
127static void info_user_data (mpeg2dec_t * mpeg2dec) 160static void info_user_data (mpeg2dec_t * mpeg2dec)
128{ 161{
129 if (mpeg2dec->user_data_len) { 162 if (mpeg2dec->user_data_len)
163 {
130 mpeg2dec->info.user_data = mpeg2dec->chunk_buffer; 164 mpeg2dec->info.user_data = mpeg2dec->chunk_buffer;
131 mpeg2dec->info.user_data_len = mpeg2dec->user_data_len - 3; 165 mpeg2dec->info.user_data_len = mpeg2dec->user_data_len - 3;
132 } 166 }
@@ -134,60 +168,81 @@ static void info_user_data (mpeg2dec_t * mpeg2dec)
134 168
135int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec) 169int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec)
136{ 170{
137 uint8_t * buffer = mpeg2dec->chunk_start; 171 static const unsigned int frame_period[16] =
138 mpeg2_sequence_t * sequence = &(mpeg2dec->new_sequence); 172 {
139 static unsigned int frame_period[16] = {
140 0, 1126125, 1125000, 1080000, 900900, 900000, 540000, 450450, 450000, 173 0, 1126125, 1125000, 1080000, 900900, 900000, 540000, 450450, 450000,
141 /* unofficial: xing 15 fps */ 174 /* unofficial: xing 15 fps */
142 1800000, 175 1800000,
143 /* unofficial: libmpeg3 "Unofficial economy rates" 5/10/12/15 fps */ 176 /* unofficial: libmpeg3 "Unofficial economy rates" 5/10/12/15 fps */
144 5400000, 2700000, 2250000, 1800000, 0, 0 177 5400000, 2700000, 2250000, 1800000, 0, 0
145 }; 178 };
179
180 uint8_t * buffer = mpeg2dec->chunk_start;
181 mpeg2_sequence_t * sequence = &mpeg2dec->new_sequence;
146 int i; 182 int i;
147 183
148 if ((buffer[6] & 0x20) != 0x20) /* missing marker_bit */ 184 if ((buffer[6] & 0x20) != 0x20) /* missing marker_bit */
149 return 1; 185 return 1;
150 186
151 i = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2]; 187 i = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
152 if (! (sequence->display_width = sequence->picture_width = i >> 12)) 188
189 if (!(sequence->display_width = sequence->picture_width = i >> 12))
153 return 1; 190 return 1;
154 if (! (sequence->display_height = sequence->picture_height = i & 0xfff)) 191
192 if (!(sequence->display_height = sequence->picture_height = i & 0xfff))
155 return 1; 193 return 1;
194
156 sequence->width = (sequence->picture_width + 15) & ~15; 195 sequence->width = (sequence->picture_width + 15) & ~15;
157 sequence->height = (sequence->picture_height + 15) & ~15; 196 sequence->height = (sequence->picture_height + 15) & ~15;
158 sequence->chroma_width = sequence->width >> 1; 197 sequence->chroma_width = sequence->width >> 1;
159 sequence->chroma_height = sequence->height >> 1; 198 sequence->chroma_height = sequence->height >> 1;
160 199
161 sequence->flags = (SEQ_FLAG_PROGRESSIVE_SEQUENCE | 200 sequence->flags = SEQ_FLAG_PROGRESSIVE_SEQUENCE |
162 SEQ_VIDEO_FORMAT_UNSPECIFIED); 201 SEQ_VIDEO_FORMAT_UNSPECIFIED;
163 202
164 sequence->pixel_width = buffer[3] >> 4; /* aspect ratio */ 203 sequence->pixel_width = buffer[3] >> 4; /* aspect ratio */
165 sequence->frame_period = frame_period[buffer[3] & 15]; 204 sequence->frame_period = frame_period[buffer[3] & 15];
166 205
167 sequence->byte_rate = (buffer[4]<<10) | (buffer[5]<<2) | (buffer[6]>>6); 206 sequence->byte_rate = (buffer[4]<<10) | (buffer[5]<<2) | (buffer[6]>>6);
168 207
169 sequence->vbv_buffer_size = ((buffer[6]<<16)|(buffer[7]<<8))&0x1ff800; 208 sequence->vbv_buffer_size = ((buffer[6]<<16) | (buffer[7]<<8)) & 0x1ff800;
170 209
171 if (buffer[7] & 4) 210 if (buffer[7] & 4)
172 sequence->flags |= SEQ_FLAG_CONSTRAINED_PARAMETERS; 211 sequence->flags |= SEQ_FLAG_CONSTRAINED_PARAMETERS;
173 212
174 mpeg2dec->copy_matrix = 3; 213 mpeg2dec->copy_matrix = 3;
175 if (buffer[7] & 2) { 214
215 if (buffer[7] & 2)
216 {
176 for (i = 0; i < 64; i++) 217 for (i = 0; i < 64; i++)
218 {
177 mpeg2dec->new_quantizer_matrix[0][mpeg2_scan_norm[i]] = 219 mpeg2dec->new_quantizer_matrix[0][mpeg2_scan_norm[i]] =
178 (buffer[i+7] << 7) | (buffer[i+8] >> 1); 220 (buffer[i+7] << 7) | (buffer[i+8] >> 1);
221 }
222
179 buffer += 64; 223 buffer += 64;
180 } else 224 }
225 else
226 {
181 for (i = 0; i < 64; i++) 227 for (i = 0; i < 64; i++)
228 {
182 mpeg2dec->new_quantizer_matrix[0][mpeg2_scan_norm[i]] = 229 mpeg2dec->new_quantizer_matrix[0][mpeg2_scan_norm[i]] =
183 default_intra_quantizer_matrix[i]; 230 default_intra_quantizer_matrix[i];
231 }
232 }
184 233
185 if (buffer[7] & 1) 234 if (buffer[7] & 1)
235 {
186 for (i = 0; i < 64; i++) 236 for (i = 0; i < 64; i++)
237 {
187 mpeg2dec->new_quantizer_matrix[1][mpeg2_scan_norm[i]] = 238 mpeg2dec->new_quantizer_matrix[1][mpeg2_scan_norm[i]] =
188 buffer[i+8]; 239 buffer[i+8];
240 }
241 }
189 else 242 else
243 {
190 rb->memset (mpeg2dec->new_quantizer_matrix[1], 16, 64); 244 rb->memset (mpeg2dec->new_quantizer_matrix[1], 16, 64);
245 }
191 246
192 sequence->profile_level_id = 0x80; 247 sequence->profile_level_id = 0x80;
193 sequence->colour_primaries = 0; 248 sequence->colour_primaries = 0;
@@ -196,7 +251,9 @@ int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec)
196 251
197 mpeg2dec->ext_state = SEQ_EXT; 252 mpeg2dec->ext_state = SEQ_EXT;
198 mpeg2dec->state = STATE_SEQUENCE; 253 mpeg2dec->state = STATE_SEQUENCE;
199 mpeg2dec->display_offset_x = mpeg2dec->display_offset_y = 0; 254
255 mpeg2dec->display_offset_x =
256 mpeg2dec->display_offset_y = 0;
200 257
201 return 0; 258 return 0;
202} 259}
@@ -204,7 +261,7 @@ int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec)
204static int sequence_ext (mpeg2dec_t * mpeg2dec) 261static int sequence_ext (mpeg2dec_t * mpeg2dec)
205{ 262{
206 uint8_t * buffer = mpeg2dec->chunk_start; 263 uint8_t * buffer = mpeg2dec->chunk_start;
207 mpeg2_sequence_t * sequence = &(mpeg2dec->new_sequence); 264 mpeg2_sequence_t * sequence = &mpeg2dec->new_sequence;
208 uint32_t flags; 265 uint32_t flags;
209 266
210 if (!(buffer[3] & 1)) 267 if (!(buffer[3] & 1))
@@ -212,23 +269,32 @@ static int sequence_ext (mpeg2dec_t * mpeg2dec)
212 269
213 sequence->profile_level_id = (buffer[0] << 4) | (buffer[1] >> 4); 270 sequence->profile_level_id = (buffer[0] << 4) | (buffer[1] >> 4);
214 271
215 sequence->display_width = sequence->picture_width += 272 sequence->picture_width += ((buffer[1] << 13) | (buffer[2] << 5)) & 0x3000;
216 ((buffer[1] << 13) | (buffer[2] << 5)) & 0x3000; 273 sequence->display_width = sequence->picture_width;
217 sequence->display_height = sequence->picture_height += 274
218 (buffer[2] << 7) & 0x3000; 275 sequence->picture_height += (buffer[2] << 7) & 0x3000;
276 sequence->display_height = sequence->picture_height;
277
219 sequence->width = (sequence->picture_width + 15) & ~15; 278 sequence->width = (sequence->picture_width + 15) & ~15;
220 sequence->height = (sequence->picture_height + 15) & ~15; 279 sequence->height = (sequence->picture_height + 15) & ~15;
280
221 flags = sequence->flags | SEQ_FLAG_MPEG2; 281 flags = sequence->flags | SEQ_FLAG_MPEG2;
222 if (!(buffer[1] & 8)) { 282
283 if (!(buffer[1] & 8))
284 {
223 flags &= ~SEQ_FLAG_PROGRESSIVE_SEQUENCE; 285 flags &= ~SEQ_FLAG_PROGRESSIVE_SEQUENCE;
224 sequence->height = (sequence->height + 31) & ~31; 286 sequence->height = (sequence->height + 31) & ~31;
225 } 287 }
288
226 if (buffer[5] & 0x80) 289 if (buffer[5] & 0x80)
227 flags |= SEQ_FLAG_LOW_DELAY; 290 flags |= SEQ_FLAG_LOW_DELAY;
291
228 sequence->flags = flags; 292 sequence->flags = flags;
229 sequence->chroma_width = sequence->width; 293 sequence->chroma_width = sequence->width;
230 sequence->chroma_height = sequence->height; 294 sequence->chroma_height = sequence->height;
231 switch (buffer[1] & 6) { 295
296 switch (buffer[1] & 6)
297 {
232 case 0: /* invalid */ 298 case 0: /* invalid */
233 return 1; 299 return 1;
234 case 2: /* 4:2:0 */ 300 case 2: /* 4:2:0 */
@@ -252,12 +318,14 @@ static int sequence_ext (mpeg2dec_t * mpeg2dec)
252static int sequence_display_ext (mpeg2dec_t * mpeg2dec) 318static int sequence_display_ext (mpeg2dec_t * mpeg2dec)
253{ 319{
254 uint8_t * buffer = mpeg2dec->chunk_start; 320 uint8_t * buffer = mpeg2dec->chunk_start;
255 mpeg2_sequence_t * sequence = &(mpeg2dec->new_sequence); 321 mpeg2_sequence_t * sequence = &mpeg2dec->new_sequence;
256 uint32_t flags; 322 uint32_t flags;
257 323
258 flags = ((sequence->flags & ~SEQ_MASK_VIDEO_FORMAT) | 324 flags = (sequence->flags & ~SEQ_MASK_VIDEO_FORMAT) |
259 ((buffer[0]<<4) & SEQ_MASK_VIDEO_FORMAT)); 325 ((buffer[0] << 4) & SEQ_MASK_VIDEO_FORMAT);
260 if (buffer[0] & 1) { 326
327 if (buffer[0] & 1)
328 {
261 flags |= SEQ_FLAG_COLOUR_DESCRIPTION; 329 flags |= SEQ_FLAG_COLOUR_DESCRIPTION;
262 sequence->colour_primaries = buffer[1]; 330 sequence->colour_primaries = buffer[1];
263 sequence->transfer_characteristics = buffer[2]; 331 sequence->transfer_characteristics = buffer[2];
@@ -268,9 +336,11 @@ static int sequence_display_ext (mpeg2dec_t * mpeg2dec)
268 if (!(buffer[2] & 2)) /* missing marker_bit */ 336 if (!(buffer[2] & 2)) /* missing marker_bit */
269 return 1; 337 return 1;
270 338
271 sequence->display_width = (buffer[1] << 6) | (buffer[2] >> 2); 339 sequence->display_width =
340 (buffer[1] << 6) | (buffer[2] >> 2);
341
272 sequence->display_height = 342 sequence->display_height =
273 ((buffer[2]& 1 ) << 13) | (buffer[3] << 5) | (buffer[4] >> 3); 343 ((buffer[2] & 1) << 13) | (buffer[3] << 5) | (buffer[4] >> 3);
274 344
275 return 0; 345 return 0;
276} 346}
@@ -282,37 +352,63 @@ static inline void finalize_sequence (mpeg2_sequence_t * sequence)
282 352
283 sequence->byte_rate *= 50; 353 sequence->byte_rate *= 50;
284 354
285 if (sequence->flags & SEQ_FLAG_MPEG2) { 355 if (sequence->flags & SEQ_FLAG_MPEG2)
286 switch (sequence->pixel_width) { 356 {
357 switch (sequence->pixel_width)
358 {
287 case 1: /* square pixels */ 359 case 1: /* square pixels */
288 sequence->pixel_width = sequence->pixel_height = 1; return; 360 sequence->pixel_width =
361 sequence->pixel_height = 1;
362 return;
289 case 2: /* 4:3 aspect ratio */ 363 case 2: /* 4:3 aspect ratio */
290 width = 4; height = 3; break; 364 width = 4;
365 height = 3;
366 break;
291 case 3: /* 16:9 aspect ratio */ 367 case 3: /* 16:9 aspect ratio */
292 width = 16; height = 9; break; 368 width = 16;
369 height = 9;
370 break;
293 case 4: /* 2.21:1 aspect ratio */ 371 case 4: /* 2.21:1 aspect ratio */
294 width = 221; height = 100; break; 372 width = 221;
373 height = 100;
374 break;
295 default: /* illegal */ 375 default: /* illegal */
296 sequence->pixel_width = sequence->pixel_height = 0; return; 376 sequence->pixel_width =
377 sequence->pixel_height = 0;
378 return;
297 } 379 }
380
298 width *= sequence->display_height; 381 width *= sequence->display_height;
299 height *= sequence->display_width; 382 height *= sequence->display_width;
300 383 }
301 } else { 384 else
302 if (sequence->byte_rate == 50 * 0x3ffff) 385 {
303 sequence->byte_rate = 0; /* mpeg-1 VBR */ 386 if (sequence->byte_rate == 50 * 0x3ffff)
304 387 sequence->byte_rate = 0; /* mpeg-1 VBR */
305 switch (sequence->pixel_width) { 388
306 case 0: case 15: /* illegal */ 389 switch (sequence->pixel_width)
307 sequence->pixel_width = sequence->pixel_height = 0; return; 390 {
391 case 0:
392 case 15: /* illegal */
393 sequence->pixel_width =
394 sequence->pixel_height = 0;
395 return;
308 case 1: /* square pixels */ 396 case 1: /* square pixels */
309 sequence->pixel_width = sequence->pixel_height = 1; return; 397 sequence->pixel_width =
398 sequence->pixel_height = 1;
399 return;
310 case 3: /* 720x576 16:9 */ 400 case 3: /* 720x576 16:9 */
311 sequence->pixel_width = 64; sequence->pixel_height = 45; return; 401 sequence->pixel_width = 64;
402 sequence->pixel_height = 45;
403 return;
312 case 6: /* 720x480 16:9 */ 404 case 6: /* 720x480 16:9 */
313 sequence->pixel_width = 32; sequence->pixel_height = 27; return; 405 sequence->pixel_width = 32;
406 sequence->pixel_height = 27;
407 return;
314 case 12: /* 720*480 4:3 */ 408 case 12: /* 720*480 4:3 */
315 sequence->pixel_width = 8; sequence->pixel_height = 9; return; 409 sequence->pixel_width = 8;
410 sequence->pixel_height = 9;
411 return;
316 default: 412 default:
317 height = 88 * sequence->pixel_width + 1171; 413 height = 88 * sequence->pixel_width + 1171;
318 width = 2000; 414 width = 2000;
@@ -321,11 +417,15 @@ static inline void finalize_sequence (mpeg2_sequence_t * sequence)
321 417
322 sequence->pixel_width = width; 418 sequence->pixel_width = width;
323 sequence->pixel_height = height; 419 sequence->pixel_height = height;
324 while (width) { /* find greatest common divisor */ 420
421 /* find greatest common divisor */
422 while (width)
423 {
325 int tmp = width; 424 int tmp = width;
326 width = height % tmp; 425 width = height % tmp;
327 height = tmp; 426 height = tmp;
328 } 427 }
428
329 sequence->pixel_width /= height; 429 sequence->pixel_width /= height;
330 sequence->pixel_height /= height; 430 sequence->pixel_height /= height;
331} 431}
@@ -333,59 +433,73 @@ static inline void finalize_sequence (mpeg2_sequence_t * sequence)
333static void copy_matrix (mpeg2dec_t * mpeg2dec, int index) 433static void copy_matrix (mpeg2dec_t * mpeg2dec, int index)
334{ 434{
335 if (rb->memcmp (mpeg2dec->quantizer_matrix[index], 435 if (rb->memcmp (mpeg2dec->quantizer_matrix[index],
336 mpeg2dec->new_quantizer_matrix[index], 64)) { 436 mpeg2dec->new_quantizer_matrix[index], 64))
437 {
337 rb->memcpy (mpeg2dec->quantizer_matrix[index], 438 rb->memcpy (mpeg2dec->quantizer_matrix[index],
338 mpeg2dec->new_quantizer_matrix[index], 64); 439 mpeg2dec->new_quantizer_matrix[index], 64);
440
339 mpeg2dec->scaled[index] = -1; 441 mpeg2dec->scaled[index] = -1;
340 } 442 }
341} 443}
342 444
343static void finalize_matrix (mpeg2dec_t * mpeg2dec) 445static void finalize_matrix (mpeg2dec_t * mpeg2dec)
344{ 446{
345 mpeg2_decoder_t * decoder = &(mpeg2dec->decoder); 447 mpeg2_decoder_t *decoder = &mpeg2dec->decoder;
346 int i; 448 int i;
347 449
348 for (i = 0; i < 2; i++) { 450 for (i = 0; i < 2; i++)
451 {
349 if (mpeg2dec->copy_matrix & (1 << i)) 452 if (mpeg2dec->copy_matrix & (1 << i))
350 copy_matrix (mpeg2dec, i); 453 copy_matrix (mpeg2dec, i);
454
351 if ((mpeg2dec->copy_matrix & (4 << i)) && 455 if ((mpeg2dec->copy_matrix & (4 << i)) &&
352 rb->memcmp (mpeg2dec->quantizer_matrix[i], 456 rb->memcmp(mpeg2dec->quantizer_matrix[i],
353 mpeg2dec->new_quantizer_matrix[i+2], 64)) { 457 mpeg2dec->new_quantizer_matrix[i+2], 64))
458 {
354 copy_matrix (mpeg2dec, i + 2); 459 copy_matrix (mpeg2dec, i + 2);
355 decoder->chroma_quantizer[i] = decoder->quantizer_prescale[i+2]; 460 decoder->chroma_quantizer[i] = decoder->quantizer_prescale[i+2];
356 } else if (mpeg2dec->copy_matrix & (5 << i)) 461 }
462 else if (mpeg2dec->copy_matrix & (5 << i))
463 {
357 decoder->chroma_quantizer[i] = decoder->quantizer_prescale[i]; 464 decoder->chroma_quantizer[i] = decoder->quantizer_prescale[i];
465 }
358 } 466 }
359} 467}
360 468
361static mpeg2_state_t invalid_end_action (mpeg2dec_t * mpeg2dec) 469static mpeg2_state_t invalid_end_action (mpeg2dec_t * mpeg2dec)
362{ 470{
363 mpeg2_reset_info (&(mpeg2dec->info)); 471 mpeg2_reset_info (&mpeg2dec->info);
472
364 mpeg2dec->info.gop = NULL; 473 mpeg2dec->info.gop = NULL;
474
365 info_user_data (mpeg2dec); 475 info_user_data (mpeg2dec);
476
366 mpeg2_header_state_init (mpeg2dec); 477 mpeg2_header_state_init (mpeg2dec);
478
367 mpeg2dec->sequence = mpeg2dec->new_sequence; 479 mpeg2dec->sequence = mpeg2dec->new_sequence;
368 mpeg2dec->action = mpeg2_seek_header; 480 mpeg2dec->action = mpeg2_seek_header;
369 mpeg2dec->state = STATE_SEQUENCE; 481 mpeg2dec->state = STATE_SEQUENCE;
482
370 return STATE_SEQUENCE; 483 return STATE_SEQUENCE;
371} 484}
372 485
373void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec) 486void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec)
374{ 487{
375 mpeg2_sequence_t * sequence = &(mpeg2dec->new_sequence); 488 mpeg2_sequence_t * sequence = &mpeg2dec->new_sequence;
376 mpeg2_decoder_t * decoder = &(mpeg2dec->decoder); 489 mpeg2_decoder_t * decoder = &mpeg2dec->decoder;
377 490
378 finalize_sequence (sequence); 491 finalize_sequence(sequence);
379 finalize_matrix (mpeg2dec); 492 finalize_matrix(mpeg2dec);
380 493
381 decoder->mpeg1 = !(sequence->flags & SEQ_FLAG_MPEG2); 494 decoder->mpeg1 = !(sequence->flags & SEQ_FLAG_MPEG2);
382 decoder->width = sequence->width; 495 decoder->width = sequence->width;
383 decoder->height = sequence->height; 496 decoder->height = sequence->height;
384 decoder->vertical_position_extension = (sequence->picture_height > 2800); 497 decoder->vertical_position_extension = sequence->picture_height > 2800;
385 decoder->chroma_format = ((sequence->chroma_width == sequence->width) + 498 decoder->chroma_format = (sequence->chroma_width == sequence->width) +
386 (sequence->chroma_height == sequence->height)); 499 (sequence->chroma_height == sequence->height);
387 500
388 if (mpeg2dec->sequence.width != (unsigned)-1) { 501 if (mpeg2dec->sequence.width != (unsigned)-1)
502 {
389 unsigned int new_byte_rate; 503 unsigned int new_byte_rate;
390 504
391 /* 505 /*
@@ -400,38 +514,50 @@ void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec)
400 */ 514 */
401 new_byte_rate = sequence->byte_rate; 515 new_byte_rate = sequence->byte_rate;
402 sequence->byte_rate = mpeg2dec->sequence.byte_rate; 516 sequence->byte_rate = mpeg2dec->sequence.byte_rate;
403 if (rb->memcmp (&(mpeg2dec->sequence), sequence, 517
404 sizeof (mpeg2_sequence_t))) { 518 if (rb->memcmp(&mpeg2dec->sequence, sequence,
519 sizeof (mpeg2_sequence_t)))
520 {
405 decoder->stride_frame = sequence->width; 521 decoder->stride_frame = sequence->width;
406 sequence->byte_rate = new_byte_rate; 522 sequence->byte_rate = new_byte_rate;
523
407 mpeg2_header_end (mpeg2dec); 524 mpeg2_header_end (mpeg2dec);
525
408 mpeg2dec->action = invalid_end_action; 526 mpeg2dec->action = invalid_end_action;
409 mpeg2dec->state = STATE_INVALID_END; 527 mpeg2dec->state = STATE_INVALID_END;
410 return; 528 return;
411 } 529 }
530
412 sequence->byte_rate = new_byte_rate; 531 sequence->byte_rate = new_byte_rate;
413 mpeg2dec->state = STATE_SEQUENCE_REPEATED; 532 mpeg2dec->state = STATE_SEQUENCE_REPEATED;
414 } else 533 }
534 else
535 {
415 decoder->stride_frame = sequence->width; 536 decoder->stride_frame = sequence->width;
537 }
538
416 mpeg2dec->sequence = *sequence; 539 mpeg2dec->sequence = *sequence;
417 mpeg2_reset_info (&(mpeg2dec->info)); 540 mpeg2_reset_info(&mpeg2dec->info);
418 mpeg2dec->info.sequence = &(mpeg2dec->sequence); 541 mpeg2dec->info.sequence = &mpeg2dec->sequence;
419 mpeg2dec->info.gop = NULL; 542 mpeg2dec->info.gop = NULL;
543
420 info_user_data (mpeg2dec); 544 info_user_data (mpeg2dec);
421} 545}
422 546
423int mpeg2_header_gop (mpeg2dec_t * mpeg2dec) 547int mpeg2_header_gop (mpeg2dec_t * mpeg2dec)
424{ 548{
425 uint8_t * buffer = mpeg2dec->chunk_start; 549 uint8_t * buffer = mpeg2dec->chunk_start;
426 mpeg2_gop_t * gop = &(mpeg2dec->new_gop); 550 mpeg2_gop_t * gop = &mpeg2dec->new_gop;
427 551
428 if (! (buffer[1] & 8)) 552 if (!(buffer[1] & 8))
429 return 1; 553 return 1;
554
430 gop->hours = (buffer[0] >> 2) & 31; 555 gop->hours = (buffer[0] >> 2) & 31;
431 gop->minutes = ((buffer[0] << 4) | (buffer[1] >> 4)) & 63; 556 gop->minutes = ((buffer[0] << 4) | (buffer[1] >> 4)) & 63;
432 gop->seconds = ((buffer[1] << 3) | (buffer[2] >> 5)) & 63; 557 gop->seconds = ((buffer[1] << 3) | (buffer[2] >> 5)) & 63;
433 gop->pictures = ((buffer[2] << 1) | (buffer[3] >> 7)) & 63; 558 gop->pictures = ((buffer[2] << 1) | (buffer[3] >> 7)) & 63;
434 gop->flags = (buffer[0] >> 7) | ((buffer[3] >> 4) & 6); 559 gop->flags = (buffer[0] >> 7) | ((buffer[3] >> 4) & 6);
560
435 mpeg2dec->state = STATE_GOP; 561 mpeg2dec->state = STATE_GOP;
436 return 0; 562 return 0;
437} 563}
@@ -439,8 +565,8 @@ int mpeg2_header_gop (mpeg2dec_t * mpeg2dec)
439void mpeg2_header_gop_finalize (mpeg2dec_t * mpeg2dec) 565void mpeg2_header_gop_finalize (mpeg2dec_t * mpeg2dec)
440{ 566{
441 mpeg2dec->gop = mpeg2dec->new_gop; 567 mpeg2dec->gop = mpeg2dec->new_gop;
442 mpeg2_reset_info (&(mpeg2dec->info)); 568 mpeg2_reset_info (&mpeg2dec->info);
443 mpeg2dec->info.gop = &(mpeg2dec->gop); 569 mpeg2dec->info.gop = &mpeg2dec->gop;
444 info_user_data (mpeg2dec); 570 info_user_data (mpeg2dec);
445} 571}
446 572
@@ -449,52 +575,67 @@ void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int b_type)
449 int i; 575 int i;
450 576
451 for (i = 0; i < 3; i++) 577 for (i = 0; i < 3; i++)
578 {
452 if (mpeg2dec->fbuf[1] != &mpeg2dec->fbuf_alloc[i].fbuf && 579 if (mpeg2dec->fbuf[1] != &mpeg2dec->fbuf_alloc[i].fbuf &&
453 mpeg2dec->fbuf[2] != &mpeg2dec->fbuf_alloc[i].fbuf) { 580 mpeg2dec->fbuf[2] != &mpeg2dec->fbuf_alloc[i].fbuf)
581 {
454 mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[i].fbuf; 582 mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[i].fbuf;
455 mpeg2dec->info.current_fbuf = mpeg2dec->fbuf[0]; 583 mpeg2dec->info.current_fbuf = mpeg2dec->fbuf[0];
456 if (b_type || (mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY)) { 584
585 if (b_type || (mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY))
586 {
457 if (b_type || mpeg2dec->convert) 587 if (b_type || mpeg2dec->convert)
458 mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[0]; 588 mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[0];
589
459 mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[0]; 590 mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[0];
460 } 591 }
592
461 break; 593 break;
462 } 594 }
595 }
463} 596}
464 597
465mpeg2_state_t mpeg2_header_picture_start (mpeg2dec_t * mpeg2dec) 598mpeg2_state_t mpeg2_header_picture_start (mpeg2dec_t * mpeg2dec)
466{ 599{
467 mpeg2_picture_t * picture = &(mpeg2dec->new_picture); 600 mpeg2_picture_t * picture = &mpeg2dec->new_picture;
468 601
469 mpeg2dec->state = ((mpeg2dec->state != STATE_SLICE_1ST) ? 602 mpeg2dec->state = (mpeg2dec->state != STATE_SLICE_1ST) ?
470 STATE_PICTURE : STATE_PICTURE_2ND); 603 STATE_PICTURE : STATE_PICTURE_2ND;
471 picture->flags = 0; 604 picture->flags = 0;
472 picture->tag = picture->tag2 = 0; 605 picture->tag = picture->tag2 = 0;
473 if (mpeg2dec->num_tags) { 606
474 if (mpeg2dec->bytes_since_tag >= 4) { 607 if (mpeg2dec->num_tags)
608 {
609 if (mpeg2dec->bytes_since_tag >= 4)
610 {
475 mpeg2dec->num_tags = 0; 611 mpeg2dec->num_tags = 0;
476 picture->tag = mpeg2dec->tag_current; 612 picture->tag = mpeg2dec->tag_current;
477 picture->tag2 = mpeg2dec->tag2_current; 613 picture->tag2 = mpeg2dec->tag2_current;
478 picture->flags = PIC_FLAG_TAGS; 614 picture->flags = PIC_FLAG_TAGS;
479 } else if (mpeg2dec->num_tags > 1) { 615 }
616 else if (mpeg2dec->num_tags > 1)
617 {
480 mpeg2dec->num_tags = 1; 618 mpeg2dec->num_tags = 1;
481 picture->tag = mpeg2dec->tag_previous; 619 picture->tag = mpeg2dec->tag_previous;
482 picture->tag2 = mpeg2dec->tag2_previous; 620 picture->tag2 = mpeg2dec->tag2_previous;
483 picture->flags = PIC_FLAG_TAGS; 621 picture->flags = PIC_FLAG_TAGS;
484 } 622 }
485 } 623 }
624
486 picture->display_offset[0].x = picture->display_offset[1].x = 625 picture->display_offset[0].x = picture->display_offset[1].x =
487 picture->display_offset[2].x = mpeg2dec->display_offset_x; 626 picture->display_offset[2].x = mpeg2dec->display_offset_x;
627
488 picture->display_offset[0].y = picture->display_offset[1].y = 628 picture->display_offset[0].y = picture->display_offset[1].y =
489 picture->display_offset[2].y = mpeg2dec->display_offset_y; 629 picture->display_offset[2].y = mpeg2dec->display_offset_y;
630
490 return mpeg2_parse_header (mpeg2dec); 631 return mpeg2_parse_header (mpeg2dec);
491} 632}
492 633
493int mpeg2_header_picture (mpeg2dec_t * mpeg2dec) 634int mpeg2_header_picture (mpeg2dec_t * mpeg2dec)
494{ 635{
495 uint8_t * buffer = mpeg2dec->chunk_start; 636 uint8_t * buffer = mpeg2dec->chunk_start;
496 mpeg2_picture_t * picture = &(mpeg2dec->new_picture); 637 mpeg2_picture_t * picture = &mpeg2dec->new_picture;
497 mpeg2_decoder_t * decoder = &(mpeg2dec->decoder); 638 mpeg2_decoder_t * decoder = &mpeg2dec->decoder;
498 int type; 639 int type;
499 640
500 type = (buffer [1] >> 3) & 7; 641 type = (buffer [1] >> 3) & 7;
@@ -504,7 +645,8 @@ int mpeg2_header_picture (mpeg2dec_t * mpeg2dec)
504 645
505 picture->flags |= type; 646 picture->flags |= type;
506 647
507 if (type == PIC_FLAG_CODING_TYPE_P || type == PIC_FLAG_CODING_TYPE_B) { 648 if (type == PIC_FLAG_CODING_TYPE_P || type == PIC_FLAG_CODING_TYPE_B)
649 {
508 /* forward_f_code and backward_f_code - used in mpeg1 only */ 650 /* forward_f_code and backward_f_code - used in mpeg1 only */
509 decoder->f_motion.f_code[1] = (buffer[3] >> 2) & 1; 651 decoder->f_motion.f_code[1] = (buffer[3] >> 2) & 1;
510 decoder->f_motion.f_code[0] = 652 decoder->f_motion.f_code[0] =
@@ -531,8 +673,8 @@ int mpeg2_header_picture (mpeg2dec_t * mpeg2dec)
531static int picture_coding_ext (mpeg2dec_t * mpeg2dec) 673static int picture_coding_ext (mpeg2dec_t * mpeg2dec)
532{ 674{
533 uint8_t * buffer = mpeg2dec->chunk_start; 675 uint8_t * buffer = mpeg2dec->chunk_start;
534 mpeg2_picture_t * picture = &(mpeg2dec->new_picture); 676 mpeg2_picture_t * picture = &mpeg2dec->new_picture;
535 mpeg2_decoder_t * decoder = &(mpeg2dec->decoder); 677 mpeg2_decoder_t * decoder = &mpeg2dec->decoder;
536 uint32_t flags; 678 uint32_t flags;
537 679
538 /* pre subtract 1 for use later in compute_motion_vector */ 680 /* pre subtract 1 for use later in compute_motion_vector */
@@ -542,24 +684,32 @@ static int picture_coding_ext (mpeg2dec_t * mpeg2dec)
542 decoder->b_motion.f_code[1] = (buffer[2] >> 4) - 1; 684 decoder->b_motion.f_code[1] = (buffer[2] >> 4) - 1;
543 685
544 flags = picture->flags; 686 flags = picture->flags;
687
545 decoder->intra_dc_precision = 7 - ((buffer[2] >> 2) & 3); 688 decoder->intra_dc_precision = 7 - ((buffer[2] >> 2) & 3);
546 decoder->picture_structure = buffer[2] & 3; 689 decoder->picture_structure = buffer[2] & 3;
547 switch (decoder->picture_structure) { 690
691 switch (decoder->picture_structure)
692 {
548 case TOP_FIELD: 693 case TOP_FIELD:
549 flags |= PIC_FLAG_TOP_FIELD_FIRST; 694 flags |= PIC_FLAG_TOP_FIELD_FIRST;
550 case BOTTOM_FIELD: 695 case BOTTOM_FIELD:
551 picture->nb_fields = 1; 696 picture->nb_fields = 1;
552 break; 697 break;
553 case FRAME_PICTURE: 698 case FRAME_PICTURE:
554 if (!(mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)) { 699 if (!(mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE))
700 {
555 picture->nb_fields = (buffer[3] & 2) ? 3 : 2; 701 picture->nb_fields = (buffer[3] & 2) ? 3 : 2;
556 flags |= (buffer[3] & 128) ? PIC_FLAG_TOP_FIELD_FIRST : 0; 702 flags |= (buffer[3] & 128) ? PIC_FLAG_TOP_FIELD_FIRST : 0;
557 } else 703 }
704 else
705 {
558 picture->nb_fields = (buffer[3]&2) ? ((buffer[3]&128) ? 6 : 4) : 2; 706 picture->nb_fields = (buffer[3]&2) ? ((buffer[3]&128) ? 6 : 4) : 2;
707 }
559 break; 708 break;
560 default: 709 default:
561 return 1; 710 return 1;
562 } 711 }
712
563 decoder->top_field_first = buffer[3] >> 7; 713 decoder->top_field_first = buffer[3] >> 7;
564 decoder->frame_pred_frame_dct = (buffer[3] >> 6) & 1; 714 decoder->frame_pred_frame_dct = (buffer[3] >> 6) & 1;
565 decoder->concealment_motion_vectors = (buffer[3] >> 5) & 1; 715 decoder->concealment_motion_vectors = (buffer[3] >> 5) & 1;
@@ -567,9 +717,13 @@ static int picture_coding_ext (mpeg2dec_t * mpeg2dec)
567 decoder->intra_vlc_format = (buffer[3] >> 3) & 1; 717 decoder->intra_vlc_format = (buffer[3] >> 3) & 1;
568 decoder->scan = (buffer[3] & 4) ? mpeg2_scan_alt : mpeg2_scan_norm; 718 decoder->scan = (buffer[3] & 4) ? mpeg2_scan_alt : mpeg2_scan_norm;
569 flags |= (buffer[4] & 0x80) ? PIC_FLAG_PROGRESSIVE_FRAME : 0; 719 flags |= (buffer[4] & 0x80) ? PIC_FLAG_PROGRESSIVE_FRAME : 0;
720
570 if (buffer[4] & 0x40) 721 if (buffer[4] & 0x40)
722 {
571 flags |= (((buffer[4]<<26) | (buffer[5]<<18) | (buffer[6]<<10)) & 723 flags |= (((buffer[4]<<26) | (buffer[5]<<18) | (buffer[6]<<10)) &
572 PIC_MASK_COMPOSITE_DISPLAY) | PIC_FLAG_COMPOSITE_DISPLAY; 724 PIC_MASK_COMPOSITE_DISPLAY) | PIC_FLAG_COMPOSITE_DISPLAY;
725 }
726
573 picture->flags = flags; 727 picture->flags = flags;
574 728
575 mpeg2dec->ext_state = PIC_DISPLAY_EXT | COPYRIGHT_EXT | QUANT_MATRIX_EXT; 729 mpeg2dec->ext_state = PIC_DISPLAY_EXT | COPYRIGHT_EXT | QUANT_MATRIX_EXT;
@@ -580,124 +734,162 @@ static int picture_coding_ext (mpeg2dec_t * mpeg2dec)
580static int picture_display_ext (mpeg2dec_t * mpeg2dec) 734static int picture_display_ext (mpeg2dec_t * mpeg2dec)
581{ 735{
582 uint8_t * buffer = mpeg2dec->chunk_start; 736 uint8_t * buffer = mpeg2dec->chunk_start;
583 mpeg2_picture_t * picture = &(mpeg2dec->new_picture); 737 mpeg2_picture_t * picture = &mpeg2dec->new_picture;
584 int i, nb_pos; 738 int i, nb_pos;
585 739
586 nb_pos = picture->nb_fields; 740 nb_pos = picture->nb_fields;
741
587 if (mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE) 742 if (mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)
588 nb_pos >>= 1; 743 nb_pos >>= 1;
589 744
590 for (i = 0; i < nb_pos; i++) { 745 for (i = 0; i < nb_pos; i++)
746 {
591 int x, y; 747 int x, y;
592 748
593 x = ((buffer[4*i] << 24) | (buffer[4*i+1] << 16) | 749 x = ((buffer[4*i] << 24) | (buffer[4*i+1] << 16) |
594 (buffer[4*i+2] << 8) | buffer[4*i+3]) >> (11-2*i); 750 (buffer[4*i+2] << 8) | buffer[4*i+3]) >> (11-2*i);
751
595 y = ((buffer[4*i+2] << 24) | (buffer[4*i+3] << 16) | 752 y = ((buffer[4*i+2] << 24) | (buffer[4*i+3] << 16) |
596 (buffer[4*i+4] << 8) | buffer[4*i+5]) >> (10-2*i); 753 (buffer[4*i+4] << 8) | buffer[4*i+5]) >> (10-2*i);
754
597 if (! (x & y & 1)) 755 if (! (x & y & 1))
598 return 1; 756 return 1;
757
599 picture->display_offset[i].x = mpeg2dec->display_offset_x = x >> 1; 758 picture->display_offset[i].x = mpeg2dec->display_offset_x = x >> 1;
600 picture->display_offset[i].y = mpeg2dec->display_offset_y = y >> 1; 759 picture->display_offset[i].y = mpeg2dec->display_offset_y = y >> 1;
601 } 760 }
602 for (; i < 3; i++) { 761
762 for (; i < 3; i++)
763 {
603 picture->display_offset[i].x = mpeg2dec->display_offset_x; 764 picture->display_offset[i].x = mpeg2dec->display_offset_x;
604 picture->display_offset[i].y = mpeg2dec->display_offset_y; 765 picture->display_offset[i].y = mpeg2dec->display_offset_y;
605 } 766 }
767
606 return 0; 768 return 0;
607} 769}
608 770
609void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec) 771void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec)
610{ 772{
611 mpeg2_decoder_t * decoder = &(mpeg2dec->decoder); 773 mpeg2_decoder_t * decoder = &mpeg2dec->decoder;
612 int old_type_b = (decoder->coding_type == B_TYPE); 774 int old_type_b = decoder->coding_type == B_TYPE;
613 int low_delay = mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY; 775 int low_delay = mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY;
614 776
615 finalize_matrix (mpeg2dec); 777 finalize_matrix (mpeg2dec);
616 decoder->coding_type = mpeg2dec->new_picture.flags & PIC_MASK_CODING_TYPE; 778 decoder->coding_type = mpeg2dec->new_picture.flags & PIC_MASK_CODING_TYPE;
617 779
618 if (mpeg2dec->state == STATE_PICTURE) { 780 if (mpeg2dec->state == STATE_PICTURE)
781 {
619 mpeg2_picture_t * picture; 782 mpeg2_picture_t * picture;
620 mpeg2_picture_t * other; 783 mpeg2_picture_t * other;
621 784
622 decoder->second_field = 0; 785 decoder->second_field = 0;
623 786
624 picture = other = mpeg2dec->pictures; 787 picture = other = mpeg2dec->pictures;
788
625 if (old_type_b ^ (mpeg2dec->picture < mpeg2dec->pictures + 2)) 789 if (old_type_b ^ (mpeg2dec->picture < mpeg2dec->pictures + 2))
626 picture += 2; 790 picture += 2;
627 else 791 else
628 other += 2; 792 other += 2;
793
629 mpeg2dec->picture = picture; 794 mpeg2dec->picture = picture;
630 *picture = mpeg2dec->new_picture; 795 *picture = mpeg2dec->new_picture;
631 796
632 if (!old_type_b) { 797 if (!old_type_b)
798 {
633 mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1]; 799 mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1];
634 mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0]; 800 mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0];
635 } 801 }
802
636 mpeg2dec->fbuf[0] = NULL; 803 mpeg2dec->fbuf[0] = NULL;
637 mpeg2_reset_info (&(mpeg2dec->info)); 804 mpeg2_reset_info (&mpeg2dec->info);
638 mpeg2dec->info.current_picture = picture; 805 mpeg2dec->info.current_picture = picture;
639 mpeg2dec->info.display_picture = picture; 806 mpeg2dec->info.display_picture = picture;
640 if (decoder->coding_type != B_TYPE) { 807
641 if (!low_delay) { 808 if (decoder->coding_type != B_TYPE)
642 if (mpeg2dec->first) { 809 {
810 if (!low_delay)
811 {
812 if (mpeg2dec->first)
813 {
643 mpeg2dec->info.display_picture = NULL; 814 mpeg2dec->info.display_picture = NULL;
644 mpeg2dec->first = 0; 815 mpeg2dec->first = 0;
645 } else { 816 }
817 else
818 {
646 mpeg2dec->info.display_picture = other; 819 mpeg2dec->info.display_picture = other;
820
647 if (other->nb_fields == 1) 821 if (other->nb_fields == 1)
648 mpeg2dec->info.display_picture_2nd = other + 1; 822 mpeg2dec->info.display_picture_2nd = other + 1;
823
649 mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[1]; 824 mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[1];
650 } 825 }
651 } 826 }
827
652 if (!low_delay + !mpeg2dec->convert) 828 if (!low_delay + !mpeg2dec->convert)
829 {
653 mpeg2dec->info.discard_fbuf = 830 mpeg2dec->info.discard_fbuf =
654 mpeg2dec->fbuf[!low_delay + !mpeg2dec->convert]; 831 mpeg2dec->fbuf[!low_delay + !mpeg2dec->convert];
832 }
655 } 833 }
656 if (mpeg2dec->convert) { 834
835 if (mpeg2dec->convert)
836 {
657 mpeg2_convert_init_t convert_init; 837 mpeg2_convert_init_t convert_init;
658 if (!mpeg2dec->convert_start) { 838
839 if (!mpeg2dec->convert_start)
840 {
659 int y_size, uv_size; 841 int y_size, uv_size;
660 842
661 mpeg2dec->decoder.convert_id = 843 mpeg2dec->decoder.convert_id =
662 mpeg2_malloc (mpeg2dec->convert_id_size, 844 mpeg2_malloc (mpeg2dec->convert_id_size,
663 MPEG2_ALLOC_CONVERT_ID); 845 MPEG2_ALLOC_CONVERT_ID);
846
664 mpeg2dec->convert (MPEG2_CONVERT_START, 847 mpeg2dec->convert (MPEG2_CONVERT_START,
665 mpeg2dec->decoder.convert_id, 848 mpeg2dec->decoder.convert_id,
666 &(mpeg2dec->sequence), 849 &mpeg2dec->sequence,
667 mpeg2dec->convert_stride, 850 mpeg2dec->convert_stride,
668 mpeg2dec->convert_arg, &convert_init); 851 mpeg2dec->convert_arg, &convert_init);
852
669 mpeg2dec->convert_start = convert_init.start; 853 mpeg2dec->convert_start = convert_init.start;
670 mpeg2dec->decoder.convert = convert_init.copy; 854 mpeg2dec->decoder.convert = convert_init.copy;
671 855
672 y_size = decoder->stride_frame * mpeg2dec->sequence.height; 856 y_size = decoder->stride_frame * mpeg2dec->sequence.height;
673 uv_size = y_size >> (2 - mpeg2dec->decoder.chroma_format); 857 uv_size = y_size >> (2 - mpeg2dec->decoder.chroma_format);
858
674 mpeg2dec->yuv_buf[0][0] = 859 mpeg2dec->yuv_buf[0][0] =
675 (uint8_t *) mpeg2_malloc (y_size, MPEG2_ALLOC_YUV); 860 (uint8_t *) mpeg2_malloc(y_size, MPEG2_ALLOC_YUV);
676 mpeg2dec->yuv_buf[0][1] = 861 mpeg2dec->yuv_buf[0][1] =
677 (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV); 862 (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
678 mpeg2dec->yuv_buf[0][2] = 863 mpeg2dec->yuv_buf[0][2] =
679 (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV); 864 (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
865
680 mpeg2dec->yuv_buf[1][0] = 866 mpeg2dec->yuv_buf[1][0] =
681 (uint8_t *) mpeg2_malloc (y_size, MPEG2_ALLOC_YUV); 867 (uint8_t *) mpeg2_malloc(y_size, MPEG2_ALLOC_YUV);
682 mpeg2dec->yuv_buf[1][1] = 868 mpeg2dec->yuv_buf[1][1] =
683 (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV); 869 (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
684 mpeg2dec->yuv_buf[1][2] = 870 mpeg2dec->yuv_buf[1][2] =
685 (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV); 871 (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
872
686 y_size = decoder->stride_frame * 32; 873 y_size = decoder->stride_frame * 32;
687 uv_size = y_size >> (2 - mpeg2dec->decoder.chroma_format); 874 uv_size = y_size >> (2 - mpeg2dec->decoder.chroma_format);
875
688 mpeg2dec->yuv_buf[2][0] = 876 mpeg2dec->yuv_buf[2][0] =
689 (uint8_t *) mpeg2_malloc (y_size, MPEG2_ALLOC_YUV); 877 (uint8_t *) mpeg2_malloc(y_size, MPEG2_ALLOC_YUV);
690 mpeg2dec->yuv_buf[2][1] = 878 mpeg2dec->yuv_buf[2][1] =
691 (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV); 879 (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
692 mpeg2dec->yuv_buf[2][2] = 880 mpeg2dec->yuv_buf[2][2] =
693 (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV); 881 (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
694 } 882 }
695 if (!mpeg2dec->custom_fbuf) { 883
696 while (mpeg2dec->alloc_index < 3) { 884 if (!mpeg2dec->custom_fbuf)
885 {
886 while (mpeg2dec->alloc_index < 3)
887 {
697 mpeg2_fbuf_t * fbuf; 888 mpeg2_fbuf_t * fbuf;
698 889
699 fbuf = &mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index++].fbuf; 890 fbuf = &mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index++].fbuf;
700 fbuf->id = NULL; 891 fbuf->id = NULL;
892
701 fbuf->buf[0] = 893 fbuf->buf[0] =
702 (uint8_t *) mpeg2_malloc (convert_init.buf_size[0], 894 (uint8_t *) mpeg2_malloc (convert_init.buf_size[0],
703 MPEG2_ALLOC_CONVERTED); 895 MPEG2_ALLOC_CONVERTED);
@@ -710,15 +902,21 @@ void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec)
710 } 902 }
711 mpeg2_set_fbuf (mpeg2dec, (decoder->coding_type == B_TYPE)); 903 mpeg2_set_fbuf (mpeg2dec, (decoder->coding_type == B_TYPE));
712 } 904 }
713 } else if (!mpeg2dec->custom_fbuf) { 905 }
714 while (mpeg2dec->alloc_index < 3) { 906 else if (!mpeg2dec->custom_fbuf)
907 {
908 while (mpeg2dec->alloc_index < 3)
909 {
715 mpeg2_fbuf_t * fbuf; 910 mpeg2_fbuf_t * fbuf;
716 int y_size, uv_size; 911 int y_size, uv_size;
717 912
718 fbuf = &(mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index++].fbuf); 913 fbuf = &mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index++].fbuf;
914
719 fbuf->id = NULL; 915 fbuf->id = NULL;
916
720 y_size = decoder->stride_frame * mpeg2dec->sequence.height; 917 y_size = decoder->stride_frame * mpeg2dec->sequence.height;
721 uv_size = y_size >> (2 - decoder->chroma_format); 918 uv_size = y_size >> (2 - decoder->chroma_format);
919
722 fbuf->buf[0] = (uint8_t *) mpeg2_malloc (y_size, 920 fbuf->buf[0] = (uint8_t *) mpeg2_malloc (y_size,
723 MPEG2_ALLOC_YUV); 921 MPEG2_ALLOC_YUV);
724 fbuf->buf[1] = (uint8_t *) mpeg2_malloc (uv_size, 922 fbuf->buf[1] = (uint8_t *) mpeg2_malloc (uv_size,
@@ -726,13 +924,19 @@ void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec)
726 fbuf->buf[2] = (uint8_t *) mpeg2_malloc (uv_size, 924 fbuf->buf[2] = (uint8_t *) mpeg2_malloc (uv_size,
727 MPEG2_ALLOC_YUV); 925 MPEG2_ALLOC_YUV);
728 } 926 }
927
729 mpeg2_set_fbuf (mpeg2dec, (decoder->coding_type == B_TYPE)); 928 mpeg2_set_fbuf (mpeg2dec, (decoder->coding_type == B_TYPE));
730 } 929 }
731 } else { 930 }
931 else
932 {
732 decoder->second_field = 1; 933 decoder->second_field = 1;
733 mpeg2dec->picture++; /* second field picture */ 934 mpeg2dec->picture++; /* second field picture */
935
734 *(mpeg2dec->picture) = mpeg2dec->new_picture; 936 *(mpeg2dec->picture) = mpeg2dec->new_picture;
937
735 mpeg2dec->info.current_picture_2nd = mpeg2dec->picture; 938 mpeg2dec->info.current_picture_2nd = mpeg2dec->picture;
939
736 if (low_delay || decoder->coding_type == B_TYPE) 940 if (low_delay || decoder->coding_type == B_TYPE)
737 mpeg2dec->info.display_picture_2nd = mpeg2dec->picture; 941 mpeg2dec->info.display_picture_2nd = mpeg2dec->picture;
738 } 942 }
@@ -752,23 +956,38 @@ static int quant_matrix_ext (mpeg2dec_t * mpeg2dec)
752 int i, j; 956 int i, j;
753 957
754 for (i = 0; i < 4; i++) 958 for (i = 0; i < 4; i++)
755 if (buffer[0] & (8 >> i)) { 959 {
960 if (buffer[0] & (8 >> i))
961 {
756 for (j = 0; j < 64; j++) 962 for (j = 0; j < 64; j++)
963 {
757 mpeg2dec->new_quantizer_matrix[i][mpeg2_scan_norm[j]] = 964 mpeg2dec->new_quantizer_matrix[i][mpeg2_scan_norm[j]] =
758 (buffer[j] << (i+5)) | (buffer[j+1] >> (3-i)); 965 (buffer[j] << (i+5)) | (buffer[j+1] >> (3-i));
966 }
967
759 mpeg2dec->copy_matrix |= 1 << i; 968 mpeg2dec->copy_matrix |= 1 << i;
760 buffer += 64; 969 buffer += 64;
761 } 970 }
971 }
762 972
763 return 0; 973 return 0;
764} 974}
765 975
766int mpeg2_header_extension (mpeg2dec_t * mpeg2dec) 976int mpeg2_header_extension (mpeg2dec_t * mpeg2dec)
767{ 977{
768 static int (* parser[]) (mpeg2dec_t *) = { 978 static int (* const parser[9]) (mpeg2dec_t *) =
769 0, sequence_ext, sequence_display_ext, quant_matrix_ext, 979 {
770 copyright_ext, 0, 0, picture_display_ext, picture_coding_ext 980 NULL,
981 sequence_ext,
982 sequence_display_ext,
983 quant_matrix_ext,
984 copyright_ext,
985 NULL,
986 NULL,
987 picture_display_ext,
988 picture_coding_ext
771 }; 989 };
990
772 int ext, ext_bit; 991 int ext, ext_bit;
773 992
774 ext = mpeg2dec->chunk_start[0] >> 4; 993 ext = mpeg2dec->chunk_start[0] >> 4;
@@ -776,7 +995,9 @@ int mpeg2_header_extension (mpeg2dec_t * mpeg2dec)
776 995
777 if (!(mpeg2dec->ext_state & ext_bit)) 996 if (!(mpeg2dec->ext_state & ext_bit))
778 return 0; /* ignore illegal extensions */ 997 return 0; /* ignore illegal extensions */
998
779 mpeg2dec->ext_state &= ~ext_bit; 999 mpeg2dec->ext_state &= ~ext_bit;
1000
780 return parser[ext] (mpeg2dec); 1001 return parser[ext] (mpeg2dec);
781} 1002}
782 1003
@@ -784,89 +1005,119 @@ int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec)
784{ 1005{
785 mpeg2dec->user_data_len += mpeg2dec->chunk_ptr - 1 - mpeg2dec->chunk_start; 1006 mpeg2dec->user_data_len += mpeg2dec->chunk_ptr - 1 - mpeg2dec->chunk_start;
786 mpeg2dec->chunk_start = mpeg2dec->chunk_ptr - 1; 1007 mpeg2dec->chunk_start = mpeg2dec->chunk_ptr - 1;
787 1008
788 return 0; 1009 return 0;
789} 1010}
790 1011
791static void prescale (mpeg2dec_t * mpeg2dec, int index) 1012static void prescale (mpeg2dec_t * mpeg2dec, int index)
792{ 1013{
793 static int non_linear_scale [] = { 1014 static const int non_linear_scale[32] =
1015 {
794 0, 1, 2, 3, 4, 5, 6, 7, 1016 0, 1, 2, 3, 4, 5, 6, 7,
795 8, 10, 12, 14, 16, 18, 20, 22, 1017 8, 10, 12, 14, 16, 18, 20, 22,
796 24, 28, 32, 36, 40, 44, 48, 52, 1018 24, 28, 32, 36, 40, 44, 48, 52,
797 56, 64, 72, 80, 88, 96, 104, 112 1019 56, 64, 72, 80, 88, 96, 104, 112
798 }; 1020 };
1021
799 int i, j, k; 1022 int i, j, k;
800 mpeg2_decoder_t * decoder = &(mpeg2dec->decoder); 1023 mpeg2_decoder_t * decoder = &mpeg2dec->decoder;
801 1024
802 if (mpeg2dec->scaled[index] != mpeg2dec->q_scale_type) { 1025 if (mpeg2dec->scaled[index] != mpeg2dec->q_scale_type)
1026 {
803 mpeg2dec->scaled[index] = mpeg2dec->q_scale_type; 1027 mpeg2dec->scaled[index] = mpeg2dec->q_scale_type;
804 for (i = 0; i < 32; i++) { 1028
1029 for (i = 0; i < 32; i++)
1030 {
805 k = mpeg2dec->q_scale_type ? non_linear_scale[i] : (i << 1); 1031 k = mpeg2dec->q_scale_type ? non_linear_scale[i] : (i << 1);
1032
806 for (j = 0; j < 64; j++) 1033 for (j = 0; j < 64; j++)
1034 {
807 decoder->quantizer_prescale[index][i][j] = 1035 decoder->quantizer_prescale[index][i][j] =
808 k * mpeg2dec->quantizer_matrix[index][j]; 1036 k * mpeg2dec->quantizer_matrix[index][j];
1037 }
809 } 1038 }
810 } 1039 }
811} 1040}
812 1041
813mpeg2_state_t mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec) 1042mpeg2_state_t mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec)
814{ 1043{
815 mpeg2_decoder_t * decoder = &(mpeg2dec->decoder); 1044 mpeg2_decoder_t * decoder = &mpeg2dec->decoder;
816 1045
817 mpeg2dec->info.user_data = NULL; mpeg2dec->info.user_data_len = 0; 1046 mpeg2dec->info.user_data = NULL;
818 mpeg2dec->state = ((mpeg2dec->picture->nb_fields > 1 || 1047 mpeg2dec->info.user_data_len = 0;
819 mpeg2dec->state == STATE_PICTURE_2ND) ? 1048 mpeg2dec->state = (mpeg2dec->picture->nb_fields > 1 ||
820 STATE_SLICE : STATE_SLICE_1ST); 1049 mpeg2dec->state == STATE_PICTURE_2ND) ?
1050 STATE_SLICE : STATE_SLICE_1ST;
821 1051
822 if (mpeg2dec->decoder.coding_type != D_TYPE) { 1052 if (mpeg2dec->decoder.coding_type != D_TYPE)
1053 {
823 prescale (mpeg2dec, 0); 1054 prescale (mpeg2dec, 0);
1055
824 if (decoder->chroma_quantizer[0] == decoder->quantizer_prescale[2]) 1056 if (decoder->chroma_quantizer[0] == decoder->quantizer_prescale[2])
825 prescale (mpeg2dec, 2); 1057 prescale (mpeg2dec, 2);
826 if (mpeg2dec->decoder.coding_type != I_TYPE) { 1058
1059 if (mpeg2dec->decoder.coding_type != I_TYPE)
1060 {
827 prescale (mpeg2dec, 1); 1061 prescale (mpeg2dec, 1);
1062
828 if (decoder->chroma_quantizer[1] == decoder->quantizer_prescale[3]) 1063 if (decoder->chroma_quantizer[1] == decoder->quantizer_prescale[3])
829 prescale (mpeg2dec, 3); 1064 prescale (mpeg2dec, 3);
830 } 1065 }
831 } 1066 }
832 1067
833 if (!(mpeg2dec->nb_decode_slices)) 1068 if (!(mpeg2dec->nb_decode_slices))
1069 {
834 mpeg2dec->picture->flags |= PIC_FLAG_SKIP; 1070 mpeg2dec->picture->flags |= PIC_FLAG_SKIP;
835 else if (mpeg2dec->convert_start) { 1071 }
1072 else if (mpeg2dec->convert_start)
1073 {
836 mpeg2dec->convert_start (decoder->convert_id, mpeg2dec->fbuf[0], 1074 mpeg2dec->convert_start (decoder->convert_id, mpeg2dec->fbuf[0],
837 mpeg2dec->picture, mpeg2dec->info.gop); 1075 mpeg2dec->picture, mpeg2dec->info.gop);
838 1076
839 if (mpeg2dec->decoder.coding_type == B_TYPE) 1077 if (mpeg2dec->decoder.coding_type == B_TYPE)
840 mpeg2_init_fbuf (&(mpeg2dec->decoder), mpeg2dec->yuv_buf[2], 1078 {
1079 mpeg2_init_fbuf (&mpeg2dec->decoder, mpeg2dec->yuv_buf[2],
841 mpeg2dec->yuv_buf[mpeg2dec->yuv_index ^ 1], 1080 mpeg2dec->yuv_buf[mpeg2dec->yuv_index ^ 1],
842 mpeg2dec->yuv_buf[mpeg2dec->yuv_index]); 1081 mpeg2dec->yuv_buf[mpeg2dec->yuv_index]);
843 else { 1082 }
844 mpeg2_init_fbuf (&(mpeg2dec->decoder), 1083 else
1084 {
1085 mpeg2_init_fbuf (&mpeg2dec->decoder,
845 mpeg2dec->yuv_buf[mpeg2dec->yuv_index ^ 1], 1086 mpeg2dec->yuv_buf[mpeg2dec->yuv_index ^ 1],
846 mpeg2dec->yuv_buf[mpeg2dec->yuv_index], 1087 mpeg2dec->yuv_buf[mpeg2dec->yuv_index],
847 mpeg2dec->yuv_buf[mpeg2dec->yuv_index]); 1088 mpeg2dec->yuv_buf[mpeg2dec->yuv_index]);
1089
848 if (mpeg2dec->state == STATE_SLICE) 1090 if (mpeg2dec->state == STATE_SLICE)
849 mpeg2dec->yuv_index ^= 1; 1091 mpeg2dec->yuv_index ^= 1;
850 } 1092 }
851 } else { 1093 }
1094 else
1095 {
852 int b_type; 1096 int b_type;
853 1097
854 b_type = (mpeg2dec->decoder.coding_type == B_TYPE); 1098 b_type = (mpeg2dec->decoder.coding_type == B_TYPE);
855 mpeg2_init_fbuf (&(mpeg2dec->decoder), mpeg2dec->fbuf[0]->buf, 1099
1100 mpeg2_init_fbuf (&mpeg2dec->decoder, mpeg2dec->fbuf[0]->buf,
856 mpeg2dec->fbuf[b_type + 1]->buf, 1101 mpeg2dec->fbuf[b_type + 1]->buf,
857 mpeg2dec->fbuf[b_type]->buf); 1102 mpeg2dec->fbuf[b_type]->buf);
858 } 1103 }
1104
859 mpeg2dec->action = NULL; 1105 mpeg2dec->action = NULL;
1106
860 return (mpeg2_state_t)-1; 1107 return (mpeg2_state_t)-1;
861} 1108}
862 1109
863static mpeg2_state_t seek_sequence (mpeg2dec_t * mpeg2dec) 1110static mpeg2_state_t seek_sequence (mpeg2dec_t * mpeg2dec)
864{ 1111{
865 mpeg2_reset_info (&(mpeg2dec->info)); 1112 mpeg2_reset_info (&mpeg2dec->info);
1113
866 mpeg2dec->info.sequence = NULL; 1114 mpeg2dec->info.sequence = NULL;
867 mpeg2dec->info.gop = NULL; 1115 mpeg2dec->info.gop = NULL;
1116
868 mpeg2_header_state_init (mpeg2dec); 1117 mpeg2_header_state_init (mpeg2dec);
1118
869 mpeg2dec->action = mpeg2_seek_header; 1119 mpeg2dec->action = mpeg2_seek_header;
1120
870 return mpeg2_seek_header (mpeg2dec); 1121 return mpeg2_seek_header (mpeg2dec);
871} 1122}
872 1123
@@ -877,19 +1128,30 @@ mpeg2_state_t mpeg2_header_end (mpeg2dec_t * mpeg2dec)
877 1128
878 b_type = (mpeg2dec->decoder.coding_type == B_TYPE); 1129 b_type = (mpeg2dec->decoder.coding_type == B_TYPE);
879 picture = mpeg2dec->pictures; 1130 picture = mpeg2dec->pictures;
1131
880 if ((mpeg2dec->picture >= picture + 2) ^ b_type) 1132 if ((mpeg2dec->picture >= picture + 2) ^ b_type)
881 picture = mpeg2dec->pictures + 2; 1133 picture = mpeg2dec->pictures + 2;
882 1134
883 mpeg2_reset_info (&(mpeg2dec->info)); 1135 mpeg2_reset_info (&mpeg2dec->info);
884 if (!(mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY)) { 1136
1137 if (!(mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY))
1138 {
885 mpeg2dec->info.display_picture = picture; 1139 mpeg2dec->info.display_picture = picture;
1140
886 if (picture->nb_fields == 1) 1141 if (picture->nb_fields == 1)
887 mpeg2dec->info.display_picture_2nd = picture + 1; 1142 mpeg2dec->info.display_picture_2nd = picture + 1;
1143
888 mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[b_type]; 1144 mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[b_type];
1145
889 if (!mpeg2dec->convert) 1146 if (!mpeg2dec->convert)
890 mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[b_type + 1]; 1147 mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[b_type + 1];
891 } else if (!mpeg2dec->convert) 1148 }
1149 else if (!mpeg2dec->convert)
1150 {
892 mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[b_type]; 1151 mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[b_type];
1152 }
1153
893 mpeg2dec->action = seek_sequence; 1154 mpeg2dec->action = seek_sequence;
1155
894 return STATE_END; 1156 return STATE_END;
895} 1157}
diff --git a/apps/plugins/mpegplayer/idct.c b/apps/plugins/mpegplayer/idct.c
index 1cd1d91990..f9e3b7d664 100644
--- a/apps/plugins/mpegplayer/idct.c
+++ b/apps/plugins/mpegplayer/idct.c
@@ -29,26 +29,11 @@
29#include "attributes.h" 29#include "attributes.h"
30#include "mpeg2_internal.h" 30#include "mpeg2_internal.h"
31 31
32/* idct main entry point */ 32#if defined(CPU_COLDFIRE) || defined (CPU_ARM)
33void (* mpeg2_idct_copy) (int16_t * block, uint8_t * dest, int stride); 33#define IDCT_ASM
34void (* mpeg2_idct_add) (int last, int16_t * block, 34#endif
35 uint8_t * dest, int stride); 35
36 36#ifndef IDCT_ASM
37#ifdef CPU_COLDFIRE
38/* assembler functions */
39extern void mpeg2_idct_copy_coldfire(int16_t * block, uint8_t * dest,
40 const int stride);
41extern void mpeg2_idct_add_coldfire(const int last, int16_t * block,
42 uint8_t * dest, const int stride);
43
44#elif defined CPU_ARM
45/* assembler functions */
46extern void mpeg2_idct_copy_arm(int16_t * block, uint8_t * dest,
47 const int stride);
48extern void mpeg2_idct_add_arm(const int last, int16_t * block,
49 uint8_t * dest, const int stride);
50
51#else /* !CPU_COLDFIRE, !CPU_ARM */
52 37
53#define W1 2841 /* 2048 * sqrt (2) * cos (1 * pi / 16) */ 38#define W1 2841 /* 2048 * sqrt (2) * cos (1 * pi / 16) */
54#define W2 2676 /* 2048 * sqrt (2) * cos (2 * pi / 16) */ 39#define W2 2676 /* 2048 * sqrt (2) * cos (2 * pi / 16) */
@@ -63,8 +48,11 @@ extern void mpeg2_idct_add_arm(const int last, int16_t * block,
63 * to +-3826 - this is the worst case for a column IDCT where the 48 * to +-3826 - this is the worst case for a column IDCT where the
64 * column inputs are 16-bit values. 49 * column inputs are 16-bit values.
65 */ 50 */
66uint8_t mpeg2_clip[3840 * 2 + 256] IBSS_ATTR; 51#define CLIP(i) \
67#define CLIP(i) ((mpeg2_clip + 3840)[i]) 52 ({ typeof (i) _i = (i); \
53 if ((_i & 0xff) != _i) \
54 _i = ~(_i >> (8*sizeof(_i) - 1)); \
55 _i; })
68 56
69#if 0 57#if 0
70#define BUTTERFLY(t0,t1,W0,W1,d0,d1) \ 58#define BUTTERFLY(t0,t1,W0,W1,d0,d1) \
@@ -89,7 +77,8 @@ static inline void idct_row (int16_t * const block)
89 77
90 /* shortcut */ 78 /* shortcut */
91 if (likely (!(block[1] | ((int32_t *)block)[1] | ((int32_t *)block)[2] | 79 if (likely (!(block[1] | ((int32_t *)block)[1] | ((int32_t *)block)[2] |
92 ((int32_t *)block)[3]))) { 80 ((int32_t *)block)[3])))
81 {
93 uint32_t tmp = (uint16_t) (block[0] >> 1); 82 uint32_t tmp = (uint16_t) (block[0] >> 1);
94 tmp |= tmp << 16; 83 tmp |= tmp << 16;
95 ((int32_t *)block)[0] = tmp; 84 ((int32_t *)block)[0] = tmp;
@@ -175,16 +164,19 @@ static inline void idct_col (int16_t * const block)
175 block[8*7] = (a0 - b0) >> 17; 164 block[8*7] = (a0 - b0) >> 17;
176} 165}
177 166
178static void mpeg2_idct_copy_c (int16_t * block, uint8_t * dest, 167void mpeg2_idct_copy (int16_t * block, uint8_t * dest,
179 const int stride) 168 const int stride)
180{ 169{
181 int i; 170 int i;
182 171
183 for (i = 0; i < 8; i++) 172 for (i = 0; i < 8; i++)
184 idct_row (block + 8 * i); 173 idct_row (block + 8 * i);
174
185 for (i = 0; i < 8; i++) 175 for (i = 0; i < 8; i++)
186 idct_col (block + i); 176 idct_col (block + i);
187 do { 177
178 do
179 {
188 dest[0] = CLIP (block[0]); 180 dest[0] = CLIP (block[0]);
189 dest[1] = CLIP (block[1]); 181 dest[1] = CLIP (block[1]);
190 dest[2] = CLIP (block[2]); 182 dest[2] = CLIP (block[2]);
@@ -194,25 +186,32 @@ static void mpeg2_idct_copy_c (int16_t * block, uint8_t * dest,
194 dest[6] = CLIP (block[6]); 186 dest[6] = CLIP (block[6]);
195 dest[7] = CLIP (block[7]); 187 dest[7] = CLIP (block[7]);
196 188
197 ((int32_t *)block)[0] = 0; ((int32_t *)block)[1] = 0; 189 ((int32_t *)block)[0] = 0;
198 ((int32_t *)block)[2] = 0; ((int32_t *)block)[3] = 0; 190 ((int32_t *)block)[1] = 0;
191 ((int32_t *)block)[2] = 0;
192 ((int32_t *)block)[3] = 0;
199 193
200 dest += stride; 194 dest += stride;
201 block += 8; 195 block += 8;
202 } while (--i); 196 }
197 while (--i);
203} 198}
204 199
205static void mpeg2_idct_add_c (const int last, int16_t * block, 200void mpeg2_idct_add (const int last, int16_t * block,
206 uint8_t * dest, const int stride) 201 uint8_t * dest, const int stride)
207{ 202{
208 int i; 203 int i;
209 204
210 if (last != 129 || (block[0] & (7 << 4)) == (4 << 4)) { 205 if (last != 129 || (block[0] & (7 << 4)) == (4 << 4))
206 {
211 for (i = 0; i < 8; i++) 207 for (i = 0; i < 8; i++)
212 idct_row (block + 8 * i); 208 idct_row (block + 8 * i);
209
213 for (i = 0; i < 8; i++) 210 for (i = 0; i < 8; i++)
214 idct_col (block + i); 211 idct_col (block + i);
215 do { 212
213 do
214 {
216 dest[0] = CLIP (block[0] + dest[0]); 215 dest[0] = CLIP (block[0] + dest[0]);
217 dest[1] = CLIP (block[1] + dest[1]); 216 dest[1] = CLIP (block[1] + dest[1]);
218 dest[2] = CLIP (block[2] + dest[2]); 217 dest[2] = CLIP (block[2] + dest[2]);
@@ -222,19 +221,24 @@ static void mpeg2_idct_add_c (const int last, int16_t * block,
222 dest[6] = CLIP (block[6] + dest[6]); 221 dest[6] = CLIP (block[6] + dest[6]);
223 dest[7] = CLIP (block[7] + dest[7]); 222 dest[7] = CLIP (block[7] + dest[7]);
224 223
225 ((int32_t *)block)[0] = 0; ((int32_t *)block)[1] = 0; 224 ((int32_t *)block)[0] = 0;
226 ((int32_t *)block)[2] = 0; ((int32_t *)block)[3] = 0; 225 ((int32_t *)block)[1] = 0;
226 ((int32_t *)block)[2] = 0;
227 ((int32_t *)block)[3] = 0;
227 228
228 dest += stride; 229 dest += stride;
229 block += 8; 230 block += 8;
230 } while (--i); 231 }
231 } else { 232 while (--i);
232 int DC; 233 }
233 234 else
234 DC = (block[0] + 64) >> 7; 235 {
236 int DC = (block[0] + 64) >> 7;
235 block[0] = block[63] = 0; 237 block[0] = block[63] = 0;
236 i = 8; 238 i = 8;
237 do { 239
240 do
241 {
238 dest[0] = CLIP (DC + dest[0]); 242 dest[0] = CLIP (DC + dest[0]);
239 dest[1] = CLIP (DC + dest[1]); 243 dest[1] = CLIP (DC + dest[1]);
240 dest[2] = CLIP (DC + dest[2]); 244 dest[2] = CLIP (DC + dest[2]);
@@ -244,34 +248,17 @@ static void mpeg2_idct_add_c (const int last, int16_t * block,
244 dest[6] = CLIP (DC + dest[6]); 248 dest[6] = CLIP (DC + dest[6]);
245 dest[7] = CLIP (DC + dest[7]); 249 dest[7] = CLIP (DC + dest[7]);
246 dest += stride; 250 dest += stride;
247 } while (--i); 251 }
252 while (--i);
248 } 253 }
249} 254}
250 255
251#endif /* CPU selection */ 256#endif /* IDCT_ASM */
252 257
253void mpeg2_idct_init (void) 258void mpeg2_idct_init (void)
254{ 259{
255 extern uint8_t default_mpeg2_scan_norm[64];
256 extern uint8_t default_mpeg2_scan_alt[64];
257 extern uint8_t mpeg2_scan_norm[64];
258 extern uint8_t mpeg2_scan_alt[64];
259 int i, j; 260 int i, j;
260 261
261#ifdef CPU_COLDFIRE
262 mpeg2_idct_copy = mpeg2_idct_copy_coldfire;
263 mpeg2_idct_add = mpeg2_idct_add_coldfire;
264#elif defined CPU_ARM
265 mpeg2_idct_copy = mpeg2_idct_copy_arm;
266 mpeg2_idct_add = mpeg2_idct_add_arm;
267#else
268 mpeg2_idct_copy = mpeg2_idct_copy_c;
269 mpeg2_idct_add = mpeg2_idct_add_c;
270
271 for (i = -3840; i < 3840 + 256; i++)
272 CLIP(i) = (i < 0) ? 0 : ((i > 255) ? 255 : i);
273#endif
274
275 for (i = 0; i < 64; i++) 262 for (i = 0; i < 64; i++)
276 { 263 {
277 j = default_mpeg2_scan_norm[i]; 264 j = default_mpeg2_scan_norm[i];
diff --git a/apps/plugins/mpegplayer/idct_arm.S b/apps/plugins/mpegplayer/idct_arm.S
index 66a84c8adc..21f47bb34a 100644
--- a/apps/plugins/mpegplayer/idct_arm.S
+++ b/apps/plugins/mpegplayer/idct_arm.S
@@ -17,10 +17,10 @@
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19 19
20 .global mpeg2_idct_copy_arm 20 .global mpeg2_idct_copy
21 .type mpeg2_idct_copy_arm, %function 21 .type mpeg2_idct_copy, %function
22 .global mpeg2_idct_add_arm 22 .global mpeg2_idct_add
23 .type mpeg2_idct_add_arm, %function 23 .type mpeg2_idct_add, %function
24 24
25 25
26/* Custom calling convention: 26/* Custom calling convention:
@@ -265,7 +265,7 @@
265 sub r0, r0, #16 265 sub r0, r0, #16
266 bx lr 266 bx lr
267 267
268mpeg2_idct_copy_arm: 268mpeg2_idct_copy:
269 stmfd sp!, { r1-r2, r4-r12, lr } 269 stmfd sp!, { r1-r2, r4-r12, lr }
270 bl .idct 270 bl .idct
271 ldmfd sp!, { r1-r2 } 271 ldmfd sp!, { r1-r2 }
@@ -313,7 +313,7 @@ mpeg2_idct_copy_arm:
313 blo 1b 313 blo 1b
314 ldmfd sp!, { r4-r12, pc } 314 ldmfd sp!, { r4-r12, pc }
315 315
316mpeg2_idct_add_arm: 316mpeg2_idct_add:
317 cmp r0, #129 317 cmp r0, #129
318 mov r0, r1 318 mov r0, r1
319 ldreqsh r1, [r0, #0] 319 ldreqsh r1, [r0, #0]
diff --git a/apps/plugins/mpegplayer/idct_coldfire.S b/apps/plugins/mpegplayer/idct_coldfire.S
index 9459c284d9..aa9a75b2e7 100644
--- a/apps/plugins/mpegplayer/idct_coldfire.S
+++ b/apps/plugins/mpegplayer/idct_coldfire.S
@@ -18,10 +18,10 @@
18 * 18 *
19 ****************************************************************************/ 19 ****************************************************************************/
20 20
21 .global mpeg2_idct_copy_coldfire 21 .global mpeg2_idct_copy
22 .type mpeg2_idct_copy_coldfire, @function 22 .type mpeg2_idct_copy, @function
23 .global mpeg2_idct_add_coldfire 23 .global mpeg2_idct_add
24 .type mpeg2_idct_add_coldfire, @function 24 .type mpeg2_idct_add, @function
25 25
26 /* The IDCT itself. 26 /* The IDCT itself.
27 * Input: %a0: block pointer 27 * Input: %a0: block pointer
@@ -240,7 +240,7 @@
240 240
241 .align 2 241 .align 2
242 242
243mpeg2_idct_copy_coldfire: 243mpeg2_idct_copy:
244 lea.l (-11*4,%sp), %sp 244 lea.l (-11*4,%sp), %sp
245 movem.l %d2-%d7/%a2-%a6, (%sp) | save some registers 245 movem.l %d2-%d7/%a2-%a6, (%sp) | save some registers
246 move.l (11*4+4,%sp), %a0 | %a0 - block pointer for idct 246 move.l (11*4+4,%sp), %a0 | %a0 - block pointer for idct
@@ -339,7 +339,7 @@ mpeg2_idct_copy_coldfire:
339 339
340 .align 2 340 .align 2
341 341
342mpeg2_idct_add_coldfire: 342mpeg2_idct_add:
343 lea.l (-11*4,%sp), %sp 343 lea.l (-11*4,%sp), %sp
344 movem.l %d2-%d7/%a2-%a6, (%sp) 344 movem.l %d2-%d7/%a2-%a6, (%sp)
345 movem.l (11*4+4,%sp), %d0/%a0-%a2 | %d0 - last value 345 movem.l (11*4+4,%sp), %d0/%a0-%a2 | %d0 - last value
diff --git a/apps/plugins/mpegplayer/motion_comp.c b/apps/plugins/mpegplayer/motion_comp.c
index beb5c00228..e76b65f6f0 100644
--- a/apps/plugins/mpegplayer/motion_comp.c
+++ b/apps/plugins/mpegplayer/motion_comp.c
@@ -19,6 +19,8 @@
19 * You should have received a copy of the GNU General Public License 19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software 20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 * $Id$
22 */ 24 */
23 25
24#include "plugin.h" 26#include "plugin.h"
@@ -48,7 +50,7 @@ extern mpeg2_mc_fct MC_avg_y_8;
48extern mpeg2_mc_fct MC_avg_xy_16; 50extern mpeg2_mc_fct MC_avg_xy_16;
49extern mpeg2_mc_fct MC_avg_xy_8; 51extern mpeg2_mc_fct MC_avg_xy_8;
50 52
51mpeg2_mc_t mpeg2_mc = 53const mpeg2_mc_t mpeg2_mc =
52{ 54{
53 { 55 {
54 MC_put_o_16, MC_put_x_16, MC_put_y_16, MC_put_xy_16, 56 MC_put_o_16, MC_put_x_16, MC_put_y_16, MC_put_xy_16,
diff --git a/apps/plugins/mpegplayer/mpeg2.h b/apps/plugins/mpegplayer/mpeg2.h
index 01b3de49eb..605a3538b0 100644
--- a/apps/plugins/mpegplayer/mpeg2.h
+++ b/apps/plugins/mpegplayer/mpeg2.h
@@ -27,21 +27,22 @@
27#define MPEG2_VERSION(a,b,c) (((a)<<16)|((b)<<8)|(c)) 27#define MPEG2_VERSION(a,b,c) (((a)<<16)|((b)<<8)|(c))
28#define MPEG2_RELEASE MPEG2_VERSION (0, 4, 0) /* 0.4.0 */ 28#define MPEG2_RELEASE MPEG2_VERSION (0, 4, 0) /* 0.4.0 */
29 29
30#define SEQ_FLAG_MPEG2 1 30#define SEQ_FLAG_MPEG2 1
31#define SEQ_FLAG_CONSTRAINED_PARAMETERS 2 31#define SEQ_FLAG_CONSTRAINED_PARAMETERS 2
32#define SEQ_FLAG_PROGRESSIVE_SEQUENCE 4 32#define SEQ_FLAG_PROGRESSIVE_SEQUENCE 4
33#define SEQ_FLAG_LOW_DELAY 8 33#define SEQ_FLAG_LOW_DELAY 8
34#define SEQ_FLAG_COLOUR_DESCRIPTION 16 34#define SEQ_FLAG_COLOUR_DESCRIPTION 16
35 35
36#define SEQ_MASK_VIDEO_FORMAT 0xe0 36#define SEQ_MASK_VIDEO_FORMAT 0xe0
37#define SEQ_VIDEO_FORMAT_COMPONENT 0 37#define SEQ_VIDEO_FORMAT_COMPONENT 0x00
38#define SEQ_VIDEO_FORMAT_PAL 0x20 38#define SEQ_VIDEO_FORMAT_PAL 0x20
39#define SEQ_VIDEO_FORMAT_NTSC 0x40 39#define SEQ_VIDEO_FORMAT_NTSC 0x40
40#define SEQ_VIDEO_FORMAT_SECAM 0x60 40#define SEQ_VIDEO_FORMAT_SECAM 0x60
41#define SEQ_VIDEO_FORMAT_MAC 0x80 41#define SEQ_VIDEO_FORMAT_MAC 0x80
42#define SEQ_VIDEO_FORMAT_UNSPECIFIED 0xa0 42#define SEQ_VIDEO_FORMAT_UNSPECIFIED 0xa0
43 43
44typedef struct mpeg2_sequence_s { 44typedef struct mpeg2_sequence_s
45{
45 unsigned int width, height; 46 unsigned int width, height;
46 unsigned int chroma_width, chroma_height; 47 unsigned int chroma_width, chroma_height;
47 unsigned int byte_rate; 48 unsigned int byte_rate;
@@ -59,11 +60,12 @@ typedef struct mpeg2_sequence_s {
59 uint8_t matrix_coefficients; 60 uint8_t matrix_coefficients;
60} mpeg2_sequence_t; 61} mpeg2_sequence_t;
61 62
62#define GOP_FLAG_DROP_FRAME 1 63#define GOP_FLAG_DROP_FRAME 1
63#define GOP_FLAG_BROKEN_LINK 2 64#define GOP_FLAG_BROKEN_LINK 2
64#define GOP_FLAG_CLOSED_GOP 4 65#define GOP_FLAG_CLOSED_GOP 4
65 66
66typedef struct mpeg2_gop_s { 67typedef struct mpeg2_gop_s
68{
67 uint8_t hours; 69 uint8_t hours;
68 uint8_t minutes; 70 uint8_t minutes;
69 uint8_t seconds; 71 uint8_t seconds;
@@ -71,35 +73,39 @@ typedef struct mpeg2_gop_s {
71 uint32_t flags; 73 uint32_t flags;
72} mpeg2_gop_t; 74} mpeg2_gop_t;
73 75
74#define PIC_MASK_CODING_TYPE 7 76#define PIC_MASK_CODING_TYPE 7
75#define PIC_FLAG_CODING_TYPE_I 1 77#define PIC_FLAG_CODING_TYPE_I 1
76#define PIC_FLAG_CODING_TYPE_P 2 78#define PIC_FLAG_CODING_TYPE_P 2
77#define PIC_FLAG_CODING_TYPE_B 3 79#define PIC_FLAG_CODING_TYPE_B 3
78#define PIC_FLAG_CODING_TYPE_D 4 80#define PIC_FLAG_CODING_TYPE_D 4
79 81
80#define PIC_FLAG_TOP_FIELD_FIRST 8 82#define PIC_FLAG_TOP_FIELD_FIRST 8
81#define PIC_FLAG_PROGRESSIVE_FRAME 16 83#define PIC_FLAG_PROGRESSIVE_FRAME 16
82#define PIC_FLAG_COMPOSITE_DISPLAY 32 84#define PIC_FLAG_COMPOSITE_DISPLAY 32
83#define PIC_FLAG_SKIP 64 85#define PIC_FLAG_SKIP 64
84#define PIC_FLAG_TAGS 128 86#define PIC_FLAG_TAGS 128
85#define PIC_MASK_COMPOSITE_DISPLAY 0xfffff000 87#define PIC_MASK_COMPOSITE_DISPLAY 0xfffff000
86 88
87typedef struct mpeg2_picture_s { 89typedef struct mpeg2_picture_s
90{
88 unsigned int temporal_reference; 91 unsigned int temporal_reference;
89 unsigned int nb_fields; 92 unsigned int nb_fields;
90 uint32_t tag, tag2; 93 uint32_t tag, tag2;
91 uint32_t flags; 94 uint32_t flags;
92 struct { 95 struct
93 int x, y; 96 {
97 int x, y;
94 } display_offset[3]; 98 } display_offset[3];
95} mpeg2_picture_t; 99} mpeg2_picture_t;
96 100
97typedef struct mpeg2_fbuf_s { 101typedef struct mpeg2_fbuf_s
102{
98 uint8_t * buf[3]; 103 uint8_t * buf[3];
99 void * id; 104 void * id;
100} mpeg2_fbuf_t; 105} mpeg2_fbuf_t;
101 106
102typedef struct mpeg2_info_s { 107typedef struct mpeg2_info_s
108{
103 const mpeg2_sequence_t * sequence; 109 const mpeg2_sequence_t * sequence;
104 const mpeg2_gop_t * gop; 110 const mpeg2_gop_t * gop;
105 const mpeg2_picture_t * current_picture; 111 const mpeg2_picture_t * current_picture;
@@ -116,32 +122,37 @@ typedef struct mpeg2_info_s {
116typedef struct mpeg2dec_s mpeg2dec_t; 122typedef struct mpeg2dec_s mpeg2dec_t;
117typedef struct mpeg2_decoder_s mpeg2_decoder_t; 123typedef struct mpeg2_decoder_s mpeg2_decoder_t;
118 124
119typedef enum { 125typedef enum
120 STATE_BUFFER = 0, 126{
121 STATE_SEQUENCE = 1, 127 STATE_BUFFER = 0,
128 STATE_SEQUENCE = 1,
122 STATE_SEQUENCE_REPEATED = 2, 129 STATE_SEQUENCE_REPEATED = 2,
123 STATE_GOP = 3, 130 STATE_GOP = 3,
124 STATE_PICTURE = 4, 131 STATE_PICTURE = 4,
125 STATE_SLICE_1ST = 5, 132 STATE_SLICE_1ST = 5,
126 STATE_PICTURE_2ND = 6, 133 STATE_PICTURE_2ND = 6,
127 STATE_SLICE = 7, 134 STATE_SLICE = 7,
128 STATE_END = 8, 135 STATE_END = 8,
129 STATE_INVALID = 9, 136 STATE_INVALID = 9,
130 STATE_INVALID_END = 10 137 STATE_INVALID_END = 10
131} mpeg2_state_t; 138} mpeg2_state_t;
132 139
133typedef struct mpeg2_convert_init_s { 140typedef struct mpeg2_convert_init_s
141{
134 unsigned int id_size; 142 unsigned int id_size;
135 unsigned int buf_size[3]; 143 unsigned int buf_size[3];
136 void (* start) (void * id, const mpeg2_fbuf_t * fbuf, 144 void (* start)(void * id, const mpeg2_fbuf_t * fbuf,
137 const mpeg2_picture_t * picture, const mpeg2_gop_t * gop); 145 const mpeg2_picture_t * picture, const mpeg2_gop_t * gop);
138 void (* copy) (void * id, uint8_t * const * src, unsigned int v_offset); 146 void (* copy)(void * id, uint8_t * const * src, unsigned int v_offset);
139} mpeg2_convert_init_t; 147} mpeg2_convert_init_t;
140typedef enum { 148
141 MPEG2_CONVERT_SET = 0, 149typedef enum
150{
151 MPEG2_CONVERT_SET = 0,
142 MPEG2_CONVERT_STRIDE = 1, 152 MPEG2_CONVERT_STRIDE = 1,
143 MPEG2_CONVERT_START = 2 153 MPEG2_CONVERT_START = 2
144} mpeg2_convert_stage_t; 154} mpeg2_convert_stage_t;
155
145typedef int mpeg2_convert_t (int stage, void * id, 156typedef int mpeg2_convert_t (int stage, void * id,
146 const mpeg2_sequence_t * sequence, int stride, 157 const mpeg2_sequence_t * sequence, int stride,
147 void * arg, mpeg2_convert_init_t * result); 158 void * arg, mpeg2_convert_init_t * result);
@@ -168,12 +179,13 @@ void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[3],
168 uint8_t * forward_fbuf[3], uint8_t * backward_fbuf[3]); 179 uint8_t * forward_fbuf[3], uint8_t * backward_fbuf[3]);
169void mpeg2_slice (mpeg2_decoder_t * decoder, int code, const uint8_t * buffer); 180void mpeg2_slice (mpeg2_decoder_t * decoder, int code, const uint8_t * buffer);
170 181
171typedef enum { 182typedef enum
172 MPEG2_ALLOC_MPEG2DEC = 0, 183{
173 MPEG2_ALLOC_CHUNK = 1, 184 MPEG2_ALLOC_MPEG2DEC = 0,
174 MPEG2_ALLOC_YUV = 2, 185 MPEG2_ALLOC_CHUNK = 1,
186 MPEG2_ALLOC_YUV = 2,
175 MPEG2_ALLOC_CONVERT_ID = 3, 187 MPEG2_ALLOC_CONVERT_ID = 3,
176 MPEG2_ALLOC_CONVERTED = 4 188 MPEG2_ALLOC_CONVERTED = 4
177} mpeg2_alloc_t; 189} mpeg2_alloc_t;
178 190
179void * mpeg2_malloc (unsigned size, mpeg2_alloc_t reason); 191void * mpeg2_malloc (unsigned size, mpeg2_alloc_t reason);
diff --git a/apps/plugins/mpegplayer/mpeg2_internal.h b/apps/plugins/mpegplayer/mpeg2_internal.h
index 1ec85c60f1..ba46b85ac4 100644
--- a/apps/plugins/mpegplayer/mpeg2_internal.h
+++ b/apps/plugins/mpegplayer/mpeg2_internal.h
@@ -20,26 +20,28 @@
20 * along with this program; if not, write to the Free Software 20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */ 22 */
23 23#ifndef MPEG2_INTERNAL_H
24#define MPEG2_INTERNAL_H
25
24#include "config.h" /* for Rockbox CPU_ #defines */ 26#include "config.h" /* for Rockbox CPU_ #defines */
25 27
26/* macroblock modes */ 28/* macroblock modes */
27#define MACROBLOCK_INTRA 1 29#define MACROBLOCK_INTRA 1
28#define MACROBLOCK_PATTERN 2 30#define MACROBLOCK_PATTERN 2
29#define MACROBLOCK_MOTION_BACKWARD 4 31#define MACROBLOCK_MOTION_BACKWARD 4
30#define MACROBLOCK_MOTION_FORWARD 8 32#define MACROBLOCK_MOTION_FORWARD 8
31#define MACROBLOCK_QUANT 16 33#define MACROBLOCK_QUANT 16
32#define DCT_TYPE_INTERLACED 32 34#define DCT_TYPE_INTERLACED 32
33/* motion_type */ 35/* motion_type */
34#define MOTION_TYPE_SHIFT 6 36#define MOTION_TYPE_SHIFT 6
35#define MC_FIELD 1 37#define MC_FIELD 1
36#define MC_FRAME 2 38#define MC_FRAME 2
37#define MC_16X8 2 39#define MC_16X8 2
38#define MC_DMV 3 40#define MC_DMV 3
39 41
40/* picture structure */ 42/* picture structure */
41#define TOP_FIELD 1 43#define TOP_FIELD 1
42#define BOTTOM_FIELD 2 44#define BOTTOM_FIELD 2
43#define FRAME_PICTURE 3 45#define FRAME_PICTURE 3
44 46
45/* picture coding type */ 47/* picture coding type */
@@ -50,18 +52,20 @@
50 52
51typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int); 53typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int);
52 54
53typedef struct { 55typedef struct
56{
54 uint8_t * ref[2][3]; 57 uint8_t * ref[2][3];
55 uint8_t ** ref2[2]; 58 uint8_t ** ref2[2];
56 int pmv[2][2]; 59 int pmv[2][2];
57 int f_code[2]; 60 int f_code[2];
58} motion_t; 61} motion_t;
59 62
60typedef void motion_parser_t (mpeg2_decoder_t * decoder, 63typedef void motion_parser_t(mpeg2_decoder_t * decoder,
61 motion_t * motion, 64 motion_t * motion,
62 mpeg2_mc_fct * const * table); 65 mpeg2_mc_fct * const * table);
63 66
64struct mpeg2_decoder_s { 67struct mpeg2_decoder_s
68{
65 /* first, state that carries information from one macroblock to the */ 69 /* first, state that carries information from one macroblock to the */
66 /* next inside a slice, and is never used outside of mpeg2_slice() */ 70 /* next inside a slice, and is never used outside of mpeg2_slice() */
67 71
@@ -102,7 +106,7 @@ struct mpeg2_decoder_s {
102 106
103 uint8_t * picture_dest[3]; 107 uint8_t * picture_dest[3];
104 void (* convert) (void * convert_id, uint8_t * const * src, 108 void (* convert) (void * convert_id, uint8_t * const * src,
105 unsigned int v_offset); 109 unsigned int v_offset);
106 void * convert_id; 110 void * convert_id;
107 111
108 int dmv_offset; 112 int dmv_offset;
@@ -152,11 +156,13 @@ struct mpeg2_decoder_s {
152 int mpeg1; 156 int mpeg1;
153}; 157};
154 158
155typedef struct { 159typedef struct
160{
156 mpeg2_fbuf_t fbuf; 161 mpeg2_fbuf_t fbuf;
157} fbuf_alloc_t; 162} fbuf_alloc_t;
158 163
159struct mpeg2dec_s { 164struct mpeg2dec_s
165{
160 mpeg2_decoder_t decoder; 166 mpeg2_decoder_t decoder;
161 167
162 mpeg2_info_t info; 168 mpeg2_info_t info;
@@ -208,8 +214,8 @@ struct mpeg2dec_s {
208 unsigned int convert_id_size; 214 unsigned int convert_id_size;
209 int convert_stride; 215 int convert_stride;
210 void (* convert_start) (void * id, const mpeg2_fbuf_t * fbuf, 216 void (* convert_start) (void * id, const mpeg2_fbuf_t * fbuf,
211 const mpeg2_picture_t * picture, 217 const mpeg2_picture_t * picture,
212 const mpeg2_gop_t * gop); 218 const mpeg2_gop_t * gop);
213 219
214 uint8_t * buf_start; 220 uint8_t * buf_start;
215 uint8_t * buf_end; 221 uint8_t * buf_end;
@@ -222,19 +228,6 @@ struct mpeg2dec_s {
222 uint8_t new_quantizer_matrix[4][64]; 228 uint8_t new_quantizer_matrix[4][64];
223}; 229};
224 230
225typedef struct {
226#ifdef ARCH_PPC
227 uint8_t regv[12*16];
228#endif
229 int dummy;
230} cpu_state_t;
231
232/* cpu_accel.c */
233uint32_t mpeg2_detect_accel (void);
234
235/* cpu_state.c */
236void mpeg2_cpu_state_init (uint32_t accel);
237
238/* decode.c */ 231/* decode.c */
239mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec); 232mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec);
240mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec); 233mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec);
@@ -257,11 +250,26 @@ void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int b_type);
257 250
258/* idct.c */ 251/* idct.c */
259void mpeg2_idct_init (void); 252void mpeg2_idct_init (void);
253void mpeg2_idct_copy(int16_t * block, uint8_t * dest,
254 const int stride);
255void mpeg2_idct_add(const int last, int16_t * block,
256 uint8_t * dest, const int stride);
257
258extern const uint8_t default_mpeg2_scan_norm[64];
259extern const uint8_t default_mpeg2_scan_alt[64];
260extern uint8_t mpeg2_scan_norm[64];
261extern uint8_t mpeg2_scan_alt[64];
260 262
261/* motion_comp.c */ 263/* motion_comp.c */
262void mpeg2_mc_init (void); 264void mpeg2_mc_init (void);
263 265
264typedef struct { 266typedef struct
267{
265 mpeg2_mc_fct * put [8]; 268 mpeg2_mc_fct * put [8];
266 mpeg2_mc_fct * avg [8]; 269 mpeg2_mc_fct * avg [8];
267} mpeg2_mc_t; 270} mpeg2_mc_t;
271
272extern const mpeg2_mc_t mpeg2_mc;
273
274#endif /* MPEG2_INTERNAL_H */
275
diff --git a/apps/plugins/mpegplayer/slice.c b/apps/plugins/mpegplayer/slice.c
index 7c1c07bf37..a039eb8a25 100644
--- a/apps/plugins/mpegplayer/slice.c
+++ b/apps/plugins/mpegplayer/slice.c
@@ -30,11 +30,6 @@
30#include "attributes.h" 30#include "attributes.h"
31#include "mpeg2_internal.h" 31#include "mpeg2_internal.h"
32 32
33extern mpeg2_mc_t mpeg2_mc;
34extern void (* mpeg2_idct_copy) (int16_t * block, uint8_t * dest, int stride);
35extern void (* mpeg2_idct_add) (int last, int16_t * block,
36 uint8_t * dest, int stride);
37
38#include "vlc.h" 33#include "vlc.h"
39 34
40static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder) 35static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder)
@@ -42,18 +37,20 @@ static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder)
42#define bit_buf (decoder->bitstream_buf) 37#define bit_buf (decoder->bitstream_buf)
43#define bits (decoder->bitstream_bits) 38#define bits (decoder->bitstream_bits)
44#define bit_ptr (decoder->bitstream_ptr) 39#define bit_ptr (decoder->bitstream_ptr)
40
45 int macroblock_modes; 41 int macroblock_modes;
46 const MBtab * tab; 42 const MBtab * tab;
47 43
48 switch (decoder->coding_type) { 44 switch (decoder->coding_type)
45 {
49 case I_TYPE: 46 case I_TYPE:
50
51 tab = MB_I + UBITS (bit_buf, 1); 47 tab = MB_I + UBITS (bit_buf, 1);
52 DUMPBITS (bit_buf, bits, tab->len); 48 DUMPBITS (bit_buf, bits, tab->len);
53 macroblock_modes = tab->modes; 49 macroblock_modes = tab->modes;
54 50
55 if ((! (decoder->frame_pred_frame_dct)) && 51 if (!(decoder->frame_pred_frame_dct) &&
56 (decoder->picture_structure == FRAME_PICTURE)) { 52 decoder->picture_structure == FRAME_PICTURE)
53 {
57 macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; 54 macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
58 DUMPBITS (bit_buf, bits, 1); 55 DUMPBITS (bit_buf, bits, 1);
59 } 56 }
@@ -61,55 +58,75 @@ static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder)
61 return macroblock_modes; 58 return macroblock_modes;
62 59
63 case P_TYPE: 60 case P_TYPE:
64
65 tab = MB_P + UBITS (bit_buf, 5); 61 tab = MB_P + UBITS (bit_buf, 5);
66 DUMPBITS (bit_buf, bits, tab->len); 62 DUMPBITS (bit_buf, bits, tab->len);
67 macroblock_modes = tab->modes; 63 macroblock_modes = tab->modes;
68 64
69 if (decoder->picture_structure != FRAME_PICTURE) { 65 if (decoder->picture_structure != FRAME_PICTURE)
70 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) { 66 {
67 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD)
68 {
71 macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; 69 macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT;
72 DUMPBITS (bit_buf, bits, 2); 70 DUMPBITS (bit_buf, bits, 2);
73 } 71 }
72
74 return macroblock_modes | MACROBLOCK_MOTION_FORWARD; 73 return macroblock_modes | MACROBLOCK_MOTION_FORWARD;
75 } else if (decoder->frame_pred_frame_dct) { 74 }
75 else if (decoder->frame_pred_frame_dct)
76 {
76 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) 77 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD)
77 macroblock_modes |= MC_FRAME << MOTION_TYPE_SHIFT; 78 macroblock_modes |= MC_FRAME << MOTION_TYPE_SHIFT;
79
78 return macroblock_modes | MACROBLOCK_MOTION_FORWARD; 80 return macroblock_modes | MACROBLOCK_MOTION_FORWARD;
79 } else { 81 }
80 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) { 82 else
83 {
84 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD)
85 {
81 macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; 86 macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT;
82 DUMPBITS (bit_buf, bits, 2); 87 DUMPBITS (bit_buf, bits, 2);
83 } 88 }
84 if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) { 89
90 if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN))
91 {
85 macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; 92 macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
86 DUMPBITS (bit_buf, bits, 1); 93 DUMPBITS (bit_buf, bits, 1);
87 } 94 }
95
88 return macroblock_modes | MACROBLOCK_MOTION_FORWARD; 96 return macroblock_modes | MACROBLOCK_MOTION_FORWARD;
89 } 97 }
90 98
91 case B_TYPE: 99 case B_TYPE:
92
93 tab = MB_B + UBITS (bit_buf, 6); 100 tab = MB_B + UBITS (bit_buf, 6);
94 DUMPBITS (bit_buf, bits, tab->len); 101 DUMPBITS (bit_buf, bits, tab->len);
95 macroblock_modes = tab->modes; 102 macroblock_modes = tab->modes;
96 103
97 if (decoder->picture_structure != FRAME_PICTURE) { 104 if (decoder->picture_structure != FRAME_PICTURE)
98 if (! (macroblock_modes & MACROBLOCK_INTRA)) { 105 {
106 if (! (macroblock_modes & MACROBLOCK_INTRA))
107 {
99 macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; 108 macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT;
100 DUMPBITS (bit_buf, bits, 2); 109 DUMPBITS (bit_buf, bits, 2);
101 } 110 }
111
102 return macroblock_modes; 112 return macroblock_modes;
103 } else if (decoder->frame_pred_frame_dct) { 113 }
114 else if (decoder->frame_pred_frame_dct)
115 {
104 /* if (! (macroblock_modes & MACROBLOCK_INTRA)) */ 116 /* if (! (macroblock_modes & MACROBLOCK_INTRA)) */
105 macroblock_modes |= MC_FRAME << MOTION_TYPE_SHIFT; 117 macroblock_modes |= MC_FRAME << MOTION_TYPE_SHIFT;
106 return macroblock_modes; 118 return macroblock_modes;
107 } else { 119 }
120 else
121 {
108 if (macroblock_modes & MACROBLOCK_INTRA) 122 if (macroblock_modes & MACROBLOCK_INTRA)
109 goto intra; 123 goto intra;
124
110 macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; 125 macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT;
111 DUMPBITS (bit_buf, bits, 2); 126 DUMPBITS (bit_buf, bits, 2);
112 if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) { 127
128 if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN))
129 {
113 intra: 130 intra:
114 macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; 131 macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
115 DUMPBITS (bit_buf, bits, 1); 132 DUMPBITS (bit_buf, bits, 1);
@@ -118,7 +135,6 @@ static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder)
118 } 135 }
119 136
120 case D_TYPE: 137 case D_TYPE:
121
122 DUMPBITS (bit_buf, bits, 1); 138 DUMPBITS (bit_buf, bits, 1);
123 return MACROBLOCK_INTRA; 139 return MACROBLOCK_INTRA;
124 140
@@ -143,10 +159,13 @@ static inline void get_quantizer_scale (mpeg2_decoder_t * const decoder)
143 159
144 decoder->quantizer_matrix[0] = 160 decoder->quantizer_matrix[0] =
145 decoder->quantizer_prescale[0][quantizer_scale_code]; 161 decoder->quantizer_prescale[0][quantizer_scale_code];
162
146 decoder->quantizer_matrix[1] = 163 decoder->quantizer_matrix[1] =
147 decoder->quantizer_prescale[1][quantizer_scale_code]; 164 decoder->quantizer_prescale[1][quantizer_scale_code];
165
148 decoder->quantizer_matrix[2] = 166 decoder->quantizer_matrix[2] =
149 decoder->chroma_quantizer[0][quantizer_scale_code]; 167 decoder->chroma_quantizer[0][quantizer_scale_code];
168
150 decoder->quantizer_matrix[3] = 169 decoder->quantizer_matrix[3] =
151 decoder->chroma_quantizer[1][quantizer_scale_code]; 170 decoder->chroma_quantizer[1][quantizer_scale_code];
152#undef bit_buf 171#undef bit_buf
@@ -165,11 +184,13 @@ static inline int get_motion_delta (mpeg2_decoder_t * const decoder,
165 int sign; 184 int sign;
166 const MVtab * tab; 185 const MVtab * tab;
167 186
168 if (bit_buf & 0x80000000) { 187 if (bit_buf & 0x80000000)
188 {
169 DUMPBITS (bit_buf, bits, 1); 189 DUMPBITS (bit_buf, bits, 1);
170 return 0; 190 return 0;
171 } else if (bit_buf >= 0x0c000000) { 191 }
172 192 else if (bit_buf >= 0x0c000000)
193 {
173 tab = MV_4 + UBITS (bit_buf, 4); 194 tab = MV_4 + UBITS (bit_buf, 4);
174 delta = (tab->delta << f_code) + 1; 195 delta = (tab->delta << f_code) + 1;
175 bits += tab->len + f_code + 1; 196 bits += tab->len + f_code + 1;
@@ -183,9 +204,9 @@ static inline int get_motion_delta (mpeg2_decoder_t * const decoder,
183 bit_buf <<= f_code; 204 bit_buf <<= f_code;
184 205
185 return (delta ^ sign) - sign; 206 return (delta ^ sign) - sign;
186 207 }
187 } else { 208 else
188 209 {
189 tab = MV_10 + UBITS (bit_buf, 10); 210 tab = MV_10 + UBITS (bit_buf, 10);
190 delta = (tab->delta << f_code) + 1; 211 delta = (tab->delta << f_code) + 1;
191 bits += tab->len + 1; 212 bits += tab->len + 1;
@@ -194,7 +215,8 @@ static inline int get_motion_delta (mpeg2_decoder_t * const decoder,
194 sign = SBITS (bit_buf, 1); 215 sign = SBITS (bit_buf, 1);
195 bit_buf <<= 1; 216 bit_buf <<= 1;
196 217
197 if (f_code) { 218 if (f_code)
219 {
198 NEEDBITS (bit_buf, bits, bit_ptr); 220 NEEDBITS (bit_buf, bits, bit_ptr);
199 delta += UBITS (bit_buf, f_code); 221 delta += UBITS (bit_buf, f_code);
200 DUMPBITS (bit_buf, bits, f_code); 222 DUMPBITS (bit_buf, bits, f_code);
@@ -224,6 +246,7 @@ static inline int get_dmv (mpeg2_decoder_t * const decoder)
224 tab = DMV_2 + UBITS (bit_buf, 2); 246 tab = DMV_2 + UBITS (bit_buf, 2);
225 DUMPBITS (bit_buf, bits, tab->len); 247 DUMPBITS (bit_buf, bits, tab->len);
226 return tab->dmv; 248 return tab->dmv;
249
227#undef bit_buf 250#undef bit_buf
228#undef bits 251#undef bits
229#undef bit_ptr 252#undef bit_ptr
@@ -239,14 +262,14 @@ static inline int get_coded_block_pattern (mpeg2_decoder_t * const decoder)
239 262
240 NEEDBITS (bit_buf, bits, bit_ptr); 263 NEEDBITS (bit_buf, bits, bit_ptr);
241 264
242 if (bit_buf >= 0x20000000) { 265 if (bit_buf >= 0x20000000)
243 266 {
244 tab = CBP_7 + (UBITS (bit_buf, 7) - 16); 267 tab = CBP_7 + (UBITS (bit_buf, 7) - 16);
245 DUMPBITS (bit_buf, bits, tab->len); 268 DUMPBITS (bit_buf, bits, tab->len);
246 return tab->cbp; 269 return tab->cbp;
247 270 }
248 } else { 271 else
249 272 {
250 tab = CBP_9 + UBITS (bit_buf, 9); 273 tab = CBP_9 + UBITS (bit_buf, 9);
251 DUMPBITS (bit_buf, bits, tab->len); 274 DUMPBITS (bit_buf, bits, tab->len);
252 return tab->cbp; 275 return tab->cbp;
@@ -262,25 +285,33 @@ static inline int get_luma_dc_dct_diff (mpeg2_decoder_t * const decoder)
262#define bit_buf (decoder->bitstream_buf) 285#define bit_buf (decoder->bitstream_buf)
263#define bits (decoder->bitstream_bits) 286#define bits (decoder->bitstream_bits)
264#define bit_ptr (decoder->bitstream_ptr) 287#define bit_ptr (decoder->bitstream_ptr)
288
265 const DCtab * tab; 289 const DCtab * tab;
266 int size; 290 int size;
267 int dc_diff; 291 int dc_diff;
268 292
269 if (bit_buf < 0xf8000000) { 293 if (bit_buf < 0xf8000000)
294 {
270 tab = DC_lum_5 + UBITS (bit_buf, 5); 295 tab = DC_lum_5 + UBITS (bit_buf, 5);
271 size = tab->size; 296 size = tab->size;
272 if (size) { 297
298 if (size)
299 {
273 bits += tab->len + size; 300 bits += tab->len + size;
274 bit_buf <<= tab->len; 301 bit_buf <<= tab->len;
275 dc_diff = 302 dc_diff =
276 UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); 303 UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
277 bit_buf <<= size; 304 bit_buf <<= size;
278 return dc_diff << decoder->intra_dc_precision; 305 return dc_diff << decoder->intra_dc_precision;
279 } else { 306 }
307 else
308 {
280 DUMPBITS (bit_buf, bits, 3); 309 DUMPBITS (bit_buf, bits, 3);
281 return 0; 310 return 0;
282 } 311 }
283 } else { 312 }
313 else
314 {
284 tab = DC_long + (UBITS (bit_buf, 9) - 0x1e0); 315 tab = DC_long + (UBITS (bit_buf, 9) - 0x1e0);
285 size = tab->size; 316 size = tab->size;
286 DUMPBITS (bit_buf, bits, tab->len); 317 DUMPBITS (bit_buf, bits, tab->len);
@@ -289,6 +320,7 @@ static inline int get_luma_dc_dct_diff (mpeg2_decoder_t * const decoder)
289 DUMPBITS (bit_buf, bits, size); 320 DUMPBITS (bit_buf, bits, size);
290 return dc_diff << decoder->intra_dc_precision; 321 return dc_diff << decoder->intra_dc_precision;
291 } 322 }
323
292#undef bit_buf 324#undef bit_buf
293#undef bits 325#undef bits
294#undef bit_ptr 326#undef bit_ptr
@@ -299,25 +331,33 @@ static inline int get_chroma_dc_dct_diff (mpeg2_decoder_t * const decoder)
299#define bit_buf (decoder->bitstream_buf) 331#define bit_buf (decoder->bitstream_buf)
300#define bits (decoder->bitstream_bits) 332#define bits (decoder->bitstream_bits)
301#define bit_ptr (decoder->bitstream_ptr) 333#define bit_ptr (decoder->bitstream_ptr)
334
302 const DCtab * tab; 335 const DCtab * tab;
303 int size; 336 int size;
304 int dc_diff; 337 int dc_diff;
305 338
306 if (bit_buf < 0xf8000000) { 339 if (bit_buf < 0xf8000000)
340 {
307 tab = DC_chrom_5 + UBITS (bit_buf, 5); 341 tab = DC_chrom_5 + UBITS (bit_buf, 5);
308 size = tab->size; 342 size = tab->size;
309 if (size) { 343
344 if (size)
345 {
310 bits += tab->len + size; 346 bits += tab->len + size;
311 bit_buf <<= tab->len; 347 bit_buf <<= tab->len;
312 dc_diff = 348 dc_diff =
313 UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); 349 UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
314 bit_buf <<= size; 350 bit_buf <<= size;
315 return dc_diff << decoder->intra_dc_precision; 351 return dc_diff << decoder->intra_dc_precision;
316 } else { 352 }
353 else
354 {
317 DUMPBITS (bit_buf, bits, 2); 355 DUMPBITS (bit_buf, bits, 2);
318 return 0; 356 return 0;
319 } 357 }
320 } else { 358 }
359 else
360 {
321 tab = DC_long + (UBITS (bit_buf, 10) - 0x3e0); 361 tab = DC_long + (UBITS (bit_buf, 10) - 0x3e0);
322 size = tab->size; 362 size = tab->size;
323 DUMPBITS (bit_buf, bits, tab->len + 1); 363 DUMPBITS (bit_buf, bits, tab->len + 1);
@@ -326,17 +366,18 @@ static inline int get_chroma_dc_dct_diff (mpeg2_decoder_t * const decoder)
326 DUMPBITS (bit_buf, bits, size); 366 DUMPBITS (bit_buf, bits, size);
327 return dc_diff << decoder->intra_dc_precision; 367 return dc_diff << decoder->intra_dc_precision;
328 } 368 }
369
329#undef bit_buf 370#undef bit_buf
330#undef bits 371#undef bits
331#undef bit_ptr 372#undef bit_ptr
332} 373}
333 374
334#define SATURATE(val) \ 375#define SATURATE(val) \
335do { \ 376 do { \
336 val <<= 4; \ 377 val <<= 4; \
337 if (unlikely (val != (int16_t) val)) \ 378 if (unlikely (val != (int16_t) val)) \
338 val = (SBITS (val, 1) ^ 2047) << 4; \ 379 val = (SBITS (val, 1) ^ 2047) << 4; \
339} while (0) 380 } while (0)
340 381
341static void get_intra_block_B14 (mpeg2_decoder_t * const decoder, 382static void get_intra_block_B14 (mpeg2_decoder_t * const decoder,
342 const uint16_t * const quant_matrix) 383 const uint16_t * const quant_matrix)
@@ -361,9 +402,10 @@ static void get_intra_block_B14 (mpeg2_decoder_t * const decoder,
361 402
362 NEEDBITS (bit_buf, bits, bit_ptr); 403 NEEDBITS (bit_buf, bits, bit_ptr);
363 404
364 while (1) { 405 while (1)
365 if (bit_buf >= 0x28000000) { 406 {
366 407 if (bit_buf >= 0x28000000)
408 {
367 tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); 409 tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
368 410
369 i += tab->run; 411 i += tab->run;
@@ -387,9 +429,9 @@ static void get_intra_block_B14 (mpeg2_decoder_t * const decoder,
387 NEEDBITS (bit_buf, bits, bit_ptr); 429 NEEDBITS (bit_buf, bits, bit_ptr);
388 430
389 continue; 431 continue;
390 432 }
391 } else if (bit_buf >= 0x04000000) { 433 else if (bit_buf >= 0x04000000)
392 434 {
393 tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); 435 tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
394 436
395 i += tab->run; 437 i += tab->run;
@@ -416,23 +458,30 @@ static void get_intra_block_B14 (mpeg2_decoder_t * const decoder,
416 NEEDBITS (bit_buf, bits, bit_ptr); 458 NEEDBITS (bit_buf, bits, bit_ptr);
417 459
418 continue; 460 continue;
419 461 }
420 } else if (bit_buf >= 0x02000000) { 462 else if (bit_buf >= 0x02000000)
463 {
421 tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); 464 tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8);
422 i += tab->run; 465 i += tab->run;
423 if (i < 64) 466 if (i < 64)
424 goto normal_code; 467 goto normal_code;
425 } else if (bit_buf >= 0x00800000) { 468 }
469 else if (bit_buf >= 0x00800000)
470 {
426 tab = DCT_13 + (UBITS (bit_buf, 13) - 16); 471 tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
427 i += tab->run; 472 i += tab->run;
428 if (i < 64) 473 if (i < 64)
429 goto normal_code; 474 goto normal_code;
430 } else if (bit_buf >= 0x00200000) { 475 }
476 else if (bit_buf >= 0x00200000)
477 {
431 tab = DCT_15 + (UBITS (bit_buf, 15) - 16); 478 tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
432 i += tab->run; 479 i += tab->run;
433 if (i < 64) 480 if (i < 64)
434 goto normal_code; 481 goto normal_code;
435 } else { 482 }
483 else
484 {
436 tab = DCT_16 + UBITS (bit_buf, 16); 485 tab = DCT_16 + UBITS (bit_buf, 16);
437 bit_buf <<= 16; 486 bit_buf <<= 16;
438 GETWORD (bit_buf, bits + 16, bit_ptr); 487 GETWORD (bit_buf, bits + 16, bit_ptr);
@@ -442,6 +491,7 @@ static void get_intra_block_B14 (mpeg2_decoder_t * const decoder,
442 } 491 }
443 break; /* illegal, check needed to avoid buffer overflow */ 492 break; /* illegal, check needed to avoid buffer overflow */
444 } 493 }
494
445 dest[63] ^= mismatch & 16; 495 dest[63] ^= mismatch & 16;
446 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ 496 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
447 decoder->bitstream_buf = bit_buf; 497 decoder->bitstream_buf = bit_buf;
@@ -472,14 +522,16 @@ static void get_intra_block_B15 (mpeg2_decoder_t * const decoder,
472 522
473 NEEDBITS (bit_buf, bits, bit_ptr); 523 NEEDBITS (bit_buf, bits, bit_ptr);
474 524
475 while (1) { 525 while (1)
476 if (bit_buf >= 0x04000000) { 526 {
477 527 if (bit_buf >= 0x04000000)
528 {
478 tab = DCT_B15_8 + (UBITS (bit_buf, 8) - 4); 529 tab = DCT_B15_8 + (UBITS (bit_buf, 8) - 4);
479 530
480 i += tab->run; 531 i += tab->run;
481 if (i < 64) {
482 532
533 if (i < 64)
534 {
483 normal_code: 535 normal_code:
484 j = scan[i]; 536 j = scan[i];
485 bit_buf <<= tab->len; 537 bit_buf <<= tab->len;
@@ -497,9 +549,9 @@ static void get_intra_block_B15 (mpeg2_decoder_t * const decoder,
497 NEEDBITS (bit_buf, bits, bit_ptr); 549 NEEDBITS (bit_buf, bits, bit_ptr);
498 550
499 continue; 551 continue;
500 552 }
501 } else { 553 else
502 554 {
503 /* end of block. I commented out this code because if we */ 555 /* end of block. I commented out this code because if we */
504 /* dont exit here we will still exit at the later test :) */ 556 /* dont exit here we will still exit at the later test :) */
505 557
@@ -525,24 +577,31 @@ static void get_intra_block_B15 (mpeg2_decoder_t * const decoder,
525 NEEDBITS (bit_buf, bits, bit_ptr); 577 NEEDBITS (bit_buf, bits, bit_ptr);
526 578
527 continue; 579 continue;
528
529 } 580 }
530 } else if (bit_buf >= 0x02000000) { 581 }
582 else if (bit_buf >= 0x02000000)
583 {
531 tab = DCT_B15_10 + (UBITS (bit_buf, 10) - 8); 584 tab = DCT_B15_10 + (UBITS (bit_buf, 10) - 8);
532 i += tab->run; 585 i += tab->run;
533 if (i < 64) 586 if (i < 64)
534 goto normal_code; 587 goto normal_code;
535 } else if (bit_buf >= 0x00800000) { 588 }
589 else if (bit_buf >= 0x00800000)
590 {
536 tab = DCT_13 + (UBITS (bit_buf, 13) - 16); 591 tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
537 i += tab->run; 592 i += tab->run;
538 if (i < 64) 593 if (i < 64)
539 goto normal_code; 594 goto normal_code;
540 } else if (bit_buf >= 0x00200000) { 595 }
596 else if (bit_buf >= 0x00200000)
597 {
541 tab = DCT_15 + (UBITS (bit_buf, 15) - 16); 598 tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
542 i += tab->run; 599 i += tab->run;
543 if (i < 64) 600 if (i < 64)
544 goto normal_code; 601 goto normal_code;
545 } else { 602 }
603 else
604 {
546 tab = DCT_16 + UBITS (bit_buf, 16); 605 tab = DCT_16 + UBITS (bit_buf, 16);
547 bit_buf <<= 16; 606 bit_buf <<= 16;
548 GETWORD (bit_buf, bits + 16, bit_ptr); 607 GETWORD (bit_buf, bits + 16, bit_ptr);
@@ -552,6 +611,7 @@ static void get_intra_block_B15 (mpeg2_decoder_t * const decoder,
552 } 611 }
553 break; /* illegal, check needed to avoid buffer overflow */ 612 break; /* illegal, check needed to avoid buffer overflow */
554 } 613 }
614
555 dest[63] ^= mismatch & 16; 615 dest[63] ^= mismatch & 16;
556 DUMPBITS (bit_buf, bits, 4); /* dump end of block code */ 616 DUMPBITS (bit_buf, bits, 4); /* dump end of block code */
557 decoder->bitstream_buf = bit_buf; 617 decoder->bitstream_buf = bit_buf;
@@ -581,15 +641,21 @@ static int get_non_intra_block (mpeg2_decoder_t * const decoder,
581 bit_ptr = decoder->bitstream_ptr; 641 bit_ptr = decoder->bitstream_ptr;
582 642
583 NEEDBITS (bit_buf, bits, bit_ptr); 643 NEEDBITS (bit_buf, bits, bit_ptr);
584 if (bit_buf >= 0x28000000) { 644
645 if (bit_buf >= 0x28000000)
646 {
585 tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5); 647 tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5);
586 goto entry_1; 648 goto entry_1;
587 } else 649 }
650 else
651 {
588 goto entry_2; 652 goto entry_2;
653 }
589 654
590 while (1) { 655 while (1)
591 if (bit_buf >= 0x28000000) { 656 {
592 657 if (bit_buf >= 0x28000000)
658 {
593 tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); 659 tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
594 660
595 entry_1: 661 entry_1:
@@ -614,12 +680,11 @@ static int get_non_intra_block (mpeg2_decoder_t * const decoder,
614 NEEDBITS (bit_buf, bits, bit_ptr); 680 NEEDBITS (bit_buf, bits, bit_ptr);
615 681
616 continue; 682 continue;
617
618 } 683 }
619 684
620 entry_2: 685 entry_2:
621 if (bit_buf >= 0x04000000) { 686 if (bit_buf >= 0x04000000)
622 687 {
623 tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); 688 tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
624 689
625 i += tab->run; 690 i += tab->run;
@@ -647,23 +712,30 @@ static int get_non_intra_block (mpeg2_decoder_t * const decoder,
647 NEEDBITS (bit_buf, bits, bit_ptr); 712 NEEDBITS (bit_buf, bits, bit_ptr);
648 713
649 continue; 714 continue;
650 715 }
651 } else if (bit_buf >= 0x02000000) { 716 else if (bit_buf >= 0x02000000)
717 {
652 tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); 718 tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8);
653 i += tab->run; 719 i += tab->run;
654 if (i < 64) 720 if (i < 64)
655 goto normal_code; 721 goto normal_code;
656 } else if (bit_buf >= 0x00800000) { 722 }
723 else if (bit_buf >= 0x00800000)
724 {
657 tab = DCT_13 + (UBITS (bit_buf, 13) - 16); 725 tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
658 i += tab->run; 726 i += tab->run;
659 if (i < 64) 727 if (i < 64)
660 goto normal_code; 728 goto normal_code;
661 } else if (bit_buf >= 0x00200000) { 729 }
730 else if (bit_buf >= 0x00200000)
731 {
662 tab = DCT_15 + (UBITS (bit_buf, 15) - 16); 732 tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
663 i += tab->run; 733 i += tab->run;
664 if (i < 64) 734 if (i < 64)
665 goto normal_code; 735 goto normal_code;
666 } else { 736 }
737 else
738 {
667 tab = DCT_16 + UBITS (bit_buf, 16); 739 tab = DCT_16 + UBITS (bit_buf, 16);
668 bit_buf <<= 16; 740 bit_buf <<= 16;
669 GETWORD (bit_buf, bits + 16, bit_ptr); 741 GETWORD (bit_buf, bits + 16, bit_ptr);
@@ -673,6 +745,7 @@ static int get_non_intra_block (mpeg2_decoder_t * const decoder,
673 } 745 }
674 break; /* illegal, check needed to avoid buffer overflow */ 746 break; /* illegal, check needed to avoid buffer overflow */
675 } 747 }
748
676 dest[63] ^= mismatch & 16; 749 dest[63] ^= mismatch & 16;
677 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ 750 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
678 decoder->bitstream_buf = bit_buf; 751 decoder->bitstream_buf = bit_buf;
@@ -702,9 +775,10 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder)
702 775
703 NEEDBITS (bit_buf, bits, bit_ptr); 776 NEEDBITS (bit_buf, bits, bit_ptr);
704 777
705 while (1) { 778 while (1)
706 if (bit_buf >= 0x28000000) { 779 {
707 780 if (bit_buf >= 0x28000000)
781 {
708 tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); 782 tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
709 783
710 i += tab->run; 784 i += tab->run;
@@ -730,9 +804,9 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder)
730 NEEDBITS (bit_buf, bits, bit_ptr); 804 NEEDBITS (bit_buf, bits, bit_ptr);
731 805
732 continue; 806 continue;
733 807 }
734 } else if (bit_buf >= 0x04000000) { 808 else if (bit_buf >= 0x04000000)
735 809 {
736 tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); 810 tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
737 811
738 i += tab->run; 812 i += tab->run;
@@ -750,10 +824,13 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder)
750 DUMPBITS (bit_buf, bits, 12); 824 DUMPBITS (bit_buf, bits, 12);
751 NEEDBITS (bit_buf, bits, bit_ptr); 825 NEEDBITS (bit_buf, bits, bit_ptr);
752 val = SBITS (bit_buf, 8); 826 val = SBITS (bit_buf, 8);
753 if (! (val & 0x7f)) { 827
828 if (! (val & 0x7f))
829 {
754 DUMPBITS (bit_buf, bits, 8); 830 DUMPBITS (bit_buf, bits, 8);
755 val = UBITS (bit_buf, 8) + 2 * val; 831 val = UBITS (bit_buf, 8) + 2 * val;
756 } 832 }
833
757 val = (val * quant_matrix[j]) / 16; 834 val = (val * quant_matrix[j]) / 16;
758 835
759 /* oddification */ 836 /* oddification */
@@ -766,23 +843,30 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder)
766 NEEDBITS (bit_buf, bits, bit_ptr); 843 NEEDBITS (bit_buf, bits, bit_ptr);
767 844
768 continue; 845 continue;
769 846 }
770 } else if (bit_buf >= 0x02000000) { 847 else if (bit_buf >= 0x02000000)
848 {
771 tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); 849 tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8);
772 i += tab->run; 850 i += tab->run;
773 if (i < 64) 851 if (i < 64)
774 goto normal_code; 852 goto normal_code;
775 } else if (bit_buf >= 0x00800000) { 853 }
854 else if (bit_buf >= 0x00800000)
855 {
776 tab = DCT_13 + (UBITS (bit_buf, 13) - 16); 856 tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
777 i += tab->run; 857 i += tab->run;
778 if (i < 64) 858 if (i < 64)
779 goto normal_code; 859 goto normal_code;
780 } else if (bit_buf >= 0x00200000) { 860 }
861 else if (bit_buf >= 0x00200000)
862 {
781 tab = DCT_15 + (UBITS (bit_buf, 15) - 16); 863 tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
782 i += tab->run; 864 i += tab->run;
783 if (i < 64) 865 if (i < 64)
784 goto normal_code; 866 goto normal_code;
785 } else { 867 }
868 else
869 {
786 tab = DCT_16 + UBITS (bit_buf, 16); 870 tab = DCT_16 + UBITS (bit_buf, 16);
787 bit_buf <<= 16; 871 bit_buf <<= 16;
788 GETWORD (bit_buf, bits + 16, bit_ptr); 872 GETWORD (bit_buf, bits + 16, bit_ptr);
@@ -792,6 +876,7 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder)
792 } 876 }
793 break; /* illegal, check needed to avoid buffer overflow */ 877 break; /* illegal, check needed to avoid buffer overflow */
794 } 878 }
879
795 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ 880 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
796 decoder->bitstream_buf = bit_buf; 881 decoder->bitstream_buf = bit_buf;
797 decoder->bitstream_bits = bits; 882 decoder->bitstream_bits = bits;
@@ -818,15 +903,20 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder)
818 bit_ptr = decoder->bitstream_ptr; 903 bit_ptr = decoder->bitstream_ptr;
819 904
820 NEEDBITS (bit_buf, bits, bit_ptr); 905 NEEDBITS (bit_buf, bits, bit_ptr);
821 if (bit_buf >= 0x28000000) { 906 if (bit_buf >= 0x28000000)
907 {
822 tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5); 908 tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5);
823 goto entry_1; 909 goto entry_1;
824 } else 910 }
911 else
912 {
825 goto entry_2; 913 goto entry_2;
914 }
826 915
827 while (1) { 916 while (1)
828 if (bit_buf >= 0x28000000) { 917 {
829 918 if (bit_buf >= 0x28000000)
919 {
830 tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); 920 tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
831 921
832 entry_1: 922 entry_1:
@@ -853,12 +943,11 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder)
853 NEEDBITS (bit_buf, bits, bit_ptr); 943 NEEDBITS (bit_buf, bits, bit_ptr);
854 944
855 continue; 945 continue;
856
857 } 946 }
858 947
859 entry_2: 948 entry_2:
860 if (bit_buf >= 0x04000000) { 949 if (bit_buf >= 0x04000000)
861 950 {
862 tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); 951 tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
863 952
864 i += tab->run; 953 i += tab->run;
@@ -876,10 +965,13 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder)
876 DUMPBITS (bit_buf, bits, 12); 965 DUMPBITS (bit_buf, bits, 12);
877 NEEDBITS (bit_buf, bits, bit_ptr); 966 NEEDBITS (bit_buf, bits, bit_ptr);
878 val = SBITS (bit_buf, 8); 967 val = SBITS (bit_buf, 8);
879 if (! (val & 0x7f)) { 968
969 if (! (val & 0x7f))
970 {
880 DUMPBITS (bit_buf, bits, 8); 971 DUMPBITS (bit_buf, bits, 8);
881 val = UBITS (bit_buf, 8) + 2 * val; 972 val = UBITS (bit_buf, 8) + 2 * val;
882 } 973 }
974
883 val = 2 * (val + SBITS (val, 1)) + 1; 975 val = 2 * (val + SBITS (val, 1)) + 1;
884 val = (val * quant_matrix[j]) / 32; 976 val = (val * quant_matrix[j]) / 32;
885 977
@@ -894,22 +986,30 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder)
894 986
895 continue; 987 continue;
896 988
897 } else if (bit_buf >= 0x02000000) { 989 }
990 else if (bit_buf >= 0x02000000)
991 {
898 tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); 992 tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8);
899 i += tab->run; 993 i += tab->run;
900 if (i < 64) 994 if (i < 64)
901 goto normal_code; 995 goto normal_code;
902 } else if (bit_buf >= 0x00800000) { 996 }
997 else if (bit_buf >= 0x00800000)
998 {
903 tab = DCT_13 + (UBITS (bit_buf, 13) - 16); 999 tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
904 i += tab->run; 1000 i += tab->run;
905 if (i < 64) 1001 if (i < 64)
906 goto normal_code; 1002 goto normal_code;
907 } else if (bit_buf >= 0x00200000) { 1003 }
1004 else if (bit_buf >= 0x00200000)
1005 {
908 tab = DCT_15 + (UBITS (bit_buf, 15) - 16); 1006 tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
909 i += tab->run; 1007 i += tab->run;
910 if (i < 64) 1008 if (i < 64)
911 goto normal_code; 1009 goto normal_code;
912 } else { 1010 }
1011 else
1012 {
913 tab = DCT_16 + UBITS (bit_buf, 16); 1013 tab = DCT_16 + UBITS (bit_buf, 16);
914 bit_buf <<= 16; 1014 bit_buf <<= 16;
915 GETWORD (bit_buf, bits + 16, bit_ptr); 1015 GETWORD (bit_buf, bits + 16, bit_ptr);
@@ -919,6 +1019,7 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder)
919 } 1019 }
920 break; /* illegal, check needed to avoid buffer overflow */ 1020 break; /* illegal, check needed to avoid buffer overflow */
921 } 1021 }
1022
922 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ 1023 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
923 decoder->bitstream_buf = bit_buf; 1024 decoder->bitstream_buf = bit_buf;
924 decoder->bitstream_bits = bits; 1025 decoder->bitstream_bits = bits;
@@ -933,23 +1034,37 @@ static inline void slice_intra_DCT (mpeg2_decoder_t * const decoder,
933#define bit_buf (decoder->bitstream_buf) 1034#define bit_buf (decoder->bitstream_buf)
934#define bits (decoder->bitstream_bits) 1035#define bits (decoder->bitstream_bits)
935#define bit_ptr (decoder->bitstream_ptr) 1036#define bit_ptr (decoder->bitstream_ptr)
1037
936 NEEDBITS (bit_buf, bits, bit_ptr); 1038 NEEDBITS (bit_buf, bits, bit_ptr);
937 /* Get the intra DC coefficient and inverse quantize it */ 1039 /* Get the intra DC coefficient and inverse quantize it */
938 if (cc == 0) 1040 if (cc == 0)
939 decoder->DCTblock[0] = 1041 {
940 decoder->dc_dct_pred[0] += get_luma_dc_dct_diff (decoder); 1042 decoder->dc_dct_pred[0] += get_luma_dc_dct_diff (decoder);
1043 decoder->DCTblock[0] = decoder->dc_dct_pred[0];
1044
1045 }
941 else 1046 else
942 decoder->DCTblock[0] = 1047 {
943 decoder->dc_dct_pred[cc] += get_chroma_dc_dct_diff (decoder); 1048 decoder->dc_dct_pred[cc] += get_chroma_dc_dct_diff (decoder);
1049 decoder->DCTblock[0] = decoder->dc_dct_pred[cc];
1050 }
944 1051
945 if (decoder->mpeg1) { 1052 if (decoder->mpeg1)
1053 {
946 if (decoder->coding_type != D_TYPE) 1054 if (decoder->coding_type != D_TYPE)
947 get_mpeg1_intra_block (decoder); 1055 get_mpeg1_intra_block (decoder);
948 } else if (decoder->intra_vlc_format) 1056 }
1057 else if (decoder->intra_vlc_format)
1058 {
949 get_intra_block_B15 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]); 1059 get_intra_block_B15 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]);
1060 }
950 else 1061 else
1062 {
951 get_intra_block_B14 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]); 1063 get_intra_block_B14 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]);
1064 }
1065
952 mpeg2_idct_copy (decoder->DCTblock, dest, stride); 1066 mpeg2_idct_copy (decoder->DCTblock, dest, stride);
1067
953#undef bit_buf 1068#undef bit_buf
954#undef bits 1069#undef bits
955#undef bit_ptr 1070#undef bit_ptr
@@ -962,289 +1077,366 @@ static inline void slice_non_intra_DCT (mpeg2_decoder_t * const decoder,
962 int last; 1077 int last;
963 1078
964 if (decoder->mpeg1) 1079 if (decoder->mpeg1)
1080 {
965 last = get_mpeg1_non_intra_block (decoder); 1081 last = get_mpeg1_non_intra_block (decoder);
1082 }
966 else 1083 else
1084 {
967 last = get_non_intra_block (decoder, 1085 last = get_non_intra_block (decoder,
968 decoder->quantizer_matrix[cc ? 3 : 1]); 1086 decoder->quantizer_matrix[cc ? 3 : 1]);
1087 }
1088
969 mpeg2_idct_add (last, decoder->DCTblock, dest, stride); 1089 mpeg2_idct_add (last, decoder->DCTblock, dest, stride);
970} 1090}
971 1091
972#define MOTION_420(table,ref,motion_x,motion_y,size,y) \ 1092#define MOTION_420(table, ref, motion_x, motion_y, size, y) \
973 pos_x = 2 * decoder->offset + motion_x; \ 1093 pos_x = 2 * decoder->offset + motion_x; \
974 pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ 1094 pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \
975 if (unlikely (pos_x > decoder->limit_x)) { \ 1095 \
1096 if (unlikely (pos_x > decoder->limit_x)) \
1097 { \
976 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ 1098 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
977 motion_x = pos_x - 2 * decoder->offset; \ 1099 motion_x = pos_x - 2 * decoder->offset; \
978 } \ 1100 } \
979 if (unlikely (pos_y > decoder->limit_y_ ## size)) { \ 1101 \
980 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ 1102 if (unlikely (pos_y > decoder->limit_y_ ## size)) \
981 motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ 1103 { \
982 } \ 1104 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \
983 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ 1105 motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \
1106 } \
1107 \
1108 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
984 table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ 1109 table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \
985 ref[0] + (pos_x >> 1) + (pos_y >> 1) * decoder->stride, \ 1110 ref[0] + (pos_x >> 1) + (pos_y >> 1) * decoder->stride, \
986 decoder->stride, size); \ 1111 decoder->stride, size); \
987 motion_x /= 2; motion_y /= 2; \ 1112 \
988 xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ 1113 motion_x /= 2; \
989 offset = (((decoder->offset + motion_x) >> 1) + \ 1114 motion_y /= 2; \
990 ((((decoder->v_offset + motion_y) >> 1) + y/2) * \ 1115 xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
991 decoder->uv_stride)); \ 1116 offset = ((decoder->offset + motion_x) >> 1) + \
992 table[4+xy_half] (decoder->dest[1] + y/2 * decoder->uv_stride + \ 1117 ((((decoder->v_offset + motion_y) >> 1) + y/2) * \
993 (decoder->offset >> 1), ref[1] + offset, \ 1118 decoder->uv_stride); \
994 decoder->uv_stride, size/2); \ 1119 \
995 table[4+xy_half] (decoder->dest[2] + y/2 * decoder->uv_stride + \ 1120 table[4+xy_half] (decoder->dest[1] + y/2 * decoder->uv_stride + \
996 (decoder->offset >> 1), ref[2] + offset, \ 1121 (decoder->offset >> 1), ref[1] + offset, \
1122 decoder->uv_stride, size/2); \
1123 table[4+xy_half] (decoder->dest[2] + y/2 * decoder->uv_stride + \
1124 (decoder->offset >> 1), ref[2] + offset, \
997 decoder->uv_stride, size/2) 1125 decoder->uv_stride, size/2)
998 1126
999#define MOTION_FIELD_420(table,ref,motion_x,motion_y,dest_field,op,src_field) \ 1127#define MOTION_FIELD_420(table, ref, motion_x, motion_y, \
1000 pos_x = 2 * decoder->offset + motion_x; \ 1128 dest_field, op, src_field) \
1001 pos_y = decoder->v_offset + motion_y; \ 1129 pos_x = 2 * decoder->offset + motion_x; \
1002 if (unlikely (pos_x > decoder->limit_x)) { \ 1130 pos_y = decoder->v_offset + motion_y; \
1131 \
1132 if (unlikely (pos_x > decoder->limit_x)) \
1133 { \
1003 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ 1134 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
1004 motion_x = pos_x - 2 * decoder->offset; \ 1135 motion_x = pos_x - 2 * decoder->offset; \
1005 } \ 1136 } \
1006 if (unlikely (pos_y > decoder->limit_y)) { \ 1137 \
1138 if (unlikely (pos_y > decoder->limit_y)) \
1139 { \
1007 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ 1140 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
1008 motion_y = pos_y - decoder->v_offset; \ 1141 motion_y = pos_y - decoder->v_offset; \
1009 } \ 1142 } \
1010 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ 1143 \
1011 table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ 1144 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
1012 decoder->offset, \ 1145 table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \
1013 (ref[0] + (pos_x >> 1) + \ 1146 decoder->offset, \
1014 ((pos_y op) + src_field) * decoder->stride), \ 1147 (ref[0] + (pos_x >> 1) + \
1015 2 * decoder->stride, 8); \ 1148 ((pos_y op) + src_field) * decoder->stride), \
1016 motion_x /= 2; motion_y /= 2; \ 1149 2 * decoder->stride, 8); \
1017 xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ 1150 \
1018 offset = (((decoder->offset + motion_x) >> 1) + \ 1151 motion_x /= 2; \
1019 (((decoder->v_offset >> 1) + (motion_y op) + src_field) * \ 1152 motion_y /= 2; \
1020 decoder->uv_stride)); \ 1153 xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
1154 offset = ((decoder->offset + motion_x) >> 1) + \
1155 (((decoder->v_offset >> 1) + (motion_y op) + src_field) * \
1156 decoder->uv_stride); \
1157 \
1021 table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \ 1158 table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \
1022 (decoder->offset >> 1), ref[1] + offset, \ 1159 (decoder->offset >> 1), ref[1] + offset, \
1023 2 * decoder->uv_stride, 4); \ 1160 2 * decoder->uv_stride, 4); \
1024 table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \ 1161 table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \
1025 (decoder->offset >> 1), ref[2] + offset, \ 1162 (decoder->offset >> 1), ref[2] + offset, \
1026 2 * decoder->uv_stride, 4) 1163 2 * decoder->uv_stride, 4)
1027 1164
1028#define MOTION_DMV_420(table,ref,motion_x,motion_y) \ 1165#define MOTION_DMV_420(table, ref, motion_x, motion_y) \
1029 pos_x = 2 * decoder->offset + motion_x; \ 1166 pos_x = 2 * decoder->offset + motion_x; \
1030 pos_y = decoder->v_offset + motion_y; \ 1167 pos_y = decoder->v_offset + motion_y; \
1031 if (unlikely (pos_x > decoder->limit_x)) { \ 1168 \
1169 if (unlikely (pos_x > decoder->limit_x)) \
1170 { \
1032 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ 1171 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
1033 motion_x = pos_x - 2 * decoder->offset; \ 1172 motion_x = pos_x - 2 * decoder->offset; \
1034 } \ 1173 } \
1035 if (unlikely (pos_y > decoder->limit_y)) { \ 1174 \
1175 if (unlikely (pos_y > decoder->limit_y)) \
1176 { \
1036 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ 1177 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
1037 motion_y = pos_y - decoder->v_offset; \ 1178 motion_y = pos_y - decoder->v_offset; \
1038 } \ 1179 } \
1039 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ 1180 \
1040 offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ 1181 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
1041 table[xy_half] (decoder->dest[0] + decoder->offset, \ 1182 offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \
1042 ref[0] + offset, 2 * decoder->stride, 8); \ 1183 table[xy_half] (decoder->dest[0] + decoder->offset, \
1184 ref[0] + offset, 2 * decoder->stride, 8); \
1043 table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ 1185 table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \
1044 ref[0] + decoder->stride + offset, \ 1186 ref[0] + decoder->stride + offset, \
1045 2 * decoder->stride, 8); \ 1187 2 * decoder->stride, 8); \
1046 motion_x /= 2; motion_y /= 2; \ 1188 \
1047 xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ 1189 motion_x /= 2; \
1048 offset = (((decoder->offset + motion_x) >> 1) + \ 1190 motion_y /= 2; \
1049 (((decoder->v_offset >> 1) + (motion_y & ~1)) * \ 1191 xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
1050 decoder->uv_stride)); \ 1192 offset = ((decoder->offset + motion_x) >> 1) + \
1193 (((decoder->v_offset >> 1) + (motion_y & ~1)) * \
1194 decoder->uv_stride); \
1195 \
1051 table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \ 1196 table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \
1052 ref[1] + offset, 2 * decoder->uv_stride, 4); \ 1197 ref[1] + offset, 2 * decoder->uv_stride, 4); \
1053 table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \ 1198 table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \
1054 (decoder->offset >> 1), \ 1199 (decoder->offset >> 1), \
1055 ref[1] + decoder->uv_stride + offset, \ 1200 ref[1] + decoder->uv_stride + offset, \
1056 2 * decoder->uv_stride, 4); \ 1201 2 * decoder->uv_stride, 4); \
1057 table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \ 1202 table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \
1058 ref[2] + offset, 2 * decoder->uv_stride, 4); \ 1203 ref[2] + offset, 2 * decoder->uv_stride, 4); \
1059 table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \ 1204 table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \
1060 (decoder->offset >> 1), \ 1205 (decoder->offset >> 1), \
1061 ref[2] + decoder->uv_stride + offset, \ 1206 ref[2] + decoder->uv_stride + offset, \
1062 2 * decoder->uv_stride, 4) 1207 2 * decoder->uv_stride, 4)
1063 1208
1064#define MOTION_ZERO_420(table,ref) \ 1209#define MOTION_ZERO_420(table, ref) \
1065 table[0] (decoder->dest[0] + decoder->offset, \ 1210 table[0] (decoder->dest[0] + decoder->offset, \
1066 (ref[0] + decoder->offset + \ 1211 (ref[0] + decoder->offset + \
1067 decoder->v_offset * decoder->stride), decoder->stride, 16); \ 1212 decoder->v_offset * decoder->stride), decoder->stride, 16); \
1068 offset = ((decoder->offset >> 1) + \ 1213 \
1069 (decoder->v_offset >> 1) * decoder->uv_stride); \ 1214 offset = ((decoder->offset >> 1) + \
1215 (decoder->v_offset >> 1) * decoder->uv_stride); \
1216 \
1070 table[4] (decoder->dest[1] + (decoder->offset >> 1), \ 1217 table[4] (decoder->dest[1] + (decoder->offset >> 1), \
1071 ref[1] + offset, decoder->uv_stride, 8); \ 1218 ref[1] + offset, decoder->uv_stride, 8); \
1072 table[4] (decoder->dest[2] + (decoder->offset >> 1), \ 1219 table[4] (decoder->dest[2] + (decoder->offset >> 1), \
1073 ref[2] + offset, decoder->uv_stride, 8) 1220 ref[2] + offset, decoder->uv_stride, 8)
1074 1221
1075#define MOTION_422(table,ref,motion_x,motion_y,size,y) \ 1222#define MOTION_422(table, ref, motion_x, motion_y, size, y) \
1076 pos_x = 2 * decoder->offset + motion_x; \ 1223 pos_x = 2 * decoder->offset + motion_x; \
1077 pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ 1224 pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \
1078 if (unlikely (pos_x > decoder->limit_x)) { \ 1225 \
1226 if (unlikely (pos_x > decoder->limit_x)) \
1227 { \
1079 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ 1228 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
1080 motion_x = pos_x - 2 * decoder->offset; \ 1229 motion_x = pos_x - 2 * decoder->offset; \
1081 } \ 1230 } \
1082 if (unlikely (pos_y > decoder->limit_y_ ## size)) { \ 1231 \
1083 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ 1232 if (unlikely (pos_y > decoder->limit_y_ ## size)) \
1084 motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ 1233 { \
1085 } \ 1234 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \
1086 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ 1235 motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \
1087 offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \ 1236 } \
1237 \
1238 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
1239 offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \
1240 \
1088 table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ 1241 table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \
1089 ref[0] + offset, decoder->stride, size); \ 1242 ref[0] + offset, decoder->stride, size); \
1090 offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ 1243 \
1091 motion_x /= 2; \ 1244 offset = (offset + (motion_x & (motion_x < 0))) >> 1; \
1092 xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ 1245 motion_x /= 2; \
1093 table[4+xy_half] (decoder->dest[1] + y * decoder->uv_stride + \ 1246 xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \
1094 (decoder->offset >> 1), ref[1] + offset, \ 1247 \
1248 table[4+xy_half] (decoder->dest[1] + y * decoder->uv_stride + \
1249 (decoder->offset >> 1), ref[1] + offset, \
1095 decoder->uv_stride, size); \ 1250 decoder->uv_stride, size); \
1096 table[4+xy_half] (decoder->dest[2] + y * decoder->uv_stride + \ 1251 table[4+xy_half] (decoder->dest[2] + y * decoder->uv_stride + \
1097 (decoder->offset >> 1), ref[2] + offset, \ 1252 (decoder->offset >> 1), ref[2] + offset, \
1098 decoder->uv_stride, size) 1253 decoder->uv_stride, size)
1099 1254
1100#define MOTION_FIELD_422(table,ref,motion_x,motion_y,dest_field,op,src_field) \ 1255#define MOTION_FIELD_422(table, ref, motion_x, motion_y, \
1101 pos_x = 2 * decoder->offset + motion_x; \ 1256 dest_field, op, src_field) \
1102 pos_y = decoder->v_offset + motion_y; \ 1257 pos_x = 2 * decoder->offset + motion_x; \
1103 if (unlikely (pos_x > decoder->limit_x)) { \ 1258 pos_y = decoder->v_offset + motion_y; \
1259 \
1260 if (unlikely (pos_x > decoder->limit_x)) \
1261 { \
1104 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ 1262 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
1105 motion_x = pos_x - 2 * decoder->offset; \ 1263 motion_x = pos_x - 2 * decoder->offset; \
1106 } \ 1264 } \
1107 if (unlikely (pos_y > decoder->limit_y)) { \ 1265 \
1266 if (unlikely (pos_y > decoder->limit_y)) \
1267 { \
1108 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ 1268 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
1109 motion_y = pos_y - decoder->v_offset; \ 1269 motion_y = pos_y - decoder->v_offset; \
1110 } \ 1270 } \
1111 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ 1271 \
1112 offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \ 1272 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
1113 table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ 1273 offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \
1114 decoder->offset, ref[0] + offset, \ 1274 \
1115 2 * decoder->stride, 8); \ 1275 table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \
1116 offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ 1276 decoder->offset, ref[0] + offset, \
1117 motion_x /= 2; \ 1277 2 * decoder->stride, 8); \
1118 xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ 1278 \
1279 offset = (offset + (motion_x & (motion_x < 0))) >> 1; \
1280 motion_x /= 2; \
1281 xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \
1282 \
1119 table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \ 1283 table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \
1120 (decoder->offset >> 1), ref[1] + offset, \ 1284 (decoder->offset >> 1), ref[1] + offset, \
1121 2 * decoder->uv_stride, 8); \ 1285 2 * decoder->uv_stride, 8); \
1122 table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \ 1286 table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \
1123 (decoder->offset >> 1), ref[2] + offset, \ 1287 (decoder->offset >> 1), ref[2] + offset, \
1124 2 * decoder->uv_stride, 8) 1288 2 * decoder->uv_stride, 8)
1125 1289
1126#define MOTION_DMV_422(table,ref,motion_x,motion_y) \ 1290#define MOTION_DMV_422(table, ref, motion_x, motion_y) \
1127 pos_x = 2 * decoder->offset + motion_x; \ 1291 pos_x = 2 * decoder->offset + motion_x; \
1128 pos_y = decoder->v_offset + motion_y; \ 1292 pos_y = decoder->v_offset + motion_y; \
1129 if (unlikely (pos_x > decoder->limit_x)) { \ 1293 \
1294 if (unlikely (pos_x > decoder->limit_x)) \
1295 { \
1130 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ 1296 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
1131 motion_x = pos_x - 2 * decoder->offset; \ 1297 motion_x = pos_x - 2 * decoder->offset; \
1132 } \ 1298 } \
1133 if (unlikely (pos_y > decoder->limit_y)) { \ 1299 \
1300 if (unlikely (pos_y > decoder->limit_y)) \
1301 { \
1134 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ 1302 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
1135 motion_y = pos_y - decoder->v_offset; \ 1303 motion_y = pos_y - decoder->v_offset; \
1136 } \ 1304 } \
1137 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ 1305 \
1138 offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ 1306 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
1139 table[xy_half] (decoder->dest[0] + decoder->offset, \ 1307 offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \
1140 ref[0] + offset, 2 * decoder->stride, 8); \ 1308 \
1309 table[xy_half] (decoder->dest[0] + decoder->offset, \
1310 ref[0] + offset, 2 * decoder->stride, 8); \
1141 table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ 1311 table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \
1142 ref[0] + decoder->stride + offset, \ 1312 ref[0] + decoder->stride + offset, \
1143 2 * decoder->stride, 8); \ 1313 2 * decoder->stride, 8); \
1144 offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ 1314 \
1145 motion_x /= 2; \ 1315 offset = (offset + (motion_x & (motion_x < 0))) >> 1; \
1146 xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ 1316 motion_x /= 2; \
1317 xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \
1318 \
1147 table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \ 1319 table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \
1148 ref[1] + offset, 2 * decoder->uv_stride, 8); \ 1320 ref[1] + offset, 2 * decoder->uv_stride, 8); \
1149 table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \ 1321 table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \
1150 (decoder->offset >> 1), \ 1322 (decoder->offset >> 1), \
1151 ref[1] + decoder->uv_stride + offset, \ 1323 ref[1] + decoder->uv_stride + offset, \
1152 2 * decoder->uv_stride, 8); \ 1324 2 * decoder->uv_stride, 8); \
1153 table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \ 1325 table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \
1154 ref[2] + offset, 2 * decoder->uv_stride, 8); \ 1326 ref[2] + offset, 2 * decoder->uv_stride, 8); \
1155 table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \ 1327 table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \
1156 (decoder->offset >> 1), \ 1328 (decoder->offset >> 1), \
1157 ref[2] + decoder->uv_stride + offset, \ 1329 ref[2] + decoder->uv_stride + offset, \
1158 2 * decoder->uv_stride, 8) 1330 2 * decoder->uv_stride, 8)
1159 1331
1160#define MOTION_ZERO_422(table,ref) \ 1332#define MOTION_ZERO_422(table, ref) \
1161 offset = decoder->offset + decoder->v_offset * decoder->stride; \ 1333 offset = decoder->offset + decoder->v_offset * decoder->stride; \
1162 table[0] (decoder->dest[0] + decoder->offset, \ 1334 table[0] (decoder->dest[0] + decoder->offset, \
1163 ref[0] + offset, decoder->stride, 16); \ 1335 ref[0] + offset, decoder->stride, 16); \
1164 offset >>= 1; \ 1336 offset >>= 1; \
1165 table[4] (decoder->dest[1] + (decoder->offset >> 1), \ 1337 table[4] (decoder->dest[1] + (decoder->offset >> 1), \
1166 ref[1] + offset, decoder->uv_stride, 16); \ 1338 ref[1] + offset, decoder->uv_stride, 16); \
1167 table[4] (decoder->dest[2] + (decoder->offset >> 1), \ 1339 table[4] (decoder->dest[2] + (decoder->offset >> 1), \
1168 ref[2] + offset, decoder->uv_stride, 16) 1340 ref[2] + offset, decoder->uv_stride, 16)
1169 1341
1170#define MOTION_444(table,ref,motion_x,motion_y,size,y) \ 1342#define MOTION_444(table, ref, motion_x, motion_y, size, y) \
1171 pos_x = 2 * decoder->offset + motion_x; \ 1343 pos_x = 2 * decoder->offset + motion_x; \
1172 pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ 1344 pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \
1173 if (unlikely (pos_x > decoder->limit_x)) { \ 1345 \
1346 if (unlikely (pos_x > decoder->limit_x)) \
1347 { \
1174 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ 1348 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
1175 motion_x = pos_x - 2 * decoder->offset; \ 1349 motion_x = pos_x - 2 * decoder->offset; \
1176 } \ 1350 } \
1177 if (unlikely (pos_y > decoder->limit_y_ ## size)) { \ 1351 \
1178 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ 1352 if (unlikely (pos_y > decoder->limit_y_ ## size)) \
1179 motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ 1353 { \
1180 } \ 1354 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \
1181 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ 1355 motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \
1182 offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \ 1356 } \
1357 \
1358 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
1359 offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \
1360 \
1183 table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ 1361 table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \
1184 ref[0] + offset, decoder->stride, size); \ 1362 ref[0] + offset, decoder->stride, size); \
1185 table[xy_half] (decoder->dest[1] + y * decoder->stride + decoder->offset, \ 1363 table[xy_half] (decoder->dest[1] + y * decoder->stride + decoder->offset, \
1186 ref[1] + offset, decoder->stride, size); \ 1364 ref[1] + offset, decoder->stride, size); \
1187 table[xy_half] (decoder->dest[2] + y * decoder->stride + decoder->offset, \ 1365 table[xy_half] (decoder->dest[2] + y * decoder->stride + decoder->offset, \
1188 ref[2] + offset, decoder->stride, size) 1366 ref[2] + offset, decoder->stride, size)
1189 1367
1190#define MOTION_FIELD_444(table,ref,motion_x,motion_y,dest_field,op,src_field) \ 1368#define MOTION_FIELD_444(table, ref, motion_x, motion_y, \
1191 pos_x = 2 * decoder->offset + motion_x; \ 1369 dest_field, op, src_field) \
1192 pos_y = decoder->v_offset + motion_y; \ 1370 pos_x = 2 * decoder->offset + motion_x; \
1193 if (unlikely (pos_x > decoder->limit_x)) { \ 1371 pos_y = decoder->v_offset + motion_y; \
1372 \
1373 if (unlikely (pos_x > decoder->limit_x)) \
1374 { \
1194 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ 1375 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
1195 motion_x = pos_x - 2 * decoder->offset; \ 1376 motion_x = pos_x - 2 * decoder->offset; \
1196 } \ 1377 } \
1197 if (unlikely (pos_y > decoder->limit_y)) { \ 1378 \
1379 if (unlikely (pos_y > decoder->limit_y)) \
1380 { \
1198 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ 1381 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
1199 motion_y = pos_y - decoder->v_offset; \ 1382 motion_y = pos_y - decoder->v_offset; \
1200 } \ 1383 } \
1201 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ 1384 \
1202 offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \ 1385 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
1203 table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ 1386 offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \
1204 decoder->offset, ref[0] + offset, \ 1387 \
1205 2 * decoder->stride, 8); \ 1388 table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \
1206 table[xy_half] (decoder->dest[1] + dest_field * decoder->stride + \ 1389 decoder->offset, ref[0] + offset, \
1207 decoder->offset, ref[1] + offset, \ 1390 2 * decoder->stride, 8); \
1208 2 * decoder->stride, 8); \ 1391 table[xy_half] (decoder->dest[1] + dest_field * decoder->stride + \
1209 table[xy_half] (decoder->dest[2] + dest_field * decoder->stride + \ 1392 decoder->offset, ref[1] + offset, \
1210 decoder->offset, ref[2] + offset, \ 1393 2 * decoder->stride, 8); \
1394 table[xy_half] (decoder->dest[2] + dest_field * decoder->stride + \
1395 decoder->offset, ref[2] + offset, \
1211 2 * decoder->stride, 8) 1396 2 * decoder->stride, 8)
1212 1397
1213#define MOTION_DMV_444(table,ref,motion_x,motion_y) \ 1398#define MOTION_DMV_444(table, ref, motion_x, motion_y) \
1214 pos_x = 2 * decoder->offset + motion_x; \ 1399 pos_x = 2 * decoder->offset + motion_x; \
1215 pos_y = decoder->v_offset + motion_y; \ 1400 pos_y = decoder->v_offset + motion_y; \
1216 if (unlikely (pos_x > decoder->limit_x)) { \ 1401 \
1402 if (unlikely (pos_x > decoder->limit_x)) \
1403 { \
1217 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ 1404 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
1218 motion_x = pos_x - 2 * decoder->offset; \ 1405 motion_x = pos_x - 2 * decoder->offset; \
1219 } \ 1406 } \
1220 if (unlikely (pos_y > decoder->limit_y)) { \ 1407 \
1408 if (unlikely (pos_y > decoder->limit_y)) \
1409 { \
1221 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ 1410 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
1222 motion_y = pos_y - decoder->v_offset; \ 1411 motion_y = pos_y - decoder->v_offset; \
1223 } \ 1412 } \
1224 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ 1413 \
1225 offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ 1414 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
1226 table[xy_half] (decoder->dest[0] + decoder->offset, \ 1415 offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \
1227 ref[0] + offset, 2 * decoder->stride, 8); \ 1416 \
1417 table[xy_half] (decoder->dest[0] + decoder->offset, \
1418 ref[0] + offset, 2 * decoder->stride, 8); \
1228 table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ 1419 table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \
1229 ref[0] + decoder->stride + offset, \ 1420 ref[0] + decoder->stride + offset, \
1230 2 * decoder->stride, 8); \ 1421 2 * decoder->stride, 8); \
1231 table[xy_half] (decoder->dest[1] + decoder->offset, \ 1422 table[xy_half] (decoder->dest[1] + decoder->offset, \
1232 ref[1] + offset, 2 * decoder->stride, 8); \ 1423 ref[1] + offset, 2 * decoder->stride, 8); \
1233 table[xy_half] (decoder->dest[1] + decoder->stride + decoder->offset, \ 1424 table[xy_half] (decoder->dest[1] + decoder->stride + decoder->offset, \
1234 ref[1] + decoder->stride + offset, \ 1425 ref[1] + decoder->stride + offset, \
1235 2 * decoder->stride, 8); \ 1426 2 * decoder->stride, 8); \
1236 table[xy_half] (decoder->dest[2] + decoder->offset, \ 1427 table[xy_half] (decoder->dest[2] + decoder->offset, \
1237 ref[2] + offset, 2 * decoder->stride, 8); \ 1428 ref[2] + offset, 2 * decoder->stride, 8); \
1238 table[xy_half] (decoder->dest[2] + decoder->stride + decoder->offset, \ 1429 table[xy_half] (decoder->dest[2] + decoder->stride + decoder->offset, \
1239 ref[2] + decoder->stride + offset, \ 1430 ref[2] + decoder->stride + offset, \
1240 2 * decoder->stride, 8) 1431 2 * decoder->stride, 8)
1241 1432
1242#define MOTION_ZERO_444(table,ref) \ 1433#define MOTION_ZERO_444(table, ref) \
1243 offset = decoder->offset + decoder->v_offset * decoder->stride; \ 1434 offset = decoder->offset + decoder->v_offset * decoder->stride; \
1244 table[0] (decoder->dest[0] + decoder->offset, \ 1435 \
1245 ref[0] + offset, decoder->stride, 16); \ 1436 table[0] (decoder->dest[0] + decoder->offset, \
1246 table[4] (decoder->dest[1] + decoder->offset, \ 1437 ref[0] + offset, decoder->stride, 16); \
1247 ref[1] + offset, decoder->stride, 16); \ 1438 table[4] (decoder->dest[1] + decoder->offset, \
1439 ref[1] + offset, decoder->stride, 16); \
1248 table[4] (decoder->dest[2] + (decoder->offset >> 1), \ 1440 table[4] (decoder->dest[2] + (decoder->offset >> 1), \
1249 ref[2] + offset, decoder->stride, 16) 1441 ref[2] + offset, decoder->stride, 16)
1250 1442
@@ -1260,17 +1452,17 @@ static void motion_mp1 (mpeg2_decoder_t * const decoder,
1260 unsigned int pos_x, pos_y, xy_half, offset; 1452 unsigned int pos_x, pos_y, xy_half, offset;
1261 1453
1262 NEEDBITS (bit_buf, bits, bit_ptr); 1454 NEEDBITS (bit_buf, bits, bit_ptr);
1263 motion_x = (motion->pmv[0][0] + 1455 motion_x = motion->pmv[0][0] +
1264 (get_motion_delta (decoder, 1456 (get_motion_delta (decoder,
1265 motion->f_code[0]) << motion->f_code[1])); 1457 motion->f_code[0]) << motion->f_code[1]);
1266 motion_x = bound_motion_vector (motion_x, 1458 motion_x = bound_motion_vector (motion_x,
1267 motion->f_code[0] + motion->f_code[1]); 1459 motion->f_code[0] + motion->f_code[1]);
1268 motion->pmv[0][0] = motion_x; 1460 motion->pmv[0][0] = motion_x;
1269 1461
1270 NEEDBITS (bit_buf, bits, bit_ptr); 1462 NEEDBITS (bit_buf, bits, bit_ptr);
1271 motion_y = (motion->pmv[0][1] + 1463 motion_y = motion->pmv[0][1] +
1272 (get_motion_delta (decoder, 1464 (get_motion_delta (decoder,
1273 motion->f_code[0]) << motion->f_code[1])); 1465 motion->f_code[0]) << motion->f_code[1]);
1274 motion_y = bound_motion_vector (motion_y, 1466 motion_y = bound_motion_vector (motion_y,
1275 motion->f_code[0] + motion->f_code[1]); 1467 motion->f_code[0] + motion->f_code[1]);
1276 motion->pmv[0][1] = motion_y; 1468 motion->pmv[0][1] = motion_y;
@@ -1278,227 +1470,228 @@ static void motion_mp1 (mpeg2_decoder_t * const decoder,
1278 MOTION_420 (table, motion->ref[0], motion_x, motion_y, 16, 0); 1470 MOTION_420 (table, motion->ref[0], motion_x, motion_y, 16, 0);
1279} 1471}
1280 1472
1281#define MOTION_FUNCTIONS(FORMAT,MOTION,MOTION_FIELD,MOTION_DMV,MOTION_ZERO) \ 1473#define MOTION_FUNCTIONS(FORMAT, MOTION, MOTION_FIELD, \
1474 MOTION_DMV, MOTION_ZERO) \
1282 \ 1475 \
1283static void motion_fr_frame_##FORMAT (mpeg2_decoder_t * const decoder, \ 1476static void motion_fr_frame_##FORMAT (mpeg2_decoder_t * const decoder, \
1284 motion_t * const motion, \ 1477 motion_t * const motion, \
1285 mpeg2_mc_fct * const * const table) \ 1478 mpeg2_mc_fct * const * const table) \
1286{ \ 1479{ \
1287 int motion_x, motion_y; \ 1480 int motion_x, motion_y; \
1288 unsigned int pos_x, pos_y, xy_half, offset; \ 1481 unsigned int pos_x, pos_y, xy_half, offset; \
1289 \ 1482 \
1290 NEEDBITS (bit_buf, bits, bit_ptr); \ 1483 NEEDBITS (bit_buf, bits, bit_ptr); \
1291 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ 1484 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
1292 motion->f_code[0]); \ 1485 motion->f_code[0]); \
1293 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ 1486 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
1294 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ 1487 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \
1295 \ 1488 \
1296 NEEDBITS (bit_buf, bits, bit_ptr); \ 1489 NEEDBITS (bit_buf, bits, bit_ptr); \
1297 motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ 1490 motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \
1298 motion->f_code[1]); \ 1491 motion->f_code[1]); \
1299 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ 1492 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
1300 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ 1493 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \
1301 \ 1494 \
1302 MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \ 1495 MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \
1303} \ 1496} \
1304 \ 1497 \
1305static void motion_fr_field_##FORMAT (mpeg2_decoder_t * const decoder, \ 1498static void motion_fr_field_##FORMAT (mpeg2_decoder_t * const decoder, \
1306 motion_t * const motion, \ 1499 motion_t * const motion, \
1307 mpeg2_mc_fct * const * const table) \ 1500 mpeg2_mc_fct * const * const table) \
1308{ \ 1501{ \
1309 int motion_x, motion_y, field; \ 1502 int motion_x, motion_y, field; \
1310 unsigned int pos_x, pos_y, xy_half, offset; \ 1503 unsigned int pos_x, pos_y, xy_half, offset; \
1311 \ 1504 \
1312 NEEDBITS (bit_buf, bits, bit_ptr); \ 1505 NEEDBITS (bit_buf, bits, bit_ptr); \
1313 field = UBITS (bit_buf, 1); \ 1506 field = UBITS (bit_buf, 1); \
1314 DUMPBITS (bit_buf, bits, 1); \ 1507 DUMPBITS (bit_buf, bits, 1); \
1315 \ 1508 \
1316 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ 1509 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
1317 motion->f_code[0]); \ 1510 motion->f_code[0]); \
1318 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ 1511 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
1319 motion->pmv[0][0] = motion_x; \ 1512 motion->pmv[0][0] = motion_x; \
1320 \ 1513 \
1321 NEEDBITS (bit_buf, bits, bit_ptr); \ 1514 NEEDBITS (bit_buf, bits, bit_ptr); \
1322 motion_y = ((motion->pmv[0][1] >> 1) + \ 1515 motion_y = ((motion->pmv[0][1] >> 1) + \
1323 get_motion_delta (decoder, motion->f_code[1])); \ 1516 get_motion_delta (decoder, motion->f_code[1])); \
1324 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ 1517 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \
1325 motion->pmv[0][1] = motion_y << 1; \ 1518 motion->pmv[0][1] = motion_y << 1; \
1326 \ 1519 \
1327 MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 0, & ~1, field); \ 1520 MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 0, & ~1, field); \
1328 \ 1521 \
1329 NEEDBITS (bit_buf, bits, bit_ptr); \ 1522 NEEDBITS (bit_buf, bits, bit_ptr); \
1330 field = UBITS (bit_buf, 1); \ 1523 field = UBITS (bit_buf, 1); \
1331 DUMPBITS (bit_buf, bits, 1); \ 1524 DUMPBITS (bit_buf, bits, 1); \
1332 \ 1525 \
1333 motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \ 1526 motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \
1334 motion->f_code[0]); \ 1527 motion->f_code[0]); \
1335 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ 1528 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
1336 motion->pmv[1][0] = motion_x; \ 1529 motion->pmv[1][0] = motion_x; \
1337 \ 1530 \
1338 NEEDBITS (bit_buf, bits, bit_ptr); \ 1531 NEEDBITS (bit_buf, bits, bit_ptr); \
1339 motion_y = ((motion->pmv[1][1] >> 1) + \ 1532 motion_y = ((motion->pmv[1][1] >> 1) + \
1340 get_motion_delta (decoder, motion->f_code[1])); \ 1533 get_motion_delta (decoder, motion->f_code[1])); \
1341 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ 1534 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \
1342 motion->pmv[1][1] = motion_y << 1; \ 1535 motion->pmv[1][1] = motion_y << 1; \
1343 \ 1536 \
1344 MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 1, & ~1, field); \ 1537 MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 1, & ~1, field); \
1345} \ 1538} \
1346 \ 1539 \
1347static void motion_fr_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \ 1540static void motion_fr_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \
1348 motion_t * const motion, \ 1541 motion_t * const motion, \
1349 mpeg2_mc_fct * const * const table) \ 1542 mpeg2_mc_fct * const * const table) \
1350{ \ 1543{ \
1351 int motion_x, motion_y, dmv_x, dmv_y, m, other_x, other_y; \ 1544 int motion_x, motion_y, dmv_x, dmv_y, m, other_x, other_y; \
1352 unsigned int pos_x, pos_y, xy_half, offset; \ 1545 unsigned int pos_x, pos_y, xy_half, offset; \
1353 \ 1546 \
1354 (void)table; \ 1547 (void)table; \
1355 NEEDBITS (bit_buf, bits, bit_ptr); \ 1548 NEEDBITS (bit_buf, bits, bit_ptr); \
1356 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ 1549 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
1357 motion->f_code[0]); \ 1550 motion->f_code[0]); \
1358 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ 1551 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
1359 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ 1552 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \
1360 NEEDBITS (bit_buf, bits, bit_ptr); \ 1553 NEEDBITS (bit_buf, bits, bit_ptr); \
1361 dmv_x = get_dmv (decoder); \ 1554 dmv_x = get_dmv (decoder); \
1362 \ 1555 \
1363 motion_y = ((motion->pmv[0][1] >> 1) + \ 1556 motion_y = ((motion->pmv[0][1] >> 1) + \
1364 get_motion_delta (decoder, motion->f_code[1])); \ 1557 get_motion_delta (decoder, motion->f_code[1])); \
1365 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ 1558 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \
1366 motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1; \ 1559 motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1; \
1367 dmv_y = get_dmv (decoder); \ 1560 dmv_y = get_dmv (decoder); \
1368 \ 1561 \
1369 m = decoder->top_field_first ? 1 : 3; \ 1562 m = decoder->top_field_first ? 1 : 3; \
1370 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \ 1563 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \
1371 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1; \ 1564 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1; \
1372 MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 0, | 1, 0); \ 1565 MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 0, | 1, 0); \
1373 \ 1566 \
1374 m = decoder->top_field_first ? 3 : 1; \ 1567 m = decoder->top_field_first ? 3 : 1; \
1375 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \ 1568 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \
1376 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1; \ 1569 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1; \
1377 MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 1, & ~1, 0);\ 1570 MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 1, & ~1, 0);\
1378 \ 1571 \
1379 MOTION_DMV (mpeg2_mc.avg, motion->ref[0], motion_x, motion_y); \ 1572 MOTION_DMV (mpeg2_mc.avg, motion->ref[0], motion_x, motion_y); \
1380} \ 1573} \
1381 \ 1574 \
1382static void motion_reuse_##FORMAT (mpeg2_decoder_t * const decoder, \ 1575static void motion_reuse_##FORMAT (mpeg2_decoder_t * const decoder, \
1383 motion_t * const motion, \ 1576 motion_t * const motion, \
1384 mpeg2_mc_fct * const * const table) \ 1577 mpeg2_mc_fct * const * const table) \
1385{ \ 1578{ \
1386 int motion_x, motion_y; \ 1579 int motion_x, motion_y; \
1387 unsigned int pos_x, pos_y, xy_half, offset; \ 1580 unsigned int pos_x, pos_y, xy_half, offset; \
1388 \ 1581 \
1389 motion_x = motion->pmv[0][0]; \ 1582 motion_x = motion->pmv[0][0]; \
1390 motion_y = motion->pmv[0][1]; \ 1583 motion_y = motion->pmv[0][1]; \
1391 \ 1584 \
1392 MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \ 1585 MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \
1393} \ 1586} \
1394 \ 1587 \
1395static void motion_zero_##FORMAT (mpeg2_decoder_t * const decoder, \ 1588static void motion_zero_##FORMAT (mpeg2_decoder_t * const decoder, \
1396 motion_t * const motion, \ 1589 motion_t * const motion, \
1397 mpeg2_mc_fct * const * const table) \ 1590 mpeg2_mc_fct * const * const table) \
1398{ \ 1591{ \
1399 unsigned int offset; \ 1592 unsigned int offset; \
1400 \ 1593 \
1401 motion->pmv[0][0] = motion->pmv[0][1] = 0; \ 1594 motion->pmv[0][0] = motion->pmv[0][1] = 0; \
1402 motion->pmv[1][0] = motion->pmv[1][1] = 0; \ 1595 motion->pmv[1][0] = motion->pmv[1][1] = 0; \
1403 \ 1596 \
1404 MOTION_ZERO (table, motion->ref[0]); \ 1597 MOTION_ZERO (table, motion->ref[0]); \
1405} \ 1598} \
1406 \ 1599 \
1407static void motion_fi_field_##FORMAT (mpeg2_decoder_t * const decoder, \ 1600static void motion_fi_field_##FORMAT (mpeg2_decoder_t * const decoder, \
1408 motion_t * const motion, \ 1601 motion_t * const motion, \
1409 mpeg2_mc_fct * const * const table) \ 1602 mpeg2_mc_fct * const * const table) \
1410{ \ 1603{ \
1411 int motion_x, motion_y; \ 1604 int motion_x, motion_y; \
1412 uint8_t ** ref_field; \ 1605 uint8_t ** ref_field; \
1413 unsigned int pos_x, pos_y, xy_half, offset; \ 1606 unsigned int pos_x, pos_y, xy_half, offset; \
1414 \ 1607 \
1415 NEEDBITS (bit_buf, bits, bit_ptr); \ 1608 NEEDBITS (bit_buf, bits, bit_ptr); \
1416 ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ 1609 ref_field = motion->ref2[UBITS (bit_buf, 1)]; \
1417 DUMPBITS (bit_buf, bits, 1); \ 1610 DUMPBITS (bit_buf, bits, 1); \
1418 \ 1611 \
1419 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ 1612 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
1420 motion->f_code[0]); \ 1613 motion->f_code[0]); \
1421 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ 1614 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
1422 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ 1615 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \
1423 \ 1616 \
1424 NEEDBITS (bit_buf, bits, bit_ptr); \ 1617 NEEDBITS (bit_buf, bits, bit_ptr); \
1425 motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ 1618 motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \
1426 motion->f_code[1]); \ 1619 motion->f_code[1]); \
1427 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ 1620 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
1428 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ 1621 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \
1429 \ 1622 \
1430 MOTION (table, ref_field, motion_x, motion_y, 16, 0); \ 1623 MOTION (table, ref_field, motion_x, motion_y, 16, 0); \
1431} \ 1624} \
1432 \ 1625 \
1433static void motion_fi_16x8_##FORMAT (mpeg2_decoder_t * const decoder, \ 1626static void motion_fi_16x8_##FORMAT (mpeg2_decoder_t * const decoder, \
1434 motion_t * const motion, \ 1627 motion_t * const motion, \
1435 mpeg2_mc_fct * const * const table) \ 1628 mpeg2_mc_fct * const * const table) \
1436{ \ 1629{ \
1437 int motion_x, motion_y; \ 1630 int motion_x, motion_y; \
1438 uint8_t ** ref_field; \ 1631 uint8_t ** ref_field; \
1439 unsigned int pos_x, pos_y, xy_half, offset; \ 1632 unsigned int pos_x, pos_y, xy_half, offset; \
1440 \ 1633 \
1441 NEEDBITS (bit_buf, bits, bit_ptr); \ 1634 NEEDBITS (bit_buf, bits, bit_ptr); \
1442 ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ 1635 ref_field = motion->ref2[UBITS (bit_buf, 1)]; \
1443 DUMPBITS (bit_buf, bits, 1); \ 1636 DUMPBITS (bit_buf, bits, 1); \
1444 \ 1637 \
1445 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ 1638 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
1446 motion->f_code[0]); \ 1639 motion->f_code[0]); \
1447 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ 1640 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
1448 motion->pmv[0][0] = motion_x; \ 1641 motion->pmv[0][0] = motion_x; \
1449 \ 1642 \
1450 NEEDBITS (bit_buf, bits, bit_ptr); \ 1643 NEEDBITS (bit_buf, bits, bit_ptr); \
1451 motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ 1644 motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \
1452 motion->f_code[1]); \ 1645 motion->f_code[1]); \
1453 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ 1646 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
1454 motion->pmv[0][1] = motion_y; \ 1647 motion->pmv[0][1] = motion_y; \
1455 \ 1648 \
1456 MOTION (table, ref_field, motion_x, motion_y, 8, 0); \ 1649 MOTION (table, ref_field, motion_x, motion_y, 8, 0); \
1457 \ 1650 \
1458 NEEDBITS (bit_buf, bits, bit_ptr); \ 1651 NEEDBITS (bit_buf, bits, bit_ptr); \
1459 ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ 1652 ref_field = motion->ref2[UBITS (bit_buf, 1)]; \
1460 DUMPBITS (bit_buf, bits, 1); \ 1653 DUMPBITS (bit_buf, bits, 1); \
1461 \ 1654 \
1462 motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \ 1655 motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \
1463 motion->f_code[0]); \ 1656 motion->f_code[0]); \
1464 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ 1657 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
1465 motion->pmv[1][0] = motion_x; \ 1658 motion->pmv[1][0] = motion_x; \
1466 \ 1659 \
1467 NEEDBITS (bit_buf, bits, bit_ptr); \ 1660 NEEDBITS (bit_buf, bits, bit_ptr); \
1468 motion_y = motion->pmv[1][1] + get_motion_delta (decoder, \ 1661 motion_y = motion->pmv[1][1] + get_motion_delta (decoder, \
1469 motion->f_code[1]); \ 1662 motion->f_code[1]); \
1470 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ 1663 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
1471 motion->pmv[1][1] = motion_y; \ 1664 motion->pmv[1][1] = motion_y; \
1472 \ 1665 \
1473 MOTION (table, ref_field, motion_x, motion_y, 8, 8); \ 1666 MOTION (table, ref_field, motion_x, motion_y, 8, 8); \
1474} \ 1667} \
1475 \ 1668 \
1476static void motion_fi_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \ 1669static void motion_fi_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \
1477 motion_t * const motion, \ 1670 motion_t * const motion, \
1478 mpeg2_mc_fct * const * const table) \ 1671 mpeg2_mc_fct * const * const table) \
1479{ \ 1672{ \
1480 int motion_x, motion_y, other_x, other_y; \ 1673 int motion_x, motion_y, other_x, other_y; \
1481 unsigned int pos_x, pos_y, xy_half, offset; \ 1674 unsigned int pos_x, pos_y, xy_half, offset; \
1482 \ 1675 \
1483 (void)table; \ 1676 (void)table; \
1484 NEEDBITS (bit_buf, bits, bit_ptr); \ 1677 NEEDBITS (bit_buf, bits, bit_ptr); \
1485 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ 1678 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
1486 motion->f_code[0]); \ 1679 motion->f_code[0]); \
1487 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ 1680 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
1488 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ 1681 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \
1489 NEEDBITS (bit_buf, bits, bit_ptr); \ 1682 NEEDBITS (bit_buf, bits, bit_ptr); \
1490 other_x = ((motion_x + (motion_x > 0)) >> 1) + get_dmv (decoder); \ 1683 other_x = ((motion_x + (motion_x > 0)) >> 1) + get_dmv (decoder); \
1491 \ 1684 \
1492 motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ 1685 motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \
1493 motion->f_code[1]); \ 1686 motion->f_code[1]); \
1494 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ 1687 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
1495 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ 1688 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \
1496 other_y = (((motion_y + (motion_y > 0)) >> 1) + get_dmv (decoder) + \ 1689 other_y = (((motion_y + (motion_y > 0)) >> 1) + get_dmv (decoder) + \
1497 decoder->dmv_offset); \ 1690 decoder->dmv_offset); \
1498 \ 1691 \
1499 MOTION (mpeg2_mc.put, motion->ref[0], motion_x, motion_y, 16, 0); \ 1692 MOTION (mpeg2_mc.put, motion->ref[0], motion_x, motion_y, 16, 0); \
1500 MOTION (mpeg2_mc.avg, motion->ref[1], other_x, other_y, 16, 0); \ 1693 MOTION (mpeg2_mc.avg, motion->ref[1], other_x, other_y, 16, 0); \
1501} \ 1694} \
1502 1695
1503MOTION_FUNCTIONS (420, MOTION_420, MOTION_FIELD_420, MOTION_DMV_420, 1696MOTION_FUNCTIONS (420, MOTION_420, MOTION_FIELD_420, MOTION_DMV_420,
1504 MOTION_ZERO_420) 1697 MOTION_ZERO_420)
@@ -1534,16 +1727,21 @@ static void motion_fi_conceal (mpeg2_decoder_t * const decoder)
1534 NEEDBITS (bit_buf, bits, bit_ptr); 1727 NEEDBITS (bit_buf, bits, bit_ptr);
1535 DUMPBITS (bit_buf, bits, 1); /* remove field_select */ 1728 DUMPBITS (bit_buf, bits, 1); /* remove field_select */
1536 1729
1537 tmp = (decoder->f_motion.pmv[0][0] + 1730 tmp = decoder->f_motion.pmv[0][0] +
1538 get_motion_delta (decoder, decoder->f_motion.f_code[0])); 1731 get_motion_delta (decoder, decoder->f_motion.f_code[0]);
1539 tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[0]); 1732 tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[0]);
1540 decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[0][0] = tmp; 1733
1734 decoder->f_motion.pmv[1][0] =
1735 decoder->f_motion.pmv[0][0] = tmp;
1541 1736
1542 NEEDBITS (bit_buf, bits, bit_ptr); 1737 NEEDBITS (bit_buf, bits, bit_ptr);
1738
1543 tmp = (decoder->f_motion.pmv[0][1] + 1739 tmp = (decoder->f_motion.pmv[0][1] +
1544 get_motion_delta (decoder, decoder->f_motion.f_code[1])); 1740 get_motion_delta (decoder, decoder->f_motion.f_code[1]));
1545 tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[1]); 1741 tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[1]);
1546 decoder->f_motion.pmv[1][1] = decoder->f_motion.pmv[0][1] = tmp; 1742
1743 decoder->f_motion.pmv[1][1] =
1744 decoder->f_motion.pmv[0][1] = tmp;
1547 1745
1548 DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */ 1746 DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */
1549} 1747}
@@ -1552,34 +1750,44 @@ static void motion_fi_conceal (mpeg2_decoder_t * const decoder)
1552#undef bits 1750#undef bits
1553#undef bit_ptr 1751#undef bit_ptr
1554 1752
1555#define MOTION_CALL(routine,direction) \ 1753#define MOTION_CALL(routine, direction) \
1556do { \ 1754do { \
1557 if ((direction) & MACROBLOCK_MOTION_FORWARD) \ 1755 if ((direction) & MACROBLOCK_MOTION_FORWARD) \
1558 routine (decoder, &(decoder->f_motion), mpeg2_mc.put); \ 1756 routine (decoder, &decoder->f_motion, mpeg2_mc.put); \
1559 if ((direction) & MACROBLOCK_MOTION_BACKWARD) \ 1757 \
1560 routine (decoder, &(decoder->b_motion), \ 1758 if ((direction) & MACROBLOCK_MOTION_BACKWARD) \
1561 ((direction) & MACROBLOCK_MOTION_FORWARD ? \ 1759 { \
1562 mpeg2_mc.avg : mpeg2_mc.put)); \ 1760 routine (decoder, &decoder->b_motion, \
1761 ((direction) & MACROBLOCK_MOTION_FORWARD ? \
1762 mpeg2_mc.avg : mpeg2_mc.put)); \
1763 } \
1563} while (0) 1764} while (0)
1564 1765
1565#define NEXT_MACROBLOCK \ 1766#define NEXT_MACROBLOCK \
1566do { \ 1767do { \
1567 decoder->offset += 16; \ 1768 decoder->offset += 16; \
1568 if (decoder->offset == decoder->width) { \ 1769 \
1770 if (decoder->offset == decoder->width) \
1771 { \
1569 do { /* just so we can use the break statement */ \ 1772 do { /* just so we can use the break statement */ \
1570 if (decoder->convert) { \ 1773 if (decoder->convert) \
1774 { \
1571 decoder->convert (decoder->convert_id, decoder->dest, \ 1775 decoder->convert (decoder->convert_id, decoder->dest, \
1572 decoder->v_offset); \ 1776 decoder->v_offset); \
1573 if (decoder->coding_type == B_TYPE) \ 1777 if (decoder->coding_type == B_TYPE) \
1574 break; \ 1778 break; \
1575 } \ 1779 } \
1780 \
1576 decoder->dest[0] += decoder->slice_stride; \ 1781 decoder->dest[0] += decoder->slice_stride; \
1577 decoder->dest[1] += decoder->slice_uv_stride; \ 1782 decoder->dest[1] += decoder->slice_uv_stride; \
1578 decoder->dest[2] += decoder->slice_uv_stride; \ 1783 decoder->dest[2] += decoder->slice_uv_stride; \
1579 } while (0); \ 1784 } while (0); \
1785 \
1580 decoder->v_offset += 16; \ 1786 decoder->v_offset += 16; \
1787 \
1581 if (decoder->v_offset > decoder->limit_y) \ 1788 if (decoder->v_offset > decoder->limit_y) \
1582 return; \ 1789 return; \
1790 \
1583 decoder->offset = 0; \ 1791 decoder->offset = 0; \
1584 } \ 1792 } \
1585} while (0) 1793} while (0)
@@ -1606,7 +1814,8 @@ void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[3],
1606 decoder->b_motion.ref[0][1] = backward_fbuf[1] + (offset >> 1); 1814 decoder->b_motion.ref[0][1] = backward_fbuf[1] + (offset >> 1);
1607 decoder->b_motion.ref[0][2] = backward_fbuf[2] + (offset >> 1); 1815 decoder->b_motion.ref[0][2] = backward_fbuf[2] + (offset >> 1);
1608 1816
1609 if (decoder->picture_structure != FRAME_PICTURE) { 1817 if (decoder->picture_structure != FRAME_PICTURE)
1818 {
1610 decoder->dmv_offset = bottom_field ? 1 : -1; 1819 decoder->dmv_offset = bottom_field ? 1 : -1;
1611 decoder->f_motion.ref2[0] = decoder->f_motion.ref[bottom_field]; 1820 decoder->f_motion.ref2[0] = decoder->f_motion.ref[bottom_field];
1612 decoder->f_motion.ref2[1] = decoder->f_motion.ref[!bottom_field]; 1821 decoder->f_motion.ref2[1] = decoder->f_motion.ref[!bottom_field];
@@ -1639,44 +1848,59 @@ void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[3],
1639 decoder->limit_y_8 = 2 * height - 16; 1848 decoder->limit_y_8 = 2 * height - 16;
1640 decoder->limit_y = height - 16; 1849 decoder->limit_y = height - 16;
1641 1850
1642 if (decoder->mpeg1) { 1851 if (decoder->mpeg1)
1852 {
1643 decoder->motion_parser[0] = motion_zero_420; 1853 decoder->motion_parser[0] = motion_zero_420;
1644 decoder->motion_parser[MC_FRAME] = motion_mp1; 1854 decoder->motion_parser[MC_FRAME] = motion_mp1;
1645 decoder->motion_parser[4] = motion_reuse_420; 1855 decoder->motion_parser[4] = motion_reuse_420;
1646 } else if (decoder->picture_structure == FRAME_PICTURE) { 1856 }
1647 if (decoder->chroma_format == 0) { 1857 else if (decoder->picture_structure == FRAME_PICTURE)
1858 {
1859 if (decoder->chroma_format == 0)
1860 {
1648 decoder->motion_parser[0] = motion_zero_420; 1861 decoder->motion_parser[0] = motion_zero_420;
1649 decoder->motion_parser[MC_FIELD] = motion_fr_field_420; 1862 decoder->motion_parser[MC_FIELD] = motion_fr_field_420;
1650 decoder->motion_parser[MC_FRAME] = motion_fr_frame_420; 1863 decoder->motion_parser[MC_FRAME] = motion_fr_frame_420;
1651 decoder->motion_parser[MC_DMV] = motion_fr_dmv_420; 1864 decoder->motion_parser[MC_DMV] = motion_fr_dmv_420;
1652 decoder->motion_parser[4] = motion_reuse_420; 1865 decoder->motion_parser[4] = motion_reuse_420;
1653 } else if (decoder->chroma_format == 1) { 1866 }
1867 else if (decoder->chroma_format == 1)
1868 {
1654 decoder->motion_parser[0] = motion_zero_422; 1869 decoder->motion_parser[0] = motion_zero_422;
1655 decoder->motion_parser[MC_FIELD] = motion_fr_field_422; 1870 decoder->motion_parser[MC_FIELD] = motion_fr_field_422;
1656 decoder->motion_parser[MC_FRAME] = motion_fr_frame_422; 1871 decoder->motion_parser[MC_FRAME] = motion_fr_frame_422;
1657 decoder->motion_parser[MC_DMV] = motion_fr_dmv_422; 1872 decoder->motion_parser[MC_DMV] = motion_fr_dmv_422;
1658 decoder->motion_parser[4] = motion_reuse_422; 1873 decoder->motion_parser[4] = motion_reuse_422;
1659 } else { 1874 }
1875 else
1876 {
1660 decoder->motion_parser[0] = motion_zero_444; 1877 decoder->motion_parser[0] = motion_zero_444;
1661 decoder->motion_parser[MC_FIELD] = motion_fr_field_444; 1878 decoder->motion_parser[MC_FIELD] = motion_fr_field_444;
1662 decoder->motion_parser[MC_FRAME] = motion_fr_frame_444; 1879 decoder->motion_parser[MC_FRAME] = motion_fr_frame_444;
1663 decoder->motion_parser[MC_DMV] = motion_fr_dmv_444; 1880 decoder->motion_parser[MC_DMV] = motion_fr_dmv_444;
1664 decoder->motion_parser[4] = motion_reuse_444; 1881 decoder->motion_parser[4] = motion_reuse_444;
1665 } 1882 }
1666 } else { 1883 }
1667 if (decoder->chroma_format == 0) { 1884 else
1885 {
1886 if (decoder->chroma_format == 0)
1887 {
1668 decoder->motion_parser[0] = motion_zero_420; 1888 decoder->motion_parser[0] = motion_zero_420;
1669 decoder->motion_parser[MC_FIELD] = motion_fi_field_420; 1889 decoder->motion_parser[MC_FIELD] = motion_fi_field_420;
1670 decoder->motion_parser[MC_16X8] = motion_fi_16x8_420; 1890 decoder->motion_parser[MC_16X8] = motion_fi_16x8_420;
1671 decoder->motion_parser[MC_DMV] = motion_fi_dmv_420; 1891 decoder->motion_parser[MC_DMV] = motion_fi_dmv_420;
1672 decoder->motion_parser[4] = motion_reuse_420; 1892 decoder->motion_parser[4] = motion_reuse_420;
1673 } else if (decoder->chroma_format == 1) { 1893 }
1894 else if (decoder->chroma_format == 1)
1895 {
1674 decoder->motion_parser[0] = motion_zero_422; 1896 decoder->motion_parser[0] = motion_zero_422;
1675 decoder->motion_parser[MC_FIELD] = motion_fi_field_422; 1897 decoder->motion_parser[MC_FIELD] = motion_fi_field_422;
1676 decoder->motion_parser[MC_16X8] = motion_fi_16x8_422; 1898 decoder->motion_parser[MC_16X8] = motion_fi_16x8_422;
1677 decoder->motion_parser[MC_DMV] = motion_fi_dmv_422; 1899 decoder->motion_parser[MC_DMV] = motion_fi_dmv_422;
1678 decoder->motion_parser[4] = motion_reuse_422; 1900 decoder->motion_parser[4] = motion_reuse_422;
1679 } else { 1901 }
1902 else
1903 {
1680 decoder->motion_parser[0] = motion_zero_444; 1904 decoder->motion_parser[0] = motion_zero_444;
1681 decoder->motion_parser[MC_FIELD] = motion_fi_field_444; 1905 decoder->motion_parser[MC_FIELD] = motion_fi_field_444;
1682 decoder->motion_parser[MC_16X8] = motion_fi_16x8_444; 1906 decoder->motion_parser[MC_16X8] = motion_fi_16x8_444;
@@ -1691,6 +1915,7 @@ static inline int slice_init (mpeg2_decoder_t * const decoder, int code)
1691#define bit_buf (decoder->bitstream_buf) 1915#define bit_buf (decoder->bitstream_buf)
1692#define bits (decoder->bitstream_bits) 1916#define bits (decoder->bitstream_bits)
1693#define bit_ptr (decoder->bitstream_ptr) 1917#define bit_ptr (decoder->bitstream_ptr)
1918
1694 int offset; 1919 int offset;
1695 const MBAtab * mba; 1920 const MBAtab * mba;
1696 1921
@@ -1702,14 +1927,19 @@ static inline int slice_init (mpeg2_decoder_t * const decoder, int code)
1702 decoder->b_motion.pmv[0][0] = decoder->b_motion.pmv[0][1] = 0; 1927 decoder->b_motion.pmv[0][0] = decoder->b_motion.pmv[0][1] = 0;
1703 decoder->b_motion.pmv[1][0] = decoder->b_motion.pmv[1][1] = 0; 1928 decoder->b_motion.pmv[1][0] = decoder->b_motion.pmv[1][1] = 0;
1704 1929
1705 if (decoder->vertical_position_extension) { 1930 if (decoder->vertical_position_extension)
1931 {
1706 code += UBITS (bit_buf, 3) << 7; 1932 code += UBITS (bit_buf, 3) << 7;
1707 DUMPBITS (bit_buf, bits, 3); 1933 DUMPBITS (bit_buf, bits, 3);
1708 } 1934 }
1935
1709 decoder->v_offset = (code - 1) * 16; 1936 decoder->v_offset = (code - 1) * 16;
1710 offset = 0; 1937 offset = 0;
1938
1711 if (!(decoder->convert) || decoder->coding_type != B_TYPE) 1939 if (!(decoder->convert) || decoder->coding_type != B_TYPE)
1940 {
1712 offset = (code - 1) * decoder->slice_stride; 1941 offset = (code - 1) * decoder->slice_stride;
1942 }
1713 1943
1714 decoder->dest[0] = decoder->picture_dest[0] + offset; 1944 decoder->dest[0] = decoder->picture_dest[0] + offset;
1715 offset >>= (2 - decoder->chroma_format); 1945 offset >>= (2 - decoder->chroma_format);
@@ -1719,51 +1949,68 @@ static inline int slice_init (mpeg2_decoder_t * const decoder, int code)
1719 get_quantizer_scale (decoder); 1949 get_quantizer_scale (decoder);
1720 1950
1721 /* ignore intra_slice and all the extra data */ 1951 /* ignore intra_slice and all the extra data */
1722 while (bit_buf & 0x80000000) { 1952 while (bit_buf & 0x80000000)
1953 {
1723 DUMPBITS (bit_buf, bits, 9); 1954 DUMPBITS (bit_buf, bits, 9);
1724 NEEDBITS (bit_buf, bits, bit_ptr); 1955 NEEDBITS (bit_buf, bits, bit_ptr);
1725 } 1956 }
1726 1957
1727 /* decode initial macroblock address increment */ 1958 /* decode initial macroblock address increment */
1728 offset = 0; 1959 offset = 0;
1729 while (1) { 1960 while (1)
1730 if (bit_buf >= 0x08000000) { 1961 {
1962 if (bit_buf >= 0x08000000)
1963 {
1731 mba = MBA_5 + (UBITS (bit_buf, 6) - 2); 1964 mba = MBA_5 + (UBITS (bit_buf, 6) - 2);
1732 break; 1965 break;
1733 } else if (bit_buf >= 0x01800000) { 1966 }
1967 else if (bit_buf >= 0x01800000)
1968 {
1734 mba = MBA_11 + (UBITS (bit_buf, 12) - 24); 1969 mba = MBA_11 + (UBITS (bit_buf, 12) - 24);
1735 break; 1970 break;
1736 } else switch (UBITS (bit_buf, 12)) { 1971 }
1737 case 8: /* macroblock_escape */ 1972 else
1738 offset += 33; 1973 {
1739 DUMPBITS (bit_buf, bits, 11); 1974 switch (UBITS (bit_buf, 12))
1740 NEEDBITS (bit_buf, bits, bit_ptr); 1975 {
1741 continue; 1976 case 8: /* macroblock_escape */
1742 case 15: /* macroblock_stuffing (MPEG1 only) */ 1977 offset += 33;
1743 bit_buf &= 0xfffff; 1978 DUMPBITS (bit_buf, bits, 11);
1744 DUMPBITS (bit_buf, bits, 11); 1979 NEEDBITS (bit_buf, bits, bit_ptr);
1745 NEEDBITS (bit_buf, bits, bit_ptr); 1980 continue;
1746 continue; 1981 case 15: /* macroblock_stuffing (MPEG1 only) */
1747 default: /* error */ 1982 bit_buf &= 0xfffff;
1748 return 1; 1983 DUMPBITS (bit_buf, bits, 11);
1984 NEEDBITS (bit_buf, bits, bit_ptr);
1985 continue;
1986 default: /* error */
1987 return 1;
1988 }
1749 } 1989 }
1750 } 1990 }
1991
1751 DUMPBITS (bit_buf, bits, mba->len + 1); 1992 DUMPBITS (bit_buf, bits, mba->len + 1);
1752 decoder->offset = (offset + mba->mba) << 4; 1993 decoder->offset = (offset + mba->mba) << 4;
1753 1994
1754 while (decoder->offset - decoder->width >= 0) { 1995 while (decoder->offset - decoder->width >= 0)
1996 {
1755 decoder->offset -= decoder->width; 1997 decoder->offset -= decoder->width;
1756 if (!(decoder->convert) || decoder->coding_type != B_TYPE) { 1998
1999 if (!(decoder->convert) || decoder->coding_type != B_TYPE)
2000 {
1757 decoder->dest[0] += decoder->slice_stride; 2001 decoder->dest[0] += decoder->slice_stride;
1758 decoder->dest[1] += decoder->slice_uv_stride; 2002 decoder->dest[1] += decoder->slice_uv_stride;
1759 decoder->dest[2] += decoder->slice_uv_stride; 2003 decoder->dest[2] += decoder->slice_uv_stride;
1760 } 2004 }
2005
1761 decoder->v_offset += 16; 2006 decoder->v_offset += 16;
1762 } 2007 }
2008
1763 if (decoder->v_offset > decoder->limit_y) 2009 if (decoder->v_offset > decoder->limit_y)
1764 return 1; 2010 return 1;
1765 2011
1766 return 0; 2012 return 0;
2013
1767#undef bit_buf 2014#undef bit_buf
1768#undef bits 2015#undef bits
1769#undef bit_ptr 2016#undef bit_ptr
@@ -1781,7 +2028,8 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
1781 if (slice_init (decoder, code)) 2028 if (slice_init (decoder, code))
1782 return; 2029 return;
1783 2030
1784 while (1) { 2031 while (1)
2032 {
1785 int macroblock_modes; 2033 int macroblock_modes;
1786 int mba_inc; 2034 int mba_inc;
1787 const MBAtab * mba; 2035 const MBAtab * mba;
@@ -1794,28 +2042,34 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
1794 if (macroblock_modes & MACROBLOCK_QUANT) 2042 if (macroblock_modes & MACROBLOCK_QUANT)
1795 get_quantizer_scale (decoder); 2043 get_quantizer_scale (decoder);
1796 2044
1797 if (macroblock_modes & MACROBLOCK_INTRA) { 2045 if (macroblock_modes & MACROBLOCK_INTRA)
1798 2046 {
1799 int DCT_offset, DCT_stride; 2047 int DCT_offset, DCT_stride;
1800 int offset; 2048 int offset;
1801 uint8_t * dest_y; 2049 uint8_t * dest_y;
1802 2050
1803 if (decoder->concealment_motion_vectors) { 2051 if (decoder->concealment_motion_vectors)
2052 {
1804 if (decoder->picture_structure == FRAME_PICTURE) 2053 if (decoder->picture_structure == FRAME_PICTURE)
1805 motion_fr_conceal (decoder); 2054 motion_fr_conceal (decoder);
1806 else 2055 else
1807 motion_fi_conceal (decoder); 2056 motion_fi_conceal (decoder);
1808 } else { 2057 }
2058 else
2059 {
1809 decoder->f_motion.pmv[0][0] = decoder->f_motion.pmv[0][1] = 0; 2060 decoder->f_motion.pmv[0][0] = decoder->f_motion.pmv[0][1] = 0;
1810 decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[1][1] = 0; 2061 decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[1][1] = 0;
1811 decoder->b_motion.pmv[0][0] = decoder->b_motion.pmv[0][1] = 0; 2062 decoder->b_motion.pmv[0][0] = decoder->b_motion.pmv[0][1] = 0;
1812 decoder->b_motion.pmv[1][0] = decoder->b_motion.pmv[1][1] = 0; 2063 decoder->b_motion.pmv[1][0] = decoder->b_motion.pmv[1][1] = 0;
1813 } 2064 }
1814 2065
1815 if (macroblock_modes & DCT_TYPE_INTERLACED) { 2066 if (macroblock_modes & DCT_TYPE_INTERLACED)
2067 {
1816 DCT_offset = decoder->stride; 2068 DCT_offset = decoder->stride;
1817 DCT_stride = decoder->stride * 2; 2069 DCT_stride = decoder->stride * 2;
1818 } else { 2070 }
2071 else
2072 {
1819 DCT_offset = decoder->stride * 8; 2073 DCT_offset = decoder->stride * 8;
1820 DCT_stride = decoder->stride; 2074 DCT_stride = decoder->stride;
1821 } 2075 }
@@ -1826,27 +2080,38 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
1826 slice_intra_DCT (decoder, 0, dest_y + 8, DCT_stride); 2080 slice_intra_DCT (decoder, 0, dest_y + 8, DCT_stride);
1827 slice_intra_DCT (decoder, 0, dest_y + DCT_offset, DCT_stride); 2081 slice_intra_DCT (decoder, 0, dest_y + DCT_offset, DCT_stride);
1828 slice_intra_DCT (decoder, 0, dest_y + DCT_offset + 8, DCT_stride); 2082 slice_intra_DCT (decoder, 0, dest_y + DCT_offset + 8, DCT_stride);
1829 if (likely (decoder->chroma_format == 0)) { 2083
2084 if (likely (decoder->chroma_format == 0))
2085 {
1830 slice_intra_DCT (decoder, 1, decoder->dest[1] + (offset >> 1), 2086 slice_intra_DCT (decoder, 1, decoder->dest[1] + (offset >> 1),
1831 decoder->uv_stride); 2087 decoder->uv_stride);
1832 slice_intra_DCT (decoder, 2, decoder->dest[2] + (offset >> 1), 2088 slice_intra_DCT (decoder, 2, decoder->dest[2] + (offset >> 1),
1833 decoder->uv_stride); 2089 decoder->uv_stride);
1834 if (decoder->coding_type == D_TYPE) { 2090
2091 if (decoder->coding_type == D_TYPE)
2092 {
1835 NEEDBITS (bit_buf, bits, bit_ptr); 2093 NEEDBITS (bit_buf, bits, bit_ptr);
1836 DUMPBITS (bit_buf, bits, 1); 2094 DUMPBITS (bit_buf, bits, 1);
1837 } 2095 }
1838 } else if (likely (decoder->chroma_format == 1)) { 2096 }
2097 else if (likely (decoder->chroma_format == 1))
2098 {
1839 uint8_t * dest_u = decoder->dest[1] + (offset >> 1); 2099 uint8_t * dest_u = decoder->dest[1] + (offset >> 1);
1840 uint8_t * dest_v = decoder->dest[2] + (offset >> 1); 2100 uint8_t * dest_v = decoder->dest[2] + (offset >> 1);
2101
1841 DCT_stride >>= 1; 2102 DCT_stride >>= 1;
1842 DCT_offset >>= 1; 2103 DCT_offset >>= 1;
2104
1843 slice_intra_DCT (decoder, 1, dest_u, DCT_stride); 2105 slice_intra_DCT (decoder, 1, dest_u, DCT_stride);
1844 slice_intra_DCT (decoder, 2, dest_v, DCT_stride); 2106 slice_intra_DCT (decoder, 2, dest_v, DCT_stride);
1845 slice_intra_DCT (decoder, 1, dest_u + DCT_offset, DCT_stride); 2107 slice_intra_DCT (decoder, 1, dest_u + DCT_offset, DCT_stride);
1846 slice_intra_DCT (decoder, 2, dest_v + DCT_offset, DCT_stride); 2108 slice_intra_DCT (decoder, 2, dest_v + DCT_offset, DCT_stride);
1847 } else { 2109 }
2110 else
2111 {
1848 uint8_t * dest_u = decoder->dest[1] + offset; 2112 uint8_t * dest_u = decoder->dest[1] + offset;
1849 uint8_t * dest_v = decoder->dest[2] + offset; 2113 uint8_t * dest_v = decoder->dest[2] + offset;
2114
1850 slice_intra_DCT (decoder, 1, dest_u, DCT_stride); 2115 slice_intra_DCT (decoder, 1, dest_u, DCT_stride);
1851 slice_intra_DCT (decoder, 2, dest_v, DCT_stride); 2116 slice_intra_DCT (decoder, 2, dest_v, DCT_stride);
1852 slice_intra_DCT (decoder, 1, dest_u + DCT_offset, DCT_stride); 2117 slice_intra_DCT (decoder, 1, dest_u + DCT_offset, DCT_stride);
@@ -1858,52 +2123,66 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
1858 slice_intra_DCT (decoder, 2, dest_v + DCT_offset + 8, 2123 slice_intra_DCT (decoder, 2, dest_v + DCT_offset + 8,
1859 DCT_stride); 2124 DCT_stride);
1860 } 2125 }
1861 } else { 2126 }
1862 2127 else
2128 {
1863 motion_parser_t * parser; 2129 motion_parser_t * parser;
1864 2130
1865 parser = 2131 parser =
1866 decoder->motion_parser[macroblock_modes >> MOTION_TYPE_SHIFT]; 2132 decoder->motion_parser[macroblock_modes >> MOTION_TYPE_SHIFT];
1867 MOTION_CALL (parser, macroblock_modes); 2133 MOTION_CALL (parser, macroblock_modes);
1868 2134
1869 if (macroblock_modes & MACROBLOCK_PATTERN) { 2135 if (macroblock_modes & MACROBLOCK_PATTERN)
2136 {
1870 int coded_block_pattern; 2137 int coded_block_pattern;
1871 int DCT_offset, DCT_stride; 2138 int DCT_offset, DCT_stride;
1872 2139
1873 if (macroblock_modes & DCT_TYPE_INTERLACED) { 2140 if (macroblock_modes & DCT_TYPE_INTERLACED)
2141 {
1874 DCT_offset = decoder->stride; 2142 DCT_offset = decoder->stride;
1875 DCT_stride = decoder->stride * 2; 2143 DCT_stride = decoder->stride * 2;
1876 } else { 2144 }
2145 else
2146 {
1877 DCT_offset = decoder->stride * 8; 2147 DCT_offset = decoder->stride * 8;
1878 DCT_stride = decoder->stride; 2148 DCT_stride = decoder->stride;
1879 } 2149 }
1880 2150
1881 coded_block_pattern = get_coded_block_pattern (decoder); 2151 coded_block_pattern = get_coded_block_pattern (decoder);
1882 2152
1883 if (likely (decoder->chroma_format == 0)) { 2153 if (likely (decoder->chroma_format == 0))
2154 {
1884 int offset = decoder->offset; 2155 int offset = decoder->offset;
1885 uint8_t * dest_y = decoder->dest[0] + offset; 2156 uint8_t * dest_y = decoder->dest[0] + offset;
2157
1886 if (coded_block_pattern & 1) 2158 if (coded_block_pattern & 1)
1887 slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); 2159 slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride);
2160
1888 if (coded_block_pattern & 2) 2161 if (coded_block_pattern & 2)
1889 slice_non_intra_DCT (decoder, 0, dest_y + 8, 2162 slice_non_intra_DCT (decoder, 0, dest_y + 8,
1890 DCT_stride); 2163 DCT_stride);
2164
1891 if (coded_block_pattern & 4) 2165 if (coded_block_pattern & 4)
1892 slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, 2166 slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset,
1893 DCT_stride); 2167 DCT_stride);
2168
1894 if (coded_block_pattern & 8) 2169 if (coded_block_pattern & 8)
1895 slice_non_intra_DCT (decoder, 0, 2170 slice_non_intra_DCT (decoder, 0,
1896 dest_y + DCT_offset + 8, 2171 dest_y + DCT_offset + 8,
1897 DCT_stride); 2172 DCT_stride);
2173
1898 if (coded_block_pattern & 16) 2174 if (coded_block_pattern & 16)
1899 slice_non_intra_DCT (decoder, 1, 2175 slice_non_intra_DCT (decoder, 1,
1900 decoder->dest[1] + (offset >> 1), 2176 decoder->dest[1] + (offset >> 1),
1901 decoder->uv_stride); 2177 decoder->uv_stride);
2178
1902 if (coded_block_pattern & 32) 2179 if (coded_block_pattern & 32)
1903 slice_non_intra_DCT (decoder, 2, 2180 slice_non_intra_DCT (decoder, 2,
1904 decoder->dest[2] + (offset >> 1), 2181 decoder->dest[2] + (offset >> 1),
1905 decoder->uv_stride); 2182 decoder->uv_stride);
1906 } else if (likely (decoder->chroma_format == 1)) { 2183 }
2184 else if (likely (decoder->chroma_format == 1))
2185 {
1907 int offset; 2186 int offset;
1908 uint8_t * dest_y; 2187 uint8_t * dest_y;
1909 2188
@@ -1912,14 +2191,18 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
1912 2191
1913 offset = decoder->offset; 2192 offset = decoder->offset;
1914 dest_y = decoder->dest[0] + offset; 2193 dest_y = decoder->dest[0] + offset;
2194
1915 if (coded_block_pattern & 1) 2195 if (coded_block_pattern & 1)
1916 slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); 2196 slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride);
2197
1917 if (coded_block_pattern & 2) 2198 if (coded_block_pattern & 2)
1918 slice_non_intra_DCT (decoder, 0, dest_y + 8, 2199 slice_non_intra_DCT (decoder, 0, dest_y + 8,
1919 DCT_stride); 2200 DCT_stride);
2201
1920 if (coded_block_pattern & 4) 2202 if (coded_block_pattern & 4)
1921 slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, 2203 slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset,
1922 DCT_stride); 2204 DCT_stride);
2205
1923 if (coded_block_pattern & 8) 2206 if (coded_block_pattern & 8)
1924 slice_non_intra_DCT (decoder, 0, 2207 slice_non_intra_DCT (decoder, 0,
1925 dest_y + DCT_offset + 8, 2208 dest_y + DCT_offset + 8,
@@ -1927,23 +2210,29 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
1927 2210
1928 DCT_stride >>= 1; 2211 DCT_stride >>= 1;
1929 DCT_offset = (DCT_offset + offset) >> 1; 2212 DCT_offset = (DCT_offset + offset) >> 1;
2213
1930 if (coded_block_pattern & 16) 2214 if (coded_block_pattern & 16)
1931 slice_non_intra_DCT (decoder, 1, 2215 slice_non_intra_DCT (decoder, 1,
1932 decoder->dest[1] + (offset >> 1), 2216 decoder->dest[1] + (offset >> 1),
1933 DCT_stride); 2217 DCT_stride);
2218
1934 if (coded_block_pattern & 32) 2219 if (coded_block_pattern & 32)
1935 slice_non_intra_DCT (decoder, 2, 2220 slice_non_intra_DCT (decoder, 2,
1936 decoder->dest[2] + (offset >> 1), 2221 decoder->dest[2] + (offset >> 1),
1937 DCT_stride); 2222 DCT_stride);
2223
1938 if (coded_block_pattern & (2 << 30)) 2224 if (coded_block_pattern & (2 << 30))
1939 slice_non_intra_DCT (decoder, 1, 2225 slice_non_intra_DCT (decoder, 1,
1940 decoder->dest[1] + DCT_offset, 2226 decoder->dest[1] + DCT_offset,
1941 DCT_stride); 2227 DCT_stride);
2228
1942 if (coded_block_pattern & (1 << 30)) 2229 if (coded_block_pattern & (1 << 30))
1943 slice_non_intra_DCT (decoder, 2, 2230 slice_non_intra_DCT (decoder, 2,
1944 decoder->dest[2] + DCT_offset, 2231 decoder->dest[2] + DCT_offset,
1945 DCT_stride); 2232 DCT_stride);
1946 } else { 2233 }
2234 else
2235 {
1947 int offset; 2236 int offset;
1948 uint8_t * dest_y, * dest_u, * dest_v; 2237 uint8_t * dest_y, * dest_u, * dest_v;
1949 2238
@@ -1957,12 +2246,15 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
1957 2246
1958 if (coded_block_pattern & 1) 2247 if (coded_block_pattern & 1)
1959 slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); 2248 slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride);
2249
1960 if (coded_block_pattern & 2) 2250 if (coded_block_pattern & 2)
1961 slice_non_intra_DCT (decoder, 0, dest_y + 8, 2251 slice_non_intra_DCT (decoder, 0, dest_y + 8,
1962 DCT_stride); 2252 DCT_stride);
2253
1963 if (coded_block_pattern & 4) 2254 if (coded_block_pattern & 4)
1964 slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, 2255 slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset,
1965 DCT_stride); 2256 DCT_stride);
2257
1966 if (coded_block_pattern & 8) 2258 if (coded_block_pattern & 8)
1967 slice_non_intra_DCT (decoder, 0, 2259 slice_non_intra_DCT (decoder, 0,
1968 dest_y + DCT_offset + 8, 2260 dest_y + DCT_offset + 8,
@@ -1970,24 +2262,31 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
1970 2262
1971 if (coded_block_pattern & 16) 2263 if (coded_block_pattern & 16)
1972 slice_non_intra_DCT (decoder, 1, dest_u, DCT_stride); 2264 slice_non_intra_DCT (decoder, 1, dest_u, DCT_stride);
2265
1973 if (coded_block_pattern & 32) 2266 if (coded_block_pattern & 32)
1974 slice_non_intra_DCT (decoder, 2, dest_v, DCT_stride); 2267 slice_non_intra_DCT (decoder, 2, dest_v, DCT_stride);
2268
1975 if (coded_block_pattern & (32 << 26)) 2269 if (coded_block_pattern & (32 << 26))
1976 slice_non_intra_DCT (decoder, 1, dest_u + DCT_offset, 2270 slice_non_intra_DCT (decoder, 1, dest_u + DCT_offset,
1977 DCT_stride); 2271 DCT_stride);
2272
1978 if (coded_block_pattern & (16 << 26)) 2273 if (coded_block_pattern & (16 << 26))
1979 slice_non_intra_DCT (decoder, 2, dest_v + DCT_offset, 2274 slice_non_intra_DCT (decoder, 2, dest_v + DCT_offset,
1980 DCT_stride); 2275 DCT_stride);
2276
1981 if (coded_block_pattern & (8 << 26)) 2277 if (coded_block_pattern & (8 << 26))
1982 slice_non_intra_DCT (decoder, 1, dest_u + 8, 2278 slice_non_intra_DCT (decoder, 1, dest_u + 8,
1983 DCT_stride); 2279 DCT_stride);
2280
1984 if (coded_block_pattern & (4 << 26)) 2281 if (coded_block_pattern & (4 << 26))
1985 slice_non_intra_DCT (decoder, 2, dest_v + 8, 2282 slice_non_intra_DCT (decoder, 2, dest_v + 8,
1986 DCT_stride); 2283 DCT_stride);
2284
1987 if (coded_block_pattern & (2 << 26)) 2285 if (coded_block_pattern & (2 << 26))
1988 slice_non_intra_DCT (decoder, 1, 2286 slice_non_intra_DCT (decoder, 1,
1989 dest_u + DCT_offset + 8, 2287 dest_u + DCT_offset + 8,
1990 DCT_stride); 2288 DCT_stride);
2289
1991 if (coded_block_pattern & (1 << 26)) 2290 if (coded_block_pattern & (1 << 26))
1992 slice_non_intra_DCT (decoder, 2, 2291 slice_non_intra_DCT (decoder, 2,
1993 dest_v + DCT_offset + 8, 2292 dest_v + DCT_offset + 8,
@@ -2003,46 +2302,66 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
2003 2302
2004 NEEDBITS (bit_buf, bits, bit_ptr); 2303 NEEDBITS (bit_buf, bits, bit_ptr);
2005 mba_inc = 0; 2304 mba_inc = 0;
2006 while (1) { 2305
2007 if (bit_buf >= 0x10000000) { 2306 while (1)
2307 {
2308 if (bit_buf >= 0x10000000)
2309 {
2008 mba = MBA_5 + (UBITS (bit_buf, 5) - 2); 2310 mba = MBA_5 + (UBITS (bit_buf, 5) - 2);
2009 break; 2311 break;
2010 } else if (bit_buf >= 0x03000000) { 2312 }
2313 else if (bit_buf >= 0x03000000)
2314 {
2011 mba = MBA_11 + (UBITS (bit_buf, 11) - 24); 2315 mba = MBA_11 + (UBITS (bit_buf, 11) - 24);
2012 break; 2316 break;
2013 } else switch (UBITS (bit_buf, 11)) { 2317 }
2014 case 8: /* macroblock_escape */ 2318 else
2015 mba_inc += 33; 2319 {
2016 /* pass through */ 2320 switch (UBITS (bit_buf, 11))
2017 case 15: /* macroblock_stuffing (MPEG1 only) */ 2321 {
2018 DUMPBITS (bit_buf, bits, 11); 2322 case 8: /* macroblock_escape */
2019 NEEDBITS (bit_buf, bits, bit_ptr); 2323 mba_inc += 33;
2020 continue; 2324 /* pass through */
2021 default: /* end of slice, or error */ 2325 case 15: /* macroblock_stuffing (MPEG1 only) */
2022 return; 2326 DUMPBITS (bit_buf, bits, 11);
2327 NEEDBITS (bit_buf, bits, bit_ptr);
2328 continue;
2329 default: /* end of slice, or error */
2330 return;
2331 }
2023 } 2332 }
2024 } 2333 }
2334
2025 DUMPBITS (bit_buf, bits, mba->len); 2335 DUMPBITS (bit_buf, bits, mba->len);
2026 mba_inc += mba->mba; 2336 mba_inc += mba->mba;
2027 2337
2028 if (mba_inc) { 2338 if (mba_inc)
2339 {
2029 decoder->dc_dct_pred[0] = decoder->dc_dct_pred[1] = 2340 decoder->dc_dct_pred[0] = decoder->dc_dct_pred[1] =
2030 decoder->dc_dct_pred[2] = 16384; 2341 decoder->dc_dct_pred[2] = 16384;
2031 2342
2032 if (decoder->coding_type == P_TYPE) { 2343 if (decoder->coding_type == P_TYPE)
2033 do { 2344 {
2345 do
2346 {
2034 MOTION_CALL (decoder->motion_parser[0], 2347 MOTION_CALL (decoder->motion_parser[0],
2035 MACROBLOCK_MOTION_FORWARD); 2348 MACROBLOCK_MOTION_FORWARD);
2036 NEXT_MACROBLOCK; 2349 NEXT_MACROBLOCK;
2037 } while (--mba_inc); 2350 }
2038 } else { 2351 while (--mba_inc);
2039 do { 2352 }
2353 else
2354 {
2355 do
2356 {
2040 MOTION_CALL (decoder->motion_parser[4], macroblock_modes); 2357 MOTION_CALL (decoder->motion_parser[4], macroblock_modes);
2041 NEXT_MACROBLOCK; 2358 NEXT_MACROBLOCK;
2042 } while (--mba_inc); 2359 }
2360 while (--mba_inc);
2043 } 2361 }
2044 } 2362 }
2045 } 2363 }
2364
2046#undef bit_buf 2365#undef bit_buf
2047#undef bits 2366#undef bits
2048#undef bit_ptr 2367#undef bit_ptr
diff --git a/apps/plugins/mpegplayer/vlc.h b/apps/plugins/mpegplayer/vlc.h
index dbef8f881f..90245cc8ea 100644
--- a/apps/plugins/mpegplayer/vlc.h
+++ b/apps/plugins/mpegplayer/vlc.h
@@ -21,35 +21,35 @@
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */ 22 */
23 23
24#define GETWORD(bit_buf,shift,bit_ptr) \ 24#define GETWORD(bit_buf, shift, bit_ptr) \
25do { \ 25do { \
26 bit_buf |= ((bit_ptr[0] << 8) | bit_ptr[1]) << (shift); \ 26 bit_buf |= ((bit_ptr[0] << 8) | bit_ptr[1]) << (shift); \
27 bit_ptr += 2; \ 27 bit_ptr += 2; \
28} while (0) 28} while (0)
29 29
30static inline void bitstream_init (mpeg2_decoder_t * decoder, 30static inline void bitstream_init (mpeg2_decoder_t * decoder,
31 const uint8_t * start) 31 const uint8_t * start)
32{ 32{
33 decoder->bitstream_buf = 33 decoder->bitstream_buf =
34 (start[0] << 24) | (start[1] << 16) | (start[2] << 8) | start[3]; 34 (start[0] << 24) | (start[1] << 16) | (start[2] << 8) | start[3];
35 decoder->bitstream_ptr = start + 4; 35 decoder->bitstream_ptr = start + 4;
36 decoder->bitstream_bits = -16; 36 decoder->bitstream_bits = -16;
37} 37}
38 38
39/* make sure that there are at least 16 valid bits in bit_buf */ 39/* make sure that there are at least 16 valid bits in bit_buf */
40#define NEEDBITS(bit_buf,bits,bit_ptr) \ 40#define NEEDBITS(bit_buf, bits, bit_ptr) \
41do { \ 41do { \
42 if (unlikely (bits > 0)) { \ 42 if (unlikely (bits > 0)) { \
43 GETWORD (bit_buf, bits, bit_ptr); \ 43 GETWORD (bit_buf, bits, bit_ptr); \
44 bits -= 16; \ 44 bits -= 16; \
45 } \ 45 } \
46} while (0) 46} while (0)
47 47
48/* remove num valid bits from bit_buf */ 48/* remove num valid bits from bit_buf */
49#define DUMPBITS(bit_buf,bits,num) \ 49#define DUMPBITS(bit_buf, bits, num) \
50do { \ 50do { \
51 bit_buf <<= (num); \ 51 bit_buf <<= (num); \
52 bits += (num); \ 52 bits += (num); \
53} while (0) 53} while (0)
54 54
55/* take num bits from the high part of bit_buf and zero extend them */ 55/* take num bits from the high part of bit_buf and zero extend them */
@@ -124,7 +124,7 @@ static const MBtab MB_B [] ICONST_ATTR = {
124 {0, 0}, {INTRA|QUANT, 6}, 124 {0, 0}, {INTRA|QUANT, 6},
125 {BWD|CODED|QUANT, 6}, {FWD|CODED|QUANT, 6}, 125 {BWD|CODED|QUANT, 6}, {FWD|CODED|QUANT, 6},
126 {INTER|CODED|QUANT, 5}, {INTER|CODED|QUANT, 5}, 126 {INTER|CODED|QUANT, 5}, {INTER|CODED|QUANT, 5},
127 {INTRA, 5}, {INTRA, 5}, 127 {INTRA, 5}, {INTRA, 5},
128 {FWD, 4}, {FWD, 4}, {FWD, 4}, {FWD, 4}, 128 {FWD, 4}, {FWD, 4}, {FWD, 4}, {FWD, 4},
129 {FWD|CODED, 4}, {FWD|CODED, 4}, {FWD|CODED, 4}, {FWD|CODED, 4}, 129 {FWD|CODED, 4}, {FWD|CODED, 4}, {FWD|CODED, 4}, {FWD|CODED, 4},
130 {BWD, 3}, {BWD, 3}, {BWD, 3}, {BWD, 3}, 130 {BWD, 3}, {BWD, 3}, {BWD, 3}, {BWD, 3},
@@ -301,7 +301,7 @@ static const DCTtab DCT_B14_8 [] ICONST_ATTR = {
301}; 301};
302 302
303static const DCTtab DCT_B14AC_5 [] ICONST_ATTR = { 303static const DCTtab DCT_B14AC_5 [] ICONST_ATTR = {
304 { 1, 3, 5}, { 5, 1, 5}, { 4, 1, 5}, 304 { 1, 3, 5}, { 5, 1, 5}, { 4, 1, 5},
305 { 1, 2, 4}, { 1, 2, 4}, { 3, 1, 4}, { 3, 1, 4}, 305 { 1, 2, 4}, { 1, 2, 4}, { 3, 1, 4}, { 3, 1, 4},
306 { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, 306 { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3},
307 {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, 307 {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2},
@@ -311,7 +311,7 @@ static const DCTtab DCT_B14AC_5 [] ICONST_ATTR = {
311}; 311};
312 312
313static const DCTtab DCT_B14DC_5 [] ICONST_ATTR = { 313static const DCTtab DCT_B14DC_5 [] ICONST_ATTR = {
314 { 1, 3, 5}, { 5, 1, 5}, { 4, 1, 5}, 314 { 1, 3, 5}, { 5, 1, 5}, { 4, 1, 5},
315 { 1, 2, 4}, { 1, 2, 4}, { 3, 1, 4}, { 3, 1, 4}, 315 { 1, 2, 4}, { 1, 2, 4}, { 3, 1, 4}, { 3, 1, 4},
316 { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, 316 { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3},
317 { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, 317 { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1},
@@ -393,7 +393,7 @@ static const DCTtab DCT_B15_8 [] ICONST_ATTR = {
393 393
394 394
395static const MBAtab MBA_5 [] ICONST_ATTR = { 395static const MBAtab MBA_5 [] ICONST_ATTR = {
396 {6, 5}, {5, 5}, {4, 4}, {4, 4}, {3, 4}, {3, 4}, 396 {6, 5}, {5, 5}, {4, 4}, {4, 4}, {3, 4}, {3, 4},
397 {2, 3}, {2, 3}, {2, 3}, {2, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, 397 {2, 3}, {2, 3}, {2, 3}, {2, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
398 {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, 398 {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1},
399 {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1} 399 {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}