b5e1f463570ed7310df7d93178f2d953accb40c9
[platform/upstream/gst-plugins-good.git] / gst / goom / plugin_info.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <gst/gst.h>
6
7 #include "goom_config.h"
8
9 #include "goom_plugin_info.h"
10 #include "goom_fx.h"
11 #include "drawmethods.h"
12 #include <math.h>
13 #include <stdio.h>
14
15
16 #if defined (HAVE_CPU_PPC64) || defined (HAVE_CPU_PPC)
17 #include <sys/types.h>
18 #include <sys/sysctl.h>
19 #include "ppc_zoom_ultimate.h"
20 #include "ppc_drawings.h"
21 #endif /* HAVE_CPU_PPC64 || HAVE_CPU_PPC */
22
23
24 #ifdef HAVE_MMX
25 #include "mmx.h"
26 #endif /* HAVE_MMX */
27
28 #include <liboil/liboil.h>
29 #include <liboil/liboilfunction.h>
30 #include <liboil/liboilcpu.h>
31
32 GST_DEBUG_CATEGORY_EXTERN (goom_debug);
33 #define GST_CAT_DEFAULT goom_debug
34
35 static void
36 setOptimizedMethods (PluginInfo * p)
37 {
38
39   unsigned int cpuFlavour = oil_cpu_get_flags ();
40
41   /* set default methods */
42   p->methods.draw_line = draw_line;
43   p->methods.zoom_filter = zoom_filter_c;
44 /*    p->methods.create_output_with_brightness = create_output_with_brightness;*/
45
46   GST_INFO ("liboil cpu flags: 0x%08x", cpuFlavour);
47
48 /* FIXME: what about HAVE_CPU_X86_64 ? */
49 #ifdef HAVE_CPU_I386
50 #ifdef HAVE_MMX
51   GST_INFO ("have an x86");
52   if (cpuFlavour & OIL_IMPL_FLAG_MMXEXT) {
53     GST_INFO ("Extended MMX detected. Using the fastest methods!");
54     p->methods.draw_line = draw_line_xmmx;
55     p->methods.zoom_filter = zoom_filter_xmmx;
56   } else if (cpuFlavour & OIL_IMPL_FLAG_MMX) {
57     GST_INFO ("MMX detected. Using fast methods!");
58     p->methods.draw_line = draw_line_mmx;
59     p->methods.zoom_filter = zoom_filter_mmx;
60   } else {
61     GST_INFO ("Too bad ! No SIMD optimization available for your CPU.");
62   }
63 #endif
64 #endif /* HAVE_CPU_I386 */
65
66 /* disable all PPC stuff until someone finds out what to use here instead of
67  * CPU_OPTION_64_BITS, and until someone fixes the assembly build for ppc */
68 #if 0
69 #ifdef HAVE_CPU_PPC64
70   if ((cpuFlavour & CPU_OPTION_64_BITS) != 0) {
71 /*            p->methods.create_output_with_brightness = ppc_brightness_G5;        */
72     p->methods.zoom_filter = ppc_zoom_generic;
73   }
74 #endif /* HAVE_CPU_PPC64 */
75
76 #ifdef HAVE_CPU_PPC
77   if ((cpuFlavour & OIL_IMPL_FLAG_ALTIVEC) != 0) {
78 /*            p->methods.create_output_with_brightness = ppc_brightness_G4;        */
79     p->methods.zoom_filter = ppc_zoom_G4;
80   } else {
81 /*            p->methods.create_output_with_brightness = ppc_brightness_generic;*/
82     p->methods.zoom_filter = ppc_zoom_generic;
83   }
84 #endif /* HAVE_CPU_PPC */
85 #endif
86
87   cpuFlavour = 0;               /* trick compiler into thinking variable is used */
88 }
89
90 void
91 plugin_info_init (PluginInfo * pp, int nbVisuals)
92 {
93
94   PluginInfo p;
95   int i;
96
97   p.sound.speedvar = p.sound.accelvar = p.sound.totalgoom = 0;
98   p.sound.prov_max = 0;
99   p.sound.goom_limit = 1;
100   p.sound.allTimesMax = 1;
101   p.sound.timeSinceLastGoom = 1;
102   p.sound.timeSinceLastBigGoom = 1;
103   p.sound.cycle = 0;
104
105   p.sound.volume_p = secure_f_feedback ("Sound Volume");
106   p.sound.accel_p = secure_f_feedback ("Sound Acceleration");
107   p.sound.speed_p = secure_f_feedback ("Sound Speed");
108   p.sound.goom_limit_p = secure_f_feedback ("Goom Limit");
109   p.sound.last_goom_p = secure_f_feedback ("Goom Detection");
110   p.sound.last_biggoom_p = secure_f_feedback ("Big Goom Detection");
111   p.sound.goom_power_p = secure_f_feedback ("Goom Power");
112
113   p.sound.biggoom_speed_limit_p = secure_i_param ("Big Goom Speed Limit");
114   IVAL (p.sound.biggoom_speed_limit_p) = 10;
115   IMIN (p.sound.biggoom_speed_limit_p) = 0;
116   IMAX (p.sound.biggoom_speed_limit_p) = 100;
117   ISTEP (p.sound.biggoom_speed_limit_p) = 1;
118
119   p.sound.biggoom_factor_p = secure_i_param ("Big Goom Factor");
120   IVAL (p.sound.biggoom_factor_p) = 10;
121   IMIN (p.sound.biggoom_factor_p) = 0;
122   IMAX (p.sound.biggoom_factor_p) = 100;
123   ISTEP (p.sound.biggoom_factor_p) = 1;
124
125   p.sound.params = plugin_parameters ("Sound", 11);
126
127   p.nbParams = 0;
128   p.params = NULL;
129   p.nbVisuals = nbVisuals;
130   p.visuals = (VisualFX **) malloc (sizeof (VisualFX *) * nbVisuals);
131
132   *pp = p;
133   pp->sound.params.params[0] = &pp->sound.biggoom_speed_limit_p;
134   pp->sound.params.params[1] = &pp->sound.biggoom_factor_p;
135   pp->sound.params.params[2] = 0;
136   pp->sound.params.params[3] = &pp->sound.volume_p;
137   pp->sound.params.params[4] = &pp->sound.accel_p;
138   pp->sound.params.params[5] = &pp->sound.speed_p;
139   pp->sound.params.params[6] = 0;
140   pp->sound.params.params[7] = &pp->sound.goom_limit_p;
141   pp->sound.params.params[8] = &pp->sound.goom_power_p;
142   pp->sound.params.params[9] = &pp->sound.last_goom_p;
143   pp->sound.params.params[10] = &pp->sound.last_biggoom_p;
144
145   pp->statesNumber = 8;
146   pp->statesRangeMax = 510;
147   {
148     GoomState states[8] = {
149       {1, 0, 0, 1, 4, 0, 100}
150       ,
151       {1, 0, 0, 0, 1, 101, 140}
152       ,
153       {1, 0, 0, 1, 2, 141, 200}
154       ,
155       {0, 1, 0, 1, 2, 201, 260}
156       ,
157       {0, 1, 0, 1, 0, 261, 330}
158       ,
159       {0, 1, 1, 1, 4, 331, 400}
160       ,
161       {0, 0, 1, 0, 5, 401, 450}
162       ,
163       {0, 0, 1, 1, 1, 451, 510}
164     };
165     for (i = 0; i < 8; ++i)
166       pp->states[i] = states[i];
167   }
168   pp->curGState = &(pp->states[6]);
169
170   /* datas for the update loop */
171   pp->update.lockvar = 0;
172   pp->update.goomvar = 0;
173   pp->update.loopvar = 0;
174   pp->update.stop_lines = 0;
175   pp->update.ifs_incr = 1;      /* dessiner l'ifs (0 = non: > = increment) */
176   pp->update.decay_ifs = 0;     /* disparition de l'ifs */
177   pp->update.recay_ifs = 0;     /* dedisparition de l'ifs */
178   pp->update.cyclesSinceLastChange = 0;
179   pp->update.drawLinesDuration = 80;
180   pp->update.lineMode = pp->update.drawLinesDuration;
181
182   pp->update.switchMultAmount = (29.0f / 30.0f);
183   pp->update.switchIncrAmount = 0x7f;
184   pp->update.switchMult = 1.0f;
185   pp->update.switchIncr = pp->update.switchIncrAmount;
186
187   pp->update.stateSelectionRnd = 0;
188   pp->update.stateSelectionBlocker = 0;
189   pp->update.previousZoomSpeed = 128;
190
191   {
192     ZoomFilterData zfd = {
193       127, 8, 16,
194       1, 1, 0, NORMAL_MODE,
195       0, 0, 0, 0, 0
196     };
197     pp->update.zoomFilterData = zfd;
198   }
199
200   setOptimizedMethods (pp);
201
202   for (i = 0; i < 0xffff; i++) {
203     pp->sintable[i] =
204         (int) (1024 * sin ((double) i * 360 / (sizeof (pp->sintable) /
205                 sizeof (pp->sintable[0]) - 1) * 3.141592 / 180) + .5);
206     /* sintable [us] = (int)(1024.0f * sin (us*2*3.31415f/0xffff)) ; */
207   }
208 }
209
210 void
211 plugin_info_add_visual (PluginInfo * p, int i, VisualFX * visual)
212 {
213   p->visuals[i] = visual;
214   if (i == p->nbVisuals - 1) {
215     ++i;
216     p->nbParams = 1;
217     while (i--) {
218       if (p->visuals[i]->params)
219         p->nbParams++;
220     }
221     p->params =
222         (PluginParameters *) malloc (sizeof (PluginParameters) * p->nbParams);
223     i = p->nbVisuals;
224     p->nbParams = 1;
225     p->params[0] = p->sound.params;
226     while (i--) {
227       if (p->visuals[i]->params)
228         p->params[p->nbParams++] = *(p->visuals[i]->params);
229     }
230   }
231 }
232
233 void
234 plugin_info_free (PluginInfo * p)
235 {
236   goom_plugin_parameters_free (&p->sound.params);
237
238   if (p->params)
239     free (p->params);
240   free (p->visuals);
241 }