Add webm/VP8 support to native matroska demuxer.
[mplayer/glamo.git] / libmpcodecs / vf_lavcdeint.c
blobe97d450112a6f6913c118fd4b632253fc65ca5e4
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"
26 #include "help_mp.h"
28 #include "img_format.h"
29 #include "mp_image.h"
30 #include "vf.h"
31 #include "libavcodec/avcodec.h"
33 extern int avcodec_initialized;
35 struct vf_priv_s
37 int width, height;
38 int pix_fmt;
41 /* Support for avcodec's built-in deinterlacer.
42 * Based on vf_lavc.c
45 //===========================================================================//
48 /* Convert mplayer's IMGFMT_* to avcodec's PIX_FMT_* for the supported
49 * IMGFMT's, and return -1 if the deinterlacer doesn't support
50 * that format (-1 because 0 is a valid PIX_FMT).
52 /* The deinterlacer supports planer 4:2:0, 4:2:2, and 4:4:4 YUV */
53 static int
54 imgfmt_to_pixfmt (int imgfmt)
56 switch(imgfmt)
58 /* I hope I got all the supported formats */
60 /* 4:2:0 */
61 case IMGFMT_YV12:
62 case IMGFMT_I420:
63 case IMGFMT_IYUV:
64 return PIX_FMT_YUV420P;
65 break;
67 #if 0
68 /* 4:2:2 */
69 case IMGFMT_UYVY:
70 case IMGFMT_UYNV:
71 case IMGFMT_Y422:
72 case IMGFMT_YUY2:
73 case IMGFMT_YUNV:
74 case IMGFMT_YVYU:
75 case IMGFMT_Y42T:
76 case IMGFMT_V422:
77 case IMGFMT_V655:
78 return PIX_FMT_YUV422P;
79 break;
80 #endif
82 /* Are there any _planar_ YUV 4:4:4 formats? */
84 default:
85 return -1;
90 static int
91 config (struct vf_instance *vf,
92 int width, int height, int d_width, int d_height,
93 unsigned int flags, unsigned int outfmt)
95 struct vf_priv_s *priv = vf->priv;
97 priv->pix_fmt = imgfmt_to_pixfmt(outfmt);
98 if(priv->pix_fmt == -1)
99 return 0;
101 /* The deinterlacer will fail if this is false */
102 if ((width & 3) != 0 || (height & 3) != 0)
103 return 0;
105 /* If we get here, the deinterlacer is guaranteed not to fail */
107 priv->width = width;
108 priv->height = height;
110 return vf_next_config(vf,
111 width, height,
112 d_width, d_height,
113 flags, outfmt);
116 static int
117 put_image (struct vf_instance *vf, mp_image_t *mpi, double pts)
119 struct vf_priv_s *priv = vf->priv;
120 mp_image_t* dmpi;
121 AVPicture pic;
122 AVPicture lavc_picture;
124 lavc_picture.data[0] = mpi->planes[0];
125 lavc_picture.data[1] = mpi->planes[1];
126 lavc_picture.data[2] = mpi->planes[2];
127 lavc_picture.linesize[0] = mpi->stride[0];
128 lavc_picture.linesize[1] = mpi->stride[1];
129 lavc_picture.linesize[2] = mpi->stride[2];
131 dmpi = vf_get_image(vf->next, mpi->imgfmt,
132 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
133 priv->width, priv->height);
135 pic.data[0] = dmpi->planes[0];
136 pic.data[1] = dmpi->planes[1];
137 pic.data[2] = dmpi->planes[2];
138 pic.linesize[0] = dmpi->stride[0];
139 pic.linesize[1] = dmpi->stride[1];
140 pic.linesize[2] = dmpi->stride[2];
142 if (avpicture_deinterlace(&pic, &lavc_picture,
143 priv->pix_fmt, priv->width, priv->height) < 0)
145 /* This should not happen -- see config() */
146 return 0;
149 return vf_next_put_image(vf, dmpi, pts);
153 static int
154 query_format (struct vf_instance *vf, unsigned int fmt)
156 if(imgfmt_to_pixfmt(fmt) == -1)
157 return 0;
159 return vf_next_query_format(vf,fmt);
163 static int
164 vf_open(vf_instance_t *vf, char *args)
166 /* We don't have any args */
167 (void) args;
169 vf->config = config;
170 vf->put_image = put_image;
171 vf->query_format = query_format;
172 vf->priv = malloc(sizeof(struct vf_priv_s));
173 memset(vf->priv,0,sizeof(struct vf_priv_s));
175 /* This may not technically be necessary just for a deinterlace,
176 * but it seems like a good idea.
178 if(!avcodec_initialized)
180 avcodec_init();
181 avcodec_register_all();
182 avcodec_initialized=1;
185 return 1;
189 const vf_info_t vf_info_lavcdeint = {
190 "libavcodec's deinterlacing filter",
191 "lavcdeint",
192 "Joe Rabinoff",
193 "libavcodec's internal deinterlacer, in case you don't like "
194 "the builtin ones (invoked with -pp or -npp)",
195 vf_open,
196 NULL
200 //===========================================================================//