vf_uspp.c
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 398 行 · 第 1/2 页
C
398 行
} } } for(j=0; j<3; j++){ int is_chroma= !!j; store_slice_c(dst[j], p->temp[j], dst_stride[j], p->temp_stride[j], width>>is_chroma, height>>is_chroma, 8-p->log2_count); }}static int config(struct vf_instance_s* vf, int width, int height, int d_width, int d_height, unsigned int flags, unsigned int outfmt){ int i; AVCodec *enc= avcodec_find_encoder(CODEC_ID_SNOW); for(i=0; i<3; i++){ int is_chroma= !!i; int w= ((width + 4*BLOCK-1) & (~(2*BLOCK-1)))>>is_chroma; int h= ((height + 4*BLOCK-1) & (~(2*BLOCK-1)))>>is_chroma; vf->priv->temp_stride[i]= w; vf->priv->temp[i]= malloc(vf->priv->temp_stride[i]*h*sizeof(int16_t)); vf->priv->src [i]= malloc(vf->priv->temp_stride[i]*h*sizeof(uint8_t)); } for(i=0; i< (1<<vf->priv->log2_count); i++){ AVCodecContext *avctx_enc; avctx_enc= vf->priv->avctx_enc[i]= avcodec_alloc_context(); avctx_enc->width = width + BLOCK; avctx_enc->height = height + BLOCK; avctx_enc->time_base= (AVRational){1,25}; // meaningless avctx_enc->gop_size = 300; avctx_enc->max_b_frames= 0; avctx_enc->pix_fmt = PIX_FMT_YUV420P; avctx_enc->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY; avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL; avctx_enc->global_quality= 123; avcodec_open(avctx_enc, enc); assert(avctx_enc->codec); } vf->priv->frame= avcodec_alloc_frame(); vf->priv->frame_dec= avcodec_alloc_frame(); vf->priv->outbuf_size= (width + BLOCK)*(height + BLOCK)*10; vf->priv->outbuf= malloc(vf->priv->outbuf_size); return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);}static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change // ok, we can do pp in-place (or pp disabled): vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height); mpi->planes[0]=vf->dmpi->planes[0]; mpi->stride[0]=vf->dmpi->stride[0]; mpi->width=vf->dmpi->width; if(mpi->flags&MP_IMGFLAG_PLANAR){ mpi->planes[1]=vf->dmpi->planes[1]; mpi->planes[2]=vf->dmpi->planes[2]; mpi->stride[1]=vf->dmpi->stride[1]; mpi->stride[2]=vf->dmpi->stride[2]; } mpi->flags|=MP_IMGFLAG_DIRECT;}static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ mp_image_t *dmpi; if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ // no DR, so get a new image! hope we'll get DR buffer: dmpi=vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, mpi->width,mpi->height); vf_clone_mpi_attributes(dmpi, mpi); }else{ dmpi=vf->dmpi; } vf->priv->mpeg2= mpi->qscale_type; if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){ if(mpi->qscale || vf->priv->qp){ filter(vf->priv, dmpi->planes, mpi->planes, dmpi->stride, mpi->stride, mpi->w, mpi->h, mpi->qscale, mpi->qstride); }else{ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]); memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]); memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]); } }#ifdef HAVE_MMX if(gCpuCaps.hasMMX) asm volatile ("emms\n\t");#endif#ifdef HAVE_MMX2 if(gCpuCaps.hasMMX2) asm volatile ("sfence\n\t");#endif return vf_next_put_image(vf,dmpi, pts);}static void uninit(struct vf_instance_s* vf){ int i; if(!vf->priv) return; for(i=0; i<3; i++){ if(vf->priv->temp[i]) free(vf->priv->temp[i]); vf->priv->temp[i]= NULL; if(vf->priv->src[i]) free(vf->priv->src[i]); vf->priv->src[i]= NULL; } for(i=0; i<BLOCK*BLOCK; i++){ av_freep(&vf->priv->avctx_enc[i]); } free(vf->priv); vf->priv=NULL;}//===========================================================================//static int query_format(struct vf_instance_s* vf, unsigned int fmt){ switch(fmt){ case IMGFMT_YV12: case IMGFMT_I420: case IMGFMT_IYUV: case IMGFMT_Y800: case IMGFMT_Y8: return vf_next_query_format(vf,fmt); } return 0;}static unsigned int fmt_list[]={ IMGFMT_YV12, IMGFMT_I420, IMGFMT_IYUV, IMGFMT_Y800, IMGFMT_Y8, 0};static int control(struct vf_instance_s* vf, int request, void* data){ switch(request){ case VFCTRL_QUERY_MAX_PP_LEVEL: return 8; case VFCTRL_SET_PP_LEVEL: vf->priv->log2_count= *((unsigned int*)data); //FIXME we have to realloc a few things here return CONTROL_TRUE; } return vf_next_control(vf,request,data);}static int open(vf_instance_t *vf, char* args){ int log2c=-1; vf->config=config; vf->put_image=put_image; vf->get_image=get_image; vf->query_format=query_format; vf->uninit=uninit; vf->control= control; vf->priv=malloc(sizeof(struct vf_priv_s)); memset(vf->priv, 0, sizeof(struct vf_priv_s)); avcodec_init(); avcodec_register_all(); vf->priv->log2_count= 4; if (args) sscanf(args, "%d:%d:%d", &log2c, &vf->priv->qp, &vf->priv->mode); if( log2c >=0 && log2c <=8 ) vf->priv->log2_count = log2c; if(vf->priv->qp < 0) vf->priv->qp = 0;// #ifdef HAVE_MMX// if(gCpuCaps.hasMMX){// store_slice= store_slice_mmx;// }// #endif return 1;}vf_info_t vf_info_uspp = { "ultra simple/slow postprocess", "uspp", "Michael Niedermayer", "", open, NULL};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?