00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <string.h>
00022 #include <inttypes.h>
00023 #include <errno.h>
00024
00025 #include "config.h"
00026 #include "mp_msg.h"
00027 #include "cpudetect.h"
00028
00029 #if HAVE_MALLOC_H
00030 #include <malloc.h>
00031 #endif
00032
00033 #include "img_format.h"
00034 #include "mp_image.h"
00035 #include "vf.h"
00036 #include "libpostproc/postprocess.h"
00037
00038 #ifdef CONFIG_FFMPEG_A
00039 #define EMU_OLD
00040 #include "libpostproc/postprocess_internal.h"
00041 #endif
00042
00043 #undef malloc
00044
00045 struct vf_priv_s {
00046 int pp;
00047 pp_mode *ppMode[PP_QUALITY_MAX+1];
00048 void *context;
00049 unsigned int outfmt;
00050 };
00051
00052
00053
00054 static int config(struct vf_instance *vf,
00055 int width, int height, int d_width, int d_height,
00056 unsigned int voflags, unsigned int outfmt){
00057 int flags=
00058 (gCpuCaps.hasMMX ? PP_CPU_CAPS_MMX : 0)
00059 | (gCpuCaps.hasMMX2 ? PP_CPU_CAPS_MMX2 : 0)
00060 | (gCpuCaps.has3DNow ? PP_CPU_CAPS_3DNOW : 0);
00061
00062 switch(outfmt){
00063 case IMGFMT_444P: flags|= PP_FORMAT_444; break;
00064 case IMGFMT_422P: flags|= PP_FORMAT_422; break;
00065 case IMGFMT_411P: flags|= PP_FORMAT_411; break;
00066 default: flags|= PP_FORMAT_420; break;
00067 }
00068
00069 if(vf->priv->context) pp_free_context(vf->priv->context);
00070 vf->priv->context= pp_get_context(width, height, flags);
00071
00072 return vf_next_config(vf,width,height,d_width,d_height,voflags,outfmt);
00073 }
00074
00075 static void uninit(struct vf_instance *vf){
00076 int i;
00077 for(i=0; i<=PP_QUALITY_MAX; i++){
00078 if(vf->priv->ppMode[i])
00079 pp_free_mode(vf->priv->ppMode[i]);
00080 }
00081 if(vf->priv->context) pp_free_context(vf->priv->context);
00082 free(vf->priv);
00083 }
00084
00085 static int query_format(struct vf_instance *vf, unsigned int fmt){
00086 switch(fmt){
00087 case IMGFMT_YV12:
00088 case IMGFMT_I420:
00089 case IMGFMT_IYUV:
00090 case IMGFMT_444P:
00091 case IMGFMT_422P:
00092 case IMGFMT_411P:
00093 return vf_next_query_format(vf,fmt);
00094 }
00095 return 0;
00096 }
00097
00098 static int control(struct vf_instance *vf, int request, void* data){
00099 switch(request){
00100 case VFCTRL_QUERY_MAX_PP_LEVEL:
00101 return PP_QUALITY_MAX;
00102 case VFCTRL_SET_PP_LEVEL:
00103 vf->priv->pp= *((unsigned int*)data);
00104 return CONTROL_TRUE;
00105 }
00106 return vf_next_control(vf,request,data);
00107 }
00108
00109 static void get_image(struct vf_instance *vf, mp_image_t *mpi){
00110 if(vf->priv->pp&0xFFFF) return;
00111 if((mpi->type==MP_IMGTYPE_IPB || vf->priv->pp) &&
00112 mpi->flags&MP_IMGFLAG_PRESERVE) return;
00113 if(!(mpi->flags&MP_IMGFLAG_ACCEPT_STRIDE) && mpi->imgfmt!=vf->priv->outfmt)
00114 return;
00115
00116 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
00117 mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
00118 mpi->planes[0]=vf->dmpi->planes[0];
00119 mpi->stride[0]=vf->dmpi->stride[0];
00120 mpi->width=vf->dmpi->width;
00121 if(mpi->flags&MP_IMGFLAG_PLANAR){
00122 mpi->planes[1]=vf->dmpi->planes[1];
00123 mpi->planes[2]=vf->dmpi->planes[2];
00124 mpi->stride[1]=vf->dmpi->stride[1];
00125 mpi->stride[2]=vf->dmpi->stride[2];
00126 }
00127 mpi->flags|=MP_IMGFLAG_DIRECT;
00128 }
00129
00130 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
00131 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
00132
00133 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
00134 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE |
00135 MP_IMGFLAG_PREFER_ALIGNED_STRIDE | MP_IMGFLAG_READABLE,
00136
00137
00138 (mpi->width+7)&(~7),(mpi->height+7)&(~7));
00139 vf->dmpi->w=mpi->w; vf->dmpi->h=mpi->h;
00140 }
00141
00142 if(vf->priv->pp || !(mpi->flags&MP_IMGFLAG_DIRECT)){
00143
00144 pp_postprocess(mpi->planes ,mpi->stride,
00145 vf->dmpi->planes,vf->dmpi->stride,
00146 (mpi->w+7)&(~7),mpi->h,
00147 mpi->qscale, mpi->qstride,
00148 vf->priv->ppMode[ vf->priv->pp ], vf->priv->context,
00149 #ifdef PP_PICT_TYPE_QP2
00150 mpi->pict_type | (mpi->qscale_type ? PP_PICT_TYPE_QP2 : 0));
00151 #else
00152 mpi->pict_type);
00153 #endif
00154 }
00155 return vf_next_put_image(vf,vf->dmpi, pts);
00156 }
00157
00158
00159
00160 static const unsigned int fmt_list[]={
00161 IMGFMT_YV12,
00162 IMGFMT_I420,
00163 IMGFMT_IYUV,
00164 IMGFMT_444P,
00165 IMGFMT_422P,
00166 IMGFMT_411P,
00167 0
00168 };
00169
00170 static int vf_open(vf_instance_t *vf, char *args){
00171 char *endptr, *name;
00172 int i;
00173 int hex_mode=0;
00174
00175 vf->query_format=query_format;
00176 vf->control=control;
00177 vf->config=config;
00178 vf->get_image=get_image;
00179 vf->put_image=put_image;
00180 vf->uninit=uninit;
00181 vf->default_caps=VFCAP_ACCEPT_STRIDE|VFCAP_POSTPROC;
00182 vf->priv=malloc(sizeof(struct vf_priv_s));
00183 vf->priv->context=NULL;
00184
00185
00186 vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12);
00187 if(!vf->priv->outfmt) return 0;
00188
00189 if(args && *args){
00190 hex_mode= strtol(args, &endptr, 0);
00191 if(*endptr){
00192 name= args;
00193 }else
00194 name= NULL;
00195 }else{
00196 name="de";
00197 }
00198
00199 #ifdef EMU_OLD
00200 if(name){
00201 #endif
00202 for(i=0; i<=PP_QUALITY_MAX; i++){
00203 vf->priv->ppMode[i]= pp_get_mode_by_name_and_quality(name, i);
00204 if(vf->priv->ppMode[i]==NULL) return -1;
00205 }
00206 #ifdef EMU_OLD
00207 }else{
00208
00209 for(i=0; i<=PP_QUALITY_MAX; i++){
00210 PPMode *ppMode;
00211
00212 ppMode = av_malloc(sizeof(PPMode));
00213
00214 ppMode->lumMode= hex_mode;
00215 ppMode->chromMode= ((hex_mode&0xFF)>>4) | (hex_mode&0xFFFFFF00);
00216 ppMode->maxTmpNoise[0]= 700;
00217 ppMode->maxTmpNoise[1]= 1500;
00218 ppMode->maxTmpNoise[2]= 3000;
00219 ppMode->maxAllowedY= 234;
00220 ppMode->minAllowedY= 16;
00221 ppMode->baseDcDiff= 256/4;
00222 ppMode->flatnessThreshold=40;
00223
00224 vf->priv->ppMode[i]= ppMode;
00225 }
00226 }
00227 #endif
00228
00229 vf->priv->pp=PP_QUALITY_MAX;
00230 return 1;
00231 }
00232
00233 const vf_info_t vf_info_pp = {
00234 "postprocessing",
00235 "pp",
00236 "A'rpi",
00237 "",
00238 vf_open,
00239 NULL
00240 };
00241
00242