Mercurial > mplayer.hg
annotate libmpcodecs/vf_pp.c @ 9233:ba7041fbcfda
ffmpeg's DV audio decoder added
author | arpi |
---|---|
date | Mon, 03 Feb 2003 00:20:46 +0000 |
parents | e547ce712577 |
children | c9dcb67e9638 |
rev | line source |
---|---|
5512 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
7946 | 4 #include <inttypes.h> |
7963 | 5 #include <errno.h> |
5512 | 6 |
7 #include "../config.h" | |
8 #include "../mp_msg.h" | |
7972 | 9 #include "../cpudetect.h" |
5512 | 10 |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8040
diff
changeset
|
11 #ifdef HAVE_MALLOC_H |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8040
diff
changeset
|
12 #include <malloc.h> |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8040
diff
changeset
|
13 #endif |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8040
diff
changeset
|
14 |
5607 | 15 #include "img_format.h" |
16 #include "mp_image.h" | |
5512 | 17 #include "vf.h" |
18 | |
8038 | 19 #define EMU_OLD |
20 | |
5512 | 21 #include "../postproc/postprocess.h" |
22 | |
8038 | 23 #ifdef EMU_OLD |
24 #include "../postproc/postprocess_internal.h" | |
25 #endif | |
26 | |
5512 | 27 struct vf_priv_s { |
7946 | 28 int pp; |
8040 | 29 pp_mode_t *ppMode[PP_QUALITY_MAX+1]; |
7946 | 30 void *context; |
5512 | 31 mp_image_t *dmpi; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
32 unsigned int outfmt; |
5512 | 33 }; |
34 | |
35 //===========================================================================// | |
36 | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
37 static int config(struct vf_instance_s* vf, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
38 int width, int height, int d_width, int d_height, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
39 unsigned int voflags, unsigned int outfmt){ |
8805 | 40 int flags= |
7985 | 41 (gCpuCaps.hasMMX ? PP_CPU_CAPS_MMX : 0) |
42 | (gCpuCaps.hasMMX2 ? PP_CPU_CAPS_MMX2 : 0) | |
8805 | 43 | (gCpuCaps.has3DNow ? PP_CPU_CAPS_3DNOW : 0); |
44 | |
45 switch(outfmt){ | |
46 case IMGFMT_444P: flags|= PP_FORMAT_444; break; | |
47 case IMGFMT_422P: flags|= PP_FORMAT_422; break; | |
48 case IMGFMT_411P: flags|= PP_FORMAT_411; break; | |
49 default: flags|= PP_FORMAT_420; break; | |
50 } | |
51 | |
52 if(vf->priv->context) pp_free_context(vf->priv->context); | |
53 vf->priv->context= pp_get_context(width, height, flags); | |
7946 | 54 |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
55 return vf_next_config(vf,width,height,d_width,d_height,voflags,vf->priv->outfmt); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
56 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
57 |
7949 | 58 static void uninit(struct vf_instance_s* vf){ |
8038 | 59 int i; |
8040 | 60 for(i=0; i<=PP_QUALITY_MAX; i++){ |
8038 | 61 if(vf->priv->ppMode[i]) |
62 pp_free_mode(vf->priv->ppMode[i]); | |
63 } | |
7961 | 64 if(vf->priv->context) pp_free_context(vf->priv->context); |
7949 | 65 } |
66 | |
5518 | 67 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ |
68 switch(fmt){ | |
69 case IMGFMT_YV12: | |
70 case IMGFMT_I420: | |
71 case IMGFMT_IYUV: | |
8805 | 72 case IMGFMT_444P: |
73 case IMGFMT_422P: | |
74 case IMGFMT_411P: | |
75 return vf_next_query_format(vf,fmt); | |
5518 | 76 } |
77 return 0; | |
78 } | |
79 | |
5519 | 80 static int control(struct vf_instance_s* vf, int request, void* data){ |
81 switch(request){ | |
82 case VFCTRL_QUERY_MAX_PP_LEVEL: | |
8040 | 83 return PP_QUALITY_MAX; |
5519 | 84 case VFCTRL_SET_PP_LEVEL: |
7946 | 85 vf->priv->pp= *((unsigned int*)data); |
5519 | 86 return CONTROL_TRUE; |
87 } | |
88 return vf_next_control(vf,request,data); | |
89 } | |
90 | |
5512 | 91 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
92 if(vf->priv->pp&0xFFFF) return; // non-local filters enabled | |
5513 | 93 if((mpi->type==MP_IMGTYPE_IPB || vf->priv->pp) && |
94 mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
95 if(!(mpi->flags&MP_IMGFLAG_ACCEPT_STRIDE) && mpi->imgfmt!=vf->priv->outfmt) |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
96 return; // colorspace differ |
5512 | 97 // ok, we can do pp in-place (or pp disabled): |
98 vf->priv->dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
99 mpi->type, mpi->flags, mpi->w, mpi->h); | |
100 mpi->planes[0]=vf->priv->dmpi->planes[0]; | |
101 mpi->stride[0]=vf->priv->dmpi->stride[0]; | |
102 mpi->width=vf->priv->dmpi->width; | |
103 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
104 mpi->planes[1]=vf->priv->dmpi->planes[1]; | |
105 mpi->planes[2]=vf->priv->dmpi->planes[2]; | |
106 mpi->stride[1]=vf->priv->dmpi->stride[1]; | |
107 mpi->stride[2]=vf->priv->dmpi->stride[2]; | |
108 } | |
109 mpi->flags|=MP_IMGFLAG_DIRECT; | |
110 } | |
111 | |
7368 | 112 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
5512 | 113 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ |
114 // no DR, so get a new image! hope we'll get DR buffer: | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
115 vf->priv->dmpi=vf_get_image(vf->next,vf->priv->outfmt, |
6875 | 116 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, |
117 // MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
118 // mpi->w,mpi->h); | |
119 (mpi->w+7)&(~7),(mpi->h+7)&(~7)); | |
120 vf->priv->dmpi->w=mpi->w; vf->priv->dmpi->h=mpi->h; // display w;h | |
5512 | 121 } |
122 | |
123 if(vf->priv->pp || !(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
124 // do the postprocessing! (or copy if no DR) | |
7961 | 125 pp_postprocess(mpi->planes ,mpi->stride, |
7946 | 126 vf->priv->dmpi->planes,vf->priv->dmpi->stride, |
6875 | 127 (mpi->w+7)&(~7),mpi->h, |
5512 | 128 mpi->qscale, mpi->qstride, |
8038 | 129 vf->priv->ppMode[ vf->priv->pp ], vf->priv->context, |
7960 | 130 mpi->pict_type); |
5512 | 131 } |
7368 | 132 return vf_next_put_image(vf,vf->priv->dmpi); |
5512 | 133 } |
134 | |
135 //===========================================================================// | |
136 | |
137 extern int divx_quality; | |
138 | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
139 static unsigned int fmt_list[]={ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
140 IMGFMT_YV12, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
141 IMGFMT_I420, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
142 IMGFMT_IYUV, |
8805 | 143 IMGFMT_444P, |
144 IMGFMT_422P, | |
145 IMGFMT_411P, | |
7127 | 146 0 |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
147 }; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
148 |
5512 | 149 static int open(vf_instance_t *vf, char* args){ |
7946 | 150 char *endptr, *name; |
151 int i; | |
152 int hex_mode=0; | |
153 | |
5518 | 154 vf->query_format=query_format; |
5519 | 155 vf->control=control; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
156 vf->config=config; |
5512 | 157 vf->get_image=get_image; |
158 vf->put_image=put_image; | |
7949 | 159 vf->uninit=uninit; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
160 vf->default_caps=VFCAP_ACCEPT_STRIDE|VFCAP_POSTPROC; |
5512 | 161 vf->priv=malloc(sizeof(struct vf_priv_s)); |
7949 | 162 vf->priv->context=NULL; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
163 |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
164 // check csp: |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
165 vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
166 if(!vf->priv->outfmt) return 0; // no csp match :( |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
167 |
5514 | 168 if(args){ |
7946 | 169 hex_mode= strtol(args, &endptr, 0); |
170 if(*endptr){ | |
171 name= args; | |
172 }else | |
173 name= NULL; | |
174 }else{ | |
175 name="de"; | |
5514 | 176 } |
7972 | 177 |
8038 | 178 #ifdef EMU_OLD |
7946 | 179 if(name){ |
8038 | 180 #endif |
8040 | 181 for(i=0; i<=PP_QUALITY_MAX; i++){ |
7961 | 182 vf->priv->ppMode[i]= pp_get_mode_by_name_and_quality(name, i); |
8038 | 183 if(vf->priv->ppMode[i]==NULL) return -1; |
7946 | 184 } |
8038 | 185 #ifdef EMU_OLD |
7946 | 186 }else{ |
187 /* hex mode for compatibility */ | |
8040 | 188 for(i=0; i<=PP_QUALITY_MAX; i++){ |
8038 | 189 PPMode *ppMode; |
190 | |
191 ppMode= (PPMode*)memalign(8, sizeof(PPMode)); | |
7946 | 192 |
8038 | 193 ppMode->lumMode= hex_mode; |
194 ppMode->chromMode= ((hex_mode&0xFF)>>4) | (hex_mode&0xFFFFFF00); | |
195 ppMode->maxTmpNoise[0]= 700; | |
196 ppMode->maxTmpNoise[1]= 1500; | |
197 ppMode->maxTmpNoise[2]= 3000; | |
198 ppMode->maxAllowedY= 234; | |
199 ppMode->minAllowedY= 16; | |
200 ppMode->baseDcDiff= 256/4; | |
201 ppMode->flatnessThreshold=40; | |
7946 | 202 |
203 vf->priv->ppMode[i]= ppMode; | |
204 } | |
205 } | |
8038 | 206 #endif |
7946 | 207 |
8040 | 208 vf->priv->pp=PP_QUALITY_MAX; //divx_quality; |
5512 | 209 return 1; |
210 } | |
211 | |
7963 | 212 int readPPOpt(void *conf, char *arg) |
213 { | |
214 int val; | |
215 | |
216 if(arg == NULL) | |
217 return -2; // ERR_MISSING_PARAM | |
218 errno = 0; | |
219 val = (int)strtol(arg,NULL,0); | |
220 if(errno != 0) | |
221 return -4; // What about include cfgparser.h and use ERR_* defines */ | |
222 if(val < 0) | |
223 return -3; // ERR_OUT_OF_RANGE | |
224 | |
225 divx_quality = val; | |
226 | |
227 return 1; | |
228 } | |
229 | |
230 void revertPPOpt(void *conf, char* opt) | |
231 { | |
232 divx_quality=0; | |
233 } | |
234 | |
5512 | 235 vf_info_t vf_info_pp = { |
236 "postprocessing", | |
237 "pp", | |
238 "A'rpi", | |
239 "", | |
240 open | |
241 }; | |
242 | |
243 //===========================================================================// |