Mercurial > mplayer.hg
annotate libmpcodecs/vd_libmpeg2.c @ 12443:ae4ae7ab636c
ENCA support (http://trific.ath.cx/software/enca/)
author | henry |
---|---|
date | Sat, 08 May 2004 17:52:25 +0000 |
parents | 26f1b3ad4a77 |
children | 7d681d8ebab8 |
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 | |
11080
26f1b3ad4a77
skip null frames in mpeg files, patch by Zoltan Hidvegi <mplayer@hzoli.2y.net>
attila
parents:
10663
diff
changeset
|
100 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
|
101 |
9859 | 102 // append extra 'end of frame' code: |
103 ((char*)data+len)[0]=0; | |
104 ((char*)data+len)[1]=0; | |
105 ((char*)data+len)[2]=1; | |
106 ((char*)data+len)[3]=0xff; | |
107 len+=4; | |
5465 | 108 |
9859 | 109 mpeg2_buffer (mpeg2dec, data, data+len); |
110 | |
111 while(1){ | |
112 int state=mpeg2_parse (mpeg2dec); | |
113 switch(state){ | |
114 case -1: | |
115 // parsing of the passed buffer finished, return. | |
116 // if(!mpi) printf("\nNO PICTURE!\n"); | |
117 return mpi; | |
118 case STATE_SEQUENCE: | |
119 // video parameters inited/changed, (re)init libvo: | |
120 if(!mpcodecs_config_vo(sh, | |
121 info->sequence->width, | |
122 info->sequence->height, IMGFMT_YV12)) return 0; | |
123 break; | |
124 case STATE_PICTURE: { | |
125 int type=info->current_picture->flags&PIC_MASK_CODING_TYPE; | |
126 mp_image_t* mpi; | |
127 | |
128 drop_frame = framedrop && (mpeg2dec->decoder.coding_type == B_TYPE); | |
129 drop_frame |= framedrop>=2; // hard drop | |
130 if (drop_frame) { | |
131 mpeg2_skip(mpeg2dec, 1); | |
132 //printf("Dropping Frame ...\n"); | |
133 break; | |
134 } | |
135 mpeg2_skip(mpeg2dec, 0); //mpeg2skip skips frames until set again to 0 | |
136 | |
137 // get_buffer "callback": | |
138 mpi=mpcodecs_get_image(sh,MP_IMGTYPE_IPB, | |
139 (type==PIC_FLAG_CODING_TYPE_B) | |
140 ? ((!framedrop && vd_use_slices && | |
141 (info->current_picture->flags&PIC_FLAG_PROGRESSIVE_FRAME)) ? | |
142 MP_IMGFLAG_DRAW_CALLBACK:0) | |
143 : (MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE), | |
10250 | 144 (info->sequence->picture_width+15)&(~15), |
145 (info->sequence->picture_height+15)&(~15) ); | |
9859 | 146 if(!mpi) return 0; // VO ERROR!!!!!!!! |
147 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
|
148 if (info->current_picture->flags&PIC_FLAG_TOP_FIELD_FIRST) |
10663 | 149 mpi->fields |= MP_IMGFIELD_TOP_FIRST; |
150 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
|
151 if (info->current_picture->flags&PIC_FLAG_REPEAT_FIRST_FIELD) |
10663 | 152 mpi->fields |= MP_IMGFIELD_REPEAT_FIRST; |
153 else mpi->fields &= ~MP_IMGFIELD_REPEAT_FIRST; | |
154 mpi->fields |= MP_IMGFIELD_ORDERED; | |
9859 | 155 |
156 #ifdef MPEG12_POSTPROC | |
157 if(!mpi->qscale){ | |
10250 | 158 mpi->qstride=(info->sequence->picture_width+15)>>4; |
159 mpi->qscale=malloc(mpi->qstride*((info->sequence->picture_height+15)>>4)); | |
9859 | 160 } |
161 mpeg2dec->decoder.quant_store=mpi->qscale; | |
162 mpeg2dec->decoder.quant_stride=mpi->qstride; | |
163 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
|
164 mpi->qscale_type= 1; |
5465 | 165 #endif |
166 | |
9859 | 167 if(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && |
168 !(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
169 // nice, filter/vo likes draw_callback :) | |
170 mpeg2dec->decoder.convert=draw_slice; | |
171 mpeg2dec->decoder.fbuf_id=sh; | |
172 } else | |
173 mpeg2dec->decoder.convert=NULL; | |
174 break; | |
175 } | |
176 case STATE_SLICE: | |
177 case STATE_END: | |
178 // decoding done: | |
179 if(mpi) printf("AJAJJJJJJJJ2!\n"); | |
180 if(info->display_fbuf) mpi=info->display_fbuf->id; | |
181 // return mpi; | |
7957
31fd09cc9ba2
passing picture_type (might be usefull for postprocessing)
michael
parents:
7756
diff
changeset
|
182 } |
31fd09cc9ba2
passing picture_type (might be usefull for postprocessing)
michael
parents:
7756
diff
changeset
|
183 } |
5465 | 184 } |
8026
b465ba5897a3
usage of libmpeg2, liba52, mp3lib & svq1 can be disabled
arpi
parents:
7957
diff
changeset
|
185 #endif |