Mercurial > mplayer.hg
comparison libmpcodecs/vf_lavcdeint.c @ 6859:ed26b2d781e9
new filter to use libavcodec's deinterlacer
patch by Joe Rabinoff <rabinoff@fas.harvard.edu>
(TODO: DOCS, DR1)
author | arpi |
---|---|
date | Wed, 31 Jul 2002 19:50:42 +0000 |
parents | |
children | e575f4ee82f1 |
comparison
equal
deleted
inserted
replaced
6858:21186a5514b4 | 6859:ed26b2d781e9 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <inttypes.h> | |
5 | |
6 #include "../config.h" | |
7 #include "../mp_msg.h" | |
8 #include "../help_mp.h" | |
9 | |
10 #ifdef USE_LIBAVCODEC | |
11 | |
12 #include "img_format.h" | |
13 #include "mp_image.h" | |
14 #include "vf.h" | |
15 | |
16 //#include "../libvo/fastmemcpy.h" | |
17 | |
18 #ifdef USE_LIBAVCODEC_SO | |
19 #include <libffmpeg/avcodec.h> | |
20 #else | |
21 #include "libavcodec/avcodec.h" | |
22 #endif | |
23 | |
24 extern int avcodec_inited; | |
25 | |
26 struct vf_priv_s | |
27 { | |
28 AVPicture pic; | |
29 UINT8 *outbuf; | |
30 int outbuf_size; | |
31 int width, height; | |
32 int pix_fmt; | |
33 }; | |
34 | |
35 #define lavc_venc_context (vf->priv->context) | |
36 | |
37 | |
38 /* Support for avcodec's built-in deinterlacer. | |
39 * Based on vf_lavc.c | |
40 */ | |
41 | |
42 //===========================================================================// | |
43 | |
44 | |
45 /* Convert mplayer's IMGFMT_* to avcodec's PIX_FMT_* for the supported | |
46 * IMGFMT's, and return -1 if the deinterlacer doesn't support | |
47 * that format (-1 because 0 is a valid PIX_FMT). | |
48 */ | |
49 /* The deinterlacer supports planer 4:2:0, 4:2:2, and 4:4:4 YUV */ | |
50 static int | |
51 imgfmt_to_pixfmt (int imgfmt) | |
52 { | |
53 switch(imgfmt) | |
54 { | |
55 /* I hope I got all the supported formats */ | |
56 | |
57 /* 4:2:0 */ | |
58 case IMGFMT_YV12: | |
59 case IMGFMT_I420: | |
60 case IMGFMT_IYUV: | |
61 return PIX_FMT_YUV420P; | |
62 break; | |
63 | |
64 /* 4:2:2 */ | |
65 case IMGFMT_UYVY: | |
66 case IMGFMT_UYNV: | |
67 case IMGFMT_Y422: | |
68 case IMGFMT_YUY2: | |
69 case IMGFMT_YUNV: | |
70 case IMGFMT_YVYU: | |
71 case IMGFMT_Y42T: | |
72 case IMGFMT_V422: | |
73 case IMGFMT_V655: | |
74 return PIX_FMT_YUV422P; | |
75 break; | |
76 | |
77 /* Are there any _planar_ YUV 4:4:4 formats? */ | |
78 | |
79 default: | |
80 return -1; | |
81 } | |
82 } | |
83 | |
84 | |
85 static int | |
86 config (struct vf_instance_s* vf, | |
87 int width, int height, int d_width, int d_height, | |
88 unsigned int flags, unsigned int outfmt) | |
89 { | |
90 struct vf_priv_s *priv = vf->priv; | |
91 | |
92 priv->pix_fmt = imgfmt_to_pixfmt(outfmt); | |
93 if(priv->pix_fmt == -1) | |
94 return 0; | |
95 | |
96 /* The deinterlacer will fail if this is false */ | |
97 if ((width & 1) != 0 || (height & 3) != 0) | |
98 return 0; | |
99 | |
100 /* If we get here, the deinterlacer is guaranteed not to fail */ | |
101 | |
102 priv->width = width; | |
103 priv->height = height; | |
104 | |
105 | |
106 if(priv->outbuf) | |
107 av_free(priv->outbuf); | |
108 | |
109 priv->outbuf_size = | |
110 avpicture_get_size(priv->pix_fmt, priv->width, priv->height); | |
111 | |
112 priv->outbuf = av_malloc(priv->outbuf_size); | |
113 avpicture_fill(&priv->pic, priv->outbuf, priv->pix_fmt, | |
114 priv->width, priv->height); | |
115 | |
116 return vf_next_config(vf, | |
117 width, height, | |
118 d_width, d_height, | |
119 flags, outfmt); | |
120 } | |
121 | |
122 | |
123 static void | |
124 uninit (struct vf_instance_s *vf) | |
125 { | |
126 if(vf->priv->outbuf) | |
127 av_free(vf->priv->outbuf); | |
128 } | |
129 | |
130 | |
131 static void | |
132 put_image (struct vf_instance_s* vf, mp_image_t *mpi) | |
133 { | |
134 struct vf_priv_s *priv = vf->priv; | |
135 mp_image_t* dmpi; | |
136 AVPicture lavc_picture; | |
137 | |
138 lavc_picture.data[0] = mpi->planes[0]; | |
139 lavc_picture.data[1] = mpi->planes[1]; | |
140 lavc_picture.data[2] = mpi->planes[2]; | |
141 lavc_picture.linesize[0] = mpi->stride[0]; | |
142 lavc_picture.linesize[1] = mpi->stride[1]; | |
143 lavc_picture.linesize[2] = mpi->stride[2]; | |
144 | |
145 | |
146 dmpi = vf_get_image(vf->next, mpi->imgfmt, | |
147 MP_IMGTYPE_EXPORT, 0, | |
148 mpi->w, mpi->h); | |
149 | |
150 | |
151 if (avpicture_deinterlace(&priv->pic, &lavc_picture, | |
152 priv->pix_fmt, priv->width, priv->height) < 0) | |
153 { | |
154 /* This should not happen -- see config() */ | |
155 return; | |
156 } | |
157 | |
158 | |
159 dmpi->planes[0] = priv->pic.data[0]; | |
160 dmpi->planes[1] = priv->pic.data[1]; | |
161 dmpi->planes[2] = priv->pic.data[2]; | |
162 dmpi->stride[0] = priv->pic.linesize[0]; | |
163 dmpi->stride[1] = priv->pic.linesize[1]; | |
164 dmpi->stride[2] = priv->pic.linesize[2]; | |
165 | |
166 vf_next_put_image(vf, dmpi); | |
167 } | |
168 | |
169 | |
170 static int | |
171 query_format (struct vf_instance_s* vf, unsigned int fmt) | |
172 { | |
173 if(imgfmt_to_pixfmt(fmt) == -1) | |
174 return 0; | |
175 | |
176 return vf_next_query_format(vf,fmt); | |
177 } | |
178 | |
179 | |
180 static int | |
181 open (vf_instance_t *vf, char* args) | |
182 { | |
183 /* We don't have any args */ | |
184 (void) args; | |
185 | |
186 vf->config = config; | |
187 vf->put_image = put_image; | |
188 vf->query_format = query_format; | |
189 vf->uninit = uninit; | |
190 vf->priv = malloc(sizeof(struct vf_priv_s)); | |
191 memset(vf->priv,0,sizeof(struct vf_priv_s)); | |
192 | |
193 /* This may not technically be necessary just for a deinterlace, | |
194 * but it seems like a good idea. | |
195 */ | |
196 if(!avcodec_inited) | |
197 { | |
198 avcodec_init(); | |
199 avcodec_register_all(); | |
200 avcodec_inited=1; | |
201 } | |
202 | |
203 return 1; | |
204 } | |
205 | |
206 | |
207 vf_info_t vf_info_lavcdeint = { | |
208 "libavcodec's deinterlacing filter", | |
209 "lavcdeint", | |
210 "Joe Rabinoff", | |
211 "libavcodec's internal deinterlacer, in case you don't like " | |
212 "the builtin ones (invoked with -pp or -npp)", | |
213 open | |
214 }; | |
215 | |
216 | |
217 //===========================================================================// | |
218 | |
219 #endif /* USE_LIBAVCODEC */ | |
220 |