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
00023 #include "config.h"
00024 #include "mp_msg.h"
00025
00026 #include "img_format.h"
00027 #include "mp_image.h"
00028 #include "vf.h"
00029
00030 #include "libvo/fastmemcpy.h"
00031
00032 struct vf_priv_s {
00033 int state;
00034 long long in;
00035 long long out;
00036 };
00037
00038 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
00039 {
00040 mp_image_t *dmpi;
00041 int ret = 0;
00042 int flags = mpi->fields;
00043 int state = vf->priv->state;
00044
00045 dmpi = vf_get_image(vf->next, mpi->imgfmt,
00046 MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
00047 MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
00048
00049 vf->priv->in++;
00050
00051 if ((state == 0 &&
00052 !(flags & MP_IMGFIELD_TOP_FIRST)) ||
00053 (state == 1 &&
00054 flags & MP_IMGFIELD_TOP_FIRST)) {
00055 mp_msg(MSGT_VFILTER, MSGL_WARN,
00056 "softpulldown: Unexpected field flags: state=%d top_field_first=%d repeat_first_field=%d\n",
00057 state,
00058 (flags & MP_IMGFIELD_TOP_FIRST) != 0,
00059 (flags & MP_IMGFIELD_REPEAT_FIRST) != 0);
00060 state ^= 1;
00061 }
00062
00063 if (state == 0) {
00064 ret = vf_next_put_image(vf, mpi, MP_NOPTS_VALUE);
00065 vf->priv->out++;
00066 if (flags & MP_IMGFIELD_REPEAT_FIRST) {
00067 my_memcpy_pic(dmpi->planes[0],
00068 mpi->planes[0], mpi->w, mpi->h/2,
00069 dmpi->stride[0]*2, mpi->stride[0]*2);
00070 if (mpi->flags & MP_IMGFLAG_PLANAR) {
00071 my_memcpy_pic(dmpi->planes[1],
00072 mpi->planes[1],
00073 mpi->chroma_width,
00074 mpi->chroma_height/2,
00075 dmpi->stride[1]*2,
00076 mpi->stride[1]*2);
00077 my_memcpy_pic(dmpi->planes[2],
00078 mpi->planes[2],
00079 mpi->chroma_width,
00080 mpi->chroma_height/2,
00081 dmpi->stride[2]*2,
00082 mpi->stride[2]*2);
00083 }
00084 state=1;
00085 }
00086 } else {
00087 my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
00088 mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
00089 dmpi->stride[0]*2, mpi->stride[0]*2);
00090 if (mpi->flags & MP_IMGFLAG_PLANAR) {
00091 my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
00092 mpi->planes[1]+mpi->stride[1],
00093 mpi->chroma_width, mpi->chroma_height/2,
00094 dmpi->stride[1]*2, mpi->stride[1]*2);
00095 my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
00096 mpi->planes[2]+mpi->stride[2],
00097 mpi->chroma_width, mpi->chroma_height/2,
00098 dmpi->stride[2]*2, mpi->stride[2]*2);
00099 }
00100 ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
00101 vf->priv->out++;
00102 if (flags & MP_IMGFIELD_REPEAT_FIRST) {
00103 ret |= vf_next_put_image(vf, mpi, MP_NOPTS_VALUE);
00104 vf->priv->out++;
00105 state=0;
00106 } else {
00107 my_memcpy_pic(dmpi->planes[0],
00108 mpi->planes[0], mpi->w, mpi->h/2,
00109 dmpi->stride[0]*2, mpi->stride[0]*2);
00110 if (mpi->flags & MP_IMGFLAG_PLANAR) {
00111 my_memcpy_pic(dmpi->planes[1],
00112 mpi->planes[1],
00113 mpi->chroma_width,
00114 mpi->chroma_height/2,
00115 dmpi->stride[1]*2,
00116 mpi->stride[1]*2);
00117 my_memcpy_pic(dmpi->planes[2],
00118 mpi->planes[2],
00119 mpi->chroma_width,
00120 mpi->chroma_height/2,
00121 dmpi->stride[2]*2,
00122 mpi->stride[2]*2);
00123 }
00124 }
00125 }
00126
00127 vf->priv->state = state;
00128
00129 return ret;
00130 }
00131
00132 static int config(struct vf_instance *vf,
00133 int width, int height, int d_width, int d_height,
00134 unsigned int flags, unsigned int outfmt)
00135 {
00136 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
00137 }
00138
00139 static void uninit(struct vf_instance *vf)
00140 {
00141 mp_msg(MSGT_VFILTER, MSGL_INFO, "softpulldown: %lld frames in, %lld frames out\n", vf->priv->in, vf->priv->out);
00142 free(vf->priv);
00143 }
00144
00145 static int vf_open(vf_instance_t *vf, char *args)
00146 {
00147 struct vf_priv_s *p;
00148 vf->config = config;
00149 vf->put_image = put_image;
00150 vf->uninit = uninit;
00151 vf->default_reqs = VFCAP_ACCEPT_STRIDE;
00152 vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
00153 vf->priv->state = 0;
00154 return 1;
00155 }
00156
00157 const vf_info_t vf_info_softpulldown = {
00158 "mpeg2 soft 3:2 pulldown",
00159 "softpulldown",
00160 "Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
00161 "",
00162 vf_open,
00163 NULL
00164 };