Mercurial > mplayer.hg
annotate libmpcodecs/vd_libmpeg2.c @ 10077:c1c35a94f695
Correct dumping hint (vc dummy faster than null).
author | ranma |
---|---|
date | Mon, 05 May 2003 23:43:30 +0000 |
parents | 6f293e709a39 |
children | 2bf4914e2253 |
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; | |
50 #ifdef HAVE_MLIB | |
51 accel |= MPEG2_ACCEL_MLIB; | |
52 #endif | |
53 mpeg2_accel(accel); | |
5465 | 54 |
9859 | 55 mpeg2dec = mpeg2_init (); |
56 | |
57 if(!mpeg2dec) return 0; | |
58 | |
59 mpeg2_custom_fbuf(mpeg2dec,1); // enable DR1 | |
5675
0ff1b9ab7afc
slices+field pictures fixed, initial sig11 workaround
arpi
parents:
5613
diff
changeset
|
60 |
9859 | 61 sh->context=mpeg2dec; |
62 | |
63 return 1; | |
64 //return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12); | |
4998 | 65 } |
66 | |
67 // uninit driver | |
68 static void uninit(sh_video_t *sh){ | |
9859 | 69 mpeg2dec_t * mpeg2dec = sh->context; |
70 mpeg2_close (mpeg2dec); | |
4998 | 71 } |
72 | |
9859 | 73 static void draw_slice (void * _sh, uint8_t ** src, unsigned int y){ |
74 sh_video_t* sh = (sh_video_t*) _sh; | |
75 mpeg2dec_t* mpeg2dec = sh->context; | |
76 const mpeg2_info_t * info = mpeg2_info (mpeg2dec); | |
77 int stride[3]; | |
5465 | 78 |
9938 | 79 // printf("draw_slice() y=%d \n",y); |
5465 | 80 |
9859 | 81 stride[0]=mpeg2dec->decoder.stride; |
82 stride[1]=stride[2]=mpeg2dec->decoder.uv_stride; | |
5465 | 83 |
9859 | 84 mpcodecs_draw_slice(sh, (uint8_t **)src, |
85 stride, info->sequence->display_width, | |
86 (y+16<=info->sequence->display_height) ? 16 : | |
87 info->sequence->display_height-y, | |
88 0, y); | |
4998 | 89 } |
90 | |
5465 | 91 // decode a frame |
92 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
9859 | 93 mpeg2dec_t * mpeg2dec = sh->context; |
94 const mpeg2_info_t * info = mpeg2_info (mpeg2dec); | |
95 mp_image_t* mpi=NULL; | |
96 int drop_frame, framedrop=flags&3; | |
97 | |
98 // append extra 'end of frame' code: | |
99 ((char*)data+len)[0]=0; | |
100 ((char*)data+len)[1]=0; | |
101 ((char*)data+len)[2]=1; | |
102 ((char*)data+len)[3]=0xff; | |
103 len+=4; | |
5465 | 104 |
9859 | 105 mpeg2_buffer (mpeg2dec, data, data+len); |
106 | |
107 while(1){ | |
108 int state=mpeg2_parse (mpeg2dec); | |
109 switch(state){ | |
110 case -1: | |
111 // parsing of the passed buffer finished, return. | |
112 // if(!mpi) printf("\nNO PICTURE!\n"); | |
113 return mpi; | |
114 case STATE_SEQUENCE: | |
115 // video parameters inited/changed, (re)init libvo: | |
116 if(!mpcodecs_config_vo(sh, | |
117 info->sequence->width, | |
118 info->sequence->height, IMGFMT_YV12)) return 0; | |
119 break; | |
120 case STATE_PICTURE: { | |
121 int type=info->current_picture->flags&PIC_MASK_CODING_TYPE; | |
122 mp_image_t* mpi; | |
123 | |
124 drop_frame = framedrop && (mpeg2dec->decoder.coding_type == B_TYPE); | |
125 drop_frame |= framedrop>=2; // hard drop | |
126 if (drop_frame) { | |
127 mpeg2_skip(mpeg2dec, 1); | |
128 //printf("Dropping Frame ...\n"); | |
129 break; | |
130 } | |
131 mpeg2_skip(mpeg2dec, 0); //mpeg2skip skips frames until set again to 0 | |
132 | |
133 // get_buffer "callback": | |
134 mpi=mpcodecs_get_image(sh,MP_IMGTYPE_IPB, | |
135 (type==PIC_FLAG_CODING_TYPE_B) | |
136 ? ((!framedrop && vd_use_slices && | |
137 (info->current_picture->flags&PIC_FLAG_PROGRESSIVE_FRAME)) ? | |
138 MP_IMGFLAG_DRAW_CALLBACK:0) | |
139 : (MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE), | |
9919 | 140 (info->sequence->picture_width+7)&(~7), |
141 (info->sequence->picture_height+7)&(~7) ); | |
9859 | 142 if(!mpi) return 0; // VO ERROR!!!!!!!! |
143 mpeg2_set_buf(mpeg2dec, mpi->planes, mpi); | |
144 | |
145 #ifdef MPEG12_POSTPROC | |
146 if(!mpi->qscale){ | |
147 mpi->qstride=info->sequence->picture_width>>4; | |
148 mpi->qscale=malloc(mpi->qstride*(info->sequence->picture_height>>4)); | |
149 } | |
150 mpeg2dec->decoder.quant_store=mpi->qscale; | |
151 mpeg2dec->decoder.quant_stride=mpi->qstride; | |
152 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
|
153 mpi->qscale_type= 1; |
5465 | 154 #endif |
155 | |
9859 | 156 if(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && |
157 !(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
158 // nice, filter/vo likes draw_callback :) | |
159 mpeg2dec->decoder.convert=draw_slice; | |
160 mpeg2dec->decoder.fbuf_id=sh; | |
161 } else | |
162 mpeg2dec->decoder.convert=NULL; | |
163 break; | |
164 } | |
165 case STATE_SLICE: | |
166 case STATE_END: | |
167 // decoding done: | |
168 if(mpi) printf("AJAJJJJJJJJ2!\n"); | |
169 if(info->display_fbuf) mpi=info->display_fbuf->id; | |
170 // return mpi; | |
7957
31fd09cc9ba2
passing picture_type (might be usefull for postprocessing)
michael
parents:
7756
diff
changeset
|
171 } |
31fd09cc9ba2
passing picture_type (might be usefull for postprocessing)
michael
parents:
7756
diff
changeset
|
172 } |
5465 | 173 } |
8026
b465ba5897a3
usage of libmpeg2, liba52, mp3lib & svq1 can be disabled
arpi
parents:
7957
diff
changeset
|
174 #endif |