example.conf: Disambiguate remarks about profiles
[mplayer.git] / libmpcodecs / vf_lavcdeint.c
blobfd564e72af27e788146ad91fd1f4dd86c018916b
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>
24 #include "config.h"
25 #include "mp_msg.h"
27 #include "img_format.h"
28 #include "mp_image.h"
29 #include "vf.h"
30 #include "vd_ffmpeg.h"
31 #include "libavcodec/avcodec.h"
34 struct vf_priv_s
36 int width, height;
37 int pix_fmt;
40 /* Support for avcodec's built-in deinterlacer.
41 * Based on vf_lavc.c
44 //===========================================================================//
47 /* Convert mplayer's IMGFMT_* to avcodec's PIX_FMT_* for the supported
48 * IMGFMT's, and return -1 if the deinterlacer doesn't support
49 * that format (-1 because 0 is a valid PIX_FMT).
51 /* The deinterlacer supports planer 4:2:0, 4:2:2, and 4:4:4 YUV */
52 static int
53 imgfmt_to_pixfmt (int imgfmt)
55 switch(imgfmt)
57 /* I hope I got all the supported formats */
59 /* 4:2:0 */
60 case IMGFMT_YV12:
61 case IMGFMT_I420:
62 case IMGFMT_IYUV:
63 return PIX_FMT_YUV420P;
64 break;
66 #if 0
67 /* 4:2:2 */
68 case IMGFMT_UYVY:
69 case IMGFMT_UYNV:
70 case IMGFMT_Y422:
71 case IMGFMT_YUY2:
72 case IMGFMT_YUNV:
73 case IMGFMT_YVYU:
74 case IMGFMT_Y42T:
75 case IMGFMT_V422:
76 case IMGFMT_V655:
77 return PIX_FMT_YUV422P;
78 break;
79 #endif
81 /* Are there any _planar_ YUV 4:4:4 formats? */
83 default:
84 return -1;
89 static int
90 config (struct vf_instance *vf,
91 int width, int height, int d_width, int d_height,
92 unsigned int flags, unsigned int outfmt)
94 struct vf_priv_s *priv = vf->priv;
96 priv->pix_fmt = imgfmt_to_pixfmt(outfmt);
97 if(priv->pix_fmt == -1)
98 return 0;
100 /* The deinterlacer will fail if this is false */
101 if ((width & 3) != 0 || (height & 3) != 0)
102 return 0;
104 /* If we get here, the deinterlacer is guaranteed not to fail */
106 priv->width = width;
107 priv->height = height;
109 return vf_next_config(vf,
110 width, height,
111 d_width, d_height,
112 flags, outfmt);
115 static int
116 put_image (struct vf_instance *vf, mp_image_t *mpi, double pts)
118 struct vf_priv_s *priv = vf->priv;
119 mp_image_t* dmpi;
120 AVPicture pic;
121 AVPicture lavc_picture;
123 lavc_picture.data[0] = mpi->planes[0];
124 lavc_picture.data[1] = mpi->planes[1];
125 lavc_picture.data[2] = mpi->planes[2];
126 lavc_picture.linesize[0] = mpi->stride[0];
127 lavc_picture.linesize[1] = mpi->stride[1];
128 lavc_picture.linesize[2] = mpi->stride[2];
130 dmpi = vf_get_image(vf->next, mpi->imgfmt,
131 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
132 priv->width, priv->height);
134 pic.data[0] = dmpi->planes[0];
135 pic.data[1] = dmpi->planes[1];
136 pic.data[2] = dmpi->planes[2];
137 pic.linesize[0] = dmpi->stride[0];
138 pic.linesize[1] = dmpi->stride[1];
139 pic.linesize[2] = dmpi->stride[2];
141 if (avpicture_deinterlace(&pic, &lavc_picture,
142 priv->pix_fmt, priv->width, priv->height) < 0)
144 /* This should not happen -- see config() */
145 return 0;
148 return vf_next_put_image(vf, dmpi, pts);
152 static int
153 query_format (struct vf_instance *vf, unsigned int fmt)
155 if(imgfmt_to_pixfmt(fmt) == -1)
156 return 0;
158 return vf_next_query_format(vf,fmt);
162 static int
163 vf_open(vf_instance_t *vf, char *args)
165 /* We don't have any args */
166 (void) args;
168 vf->config = config;
169 vf->put_image = put_image;
170 vf->query_format = query_format;
171 vf->priv = malloc(sizeof(struct vf_priv_s));
172 memset(vf->priv,0,sizeof(struct vf_priv_s));
174 /* This may not technically be necessary just for a deinterlace,
175 * but it seems like a good idea.
177 init_avcodec();
179 return 1;
183 const vf_info_t vf_info_lavcdeint = {
184 "libavcodec's deinterlacing filter",
185 "lavcdeint",
186 "Joe Rabinoff",
187 "libavcodec's internal deinterlacer, in case you don't like "
188 "the builtin ones (invoked with -pp or -npp)",
189 vf_open,
190 NULL
194 //===========================================================================//