Mercurial > mplayer.hg
annotate libmpcodecs/vf_pp.c @ 36442:ee46a4670903
Query codec support first.
The filter chain query is more complex.
In addition this for the moment avoids a vo_vdpau bug
where the query function destroys the old decoder.
author | reimar |
---|---|
date | Sun, 08 Dec 2013 17:52:23 +0000 |
parents | f7cef684f2a0 |
children |
rev | line source |
---|---|
30421
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
1 /* |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
2 * This file is part of MPlayer. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
3 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
7 * (at your option) any later version. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
8 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
12 * GNU General Public License for more details. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
13 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
17 */ |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
18 |
5512 | 19 #include <stdio.h> |
20 #include <stdlib.h> | |
21 #include <string.h> | |
7946 | 22 #include <inttypes.h> |
7963 | 23 #include <errno.h> |
5512 | 24 |
17012 | 25 #include "config.h" |
26 #include "mp_msg.h" | |
27 #include "cpudetect.h" | |
5512 | 28 |
28594
df67d03dde3b
Convert HAVE_MALLOC_H into a 0/1 definition, fixes the warning:
diego
parents:
28327
diff
changeset
|
29 #if HAVE_MALLOC_H |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8040
diff
changeset
|
30 #include <malloc.h> |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8040
diff
changeset
|
31 #endif |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8040
diff
changeset
|
32 |
31979
ed8a577b9a20
Add the proper include instead of declaring the divx_quality variable extern.
diego
parents:
30708
diff
changeset
|
33 #include "dec_video.h" |
5607 | 34 #include "img_format.h" |
35 #include "mp_image.h" | |
5512 | 36 #include "vf.h" |
18557
b7746166426c
libpostproc is not a subdirectory of libavcodec anymore.
diego
parents:
17906
diff
changeset
|
37 #include "libpostproc/postprocess.h" |
26068 | 38 |
32142
4614728cab25
build system: Merge all FFmpeg library checks into a single FFmpeg check.
diego
parents:
31979
diff
changeset
|
39 #ifdef CONFIG_FFMPEG_A |
26069
1318e956c092
FFmpeg now uses different (unified) #include paths.
diego
parents:
26068
diff
changeset
|
40 #define EMU_OLD |
26068 | 41 #include "libpostproc/postprocess_internal.h" |
42 #endif | |
8038 | 43 |
28327
c39a1fd7d45c
Fix compilation after DECLARE_ASM_CONST/DECLARE_ALIGNED moving within FFmpeg.
diego
parents:
27341
diff
changeset
|
44 #undef malloc |
c39a1fd7d45c
Fix compilation after DECLARE_ASM_CONST/DECLARE_ALIGNED moving within FFmpeg.
diego
parents:
27341
diff
changeset
|
45 |
5512 | 46 struct vf_priv_s { |
7946 | 47 int pp; |
33231 | 48 pp_mode *ppMode[PP_QUALITY_MAX+1]; |
7946 | 49 void *context; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
50 unsigned int outfmt; |
5512 | 51 }; |
52 | |
53 //===========================================================================// | |
54 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
55 static int config(struct vf_instance *vf, |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
56 int width, int height, int d_width, int d_height, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
57 unsigned int voflags, unsigned int outfmt){ |
8805 | 58 int flags= |
7985 | 59 (gCpuCaps.hasMMX ? PP_CPU_CAPS_MMX : 0) |
60 | (gCpuCaps.hasMMX2 ? PP_CPU_CAPS_MMX2 : 0) | |
8805 | 61 | (gCpuCaps.has3DNow ? PP_CPU_CAPS_3DNOW : 0); |
62 | |
63 switch(outfmt){ | |
64 case IMGFMT_444P: flags|= PP_FORMAT_444; break; | |
65 case IMGFMT_422P: flags|= PP_FORMAT_422; break; | |
66 case IMGFMT_411P: flags|= PP_FORMAT_411; break; | |
67 default: flags|= PP_FORMAT_420; break; | |
68 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28594
diff
changeset
|
69 |
8805 | 70 if(vf->priv->context) pp_free_context(vf->priv->context); |
71 vf->priv->context= pp_get_context(width, height, flags); | |
7946 | 72 |
9528 | 73 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
|
74 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
75 |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
76 static void uninit(struct vf_instance *vf){ |
8038 | 77 int i; |
8040 | 78 for(i=0; i<=PP_QUALITY_MAX; i++){ |
8038 | 79 if(vf->priv->ppMode[i]) |
80 pp_free_mode(vf->priv->ppMode[i]); | |
81 } | |
7961 | 82 if(vf->priv->context) pp_free_context(vf->priv->context); |
34695 | 83 free(vf->priv); |
7949 | 84 } |
85 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
86 static int query_format(struct vf_instance *vf, unsigned int fmt){ |
5518 | 87 switch(fmt){ |
88 case IMGFMT_YV12: | |
89 case IMGFMT_I420: | |
90 case IMGFMT_IYUV: | |
8805 | 91 case IMGFMT_444P: |
92 case IMGFMT_422P: | |
93 case IMGFMT_411P: | |
94 return vf_next_query_format(vf,fmt); | |
5518 | 95 } |
96 return 0; | |
97 } | |
98 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
99 static int control(struct vf_instance *vf, int request, void* data){ |
5519 | 100 switch(request){ |
101 case VFCTRL_QUERY_MAX_PP_LEVEL: | |
8040 | 102 return PP_QUALITY_MAX; |
5519 | 103 case VFCTRL_SET_PP_LEVEL: |
7946 | 104 vf->priv->pp= *((unsigned int*)data); |
5519 | 105 return CONTROL_TRUE; |
106 } | |
107 return vf_next_control(vf,request,data); | |
108 } | |
109 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
110 static void get_image(struct vf_instance *vf, mp_image_t *mpi){ |
5512 | 111 if(vf->priv->pp&0xFFFF) return; // non-local filters enabled |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28594
diff
changeset
|
112 if((mpi->type==MP_IMGTYPE_IPB || vf->priv->pp) && |
5513 | 113 mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
114 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
|
115 return; // colorspace differ |
5512 | 116 // 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
|
117 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
|
118 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
|
119 mpi->planes[0]=vf->dmpi->planes[0]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
120 mpi->stride[0]=vf->dmpi->stride[0]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
121 mpi->width=vf->dmpi->width; |
5512 | 122 if(mpi->flags&MP_IMGFLAG_PLANAR){ |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
123 mpi->planes[1]=vf->dmpi->planes[1]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
124 mpi->planes[2]=vf->dmpi->planes[2]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
125 mpi->stride[1]=vf->dmpi->stride[1]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
126 mpi->stride[2]=vf->dmpi->stride[2]; |
5512 | 127 } |
128 mpi->flags|=MP_IMGFLAG_DIRECT; | |
129 } | |
130 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
131 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ |
5512 | 132 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ |
133 // 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
|
134 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
|
135 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | |
9f516ed86916
pp_postprocess reads from target image, so request a readable one.
reimar
parents:
16018
diff
changeset
|
136 MP_IMGFLAG_PREFER_ALIGNED_STRIDE | MP_IMGFLAG_READABLE, |
6875 | 137 // MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, |
138 // mpi->w,mpi->h); | |
16018
bdf1b4ecb906
use stored dimensions instead of visible one when (vf_)get_image is called
iive
parents:
15965
diff
changeset
|
139 (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
|
140 vf->dmpi->w=mpi->w; vf->dmpi->h=mpi->h; // display w;h |
5512 | 141 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28594
diff
changeset
|
142 |
5512 | 143 if(vf->priv->pp || !(mpi->flags&MP_IMGFLAG_DIRECT)){ |
144 // do the postprocessing! (or copy if no DR) | |
7961 | 145 pp_postprocess(mpi->planes ,mpi->stride, |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
146 vf->dmpi->planes,vf->dmpi->stride, |
6875 | 147 (mpi->w+7)&(~7),mpi->h, |
5512 | 148 mpi->qscale, mpi->qstride, |
8038 | 149 vf->priv->ppMode[ vf->priv->pp ], vf->priv->context, |
9931 | 150 #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
|
151 mpi->pict_type | (mpi->qscale_type ? PP_PICT_TYPE_QP2 : 0)); |
9931 | 152 #else |
153 mpi->pict_type); | |
154 #endif | |
5512 | 155 } |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17463
diff
changeset
|
156 return vf_next_put_image(vf,vf->dmpi, pts); |
5512 | 157 } |
158 | |
159 //===========================================================================// | |
160 | |
30708 | 161 static const unsigned int fmt_list[]={ |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
162 IMGFMT_YV12, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
163 IMGFMT_I420, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
164 IMGFMT_IYUV, |
8805 | 165 IMGFMT_444P, |
166 IMGFMT_422P, | |
167 IMGFMT_411P, | |
7127 | 168 0 |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
169 }; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
170 |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
30633
diff
changeset
|
171 static int vf_open(vf_instance_t *vf, char *args){ |
7946 | 172 char *endptr, *name; |
173 int i; | |
174 int hex_mode=0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28594
diff
changeset
|
175 |
5518 | 176 vf->query_format=query_format; |
5519 | 177 vf->control=control; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
178 vf->config=config; |
5512 | 179 vf->get_image=get_image; |
180 vf->put_image=put_image; | |
7949 | 181 vf->uninit=uninit; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
182 vf->default_caps=VFCAP_ACCEPT_STRIDE|VFCAP_POSTPROC; |
5512 | 183 vf->priv=malloc(sizeof(struct vf_priv_s)); |
7949 | 184 vf->priv->context=NULL; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
185 |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
186 // check csp: |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
187 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
|
188 if(!vf->priv->outfmt) return 0; // no csp match :( |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28594
diff
changeset
|
189 |
5514 | 190 if(args){ |
7946 | 191 hex_mode= strtol(args, &endptr, 0); |
192 if(*endptr){ | |
193 name= args; | |
194 }else | |
195 name= NULL; | |
196 }else{ | |
197 name="de"; | |
5514 | 198 } |
7972 | 199 |
8038 | 200 #ifdef EMU_OLD |
7946 | 201 if(name){ |
8038 | 202 #endif |
8040 | 203 for(i=0; i<=PP_QUALITY_MAX; i++){ |
7961 | 204 vf->priv->ppMode[i]= pp_get_mode_by_name_and_quality(name, i); |
8038 | 205 if(vf->priv->ppMode[i]==NULL) return -1; |
7946 | 206 } |
8038 | 207 #ifdef EMU_OLD |
7946 | 208 }else{ |
209 /* hex mode for compatibility */ | |
8040 | 210 for(i=0; i<=PP_QUALITY_MAX; i++){ |
8038 | 211 PPMode *ppMode; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28594
diff
changeset
|
212 |
32762
5d1ad5720b32
Replace one more instance of memalign in libmpcodecs with av_malloc.
diego
parents:
32142
diff
changeset
|
213 ppMode = av_malloc(sizeof(PPMode)); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28594
diff
changeset
|
214 |
8038 | 215 ppMode->lumMode= hex_mode; |
216 ppMode->chromMode= ((hex_mode&0xFF)>>4) | (hex_mode&0xFFFFFF00); | |
217 ppMode->maxTmpNoise[0]= 700; | |
218 ppMode->maxTmpNoise[1]= 1500; | |
219 ppMode->maxTmpNoise[2]= 3000; | |
220 ppMode->maxAllowedY= 234; | |
221 ppMode->minAllowedY= 16; | |
222 ppMode->baseDcDiff= 256/4; | |
223 ppMode->flatnessThreshold=40; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28594
diff
changeset
|
224 |
7946 | 225 vf->priv->ppMode[i]= ppMode; |
226 } | |
227 } | |
8038 | 228 #endif |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28594
diff
changeset
|
229 |
10756 | 230 vf->priv->pp=PP_QUALITY_MAX; |
5512 | 231 return 1; |
232 } | |
233 | |
25221 | 234 const vf_info_t vf_info_pp = { |
5512 | 235 "postprocessing", |
236 "pp", | |
237 "A'rpi", | |
238 "", | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
30633
diff
changeset
|
239 vf_open, |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9528
diff
changeset
|
240 NULL |
5512 | 241 }; |
242 | |
243 //===========================================================================// |