Mercurial > mplayer.hg
annotate libmpcodecs/vd_libmpeg2.c @ 13082:1c86edd4e51a
spelling
author | diego |
---|---|
date | Sun, 22 Aug 2004 14:50:51 +0000 |
parents | cda4ad0d3e70 |
children | 3e4bea88c1c1 |
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 { | |
12932 | 15 "MPEG 1/2 Video decoder libmpeg2-v0.4.0b", |
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" |
12932 | 27 #include "libmpeg2/attributes.h" |
4998 | 28 #include "libmpeg2/mpeg2_internal.h" |
9859 | 29 //#include "libmpeg2/convert.h" |
4998 | 30 |
5465 | 31 #include "../cpudetect.h" |
32 | |
4998 | 33 // to set/get/query special features/parameters |
34 static int control(sh_video_t *sh,int cmd,void* arg,...){ | |
35 return CONTROL_UNKNOWN; | |
36 } | |
37 | |
38 // init driver | |
39 static int init(sh_video_t *sh){ | |
9859 | 40 mpeg2dec_t * mpeg2dec; |
41 const mpeg2_info_t * info; | |
42 int accel; | |
5465 | 43 |
9859 | 44 accel = 0; |
45 if(gCpuCaps.hasMMX) | |
46 accel |= MPEG2_ACCEL_X86_MMX; | |
47 if(gCpuCaps.hasMMX2) | |
48 accel |= MPEG2_ACCEL_X86_MMXEXT; | |
49 if(gCpuCaps.has3DNow) | |
50 accel |= MPEG2_ACCEL_X86_3DNOW; | |
10267
d953763cc555
libmpeg2-altivec patch by Magnus Damm <damm@opensource.se>:
arpi
parents:
10250
diff
changeset
|
51 if(gCpuCaps.hasAltiVec) |
d953763cc555
libmpeg2-altivec patch by Magnus Damm <damm@opensource.se>:
arpi
parents:
10250
diff
changeset
|
52 accel |= MPEG2_ACCEL_PPC_ALTIVEC; |
9859 | 53 #ifdef HAVE_MLIB |
54 accel |= MPEG2_ACCEL_MLIB; | |
55 #endif | |
56 mpeg2_accel(accel); | |
5465 | 57 |
9859 | 58 mpeg2dec = mpeg2_init (); |
59 | |
60 if(!mpeg2dec) return 0; | |
61 | |
62 mpeg2_custom_fbuf(mpeg2dec,1); // enable DR1 | |
5675
0ff1b9ab7afc
slices+field pictures fixed, initial sig11 workaround
arpi
parents:
5613
diff
changeset
|
63 |
9859 | 64 sh->context=mpeg2dec; |
65 | |
66 return 1; | |
67 //return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12); | |
4998 | 68 } |
69 | |
70 // uninit driver | |
71 static void uninit(sh_video_t *sh){ | |
9859 | 72 mpeg2dec_t * mpeg2dec = sh->context; |
73 mpeg2_close (mpeg2dec); | |
4998 | 74 } |
75 | |
9859 | 76 static void draw_slice (void * _sh, uint8_t ** src, unsigned int y){ |
77 sh_video_t* sh = (sh_video_t*) _sh; | |
78 mpeg2dec_t* mpeg2dec = sh->context; | |
79 const mpeg2_info_t * info = mpeg2_info (mpeg2dec); | |
80 int stride[3]; | |
5465 | 81 |
9938 | 82 // printf("draw_slice() y=%d \n",y); |
5465 | 83 |
9859 | 84 stride[0]=mpeg2dec->decoder.stride; |
85 stride[1]=stride[2]=mpeg2dec->decoder.uv_stride; | |
5465 | 86 |
9859 | 87 mpcodecs_draw_slice(sh, (uint8_t **)src, |
12572
7d681d8ebab8
display height may be a lot smaller or larger than picture height, sample provided by winnicki
iive
parents:
11080
diff
changeset
|
88 stride, info->sequence->picture_width, |
7d681d8ebab8
display height may be a lot smaller or larger than picture height, sample provided by winnicki
iive
parents:
11080
diff
changeset
|
89 (y+16<=info->sequence->picture_height) ? 16 : |
7d681d8ebab8
display height may be a lot smaller or larger than picture height, sample provided by winnicki
iive
parents:
11080
diff
changeset
|
90 info->sequence->picture_height-y, |
9859 | 91 0, y); |
4998 | 92 } |
93 | |
5465 | 94 // decode a frame |
95 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
9859 | 96 mpeg2dec_t * mpeg2dec = sh->context; |
97 const mpeg2_info_t * info = mpeg2_info (mpeg2dec); | |
98 mp_image_t* mpi=NULL; | |
99 int drop_frame, framedrop=flags&3; | |
100 | |
11080
26f1b3ad4a77
skip null frames in mpeg files, patch by Zoltan Hidvegi <mplayer@hzoli.2y.net>
attila
parents:
10663
diff
changeset
|
101 if(len<=0) return NULL; // skipped null frame |
26f1b3ad4a77
skip null frames in mpeg files, patch by Zoltan Hidvegi <mplayer@hzoli.2y.net>
attila
parents:
10663
diff
changeset
|
102 |
9859 | 103 // append extra 'end of frame' code: |
104 ((char*)data+len)[0]=0; | |
105 ((char*)data+len)[1]=0; | |
106 ((char*)data+len)[2]=1; | |
107 ((char*)data+len)[3]=0xff; | |
108 len+=4; | |
5465 | 109 |
9859 | 110 mpeg2_buffer (mpeg2dec, data, data+len); |
111 | |
112 while(1){ | |
113 int state=mpeg2_parse (mpeg2dec); | |
114 switch(state){ | |
12932 | 115 case STATE_BUFFER: |
9859 | 116 // parsing of the passed buffer finished, return. |
117 // if(!mpi) printf("\nNO PICTURE!\n"); | |
118 return mpi; | |
119 case STATE_SEQUENCE: | |
120 // video parameters inited/changed, (re)init libvo: | |
121 if(!mpcodecs_config_vo(sh, | |
122 info->sequence->width, | |
123 info->sequence->height, IMGFMT_YV12)) return 0; | |
124 break; | |
125 case STATE_PICTURE: { | |
126 int type=info->current_picture->flags&PIC_MASK_CODING_TYPE; | |
127 mp_image_t* mpi; | |
128 | |
129 drop_frame = framedrop && (mpeg2dec->decoder.coding_type == B_TYPE); | |
130 drop_frame |= framedrop>=2; // hard drop | |
131 if (drop_frame) { | |
132 mpeg2_skip(mpeg2dec, 1); | |
133 //printf("Dropping Frame ...\n"); | |
134 break; | |
135 } | |
136 mpeg2_skip(mpeg2dec, 0); //mpeg2skip skips frames until set again to 0 | |
137 | |
138 // get_buffer "callback": | |
139 mpi=mpcodecs_get_image(sh,MP_IMGTYPE_IPB, | |
140 (type==PIC_FLAG_CODING_TYPE_B) | |
141 ? ((!framedrop && vd_use_slices && | |
142 (info->current_picture->flags&PIC_FLAG_PROGRESSIVE_FRAME)) ? | |
143 MP_IMGFLAG_DRAW_CALLBACK:0) | |
144 : (MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE), | |
10250 | 145 (info->sequence->picture_width+15)&(~15), |
146 (info->sequence->picture_height+15)&(~15) ); | |
9859 | 147 if(!mpi) return 0; // VO ERROR!!!!!!!! |
148 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
|
149 if (info->current_picture->flags&PIC_FLAG_TOP_FIELD_FIRST) |
10663 | 150 mpi->fields |= MP_IMGFIELD_TOP_FIRST; |
151 else mpi->fields &= ~MP_IMGFIELD_TOP_FIRST; | |
10510
73b3e4336cd4
Add mpeg2_flags to mp_image_t, copy flags in vd_libmpeg2.c,
ranma
parents:
10267
diff
changeset
|
152 if (info->current_picture->flags&PIC_FLAG_REPEAT_FIRST_FIELD) |
10663 | 153 mpi->fields |= MP_IMGFIELD_REPEAT_FIRST; |
154 else mpi->fields &= ~MP_IMGFIELD_REPEAT_FIRST; | |
155 mpi->fields |= MP_IMGFIELD_ORDERED; | |
9859 | 156 |
12935 | 157 #ifdef MPEG12_POSTPROC |
158 if(!mpi->qscale){ | |
159 mpi->qstride=(info->sequence->picture_width+15)>>4; | |
160 mpi->qscale=malloc(mpi->qstride*((info->sequence->picture_height+15)>>4)); | |
161 } | |
162 mpeg2dec->decoder.quant_store=mpi->qscale; | |
163 mpeg2dec->decoder.quant_stride=mpi->qstride; | |
164 mpi->pict_type=type; // 1->I, 2->P, 3->B | |
165 mpi->qscale_type= 1; | |
166 #endif | |
167 | |
9859 | 168 if(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && |
169 !(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
170 // nice, filter/vo likes draw_callback :) | |
171 mpeg2dec->decoder.convert=draw_slice; | |
12932 | 172 mpeg2dec->decoder.convert_id=sh; |
9859 | 173 } else |
174 mpeg2dec->decoder.convert=NULL; | |
175 break; | |
176 } | |
177 case STATE_SLICE: | |
178 case STATE_END: | |
12932 | 179 case STATE_INVALID_END: |
9859 | 180 // decoding done: |
181 if(mpi) printf("AJAJJJJJJJJ2!\n"); | |
182 if(info->display_fbuf) mpi=info->display_fbuf->id; | |
183 // return mpi; | |
7957
31fd09cc9ba2
passing picture_type (might be usefull for postprocessing)
michael
parents:
7756
diff
changeset
|
184 } |
31fd09cc9ba2
passing picture_type (might be usefull for postprocessing)
michael
parents:
7756
diff
changeset
|
185 } |
5465 | 186 } |
8026
b465ba5897a3
usage of libmpeg2, liba52, mp3lib & svq1 can be disabled
arpi
parents:
7957
diff
changeset
|
187 #endif |