audio: add af_lavrresample, remove old resampling filters
[mplayer.git] / libmpcodecs / vf_pp.c
blob4bf649cd2407d658bcbc125ab21f8673a8758a8b
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <inttypes.h>
23 #include <errno.h>
25 #include "config.h"
26 #include "mp_msg.h"
27 #include "cpudetect.h"
29 #include "img_format.h"
30 #include "mp_image.h"
31 #include "vf.h"
32 #include "libpostproc/postprocess.h"
34 struct vf_priv_s {
35 int pp;
36 pp_mode *ppMode[PP_QUALITY_MAX+1];
37 void *context;
38 unsigned int outfmt;
41 //===========================================================================//
43 static int config(struct vf_instance *vf,
44 int width, int height, int d_width, int d_height,
45 unsigned int voflags, unsigned int outfmt){
46 int flags=
47 (gCpuCaps.hasMMX ? PP_CPU_CAPS_MMX : 0)
48 | (gCpuCaps.hasMMX2 ? PP_CPU_CAPS_MMX2 : 0)
49 | (gCpuCaps.has3DNow ? PP_CPU_CAPS_3DNOW : 0);
51 switch(outfmt){
52 case IMGFMT_444P: flags|= PP_FORMAT_444; break;
53 case IMGFMT_422P: flags|= PP_FORMAT_422; break;
54 case IMGFMT_411P: flags|= PP_FORMAT_411; break;
55 default: flags|= PP_FORMAT_420; break;
58 if(vf->priv->context) pp_free_context(vf->priv->context);
59 vf->priv->context= pp_get_context(width, height, flags);
61 return vf_next_config(vf,width,height,d_width,d_height,voflags,outfmt);
64 static void uninit(struct vf_instance *vf){
65 int i;
66 for(i=0; i<=PP_QUALITY_MAX; i++){
67 if(vf->priv->ppMode[i])
68 pp_free_mode(vf->priv->ppMode[i]);
70 if(vf->priv->context) pp_free_context(vf->priv->context);
73 static int query_format(struct vf_instance *vf, unsigned int fmt){
74 switch(fmt){
75 case IMGFMT_YV12:
76 case IMGFMT_I420:
77 case IMGFMT_IYUV:
78 case IMGFMT_444P:
79 case IMGFMT_422P:
80 case IMGFMT_411P:
81 return vf_next_query_format(vf,fmt);
83 return 0;
86 static int control(struct vf_instance *vf, int request, void* data){
87 switch(request){
88 case VFCTRL_QUERY_MAX_PP_LEVEL:
89 return PP_QUALITY_MAX;
90 case VFCTRL_SET_PP_LEVEL:
91 vf->priv->pp= *((unsigned int*)data);
92 return CONTROL_TRUE;
94 return vf_next_control(vf,request,data);
97 static void get_image(struct vf_instance *vf, mp_image_t *mpi){
98 if(vf->priv->pp&0xFFFF) return; // non-local filters enabled
99 if((mpi->type==MP_IMGTYPE_IPB || vf->priv->pp) &&
100 mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
101 if(!(mpi->flags&MP_IMGFLAG_ACCEPT_STRIDE) && mpi->imgfmt!=vf->priv->outfmt)
102 return; // colorspace differ
103 // ok, we can do pp in-place (or pp disabled):
104 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
105 mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
106 mpi->planes[0]=vf->dmpi->planes[0];
107 mpi->stride[0]=vf->dmpi->stride[0];
108 mpi->width=vf->dmpi->width;
109 if(mpi->flags&MP_IMGFLAG_PLANAR){
110 mpi->planes[1]=vf->dmpi->planes[1];
111 mpi->planes[2]=vf->dmpi->planes[2];
112 mpi->stride[1]=vf->dmpi->stride[1];
113 mpi->stride[2]=vf->dmpi->stride[2];
115 mpi->flags|=MP_IMGFLAG_DIRECT;
118 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
119 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
120 // no DR, so get a new image! hope we'll get DR buffer:
121 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
122 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE |
123 MP_IMGFLAG_PREFER_ALIGNED_STRIDE | MP_IMGFLAG_READABLE,
124 // MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
125 // mpi->w,mpi->h);
126 (mpi->width+7)&(~7),(mpi->height+7)&(~7));
127 vf->dmpi->w=mpi->w; vf->dmpi->h=mpi->h; // display w;h
130 if(vf->priv->pp || !(mpi->flags&MP_IMGFLAG_DIRECT)){
131 // do the postprocessing! (or copy if no DR)
132 pp_postprocess((const uint8_t **)mpi->planes, mpi->stride,
133 vf->dmpi->planes,vf->dmpi->stride,
134 (mpi->w+7)&(~7),mpi->h,
135 mpi->qscale, mpi->qstride,
136 vf->priv->ppMode[ vf->priv->pp ], vf->priv->context,
137 #ifdef PP_PICT_TYPE_QP2
138 mpi->pict_type | (mpi->qscale_type ? PP_PICT_TYPE_QP2 : 0));
139 #else
140 mpi->pict_type);
141 #endif
143 return vf_next_put_image(vf,vf->dmpi, pts);
146 //===========================================================================//
148 extern int divx_quality;
150 static const unsigned int fmt_list[]={
151 IMGFMT_YV12,
152 IMGFMT_I420,
153 IMGFMT_IYUV,
154 IMGFMT_444P,
155 IMGFMT_422P,
156 IMGFMT_411P,
160 static int vf_open(vf_instance_t *vf, char *args){
161 int i;
163 vf->query_format=query_format;
164 vf->control=control;
165 vf->config=config;
166 vf->get_image=get_image;
167 vf->put_image=put_image;
168 vf->uninit=uninit;
169 vf->default_caps=VFCAP_ACCEPT_STRIDE|VFCAP_POSTPROC;
170 vf->priv=malloc(sizeof(struct vf_priv_s));
171 vf->priv->context=NULL;
173 // check csp:
174 vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12);
175 if(!vf->priv->outfmt) return 0; // no csp match :(
177 char *name = args ? args : "de";
179 for(i=0; i<=PP_QUALITY_MAX; i++){
180 vf->priv->ppMode[i]= pp_get_mode_by_name_and_quality(name, i);
181 if(vf->priv->ppMode[i]==NULL) return -1;
184 vf->priv->pp=PP_QUALITY_MAX;
185 return 1;
188 const vf_info_t vf_info_pp = {
189 "postprocessing",
190 "pp",
191 "A'rpi",
193 vf_open,
194 NULL
197 //===========================================================================//