Mercurial > mplayer.hg
annotate libmpcodecs/vf_yadif.c @ 19294:6e6b33b0b57e
correctly report audio input
author | ben |
---|---|
date | Thu, 03 Aug 2006 18:59:37 +0000 |
parents | d9a75b26da6c |
children | 1d5832b4b204 |
rev | line source |
---|---|
18608 | 1 /* |
2 Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at> | |
3 | |
4 This program 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. | |
8 | |
9 This program 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. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program; if not, write to the Free Software | |
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
17 */ | |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 #include <inttypes.h> | |
23 #include <math.h> | |
24 | |
25 #include "config.h" | |
26 | |
27 #include "mp_msg.h" | |
28 | |
29 #ifdef HAVE_MALLOC_H | |
30 #include <malloc.h> | |
31 #endif | |
32 | |
33 #include "img_format.h" | |
34 #include "mp_image.h" | |
35 #include "vf.h" | |
36 #include "libvo/fastmemcpy.h" | |
37 | |
38 #define MIN(a,b) ((a) > (b) ? (b) : (a)) | |
39 #define MAX(a,b) ((a) < (b) ? (b) : (a)) | |
40 #define ABS(a) ((a) > 0 ? (a) : (-(a))) | |
41 | |
42 #define MIN3(a,b,c) MIN(MIN(a,b),c) | |
43 #define MAX3(a,b,c) MAX(MAX(a,b),c) | |
44 | |
45 //===========================================================================// | |
46 | |
47 struct vf_priv_s { | |
48 int mode; | |
49 int parity; | |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
50 int buffered_i; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
51 int buffered_tff; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
52 double buffered_pts; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
53 mp_image_t *buffered_mpi; |
18608 | 54 int stride[3]; |
18625 | 55 uint8_t *ref[4][3]; |
18608 | 56 }; |
57 | |
58 static void store_ref(struct vf_priv_s *p, uint8_t *src[3], int src_stride[3], int width, int height){ | |
59 int i; | |
60 | |
18625 | 61 memcpy (p->ref[3], p->ref[0], sizeof(uint8_t *)*3); |
62 memmove(p->ref[0], p->ref[1], sizeof(uint8_t *)*3*3); | |
18608 | 63 |
64 for(i=0; i<3; i++){ | |
65 int is_chroma= !!i; | |
66 | |
18625 | 67 memcpy_pic(p->ref[2][i], src[i], width>>is_chroma, height>>is_chroma, p->stride[i], src_stride[i]); |
18608 | 68 } |
69 } | |
70 | |
18625 | 71 static void filter(struct vf_priv_s *p, uint8_t *dst[3], int dst_stride[3], int width, int height, int parity, int tff){ |
18657 | 72 int x, y, i; |
18608 | 73 |
74 for(i=0; i<3; i++){ | |
75 int is_chroma= !!i; | |
76 int w= width >>is_chroma; | |
77 int h= height>>is_chroma; | |
78 int refs= p->stride[i]; | |
79 | |
80 for(y=0; y<h; y++){ | |
81 if((y ^ parity) & 1){ | |
82 for(x=0; x<w; x++){ | |
83 uint8_t *prev= &p->ref[0][i][x + y*refs]; | |
84 uint8_t *cur = &p->ref[1][i][x + y*refs]; | |
18625 | 85 uint8_t *next= &p->ref[2][i][x + y*refs]; |
18621 | 86 uint8_t *prev2= (tff ^ parity) ? prev : cur ; |
87 uint8_t *next2= (tff ^ parity) ? cur : next; | |
18608 | 88 |
18623 | 89 int c= cur[-refs]; |
90 int d= (prev2[0] + next2[0])>>1; | |
91 int e= cur[+refs]; | |
18608 | 92 int temporal_diff0= ABS(prev2[0] - next2[0]); |
18623 | 93 int temporal_diff1=( ABS(prev[-refs] - c) + ABS(prev[+refs] - e) )>>1; |
18625 | 94 int temporal_diff2=( ABS(next[-refs] - c) + ABS(next[+refs] - e) )>>1; |
18610 | 95 int diff= MAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2); |
18623 | 96 int spatial_pred= (c+e)>>1; |
97 int spatial_score= ABS(cur[-refs-1] - cur[+refs-1]) + ABS(c-e) | |
18657 | 98 + ABS(cur[-refs+1] - cur[+refs+1]) - 1; |
18621 | 99 |
18657 | 100 #define CHECK(j)\ |
101 { int score= ABS(cur[-refs-1+j] - cur[+refs-1-j])\ | |
102 + ABS(cur[-refs +j] - cur[+refs -j])\ | |
103 + ABS(cur[-refs+1+j] - cur[+refs+1-j]);\ | |
104 if(score < spatial_score){\ | |
105 spatial_score= score;\ | |
106 spatial_pred= (cur[-refs +j] + cur[+refs -j])>>1;\ | |
18608 | 107 |
18657 | 108 CHECK(-1) CHECK(-2) }} }} |
109 CHECK( 1) CHECK( 2) }} }} | |
110 | |
18626 | 111 if(p->mode<2){ |
18625 | 112 int b= (prev2[-2*refs] + next2[-2*refs])>>1; |
113 int f= (prev2[+2*refs] + next2[+2*refs])>>1; | |
18608 | 114 #if 0 |
18625 | 115 int a= cur[-3*refs]; |
116 int g= cur[+3*refs]; | |
18608 | 117 int max= MAX3(d-e, d-c, MIN3(MAX(b-c,f-e),MAX(b-c,b-a),MAX(f-g,f-e)) ); |
118 int min= MIN3(d-e, d-c, MAX3(MIN(b-c,f-e),MIN(b-c,b-a),MIN(f-g,f-e)) ); | |
119 #else | |
120 int max= MAX3(d-e, d-c, MIN(b-c, f-e)); | |
121 int min= MIN3(d-e, d-c, MAX(b-c, f-e)); | |
122 #endif | |
123 | |
124 diff= MAX3(diff, min, -max); | |
125 } | |
126 | |
18623 | 127 if(d < spatial_pred) d= MIN(d + diff, spatial_pred); |
128 else d= MAX(d - diff, spatial_pred); | |
18608 | 129 |
18623 | 130 dst[i][x + y*dst_stride[i]]= d; |
18608 | 131 } |
132 }else{ | |
18610 | 133 memcpy(&dst[i][y*dst_stride[i]], &p->ref[1][i][y*refs], w); |
18608 | 134 } |
135 } | |
136 } | |
137 } | |
138 | |
139 static int config(struct vf_instance_s* vf, | |
140 int width, int height, int d_width, int d_height, | |
141 unsigned int flags, unsigned int outfmt){ | |
18625 | 142 int i, j; |
18608 | 143 |
144 for(i=0; i<3; i++){ | |
145 int is_chroma= !!i; | |
18625 | 146 int w= ((width + 31) & (~31))>>is_chroma; |
147 int h= ((height+6+ 31) & (~31))>>is_chroma; | |
18608 | 148 |
149 vf->priv->stride[i]= w; | |
18625 | 150 for(j=0; j<3; j++) |
151 vf->priv->ref[j][i]= malloc(w*h*sizeof(uint8_t))+3*w; | |
18608 | 152 } |
153 | |
154 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
155 } | |
156 | |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
157 static int continue_buffered_image(struct vf_instance_s *vf); |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
158 extern int correct_pts; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
159 |
18608 | 160 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
161 int tff; |
18608 | 162 |
163 if(vf->priv->parity < 0) { | |
164 if (mpi->fields & MP_IMGFIELD_ORDERED) | |
165 tff = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST); | |
166 else | |
167 tff = 1; | |
168 } | |
169 else tff = (vf->priv->parity&1)^1; | |
170 | |
18625 | 171 store_ref(vf->priv, mpi->planes, mpi->stride, mpi->w, mpi->h); |
172 | |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
173 vf->priv->buffered_mpi = mpi; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
174 vf->priv->buffered_tff = tff; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
175 vf->priv->buffered_i = 0; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
176 vf->priv->buffered_pts = pts; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
177 |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
178 return continue_buffered_image(vf); |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
179 } |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
180 |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
181 static int continue_buffered_image(struct vf_instance_s *vf) |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
182 { |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
183 mp_image_t *mpi = vf->priv->buffered_mpi; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
184 int tff = vf->priv->buffered_tff; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
185 double pts = vf->priv->buffered_pts; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
186 int i; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
187 int ret=0; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
188 mp_image_t *dmpi; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
189 |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
190 pts += vf->priv->buffered_i * .02; // XXX not right |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
191 |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
192 for(i = vf->priv->buffered_i; i<=(vf->priv->mode&1); i++){ |
18608 | 193 dmpi=vf_get_image(vf->next,mpi->imgfmt, |
194 MP_IMGTYPE_TEMP, | |
195 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
196 mpi->width,mpi->height); | |
197 vf_clone_mpi_attributes(dmpi, mpi); | |
18625 | 198 filter(vf->priv, dmpi->planes, dmpi->stride, mpi->w, mpi->h, i ^ tff ^ 1, tff); |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
199 if (correct_pts && i < (vf->priv->mode & 1)) |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
200 vf_queue_frame(vf, continue_buffered_image); |
18608 | 201 ret |= vf_next_put_image(vf, dmpi, pts /*FIXME*/); |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
202 if (correct_pts) |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
203 break; |
18626 | 204 if(i<(vf->priv->mode&1)) |
18608 | 205 vf_next_control(vf, VFCTRL_FLIP_PAGE, NULL); |
206 } | |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
207 vf->priv->buffered_i = 1; |
18608 | 208 return ret; |
209 } | |
210 | |
211 static void uninit(struct vf_instance_s* vf){ | |
212 int i; | |
213 if(!vf->priv) return; | |
214 | |
18625 | 215 for(i=0; i<3*3; i++){ |
216 uint8_t **p= &vf->priv->ref[i%3][i/3]; | |
217 if(*p) free(*p - 3*vf->priv->stride[i/3]); | |
218 *p= NULL; | |
18608 | 219 } |
220 free(vf->priv); | |
221 vf->priv=NULL; | |
222 } | |
223 | |
224 //===========================================================================// | |
225 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
226 switch(fmt){ | |
227 case IMGFMT_YV12: | |
228 case IMGFMT_I420: | |
229 case IMGFMT_IYUV: | |
230 case IMGFMT_Y800: | |
231 case IMGFMT_Y8: | |
232 return vf_next_query_format(vf,fmt); | |
233 } | |
234 return 0; | |
235 } | |
236 | |
237 static int open(vf_instance_t *vf, char* args){ | |
238 | |
239 vf->config=config; | |
240 vf->put_image=put_image; | |
241 vf->query_format=query_format; | |
242 vf->uninit=uninit; | |
243 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
244 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
245 | |
246 vf->priv->mode=0; | |
247 vf->priv->parity= -1; | |
248 | |
249 if (args) sscanf(args, "%d:%d", &vf->priv->mode, &vf->priv->parity); | |
250 | |
251 return 1; | |
252 } | |
253 | |
254 vf_info_t vf_info_yadif = { | |
255 "Yet Another DeInterlacing Filter", | |
256 "yadif", | |
257 "Michael Niedermayer", | |
258 "", | |
259 open, | |
260 NULL | |
261 }; |