annotate libmpeg2/decode.c @ 2637:8101229be3a5

code cleanup
author nick
date Fri, 02 Nov 2001 18:24:25 +0000
parents 0cc88042ff21
children b3624c70aba2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 /* Copyright (C) Aaron Holtzman <aholtzma@ess.engr.uvic.ca> - Nov 1999 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 /* Some cleanup & hacking by A'rpi/ESP-team - Oct 2000 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 /* mpeg2dec version: */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 #define PACKAGE "mpeg2dec"
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
6 #define VERSION "0.2.0-release"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 #include <stdio.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 #include <stdlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 #include <unistd.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 #include <fcntl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 #include <errno.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13
111
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
14 #include <signal.h>
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
15 #include <setjmp.h>
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
16
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
17
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 #include "config.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
20 #include "video_out.h"
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
21 #include <inttypes.h>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 #include "mpeg2.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 #include "mpeg2_internal.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 #include "../linux/shmem.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 //#include "motion_comp.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 //#include "idct.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 //#include "header.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 //#include "slice.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 //#include "stats.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 #include "attributes.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 #ifdef __i386__
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 #include "mmx.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
39 #include "mm_accel.h"
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
40
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
41
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 //this is where we keep the state of the decoder
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 //picture_t picture_data;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 //picture_t *picture=&picture_data;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 picture_t *picture=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 //global config struct
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 mpeg2_config_t config;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 // the maximum chunk size is determined by vbv_buffer_size which is 224K for
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 // MP@ML streams. (we make no pretenses ofdecoding anything more than that)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 //static uint8_t chunk_buffer[224 * 1024 + 4];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 //static uint32_t shift = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54
967
5f07e67982d6 -framedrop worx fro mpeg files
arpi_esp
parents: 499
diff changeset
55 //static int drop_flag = 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 static int drop_frame = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57
41
0d76b2b962ad added mpeg 1/2 postprocessing
arpi_esp
parents: 36
diff changeset
58 #ifdef MPEG12_POSTPROC
2187
c568f4fffb0a postprocess fixes
arpi
parents: 2080
diff changeset
59 #include "../postproc/postprocess.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 int quant_store[MBR+1][MBC+1]; // [Review]
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
61 #endif
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62
1636
3c33deb3e561 do table permutation only once
arpi
parents: 967
diff changeset
63 static table_init_state=0;
3c33deb3e561 do table permutation only once
arpi
parents: 967
diff changeset
64
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 void mpeg2_init (void)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67
499
3601edb3805c printfs changed...
arpi_esp
parents: 204
diff changeset
68 printf (PACKAGE"-"VERSION" (C) 2000-2001 Aaron Holtzman & Michel Lespinasse\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 config.flags = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 #ifdef HAVE_MMX
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 config.flags |= MM_ACCEL_X86_MMX;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 #ifdef HAVE_SSE
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 config.flags |= MM_ACCEL_X86_MMXEXT;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 #ifdef HAVE_3DNOW
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 config.flags |= MM_ACCEL_X86_3DNOW;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 #ifdef HAVE_MLIB
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 config.flags |= MM_ACCEL_MLIB;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82
499
3601edb3805c printfs changed...
arpi_esp
parents: 204
diff changeset
83 // printf("libmpeg2 config flags = 0x%X\n",config.flags);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84
1652
e78cf3fc992e shmem_alloc->memalign, adding function to free memory
arpi
parents: 1636
diff changeset
85 picture=malloc(sizeof(picture_t)); // !!! NEW HACK :) !!!
1655
1d741dfa190c zeroing picture struct
arpi
parents: 1652
diff changeset
86 memset(picture,0,sizeof(picture_t));
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 header_state_init (picture);
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
89 // picture->repeat_count=0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 picture->pp_options=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92
1636
3c33deb3e561 do table permutation only once
arpi
parents: 967
diff changeset
93 if(!table_init_state){
3c33deb3e561 do table permutation only once
arpi
parents: 967
diff changeset
94 idct_init ();
3c33deb3e561 do table permutation only once
arpi
parents: 967
diff changeset
95 motion_comp_init ();
3c33deb3e561 do table permutation only once
arpi
parents: 967
diff changeset
96 table_init_state=1;
3c33deb3e561 do table permutation only once
arpi
parents: 967
diff changeset
97 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99
41
0d76b2b962ad added mpeg 1/2 postprocessing
arpi_esp
parents: 36
diff changeset
100 static vo_frame_t frames[4];
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
101
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 void mpeg2_allocate_image_buffers (picture_t * picture)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 int frame_size,buff_size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 unsigned char *base=NULL;
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
106 int i;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 // height+1 requires for yuv2rgb_mmx code (it reads next line after last)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 frame_size = picture->coded_picture_width * (1+picture->coded_picture_height);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 frame_size = (frame_size+31)&(~31); // align to 32 byte boundary
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 buff_size = frame_size + (frame_size/4)*2; // 4Y + 1U + 1V
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 // allocate images in YV12 format
41
0d76b2b962ad added mpeg 1/2 postprocessing
arpi_esp
parents: 36
diff changeset
114 #ifdef MPEG12_POSTPROC
0d76b2b962ad added mpeg 1/2 postprocessing
arpi_esp
parents: 36
diff changeset
115 for(i=0;i<4;i++){
0d76b2b962ad added mpeg 1/2 postprocessing
arpi_esp
parents: 36
diff changeset
116 #else
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
117 for(i=0;i<3;i++){
41
0d76b2b962ad added mpeg 1/2 postprocessing
arpi_esp
parents: 36
diff changeset
118 #endif
2080
f91ad6d23ce9 gcc3 warning fixed
arpi
parents: 2019
diff changeset
119 base = (unsigned char *)memalign(64,buff_size);
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
120 frames[i].base[0] = base;
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
121 frames[i].base[1] = base + frame_size * 5 / 4;
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
122 frames[i].base[2] = base + frame_size;
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
123 frames[i].copy = NULL;
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
124 frames[i].vo = NULL;
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
125 }
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
126
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
127 picture->forward_reference_frame=&frames[0];
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
128 picture->backward_reference_frame=&frames[1];
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
129 picture->current_frame=&frames[2];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132
1652
e78cf3fc992e shmem_alloc->memalign, adding function to free memory
arpi
parents: 1636
diff changeset
133 void mpeg2_free_image_buffers (picture_t * picture){
e78cf3fc992e shmem_alloc->memalign, adding function to free memory
arpi
parents: 1636
diff changeset
134 int i;
e78cf3fc992e shmem_alloc->memalign, adding function to free memory
arpi
parents: 1636
diff changeset
135
e78cf3fc992e shmem_alloc->memalign, adding function to free memory
arpi
parents: 1636
diff changeset
136 #ifdef MPEG12_POSTPROC
e78cf3fc992e shmem_alloc->memalign, adding function to free memory
arpi
parents: 1636
diff changeset
137 for(i=0;i<4;i++){
e78cf3fc992e shmem_alloc->memalign, adding function to free memory
arpi
parents: 1636
diff changeset
138 #else
e78cf3fc992e shmem_alloc->memalign, adding function to free memory
arpi
parents: 1636
diff changeset
139 for(i=0;i<3;i++){
e78cf3fc992e shmem_alloc->memalign, adding function to free memory
arpi
parents: 1636
diff changeset
140 #endif
e78cf3fc992e shmem_alloc->memalign, adding function to free memory
arpi
parents: 1636
diff changeset
141 free(frames[i].base[0]);
e78cf3fc992e shmem_alloc->memalign, adding function to free memory
arpi
parents: 1636
diff changeset
142 }
e78cf3fc992e shmem_alloc->memalign, adding function to free memory
arpi
parents: 1636
diff changeset
143
e78cf3fc992e shmem_alloc->memalign, adding function to free memory
arpi
parents: 1636
diff changeset
144 }
e78cf3fc992e shmem_alloc->memalign, adding function to free memory
arpi
parents: 1636
diff changeset
145
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
146 static void copy_slice (vo_frame_t * frame, uint8_t ** src){
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
147 vo_functions_t * output = frame->vo;
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
148 int stride[3];
79
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
149 int y=picture->slice<<4;
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
150 uint8_t* src_tmp[3];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
152 stride[0]=picture->coded_picture_width;
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
153 stride[1]=stride[2]=stride[0]/2;
79
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
154
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
155 if(frame!=picture->display_frame){
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
156 uint8_t** base=picture->display_frame->base;
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
157 src_tmp[0]=base[0]+stride[0]*y;
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
158 src_tmp[1]=base[1]+stride[1]*(y>>1);
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
159 src_tmp[2]=base[2]+stride[2]*(y>>1);
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
160 src=src_tmp;
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
161 }
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
162
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
163 output->draw_slice (src,
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
164 stride, picture->display_picture_width,
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
165 (y+16<=picture->display_picture_height) ? 16 :
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
166 picture->display_picture_height-y,
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
167 0, y);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168
79
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
169 ++picture->slice;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 }
2253
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
171 void draw_frame(vo_functions_t * output)
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
172 {
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
173 int stride[3];
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
174
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
175 stride[0]=picture->coded_picture_width;
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
176 stride[1]=stride[2]=stride[0]/2;
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
177 #ifdef MPEG12_POSTPROC
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
178 if( picture->pp_options )
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
179 {// apply postprocess filter
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
180 postprocess((picture->picture_coding_type == B_TYPE) ?
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
181 picture->current_frame->base :
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
182 picture->forward_reference_frame->base,
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
183 stride[0], frames[3].base, stride[0],
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
184 picture->coded_picture_width, picture->coded_picture_height,
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
185 &quant_store[1][1], (MBC+1), picture->pp_options);
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
186 output->draw_slice (frames[3].base, stride,
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
187 picture->display_picture_width,
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
188 picture->display_picture_height, 0, 0);
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
189 }else
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
190 #endif
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
191 {
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
192 output->draw_slice ((picture->picture_coding_type == B_TYPE) ?
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
193 picture->current_frame->base :
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
194 picture->forward_reference_frame->base,
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
195 stride,
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
196 picture->display_picture_width,
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
197 picture->display_picture_height, 0, 0);
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
198 }
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
199 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201 static int in_slice_flag=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202
967
5f07e67982d6 -framedrop worx fro mpeg files
arpi_esp
parents: 499
diff changeset
203 static int parse_chunk (vo_functions_t * output, int code, uint8_t * buffer, int framedrop)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 int is_frame_done = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 stats_header (code, buffer);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 is_frame_done = in_slice_flag && ((!code) || (code >= 0xb0));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 if (is_frame_done) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 in_slice_flag = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
213 // if(picture->picture_structure != FRAME_PICTURE) printf("Field! %d \n",picture->second_field);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214
2019
7de4eceac32f mpeg2-interlaced patch by Ivan Kalvatchev <iive@yahoo.com>
arpi
parents: 1655
diff changeset
215 if(picture->picture_structure == FRAME_PICTURE)
7de4eceac32f mpeg2-interlaced patch by Ivan Kalvatchev <iive@yahoo.com>
arpi
parents: 1655
diff changeset
216 {
41
0d76b2b962ad added mpeg 1/2 postprocessing
arpi_esp
parents: 36
diff changeset
217 #ifdef MPEG12_POSTPROC
2253
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
218 if( (picture->pp_options) && (!framedrop) )
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
219 draw_frame(output);
2019
7de4eceac32f mpeg2-interlaced patch by Ivan Kalvatchev <iive@yahoo.com>
arpi
parents: 1655
diff changeset
220 #endif
2253
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
221 }else
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
222 {
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
223 if( (picture->second_field) && (!framedrop) )
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
224 draw_frame(output);
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
225 else
0cc88042ff21 enable postprocess for interlaced fields
iive
parents: 2187
diff changeset
226 is_frame_done=0;// we don't draw first fields
2019
7de4eceac32f mpeg2-interlaced patch by Ivan Kalvatchev <iive@yahoo.com>
arpi
parents: 1655
diff changeset
227 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 #ifdef ARCH_X86
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
229 if (config.flags & MM_ACCEL_X86_MMX) emms();
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 #endif
116
a6bba36c8db7 vo->flip_page() call removed
arpi_esp
parents: 114
diff changeset
231 // output->flip_page();
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 switch (code) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235 case 0x00: /* picture_start_code */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 if (header_process_picture_header (picture, buffer)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 printf ("bad picture header\n");
114
47515462adc0 removed exit(1);
arpi_esp
parents: 111
diff changeset
238 //exit (1);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240
967
5f07e67982d6 -framedrop worx fro mpeg files
arpi_esp
parents: 499
diff changeset
241 drop_frame = framedrop && (picture->picture_coding_type == B_TYPE);
5f07e67982d6 -framedrop worx fro mpeg files
arpi_esp
parents: 499
diff changeset
242 drop_frame |= framedrop>=2; // hard drop
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 //decode_reorder_frames ();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 case 0xb3: /* sequence_header_code */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 if (header_process_sequence_header (picture, buffer)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 printf ("bad sequence header\n");
114
47515462adc0 removed exit(1);
arpi_esp
parents: 111
diff changeset
249 //exit (1);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 case 0xb5: /* extension_start_code */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 if (header_process_extension (picture, buffer)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 printf ("bad extension\n");
114
47515462adc0 removed exit(1);
arpi_esp
parents: 111
diff changeset
256 //exit (1);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 default:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 // if (code >= 0xb9) printf ("stream not demultiplexed ?\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262 if (code >= 0xb0) break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 if (!(in_slice_flag)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265 in_slice_flag = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
267 // if(!(picture->second_field)) decode_reorder_frames ();
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
268
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
269 // set current_frame pointer:
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
270 if (picture->second_field){
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
271 // vo_field (picture->current_frame, picture->picture_structure);
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
272 } else {
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
273 if (picture->picture_coding_type == B_TYPE){
79
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
274 picture->display_frame=
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
275 picture->current_frame = &frames[2];
79
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
276 // picture->current_frame->copy=copy_slice;
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
277 } else {
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
278 picture->current_frame = picture->forward_reference_frame;
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
279 picture->display_frame=
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
280 picture->forward_reference_frame = picture->backward_reference_frame;
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
281 picture->backward_reference_frame = picture->current_frame;
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
282 // picture->current_frame->copy=NULL;
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
283 }
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
284 }
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
285
41
0d76b2b962ad added mpeg 1/2 postprocessing
arpi_esp
parents: 36
diff changeset
286 #ifdef MPEG12_POSTPROC
2019
7de4eceac32f mpeg2-interlaced patch by Ivan Kalvatchev <iive@yahoo.com>
arpi
parents: 1655
diff changeset
287 if(picture->pp_options)
7de4eceac32f mpeg2-interlaced patch by Ivan Kalvatchev <iive@yahoo.com>
arpi
parents: 1655
diff changeset
288 picture->current_frame->copy=NULL;
7de4eceac32f mpeg2-interlaced patch by Ivan Kalvatchev <iive@yahoo.com>
arpi
parents: 1655
diff changeset
289 else
41
0d76b2b962ad added mpeg 1/2 postprocessing
arpi_esp
parents: 36
diff changeset
290 #endif
2019
7de4eceac32f mpeg2-interlaced patch by Ivan Kalvatchev <iive@yahoo.com>
arpi
parents: 1655
diff changeset
291 picture->current_frame->copy=copy_slice;
7de4eceac32f mpeg2-interlaced patch by Ivan Kalvatchev <iive@yahoo.com>
arpi
parents: 1655
diff changeset
292
7de4eceac32f mpeg2-interlaced patch by Ivan Kalvatchev <iive@yahoo.com>
arpi
parents: 1655
diff changeset
293
7de4eceac32f mpeg2-interlaced patch by Ivan Kalvatchev <iive@yahoo.com>
arpi
parents: 1655
diff changeset
294 if ((framedrop) || (picture->picture_structure != FRAME_PICTURE) )
7de4eceac32f mpeg2-interlaced patch by Ivan Kalvatchev <iive@yahoo.com>
arpi
parents: 1655
diff changeset
295 picture->current_frame->copy=NULL;
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
296 picture->current_frame->vo=output;
79
b7b038ee3fde backward-frame rendering by slices
arpi_esp
parents: 41
diff changeset
297 picture->slice=0;
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
298
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
301 if (!drop_frame) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
303 slice_process (picture, code, buffer);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
304
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305 #ifdef ARCH_X86
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
306 if (config.flags & MM_ACCEL_X86_MMX) emms ();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
307 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
308
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
309 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
310 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
311
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312 return is_frame_done;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
313 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
314
111
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
315 static jmp_buf mpeg2_jmp_buf;
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
316
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
317 static void mpeg2_sighandler(int sig){
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
318 longjmp(mpeg2_jmp_buf,1);
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
319 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
320
967
5f07e67982d6 -framedrop worx fro mpeg files
arpi_esp
parents: 499
diff changeset
321 int mpeg2_decode_data (vo_functions_t *output, uint8_t *current, uint8_t *end,int framedrop)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
322 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
323 //static uint8_t code = 0xff;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
324 //static uint8_t chunk_buffer[65536];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
325 //static uint8_t *chunk_ptr = chunk_buffer;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
326 //static uint32_t shift = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
327 uint8_t code;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
328 uint8_t *pos=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
329 uint8_t *start=current;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
330 int ret = 0;
111
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
331 void* old_sigh;
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
332
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
333 if(setjmp(mpeg2_jmp_buf)!=0){
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
334 printf("@@@ FATAL!!!??? libmpeg2 returned from sig11 before the actual decoding! @@@\n");
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
335 return 0;
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
336 }
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
337
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
338 old_sigh=signal(SIGSEGV,mpeg2_sighandler);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
339
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
340 // printf("RCVD %d bytes\n",end-current);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
341
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
342 while(current<end){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
343 // FIND NEXT HEAD:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
344 unsigned int head=-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
345 uint8_t c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
346 //--------------------
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
347 while(current<end){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
348 c=current[0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
349 ++current;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
350 head<<=8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
351 if(head==0x100) break; // synced
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
352 head|=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
353 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
354 //--------------------
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
355 if(pos){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
356 //if((code&0x100)!=0x100) printf("libmpeg2: FATAL! code=%X\n",code);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
357 //printf("pos=%d chunk %3X size=%d next-code=%X\n",pos-start,code,current-pos,head|c);
111
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
358 if(setjmp(mpeg2_jmp_buf)==0){
967
5f07e67982d6 -framedrop worx fro mpeg files
arpi_esp
parents: 499
diff changeset
359 ret+=parse_chunk(output, code&0xFF, pos, framedrop);
111
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
360 } else {
204
56f4cfbcadd5 MMX fix (missing emms() in sig11handler)
arpi_esp
parents: 116
diff changeset
361 #ifdef ARCH_X86
56f4cfbcadd5 MMX fix (missing emms() in sig11handler)
arpi_esp
parents: 116
diff changeset
362 if (config.flags & MM_ACCEL_X86_MMX) emms ();
56f4cfbcadd5 MMX fix (missing emms() in sig11handler)
arpi_esp
parents: 116
diff changeset
363 #endif
499
3601edb3805c printfs changed...
arpi_esp
parents: 204
diff changeset
364 printf("@@@ libmpeg2 returned from sig11... (bad file?) @@@\n");
111
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
365 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
366 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
367 //--------------------
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
368 pos=current;code=head|c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
369 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
370
111
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
371 signal(SIGSEGV,old_sigh); // restore sighandler
3b4ccfecb823 using setjmp/longjmp to handle sig11 in libmpeg2
arpi_esp
parents: 79
diff changeset
372
967
5f07e67982d6 -framedrop worx fro mpeg files
arpi_esp
parents: 499
diff changeset
373 if(code==0x1FF) ret+=parse_chunk(output, 0xFF, NULL, framedrop); // send 'end of frame'
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
374
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
375 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
376 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
377
967
5f07e67982d6 -framedrop worx fro mpeg files
arpi_esp
parents: 499
diff changeset
378 //void mpeg2_drop (int flag)
5f07e67982d6 -framedrop worx fro mpeg files
arpi_esp
parents: 499
diff changeset
379 //{
5f07e67982d6 -framedrop worx fro mpeg files
arpi_esp
parents: 499
diff changeset
380 // drop_flag = flag;
5f07e67982d6 -framedrop worx fro mpeg files
arpi_esp
parents: 499
diff changeset
381 //}
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
382