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= PP_CPU_CAPS_AUTO;
00058
00059 switch(outfmt){
00060 case IMGFMT_444P: flags|= PP_FORMAT_444; break;
00061 case IMGFMT_422P: flags|= PP_FORMAT_422; break;
00062 case IMGFMT_411P: flags|= PP_FORMAT_411; break;
00063 default: flags|= PP_FORMAT_420; break;
00064 }
00065
00066 if(vf->priv->context) pp_free_context(vf->priv->context);
00067 vf->priv->context= pp_get_context(width, height, flags);
00068
00069 return ff_vf_next_config(vf,width,height,d_width,d_height,voflags,outfmt);
00070 }
00071
00072 static void uninit(struct vf_instance *vf){
00073 int i;
00074 for(i=0; i<=PP_QUALITY_MAX; i++){
00075 if(vf->priv->ppMode[i])
00076 pp_free_mode(vf->priv->ppMode[i]);
00077 }
00078 if(vf->priv->context) pp_free_context(vf->priv->context);
00079 free(vf->priv);
00080 }
00081
00082 static int query_format(struct vf_instance *vf, unsigned int fmt){
00083 switch(fmt){
00084 case IMGFMT_YV12:
00085 case IMGFMT_I420:
00086 case IMGFMT_IYUV:
00087 case IMGFMT_444P:
00088 case IMGFMT_422P:
00089 case IMGFMT_411P:
00090 return ff_vf_next_query_format(vf,fmt);
00091 }
00092 return 0;
00093 }
00094
00095 static int control(struct vf_instance *vf, int request, void* data){
00096 switch(request){
00097 case VFCTRL_QUERY_MAX_PP_LEVEL:
00098 return PP_QUALITY_MAX;
00099 case VFCTRL_SET_PP_LEVEL:
00100 vf->priv->pp= *((unsigned int*)data);
00101 return CONTROL_TRUE;
00102 }
00103 return ff_vf_next_control(vf,request,data);
00104 }
00105
00106 static void get_image(struct vf_instance *vf, mp_image_t *mpi){
00107 if(vf->priv->pp&0xFFFF) return;
00108 if((mpi->type==MP_IMGTYPE_IPB || vf->priv->pp) &&
00109 mpi->flags&MP_IMGFLAG_PRESERVE) return;
00110 if(!(mpi->flags&MP_IMGFLAG_ACCEPT_STRIDE) && mpi->imgfmt!=vf->priv->outfmt)
00111 return;
00112
00113 vf->dmpi=ff_vf_get_image(vf->next,mpi->imgfmt,
00114 mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
00115 mpi->planes[0]=vf->dmpi->planes[0];
00116 mpi->stride[0]=vf->dmpi->stride[0];
00117 mpi->width=vf->dmpi->width;
00118 if(mpi->flags&MP_IMGFLAG_PLANAR){
00119 mpi->planes[1]=vf->dmpi->planes[1];
00120 mpi->planes[2]=vf->dmpi->planes[2];
00121 mpi->stride[1]=vf->dmpi->stride[1];
00122 mpi->stride[2]=vf->dmpi->stride[2];
00123 }
00124 mpi->flags|=MP_IMGFLAG_DIRECT;
00125 }
00126
00127 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
00128 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
00129
00130 vf->dmpi=ff_vf_get_image(vf->next,mpi->imgfmt,
00131 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE |
00132 MP_IMGFLAG_PREFER_ALIGNED_STRIDE | MP_IMGFLAG_READABLE,
00133
00134
00135 (mpi->width+7)&(~7),(mpi->height+7)&(~7));
00136 vf->dmpi->w=mpi->w; vf->dmpi->h=mpi->h;
00137 }
00138
00139 if(vf->priv->pp || !(mpi->flags&MP_IMGFLAG_DIRECT)){
00140
00141 pp_postprocess(mpi->planes ,mpi->stride,
00142 vf->dmpi->planes,vf->dmpi->stride,
00143 (mpi->w+7)&(~7),mpi->h,
00144 mpi->qscale, mpi->qstride,
00145 vf->priv->ppMode[ vf->priv->pp ], vf->priv->context,
00146 #ifdef PP_PICT_TYPE_QP2
00147 mpi->pict_type | (mpi->qscale_type ? PP_PICT_TYPE_QP2 : 0));
00148 #else
00149 mpi->pict_type);
00150 #endif
00151 }
00152 return ff_vf_next_put_image(vf,vf->dmpi, pts);
00153 }
00154
00155
00156
00157 static const unsigned int fmt_list[]={
00158 IMGFMT_YV12,
00159 IMGFMT_I420,
00160 IMGFMT_IYUV,
00161 IMGFMT_444P,
00162 IMGFMT_422P,
00163 IMGFMT_411P,
00164 0
00165 };
00166
00167 static int vf_open(vf_instance_t *vf, char *args){
00168 char *endptr, *name;
00169 int i;
00170 int hex_mode=0;
00171
00172 vf->query_format=query_format;
00173 vf->control=control;
00174 vf->config=config;
00175 vf->get_image=get_image;
00176 vf->put_image=put_image;
00177 vf->uninit=uninit;
00178 vf->default_caps=VFCAP_ACCEPT_STRIDE|VFCAP_POSTPROC;
00179 vf->priv=malloc(sizeof(struct vf_priv_s));
00180 vf->priv->context=NULL;
00181
00182
00183 vf->priv->outfmt=ff_vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12);
00184 if(!vf->priv->outfmt) return 0;
00185
00186 if(args && *args){
00187 hex_mode= strtol(args, &endptr, 0);
00188 if(*endptr){
00189 name= args;
00190 }else
00191 name= NULL;
00192 }else{
00193 name="de";
00194 }
00195
00196 #ifdef EMU_OLD
00197 if(name){
00198 #endif
00199 for(i=0; i<=PP_QUALITY_MAX; i++){
00200 vf->priv->ppMode[i]= pp_get_mode_by_name_and_quality(name, i);
00201 if(vf->priv->ppMode[i]==NULL) return -1;
00202 }
00203 #ifdef EMU_OLD
00204 }else{
00205
00206 for(i=0; i<=PP_QUALITY_MAX; i++){
00207 PPMode *ppMode;
00208
00209 ppMode = av_malloc(sizeof(PPMode));
00210
00211 ppMode->lumMode= hex_mode;
00212 ppMode->chromMode= ((hex_mode&0xFF)>>4) | (hex_mode&0xFFFFFF00);
00213 ppMode->maxTmpNoise[0]= 700;
00214 ppMode->maxTmpNoise[1]= 1500;
00215 ppMode->maxTmpNoise[2]= 3000;
00216 ppMode->maxAllowedY= 234;
00217 ppMode->minAllowedY= 16;
00218 ppMode->baseDcDiff= 256/4;
00219 ppMode->flatnessThreshold=40;
00220
00221 vf->priv->ppMode[i]= ppMode;
00222 }
00223 }
00224 #endif
00225
00226 vf->priv->pp=PP_QUALITY_MAX;
00227 return 1;
00228 }
00229
00230 const vf_info_t ff_vf_info_pp = {
00231 "postprocessing",
00232 "pp",
00233 "A'rpi",
00234 "",
00235 vf_open,
00236 NULL
00237 };
00238
00239