summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmpeg3/video/getpicture.c
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/libmpeg3/video/getpicture.c') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmpeg3/video/getpicture.c767
1 files changed, 767 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/libmpeg3/video/getpicture.c b/core/multimedia/opieplayer/libmpeg3/video/getpicture.c
new file mode 100644
index 0000000..4f67484
--- a/dev/null
+++ b/core/multimedia/opieplayer/libmpeg3/video/getpicture.c
@@ -0,0 +1,767 @@
1#include "../libmpeg3.h"
2#include "../mpeg3protos.h"
3#include "mpeg3video.h"
4#include "vlc.h"
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9
10int mpeg3video_get_cbp(mpeg3_slice_t *slice)
11{
12 int code;
13 mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer;
14
15 if((code = mpeg3slice_showbits9(slice_buffer)) >= 128)
16 {
17 code >>= 4;
18 mpeg3slice_flushbits(slice_buffer, mpeg3_CBPtab0[code].len);
19 return mpeg3_CBPtab0[code].val;
20 }
21
22 if(code >= 8)
23 {
24 code >>= 1;
25 mpeg3slice_flushbits(slice_buffer, mpeg3_CBPtab1[code].len);
26 return mpeg3_CBPtab1[code].val;
27 }
28
29 if(code < 1)
30 {
31 /* fprintf(stderr,"mpeg3video_get_cbp: invalid coded_block_pattern code\n"); */
32 slice->fault = 1;
33 return 0;
34 }
35
36 mpeg3slice_flushbits(slice_buffer, mpeg3_CBPtab2[code].len);
37 return mpeg3_CBPtab2[code].val;
38}
39
40
41/* set block to zero */
42int mpeg3video_clearblock(mpeg3_slice_t *slice, int comp, int size)
43{
44 slice->sparse[comp] = 1;
45
46/* Compiler error */
47/*
48 * for(i = 0; i < size; i++)
49 * {
50 * bzero(slice->block[comp] + sizeof(short) * 64 * i, sizeof(short) * 64);
51 * }
52 */
53
54 if(size == 6)
55 {
56 bzero(slice->block[comp], sizeof(short) * 64 * 6);
57 }
58 else
59 {
60printf("mpeg3video_clearblock size = %d\n", size);
61 memset(slice->block[comp], 0, sizeof(short) * 64 * size);
62 }
63 return 0;
64}
65
66static inline int mpeg3video_getdclum(mpeg3_slice_buffer_t *slice_buffer)
67{
68 int code, size, val;
69/* decode length */
70 code = mpeg3slice_showbits5(slice_buffer);
71
72 if(code < 31)
73 {
74 size = mpeg3_DClumtab0[code].val;
75 mpeg3slice_flushbits(slice_buffer, mpeg3_DClumtab0[code].len);
76 }
77 else
78 {
79 code = mpeg3slice_showbits9(slice_buffer) - 0x1f0;
80 size = mpeg3_DClumtab1[code].val;
81 mpeg3slice_flushbits(slice_buffer, mpeg3_DClumtab1[code].len);
82 }
83
84 if(size == 0) val = 0;
85 else
86 {
87 val = mpeg3slice_getbits(slice_buffer, size);
88 if((val & (1 << (size - 1))) == 0) val -= (1 << size) - 1;
89 }
90
91 return val;
92}
93
94
95int mpeg3video_getdcchrom(mpeg3_slice_buffer_t *slice_buffer)
96{
97 int code, size, val;
98
99/* decode length */
100 code = mpeg3slice_showbits5(slice_buffer);
101
102 if(code < 31)
103 {
104 size = mpeg3_DCchromtab0[code].val;
105 mpeg3slice_flushbits(slice_buffer, mpeg3_DCchromtab0[code].len);
106 }
107 else
108 {
109 code = mpeg3slice_showbits(slice_buffer, 10) - 0x3e0;
110 size = mpeg3_DCchromtab1[code].val;
111 mpeg3slice_flushbits(slice_buffer, mpeg3_DCchromtab1[code].len);
112 }
113
114 if(size == 0) val = 0;
115 else
116 {
117 val = mpeg3slice_getbits(slice_buffer, size);
118 if((val & (1 << (size - 1))) == 0) val -= (1 << size) - 1;
119 }
120
121 return val;
122}
123
124
125/* decode one intra coded MPEG-1 block */
126
127int mpeg3video_getintrablock(mpeg3_slice_t *slice,
128 mpeg3video_t *video,
129 int comp,
130 int dc_dct_pred[])
131{
132 int val, i, j, sign;
133 unsigned int code;
134 mpeg3_DCTtab_t *tab = 0;
135 short *bp = slice->block[comp];
136 mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer;
137
138/* decode DC coefficients */
139 if(comp < 4)
140 bp[0] = (dc_dct_pred[0] += mpeg3video_getdclum(slice_buffer)) << 3;
141 else
142 if(comp == 4)
143 bp[0] = (dc_dct_pred[1] += mpeg3video_getdcchrom(slice_buffer)) << 3;
144 else
145 bp[0] = (dc_dct_pred[2] += mpeg3video_getdcchrom(slice_buffer)) << 3;
146
147#ifdef HAVE_MMX
148 if(video->have_mmx)
149 bp[0] <<= 4;
150#endif
151
152 if(slice->fault) return 1;
153
154/* decode AC coefficients */
155 for(i = 1; ; i++)
156 {
157 code = mpeg3slice_showbits16(slice_buffer);
158 if(code >= 16384)
159 tab = &mpeg3_DCTtabnext[(code >> 12) - 4];
160 else
161 if(code >= 1024) tab = &mpeg3_DCTtab0[(code >> 8) - 4];
162 else
163 if(code >= 512) tab = &mpeg3_DCTtab1[(code >> 6) - 8];
164 else
165 if(code >= 256) tab = &mpeg3_DCTtab2[(code >> 4) - 16];
166 else
167 if(code >= 128) tab = &mpeg3_DCTtab3[(code >> 3) - 16];
168 else
169 if(code >= 64) tab = &mpeg3_DCTtab4[(code >> 2) - 16];
170 else
171 if(code >= 32) tab = &mpeg3_DCTtab5[(code >> 1) - 16];
172 else
173 if(code >= 16) tab = &mpeg3_DCTtab6[code - 16];
174 else
175 {
176 /* fprintf(stderr, "mpeg3video_getintrablock: invalid Huffman code\n"); */
177 slice->fault = 1;
178 return 1;
179 }
180
181 mpeg3slice_flushbits(slice_buffer, tab->len);
182
183 if(tab->run == 64) break; /* end_of_block */
184
185 if(tab->run == 65)
186 {
187/* escape */
188 i += mpeg3slice_getbits(slice_buffer, 6);
189
190 if((val = mpeg3slice_getbits(slice_buffer, 8)) == 0)
191 val = mpeg3slice_getbits(slice_buffer, 8);
192 else
193 if(val == 128)
194 val = mpeg3slice_getbits(slice_buffer, 8) - 256;
195 else
196 if(val > 128)
197 val -= 256;
198
199 if((sign = (val < 0)) != 0) val= -val;
200 }
201 else
202 {
203 i += tab->run;
204 val = tab->level;
205 sign = mpeg3slice_getbit(slice_buffer);
206 }
207
208 if(i < 64)
209 j = video->mpeg3_zigzag_scan_table[i];
210 else
211 {
212 slice->fault = 1;
213 return 1;
214 }
215
216
217#ifdef HAVE_MMX
218 if(video->have_mmx)
219 {
220 val = (val * slice->quant_scale * video->intra_quantizer_matrix[j]) << 1;
221 val = (val - 16) | 16;
222 }
223 else
224#endif
225 {
226 val = (val * slice->quant_scale * video->intra_quantizer_matrix[j]) >> 3;
227 val = (val - 1) | 1;
228 }
229
230 bp[j] = sign ? -val : val;
231 }
232
233 if(j != 0)
234 {
235/* not a sparse matrix ! */
236 slice->sparse[comp] = 0;
237 }
238 return 0;
239}
240
241
242/* decode one non-intra coded MPEG-1 block */
243
244int mpeg3video_getinterblock(mpeg3_slice_t *slice,
245 mpeg3video_t *video,
246 int comp)
247{
248 int val, i, j, sign;
249 unsigned int code;
250 mpeg3_DCTtab_t *tab;
251 short *bp = slice->block[comp];
252 mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer;
253
254/* decode AC coefficients */
255 for(i = 0; ; i++)
256 {
257 code = mpeg3slice_showbits16(slice_buffer);
258 if(code >= 16384)
259 {
260 if(i == 0)
261 tab = &mpeg3_DCTtabfirst[(code >> 12) - 4];
262 else
263 tab = &mpeg3_DCTtabnext[(code >> 12) - 4];
264 }
265 else
266 if(code >= 1024) tab = &mpeg3_DCTtab0[(code >> 8) - 4];
267 else
268 if(code >= 512) tab = &mpeg3_DCTtab1[(code >> 6) - 8];
269 else
270 if(code >= 256) tab = &mpeg3_DCTtab2[(code >> 4) - 16];
271 else
272 if(code >= 128) tab = &mpeg3_DCTtab3[(code >> 3) - 16];
273 else
274 if(code >= 64) tab = &mpeg3_DCTtab4[(code >> 2) - 16];
275 else
276 if(code >= 32) tab = &mpeg3_DCTtab5[(code >> 1) - 16];
277 else
278 if(code >= 16) tab = &mpeg3_DCTtab6[code - 16];
279 else
280 {
281// invalid Huffman code
282 slice->fault = 1;
283 return 1;
284 }
285
286 mpeg3slice_flushbits(slice_buffer, tab->len);
287
288/* end of block */
289 if(tab->run == 64)
290 break;
291
292 if(tab->run == 65)
293 {
294/* escape */
295 i += mpeg3slice_getbits(slice_buffer, 6);
296 if((val = mpeg3slice_getbits(slice_buffer, 8)) == 0)
297 val = mpeg3slice_getbits(slice_buffer, 8);
298 else
299 if(val == 128)
300 val = mpeg3slice_getbits(slice_buffer, 8) - 256;
301 else
302 if(val > 128)
303 val -= 256;
304
305 if((sign = (val < 0)) != 0) val = -val;
306 }
307 else
308 {
309 i += tab->run;
310 val = tab->level;
311 sign = mpeg3slice_getbit(slice_buffer);
312 }
313
314 j = video->mpeg3_zigzag_scan_table[i];
315
316#ifdef HAVE_MMX
317 if(video->have_mmx)
318 {
319 val = (((val << 1)+1) * slice->quant_scale * video->non_intra_quantizer_matrix[j]);
320 val = (val - 16) | 16;
321 }
322 else
323#endif
324 {
325 val = (((val << 1)+1) * slice->quant_scale * video->non_intra_quantizer_matrix[j]) >> 4;
326 val = (val - 1) | 1;
327 }
328
329 bp[j] = sign ? -val : val;
330 }
331
332 if(j != 0)
333 {
334/* not a sparse matrix ! */
335 slice->sparse[comp] = 0;
336 }
337 return 0;
338}
339
340
341/* decode one intra coded MPEG-2 block */
342int mpeg3video_getmpg2intrablock(mpeg3_slice_t *slice,
343 mpeg3video_t *video,
344 int comp,
345 int dc_dct_pred[])
346{
347 int val, i, j, sign, nc;
348 unsigned int code;
349 mpeg3_DCTtab_t *tab;
350 short *bp;
351 int *qmat;
352 mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer;
353
354/* with data partitioning, data always goes to base layer */
355 bp = slice->block[comp];
356
357 qmat = (comp < 4 || video->chroma_format == CHROMA420)
358 ? video->intra_quantizer_matrix
359 : video->chroma_intra_quantizer_matrix;
360
361/* decode DC coefficients */
362 if(comp < 4)
363 val = (dc_dct_pred[0] += mpeg3video_getdclum(slice_buffer));
364 else
365 if((comp & 1) == 0)
366 val = (dc_dct_pred[1] += mpeg3video_getdcchrom(slice_buffer));
367 else
368 val = (dc_dct_pred[2] += mpeg3video_getdcchrom(slice_buffer));
369
370 if(slice->fault) return 1;
371#ifdef HAVE_MMX
372 if(video->have_mmx)
373 bp[0] = val << (7 - video->dc_prec);
374 else
375#endif
376 bp[0] = val << (3 - video->dc_prec);
377
378 nc = 0;
379
380/* decode AC coefficients */
381 for(i = 1; ; i++)
382 {
383 code = mpeg3slice_showbits16(slice_buffer);
384
385 if(code >= 16384 && !video->intravlc)
386 tab = &mpeg3_DCTtabnext[(code >> 12) - 4];
387 else
388 if(code >= 1024)
389 {
390 if(video->intravlc)
391 tab = &mpeg3_DCTtab0a[(code >> 8) - 4];
392 else
393 tab = &mpeg3_DCTtab0[(code >> 8) - 4];
394 }
395 else
396 if(code >= 512)
397 {
398 if(video->intravlc)
399 tab = &mpeg3_DCTtab1a[(code >> 6) - 8];
400 else
401 tab = &mpeg3_DCTtab1[(code >> 6) - 8];
402 }
403 else
404 if(code >= 256) tab = &mpeg3_DCTtab2[(code >> 4) - 16];
405 else
406 if(code >= 128) tab = &mpeg3_DCTtab3[(code >> 3) - 16];
407 else
408 if(code >= 64) tab = &mpeg3_DCTtab4[(code >> 2) - 16];
409 else
410 if(code >= 32) tab = &mpeg3_DCTtab5[(code >> 1) - 16];
411 else
412 if(code >= 16) tab = &mpeg3_DCTtab6[code - 16];
413 else
414 {
415 /* fprintf(stderr,"mpeg3video_getmpg2intrablock: invalid Huffman code\n"); */
416 slice->fault = 1;
417 return 1;
418 }
419
420 mpeg3slice_flushbits(slice_buffer, tab->len);
421
422/* end_of_block */
423 if(tab->run == 64)
424 break;
425
426 if(tab->run == 65)
427 {
428/* escape */
429 i += mpeg3slice_getbits(slice_buffer, 6);
430
431 val = mpeg3slice_getbits(slice_buffer, 12);
432 if((val & 2047) == 0)
433 {
434// invalid signed_level (escape)
435 slice->fault = 1;
436 return 1;
437 }
438 if((sign = (val >= 2048)) != 0) val = 4096 - val;
439 }
440 else
441 {
442 i += tab->run;
443 val = tab->level;
444 sign = mpeg3slice_getbit(slice_buffer);
445 }
446
447 j = (video->altscan ? video->mpeg3_alternate_scan_table : video->mpeg3_zigzag_scan_table)[i];
448
449#ifdef HAVE_MMX
450 if(video->have_mmx)
451 val = (val * slice->quant_scale * qmat[j]);
452 else
453#endif
454 val = (val * slice->quant_scale * qmat[j]) >> 4;
455
456 bp[j] = sign ? -val : val;
457 nc++;
458 }
459
460 if(j != 0)
461 {
462/* not a sparse matrix ! */
463 slice->sparse[comp] = 0;
464 }
465 return 1;
466}
467
468
469/* decode one non-intra coded MPEG-2 block */
470
471int mpeg3video_getmpg2interblock(mpeg3_slice_t *slice,
472 mpeg3video_t *video,
473 int comp)
474{
475 int val, i, j, sign, nc;
476 unsigned int code;
477 mpeg3_DCTtab_t *tab;
478 short *bp;
479 int *qmat;
480 mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer;
481
482/* with data partitioning, data always goes to base layer */
483 bp = slice->block[comp];
484
485 qmat = (comp < 4 || video->chroma_format == CHROMA420)
486 ? video->non_intra_quantizer_matrix
487 : video->chroma_non_intra_quantizer_matrix;
488
489 nc = 0;
490
491/* decode AC coefficients */
492 for(i = 0; ; i++)
493 {
494 code = mpeg3slice_showbits16(slice_buffer);
495 if(code >= 16384)
496 {
497 if(i == 0) tab = &mpeg3_DCTtabfirst[(code >> 12) - 4];
498 else tab = &mpeg3_DCTtabnext[(code >> 12) - 4];
499 }
500 else
501 if(code >= 1024) tab = &mpeg3_DCTtab0[(code >> 8) - 4];
502 else
503 if(code >= 512) tab = &mpeg3_DCTtab1[(code >> 6) - 8];
504 else
505 if(code >= 256) tab = &mpeg3_DCTtab2[(code >> 4) - 16];
506 else
507 if(code >= 128) tab = &mpeg3_DCTtab3[(code >> 3) - 16];
508 else
509 if(code >= 64) tab = &mpeg3_DCTtab4[(code >> 2) - 16];
510 else
511 if(code >= 32) tab = &mpeg3_DCTtab5[(code >> 1) - 16];
512 else
513 if(code >= 16) tab = &mpeg3_DCTtab6[code - 16];
514 else
515 {
516// invalid Huffman code
517 slice->fault = 1;
518 return 1;
519 }
520
521 mpeg3slice_flushbits(slice_buffer, tab->len);
522
523/* end_of_block */
524 if(tab->run == 64)
525 break;
526
527 if(tab->run == 65)
528 {
529/* escape */
530 i += mpeg3slice_getbits(slice_buffer, 6);
531 val = mpeg3slice_getbits(slice_buffer, 12);
532 if((val & 2047) == 0)
533 {
534 /* fprintf(stderr, "mpeg3video_getmpg2interblock: invalid signed_level (escape)\n"); */
535 slice->fault = 1;
536 return 1;
537 }
538 if((sign = (val >= 2048)) != 0) val = 4096 - val;
539 }
540 else
541 {
542 i += tab->run;
543 val = tab->level;
544 sign = mpeg3slice_getbit(slice_buffer);
545 }
546
547 j = (video->altscan ? video->mpeg3_alternate_scan_table : video->mpeg3_zigzag_scan_table)[i];
548
549#ifdef HAVE_MMX
550 if(video->have_mmx)
551 val = (((val << 1)+1) * slice->quant_scale * qmat[j]) >> 1;
552 else
553#endif
554 val = (((val << 1)+1) * slice->quant_scale * qmat[j]) >> 5;
555
556 bp[j] = sign ? (-val) : val ;
557 nc++;
558 }
559
560 if(j != 0)
561 {
562 slice->sparse[comp] = 0;
563 }
564 return 0;
565}
566
567
568/* decode all macroblocks of the current picture */
569int mpeg3video_get_macroblocks(mpeg3video_t *video, int framenum)
570{
571 unsigned int code;
572 mpeg3_slice_buffer_t *slice_buffer; /* Buffer being loaded */
573 int i;
574 int current_buffer;
575 mpeg3_bits_t *vstream = video->vstream;
576
577/* Load every slice into a buffer array */
578 video->total_slice_buffers = 0;
579 current_buffer = 0;
580 while(!mpeg3bits_eof(vstream) &&
581 mpeg3bits_showbits32_noptr(vstream) >= MPEG3_SLICE_MIN_START &&
582 mpeg3bits_showbits32_noptr(vstream) <= MPEG3_SLICE_MAX_START)
583 {
584/* Initialize the buffer */
585 if(current_buffer >= video->slice_buffers_initialized)
586 mpeg3_new_slice_buffer(&(video->slice_buffers[video->slice_buffers_initialized++]));
587 slice_buffer = &(video->slice_buffers[current_buffer]);
588 slice_buffer->buffer_size = 0;
589 slice_buffer->current_position = 0;
590 slice_buffer->bits_size = 0;
591 slice_buffer->done = 0;
592
593/* Read the slice into the buffer including the slice start code */
594 do
595 {
596/* Expand buffer */
597 if(slice_buffer->buffer_allocation <= slice_buffer->buffer_size)
598 mpeg3_expand_slice_buffer(slice_buffer);
599
600/* Load 1 char into buffer */
601 slice_buffer->data[slice_buffer->buffer_size++] = mpeg3bits_getbyte_noptr(vstream);
602 }while(!mpeg3bits_eof(vstream) &&
603 mpeg3bits_showbits24_noptr(vstream) != MPEG3_PACKET_START_CODE_PREFIX);
604
605/* Pad the buffer to get the last macroblock */
606 if(slice_buffer->buffer_allocation <= slice_buffer->buffer_size + 4)
607 mpeg3_expand_slice_buffer(slice_buffer);
608
609 slice_buffer->data[slice_buffer->buffer_size++] = 0;
610 slice_buffer->data[slice_buffer->buffer_size++] = 0;
611 slice_buffer->data[slice_buffer->buffer_size++] = 1;
612 slice_buffer->data[slice_buffer->buffer_size++] = 0;
613 slice_buffer->bits_size = 0;
614
615 pthread_mutex_lock(&(slice_buffer->completion_lock)); fflush(stdout);
616 current_buffer++;
617 video->total_slice_buffers++;
618 }
619
620/* Run the slice decoders */
621 if(video->total_slice_buffers > 0)
622 {
623 for(i = 0; i < video->total_slice_decoders; i++)
624 {
625 if(i == 0 && video->total_slice_decoders > 1)
626 {
627 video->slice_decoders[i].current_buffer = 0;
628 video->slice_decoders[i].buffer_step = 1;
629 video->slice_decoders[i].last_buffer = (video->total_slice_buffers - 1);
630 }
631 else
632 if(i == 1)
633 {
634 video->slice_decoders[i].current_buffer = video->total_slice_buffers - 1;
635 video->slice_decoders[i].buffer_step = -1;
636 video->slice_decoders[i].last_buffer = 0;
637 }
638 else
639 {
640 video->slice_decoders[i].current_buffer = i;
641 video->slice_decoders[i].buffer_step = 1;
642 video->slice_decoders[i].last_buffer = video->total_slice_buffers - 1;
643 }
644 pthread_mutex_unlock(&(video->slice_decoders[i].input_lock));
645 }
646 }
647
648/* Wait for the slice decoders to finish */
649 if(video->total_slice_buffers > 0)
650 {
651 for(i = 0; i < video->total_slice_buffers; i++)
652 {
653 pthread_mutex_lock(&(video->slice_buffers[i].completion_lock));
654 pthread_mutex_unlock(&(video->slice_buffers[i].completion_lock));
655 }
656 }
657 return 0;
658}
659
660int mpeg3video_allocate_decoders(mpeg3video_t *video, int decoder_count)
661{
662 int i;
663 mpeg3_t *file = video->file;
664/* Get the slice decoders */
665 if(video->total_slice_decoders != file->cpus)
666 {
667 for(i = 0; i < video->total_slice_decoders; i++)
668 {
669 mpeg3_delete_slice_decoder(&video->slice_decoders[i]);
670 }
671
672 for(i = 0; i < file->cpus && i < MPEG3_MAX_CPUS; i++)
673 {
674 mpeg3_new_slice_decoder(video, &(video->slice_decoders[i]));
675 video->slice_decoders[i].thread_number = i;
676 }
677
678 video->total_slice_decoders = file->cpus;
679 }
680 return 0;
681}
682
683/* decode one frame or field picture */
684
685int mpeg3video_getpicture(mpeg3video_t *video, int framenum)
686{
687 int i, result = 0;
688 mpeg3_t *file = video->file;
689
690 if(video->pict_struct == FRAME_PICTURE && video->secondfield)
691 {
692/* recover from illegal number of field pictures */
693 video->secondfield = 0;
694 }
695
696 if(!video->mpeg2)
697 {
698 video->current_repeat = video->repeat_count = 0;
699 }
700
701 mpeg3video_allocate_decoders(video, file->cpus);
702
703 for(i = 0; i < 3; i++)
704 {
705 if(video->pict_type == B_TYPE)
706 {
707 video->newframe[i] = video->auxframe[i];
708 }
709 else
710 {
711 if(!video->secondfield && !video->current_repeat)
712 {
713/* Swap refframes for I frames */
714 unsigned char* tmp = video->oldrefframe[i];
715 video->oldrefframe[i] = video->refframe[i];
716 video->refframe[i] = tmp;
717 }
718
719 video->newframe[i] = video->refframe[i];
720 }
721
722 if(video->pict_struct == BOTTOM_FIELD)
723 {
724/* Only used if fields are in different pictures */
725 video->newframe[i] += (i == 0) ? video->coded_picture_width : video->chrom_width;
726 }
727 }
728
729/* The problem is when a B frame lands on the first repeat and is skipped, */
730/* the second repeat goes for the same bitmap as the skipped repeat, */
731/* so it picks up a frame from 3 frames back. */
732/* The first repeat must consititutively read a B frame if its B frame is going to be */
733/* used in a later repeat. */
734 if(!video->current_repeat)
735 if(!(video->skip_bframes && video->pict_type == B_TYPE) ||
736 (video->repeat_count >= 100 + 100 * video->skip_bframes))
737 result = mpeg3video_get_macroblocks(video, framenum);
738
739/* Set the frame to display */
740 video->output_src = 0;
741 if(framenum > -1 && !result)
742 {
743 if(video->pict_struct == FRAME_PICTURE || video->secondfield)
744 {
745 if(video->pict_type == B_TYPE)
746 {
747 video->output_src = video->auxframe;
748 }
749 else
750 {
751 video->output_src = video->oldrefframe;
752 }
753 }
754 else
755 {
756 mpeg3video_display_second_field(video);
757 }
758 }
759
760 if(video->mpeg2)
761 {
762 video->current_repeat += 100;
763 }
764
765 if(video->pict_struct != FRAME_PICTURE) video->secondfield = !video->secondfield;
766 return result;
767}