Mercurial > mplayer.hg
annotate libmpcodecs/vd_libmpeg2.c @ 10575:148f029ff426
Real Win32 vs Linux codec clarification.
author | diego |
---|---|
date | Tue, 12 Aug 2003 00:30:27 +0000 |
parents | 73b3e4336cd4 |
children | 711159267b2d |
rev | line source |
---|---|
4998 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 | |
4 #include "config.h" | |
8026
b465ba5897a3
usage of libmpeg2, liba52, mp3lib & svq1 can be disabled
arpi
parents:
7957
diff
changeset
|
5 #ifdef USE_LIBMPEG2 |
b465ba5897a3
usage of libmpeg2, liba52, mp3lib & svq1 can be disabled
arpi
parents:
7957
diff
changeset
|
6 |
4998 | 7 #include "mp_msg.h" |
8 | |
9 #include "vd_internal.h" | |
10 | |
9859 | 11 //#undef MPEG12_POSTPROC |
12 | |
4998 | 13 static vd_info_t info = |
14 { | |
9859 | 15 "MPEG 1/2 Video decoder libmpeg2-v0.3.1", |
4998 | 16 "libmpeg2", |
9859 | 17 "A'rpi & Fabian Franz", |
4998 | 18 "Aaron & Walken", |
19 "native" | |
20 }; | |
21 | |
22 LIBVD_EXTERN(libmpeg2) | |
23 | |
9859 | 24 //#include "libvo/video_out.h" // FIXME!!! |
5465 | 25 |
4998 | 26 #include "libmpeg2/mpeg2.h" |
27 #include "libmpeg2/mpeg2_internal.h" | |
9859 | 28 //#include "libmpeg2/convert.h" |
4998 | 29 |
5465 | 30 #include "../cpudetect.h" |
31 | |
4998 | 32 // to set/get/query special features/parameters |
33 static int control(sh_video_t *sh,int cmd,void* arg,...){ | |
34 return CONTROL_UNKNOWN; | |
35 } | |
36 | |
37 // init driver | |
38 static int init(sh_video_t *sh){ | |
9859 | 39 mpeg2dec_t * mpeg2dec; |
40 const mpeg2_info_t * info; | |
41 int accel; | |
5465 | 42 |
9859 | 43 accel = 0; |
44 if(gCpuCaps.hasMMX) | |
45 accel |= MPEG2_ACCEL_X86_MMX; | |
46 if(gCpuCaps.hasMMX2) | |
47 accel |= MPEG2_ACCEL_X86_MMXEXT; | |
48 if(gCpuCaps.has3DNow) | |
49 accel |= MPEG2_ACCEL_X86_3DNOW; | |
10267
d953763cc555
libmpeg2-altivec patch by Magnus Damm <damm@opensource.se>:
arpi
parents:
10250
diff
changeset
|
50 if(gCpuCaps.hasAltiVec) |
d953763cc555
libmpeg2-altivec patch by Magnus Damm <damm@opensource.se>:
arpi
parents:
10250
diff
changeset
|
51 accel |= MPEG2_ACCEL_PPC_ALTIVEC; |
9859 | 52 #ifdef HAVE_MLIB |
53 accel |= MPEG2_ACCEL_MLIB; | |
54 #endif | |
55 mpeg2_accel(accel); | |
5465 | 56 |
9859 | 57 mpeg2dec = mpeg2_init (); |
58 | |
59 if(!mpeg2dec) return 0; | |
60 | |
61 mpeg2_custom_fbuf(mpeg2dec,1); // enable DR1 | |
5675
0ff1b9ab7afc
slices+field pictures fixed, initial sig11 workaround
arpi
parents:
5613
diff
changeset
|
62 |
9859 | 63 sh->context=mpeg2dec; |
64 | |
65 return 1; | |
66 //return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12); | |
4998 | 67 } |
68 | |
69 // uninit driver | |
70 static void uninit(sh_video_t *sh){ | |
9859 | 71 mpeg2dec_t * mpeg2dec = sh->context; |
72 mpeg2_close (mpeg2dec); | |
4998 | 73 } |
74 | |
9859 | 75 static void draw_slice (void * _sh, uint8_t ** src, unsigned int y){ |
76 sh_video_t* sh = (sh_video_t*) _sh; | |
77 mpeg2dec_t* mpeg2dec = sh->context; | |
78 const mpeg2_info_t * info = mpeg2_info (mpeg2dec); | |
79 int stride[3]; | |
5465 | 80 |
9938 | 81 // printf("draw_slice() y=%d \n",y); |
5465 | 82 |
9859 | 83 stride[0]=mpeg2dec->decoder.stride; |
84 stride[1]=stride[2]=mpeg2dec->decoder.uv_stride; | |
5465 | 85 |
9859 | 86 mpcodecs_draw_slice(sh, (uint8_t **)src, |
87 stride, info->sequence->display_width, | |
88 (y+16<=info->sequence->display_height) ? 16 : | |
89 info->sequence->display_height-y, | |
90 0, y); | |
4998 | 91 } |
92 | |
5465 | 93 // decode a frame |
94 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
9859 | 95 mpeg2dec_t * mpeg2dec = sh->context; |
96 const mpeg2_info_t * info = mpeg2_info (mpeg2dec); | |
97 mp_image_t* mpi=NULL; | |
98 int drop_frame, framedrop=flags&3; | |
99 | |
100 // append extra 'end of frame' code: | |
101 ((char*)data+len)[0]=0; | |
102 ((char*)data+len)[1]=0; | |
103 ((char*)data+len)[2]=1; | |
104 ((char*)data+len)[3]=0xff; | |
105 len+=4; | |
5465 | 106 |
9859 | 107 mpeg2_buffer (mpeg2dec, data, data+len); |
108 | |
109 while(1){ | |
110 int state=mpeg2_parse (mpeg2dec); | |
111 switch(state){ | |
112 case -1: | |
113 // parsing of the passed buffer finished, return. | |
114 // if(!mpi) printf("\nNO PICTURE!\n"); | |
115 return mpi; | |
116 case STATE_SEQUENCE: | |
117 // video parameters inited/changed, (re)init libvo: | |
118 if(!mpcodecs_config_vo(sh, | |
119 info->sequence->width, | |
120 info->sequence->height, IMGFMT_YV12)) return 0; | |
121 break; | |
122 case STATE_PICTURE: { | |
123 int type=info->current_picture->flags&PIC_MASK_CODING_TYPE; | |
124 mp_image_t* mpi; | |
125 | |
126 drop_frame = framedrop && (mpeg2dec->decoder.coding_type == B_TYPE); | |
127 drop_frame |= framedrop>=2; // hard drop | |
128 if (drop_frame) { | |
129 mpeg2_skip(mpeg2dec, 1); | |
130 //printf("Dropping Frame ...\n"); | |
131 break; | |
132 } | |
133 mpeg2_skip(mpeg2dec, 0); //mpeg2skip skips frames until set again to 0 | |
134 | |
135 // get_buffer "callback": | |
136 mpi=mpcodecs_get_image(sh,MP_IMGTYPE_IPB, | |
137 (type==PIC_FLAG_CODING_TYPE_B) | |
138 ? ((!framedrop && vd_use_slices && | |
139 (info->current_picture->flags&PIC_FLAG_PROGRESSIVE_FRAME)) ? | |
140 MP_IMGFLAG_DRAW_CALLBACK:0) | |
141 : (MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE), | |
10250 | 142 (info->sequence->picture_width+15)&(~15), |
143 (info->sequence->picture_height+15)&(~15) ); | |
9859 | 144 if(!mpi) return 0; // VO ERROR!!!!!!!! |
145 mpeg2_set_buf(mpeg2dec, mpi->planes, mpi); | |
10510
73b3e4336cd4
Add mpeg2_flags to mp_image_t, copy flags in vd_libmpeg2.c,
ranma
parents:
10267
diff
changeset
|
146 if (info->current_picture->flags&PIC_FLAG_TOP_FIELD_FIRST) |
73b3e4336cd4
Add mpeg2_flags to mp_image_t, copy flags in vd_libmpeg2.c,
ranma
parents:
10267
diff
changeset
|
147 mpi->mpeg2_flags |= MP_IMGMPEG2FLAG_TOP_FIELD_FIRST; |
73b3e4336cd4
Add mpeg2_flags to mp_image_t, copy flags in vd_libmpeg2.c,
ranma
parents:
10267
diff
changeset
|
148 else mpi->mpeg2_flags &= ~MP_IMGMPEG2FLAG_TOP_FIELD_FIRST; |
73b3e4336cd4
Add mpeg2_flags to mp_image_t, copy flags in vd_libmpeg2.c,
ranma
parents:
10267
diff
changeset
|
149 if (info->current_picture->flags&PIC_FLAG_REPEAT_FIRST_FIELD) |
73b3e4336cd4
Add mpeg2_flags to mp_image_t, copy flags in vd_libmpeg2.c,
ranma
parents:
10267
diff
changeset
|
150 mpi->mpeg2_flags |= MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD; |
73b3e4336cd4
Add mpeg2_flags to mp_image_t, copy flags in vd_libmpeg2.c,
ranma
parents:
10267
diff
changeset
|
151 else mpi->mpeg2_flags &= ~MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD; |
9859 | 152 |
153 #ifdef MPEG12_POSTPROC | |
154 if(!mpi->qscale){ | |
10250 | 155 mpi->qstride=(info->sequence->picture_width+15)>>4; |
156 mpi->qscale=malloc(mpi->qstride*((info->sequence->picture_height+15)>>4)); | |
9859 | 157 } |
158 mpeg2dec->decoder.quant_store=mpi->qscale; | |
159 mpeg2dec->decoder.quant_stride=mpi->qstride; | |
160 mpi->pict_type=type; // 1->I, 2->P, 3->B | |
9925
420640a0f6d0
passing qscale_type around so the pp code can fix the mpeg2 <<1 thing
michael
parents:
9919
diff
changeset
|
161 mpi->qscale_type= 1; |
5465 | 162 #endif |
163 | |
9859 | 164 if(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && |
165 !(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
166 // nice, filter/vo likes draw_callback :) | |
167 mpeg2dec->decoder.convert=draw_slice; | |
168 mpeg2dec->decoder.fbuf_id=sh; | |
169 } else | |
170 mpeg2dec->decoder.convert=NULL; | |
171 break; | |
172 } | |
173 case STATE_SLICE: | |
174 case STATE_END: | |
175 // decoding done: | |
176 if(mpi) printf("AJAJJJJJJJJ2!\n"); | |
177 if(info->display_fbuf) mpi=info->display_fbuf->id; | |
178 // return mpi; | |
7957
31fd09cc9ba2
passing picture_type (might be usefull for postprocessing)
michael
parents:
7756
diff
changeset
|
179 } |
31fd09cc9ba2
passing picture_type (might be usefull for postprocessing)
michael
parents:
7756
diff
changeset
|
180 } |
5465 | 181 } |
8026
b465ba5897a3
usage of libmpeg2, liba52, mp3lib & svq1 can be disabled
arpi
parents:
7957
diff
changeset
|
182 #endif |