Mercurial > mplayer.hg
annotate libmpcodecs/vf_qp.c @ 17023:dd5be8f8d16d
buffering in the muxer layer; patch by Corey Hickey (bugfood-ml ad fatooh punctum org) plus small fixes by me
author | nicodvb |
---|---|
date | Mon, 21 Nov 2005 22:53:14 +0000 |
parents | 6ff3379a0862 |
children | 401b440a6d76 |
rev | line source |
---|---|
11921 | 1 /* |
2 Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 */ | |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 #include <math.h> | |
23 #include <inttypes.h> | |
24 | |
17012 | 25 #include "config.h" |
11921 | 26 |
27 #ifdef USE_LIBAVCODEC | |
28 | |
17012 | 29 #include "mp_msg.h" |
30 #include "cpudetect.h" | |
11921 | 31 |
32 #if 1 | |
33 double ff_eval(char *s, double *const_value, const char **const_name, | |
34 double (**func1)(void *, double), const char **func1_name, | |
35 double (**func2)(void *, double, double), char **func2_name, | |
36 void *opaque); | |
11923
e9ab21c4db24
#include dsputil.h as it contains the lrintf emu code
michael
parents:
11921
diff
changeset
|
37 #endif |
e9ab21c4db24
#include dsputil.h as it contains the lrintf emu code
michael
parents:
11921
diff
changeset
|
38 |
16677
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
39 // Needed to bring in lrintf. |
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
40 #define HAVE_AV_CONFIG_H |
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
41 |
11921 | 42 #ifdef USE_LIBAVCODEC_SO |
43 #include <ffmpeg/avcodec.h> | |
11923
e9ab21c4db24
#include dsputil.h as it contains the lrintf emu code
michael
parents:
11921
diff
changeset
|
44 #include <ffmpeg/dsputil.h> |
16677
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
45 #include <ffmpeg/common.h> |
11921 | 46 #else |
17012 | 47 #include "libavcodec/avcodec.h" |
48 #include "libavcodec/dsputil.h" | |
49 #include "libavutil/common.h" | |
11921 | 50 #endif |
51 | |
16677
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
52 /* FIXME: common.h defines printf away when HAVE_AV_CONFIG |
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
53 * is defined, but mp_image.h needs printf. |
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
54 */ |
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
55 #undef printf |
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
56 |
11921 | 57 #ifdef HAVE_MALLOC_H |
58 #include <malloc.h> | |
59 #endif | |
60 | |
61 #include "img_format.h" | |
62 #include "mp_image.h" | |
63 #include "vf.h" | |
17012 | 64 #include "libvo/fastmemcpy.h" |
11921 | 65 |
66 | |
67 struct vf_priv_s { | |
68 char eq[200]; | |
69 int8_t *qp; | |
70 int8_t lut[257]; | |
71 int qp_stride; | |
72 }; | |
73 | |
74 static int config(struct vf_instance_s* vf, | |
75 int width, int height, int d_width, int d_height, | |
76 unsigned int flags, unsigned int outfmt){ | |
77 int h= (height+15)>>4; | |
78 int i; | |
79 | |
80 vf->priv->qp_stride= (width+15)>>4; | |
16677
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
81 vf->priv->qp= av_malloc(vf->priv->qp_stride*h*sizeof(int8_t)); |
11921 | 82 |
83 for(i=-129; i<128; i++){ | |
84 double const_values[]={ | |
85 M_PI, | |
86 M_E, | |
87 i != -129, | |
88 i, | |
89 0 | |
90 }; | |
91 static const char *const_names[]={ | |
92 "PI", | |
93 "E", | |
94 "known", | |
95 "qp", | |
96 NULL | |
97 }; | |
98 | |
99 vf->priv->lut[i+129]= lrintf(ff_eval(vf->priv->eq, const_values, const_names, NULL, NULL, NULL, NULL, NULL)); | |
100 } | |
101 | |
102 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
103 } | |
104 | |
105 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
106 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change | |
107 // ok, we can do pp in-place (or pp disabled): | |
108 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
109 mpi->type, mpi->flags, mpi->w, mpi->h); | |
110 mpi->planes[0]=vf->dmpi->planes[0]; | |
111 mpi->stride[0]=vf->dmpi->stride[0]; | |
112 mpi->width=vf->dmpi->width; | |
113 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
114 mpi->planes[1]=vf->dmpi->planes[1]; | |
115 mpi->planes[2]=vf->dmpi->planes[2]; | |
116 mpi->stride[1]=vf->dmpi->stride[1]; | |
117 mpi->stride[2]=vf->dmpi->stride[2]; | |
118 } | |
119 mpi->flags|=MP_IMGFLAG_DIRECT; | |
120 } | |
121 | |
122 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
123 mp_image_t *dmpi; | |
124 int x,y; | |
125 | |
126 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
127 // no DR, so get a new image! hope we'll get DR buffer: | |
128 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
129 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
130 mpi->w,mpi->h); | |
131 } | |
132 | |
133 dmpi= vf->dmpi; | |
134 | |
135 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
136 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]); | |
137 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
138 memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]); | |
139 memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]); | |
140 } | |
141 } | |
142 vf_clone_mpi_attributes(dmpi, mpi); | |
143 | |
144 dmpi->qscale = vf->priv->qp; | |
145 dmpi->qstride= vf->priv->qp_stride; | |
146 if(mpi->qscale){ | |
147 for(y=0; y<((dmpi->h+15)>>4); y++){ | |
148 for(x=0; x<vf->priv->qp_stride; x++){ | |
149 dmpi->qscale[x + dmpi->qstride*y]= | |
150 vf->priv->lut[ 129 + ((int8_t)mpi->qscale[x + mpi->qstride*y]) ]; | |
151 } | |
152 } | |
153 }else{ | |
154 int qp= vf->priv->lut[0]; | |
155 for(y=0; y<((dmpi->h+15)>>4); y++){ | |
156 for(x=0; x<vf->priv->qp_stride; x++){ | |
157 dmpi->qscale[x + dmpi->qstride*y]= qp; | |
158 } | |
159 } | |
160 } | |
161 | |
162 return vf_next_put_image(vf,dmpi); | |
163 } | |
164 | |
165 static void uninit(struct vf_instance_s* vf){ | |
166 if(!vf->priv) return; | |
167 | |
16677
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
168 if(vf->priv->qp) av_free(vf->priv->qp); |
11921 | 169 vf->priv->qp= NULL; |
170 | |
16677
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
171 av_free(vf->priv); |
11921 | 172 vf->priv=NULL; |
173 } | |
174 | |
175 //===========================================================================// | |
176 static int open(vf_instance_t *vf, char* args){ | |
177 vf->config=config; | |
178 vf->put_image=put_image; | |
179 vf->get_image=get_image; | |
180 vf->uninit=uninit; | |
16677
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
181 vf->priv=av_malloc(sizeof(struct vf_priv_s)); |
11921 | 182 memset(vf->priv, 0, sizeof(struct vf_priv_s)); |
183 | |
184 // avcodec_init(); | |
185 | |
186 if (args) strncpy(vf->priv->eq, args, 199); | |
187 | |
188 return 1; | |
189 } | |
190 | |
191 vf_info_t vf_info_qp = { | |
192 "QP changer", | |
193 "qp", | |
194 "Michael Niedermayer", | |
195 "", | |
196 open, | |
197 NULL | |
198 }; | |
199 | |
200 #endif //USE_LIBAVCODEC |