Mercurial > mplayer.hg
annotate libmpcodecs/vf_pp.c @ 17593:7c700dc8e37d
Gives some examples of in which form MPEG* videos can come
author | gpoirier |
---|---|
date | Sat, 11 Feb 2006 22:13:12 +0000 |
parents | b56f34ba3f2f |
children | 20aca9baf5d8 |
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 |
17012 | 7 #include "config.h" |
8 #include "mp_msg.h" | |
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 | |
9426 | 19 |
17463 | 20 #ifdef USE_LIBPOSTPROC_SO |
21 #include <postproc/postprocess.h> | |
22 #elif defined(USE_LIBPOSTPROC) | |
8038 | 23 #define EMU_OLD |
17012 | 24 #include "libavcodec/libpostproc/postprocess.h" |
5512 | 25 |
8038 | 26 #ifdef EMU_OLD |
17012 | 27 #include "libavcodec/libpostproc/postprocess_internal.h" |
8038 | 28 #endif |
17463 | 29 #endif |
8038 | 30 |
5512 | 31 struct vf_priv_s { |
7946 | 32 int pp; |
8040 | 33 pp_mode_t *ppMode[PP_QUALITY_MAX+1]; |
7946 | 34 void *context; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
35 unsigned int outfmt; |
5512 | 36 }; |
37 | |
38 //===========================================================================// | |
39 | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
40 static int config(struct vf_instance_s* vf, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
41 int width, int height, int d_width, int d_height, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
42 unsigned int voflags, unsigned int outfmt){ |
8805 | 43 int flags= |
7985 | 44 (gCpuCaps.hasMMX ? PP_CPU_CAPS_MMX : 0) |
45 | (gCpuCaps.hasMMX2 ? PP_CPU_CAPS_MMX2 : 0) | |
8805 | 46 | (gCpuCaps.has3DNow ? PP_CPU_CAPS_3DNOW : 0); |
47 | |
48 switch(outfmt){ | |
49 case IMGFMT_444P: flags|= PP_FORMAT_444; break; | |
50 case IMGFMT_422P: flags|= PP_FORMAT_422; break; | |
51 case IMGFMT_411P: flags|= PP_FORMAT_411; break; | |
52 default: flags|= PP_FORMAT_420; break; | |
53 } | |
54 | |
55 if(vf->priv->context) pp_free_context(vf->priv->context); | |
56 vf->priv->context= pp_get_context(width, height, flags); | |
7946 | 57 |
9528 | 58 return vf_next_config(vf,width,height,d_width,d_height,voflags,outfmt); |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
59 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
60 |
7949 | 61 static void uninit(struct vf_instance_s* vf){ |
8038 | 62 int i; |
8040 | 63 for(i=0; i<=PP_QUALITY_MAX; i++){ |
8038 | 64 if(vf->priv->ppMode[i]) |
65 pp_free_mode(vf->priv->ppMode[i]); | |
66 } | |
7961 | 67 if(vf->priv->context) pp_free_context(vf->priv->context); |
7949 | 68 } |
69 | |
5518 | 70 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ |
71 switch(fmt){ | |
72 case IMGFMT_YV12: | |
73 case IMGFMT_I420: | |
74 case IMGFMT_IYUV: | |
8805 | 75 case IMGFMT_444P: |
76 case IMGFMT_422P: | |
77 case IMGFMT_411P: | |
78 return vf_next_query_format(vf,fmt); | |
5518 | 79 } |
80 return 0; | |
81 } | |
82 | |
5519 | 83 static int control(struct vf_instance_s* vf, int request, void* data){ |
84 switch(request){ | |
85 case VFCTRL_QUERY_MAX_PP_LEVEL: | |
8040 | 86 return PP_QUALITY_MAX; |
5519 | 87 case VFCTRL_SET_PP_LEVEL: |
7946 | 88 vf->priv->pp= *((unsigned int*)data); |
5519 | 89 return CONTROL_TRUE; |
90 } | |
91 return vf_next_control(vf,request,data); | |
92 } | |
93 | |
5512 | 94 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
95 if(vf->priv->pp&0xFFFF) return; // non-local filters enabled | |
5513 | 96 if((mpi->type==MP_IMGTYPE_IPB || vf->priv->pp) && |
97 mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
98 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
|
99 return; // colorspace differ |
5512 | 100 // ok, we can do pp in-place (or pp disabled): |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
101 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, |
16018
bdf1b4ecb906
use stored dimensions instead of visible one when (vf_)get_image is called
iive
parents:
15965
diff
changeset
|
102 mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height); |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
103 mpi->planes[0]=vf->dmpi->planes[0]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
104 mpi->stride[0]=vf->dmpi->stride[0]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
105 mpi->width=vf->dmpi->width; |
5512 | 106 if(mpi->flags&MP_IMGFLAG_PLANAR){ |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
107 mpi->planes[1]=vf->dmpi->planes[1]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
108 mpi->planes[2]=vf->dmpi->planes[2]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
109 mpi->stride[1]=vf->dmpi->stride[1]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
110 mpi->stride[2]=vf->dmpi->stride[2]; |
5512 | 111 } |
112 mpi->flags|=MP_IMGFLAG_DIRECT; | |
113 } | |
114 | |
7368 | 115 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
5512 | 116 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ |
117 // no DR, so get a new image! hope we'll get DR buffer: | |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
118 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, |
16471
9f516ed86916
pp_postprocess reads from target image, so request a readable one.
reimar
parents:
16018
diff
changeset
|
119 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | |
9f516ed86916
pp_postprocess reads from target image, so request a readable one.
reimar
parents:
16018
diff
changeset
|
120 MP_IMGFLAG_PREFER_ALIGNED_STRIDE | MP_IMGFLAG_READABLE, |
6875 | 121 // MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, |
122 // mpi->w,mpi->h); | |
16018
bdf1b4ecb906
use stored dimensions instead of visible one when (vf_)get_image is called
iive
parents:
15965
diff
changeset
|
123 (mpi->width+7)&(~7),(mpi->height+7)&(~7)); |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
124 vf->dmpi->w=mpi->w; vf->dmpi->h=mpi->h; // display w;h |
5512 | 125 } |
126 | |
127 if(vf->priv->pp || !(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
128 // do the postprocessing! (or copy if no DR) | |
7961 | 129 pp_postprocess(mpi->planes ,mpi->stride, |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
130 vf->dmpi->planes,vf->dmpi->stride, |
6875 | 131 (mpi->w+7)&(~7),mpi->h, |
5512 | 132 mpi->qscale, mpi->qstride, |
8038 | 133 vf->priv->ppMode[ vf->priv->pp ], vf->priv->context, |
9931 | 134 #ifdef PP_PICT_TYPE_QP2 |
9925
420640a0f6d0
passing qscale_type around so the pp code can fix the mpeg2 <<1 thing
michael
parents:
9593
diff
changeset
|
135 mpi->pict_type | (mpi->qscale_type ? PP_PICT_TYPE_QP2 : 0)); |
9931 | 136 #else |
137 mpi->pict_type); | |
138 #endif | |
5512 | 139 } |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
140 return vf_next_put_image(vf,vf->dmpi); |
5512 | 141 } |
142 | |
143 //===========================================================================// | |
144 | |
145 extern int divx_quality; | |
146 | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
147 static unsigned int fmt_list[]={ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
148 IMGFMT_YV12, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
149 IMGFMT_I420, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
150 IMGFMT_IYUV, |
8805 | 151 IMGFMT_444P, |
152 IMGFMT_422P, | |
153 IMGFMT_411P, | |
7127 | 154 0 |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
155 }; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
156 |
5512 | 157 static int open(vf_instance_t *vf, char* args){ |
7946 | 158 char *endptr, *name; |
159 int i; | |
160 int hex_mode=0; | |
161 | |
5518 | 162 vf->query_format=query_format; |
5519 | 163 vf->control=control; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
164 vf->config=config; |
5512 | 165 vf->get_image=get_image; |
166 vf->put_image=put_image; | |
7949 | 167 vf->uninit=uninit; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
168 vf->default_caps=VFCAP_ACCEPT_STRIDE|VFCAP_POSTPROC; |
5512 | 169 vf->priv=malloc(sizeof(struct vf_priv_s)); |
7949 | 170 vf->priv->context=NULL; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
171 |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
172 // check csp: |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
173 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
|
174 if(!vf->priv->outfmt) return 0; // no csp match :( |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
175 |
5514 | 176 if(args){ |
7946 | 177 hex_mode= strtol(args, &endptr, 0); |
178 if(*endptr){ | |
179 name= args; | |
180 }else | |
181 name= NULL; | |
182 }else{ | |
183 name="de"; | |
5514 | 184 } |
7972 | 185 |
8038 | 186 #ifdef EMU_OLD |
7946 | 187 if(name){ |
8038 | 188 #endif |
8040 | 189 for(i=0; i<=PP_QUALITY_MAX; i++){ |
7961 | 190 vf->priv->ppMode[i]= pp_get_mode_by_name_and_quality(name, i); |
8038 | 191 if(vf->priv->ppMode[i]==NULL) return -1; |
7946 | 192 } |
8038 | 193 #ifdef EMU_OLD |
7946 | 194 }else{ |
195 /* hex mode for compatibility */ | |
8040 | 196 for(i=0; i<=PP_QUALITY_MAX; i++){ |
8038 | 197 PPMode *ppMode; |
198 | |
199 ppMode= (PPMode*)memalign(8, sizeof(PPMode)); | |
7946 | 200 |
8038 | 201 ppMode->lumMode= hex_mode; |
202 ppMode->chromMode= ((hex_mode&0xFF)>>4) | (hex_mode&0xFFFFFF00); | |
203 ppMode->maxTmpNoise[0]= 700; | |
204 ppMode->maxTmpNoise[1]= 1500; | |
205 ppMode->maxTmpNoise[2]= 3000; | |
206 ppMode->maxAllowedY= 234; | |
207 ppMode->minAllowedY= 16; | |
208 ppMode->baseDcDiff= 256/4; | |
209 ppMode->flatnessThreshold=40; | |
7946 | 210 |
211 vf->priv->ppMode[i]= ppMode; | |
212 } | |
213 } | |
8038 | 214 #endif |
7946 | 215 |
10756 | 216 vf->priv->pp=PP_QUALITY_MAX; |
5512 | 217 return 1; |
218 } | |
219 | |
220 vf_info_t vf_info_pp = { | |
221 "postprocessing", | |
222 "pp", | |
223 "A'rpi", | |
224 "", | |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9528
diff
changeset
|
225 open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9528
diff
changeset
|
226 NULL |
5512 | 227 }; |
228 | |
229 //===========================================================================// | |
9426 | 230 |