1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@videolan.org>
8 * Implementation of the winamp plugin MilkDrop
9 * based on projectM http://xmms-projectm.sourceforge.net
10 * and SciVi http://xmms-scivi.sourceforge.net
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
34 #include "video_init.h"
37 #include <vlc_input.h>
38 #include <vlc_playlist.h>
40 /*****************************************************************************
42 *****************************************************************************/
43 static int Open ( vlc_object_t * );
44 static void Close ( vlc_object_t * );
47 set_description( _("GaLaktos visualization plugin") );
48 set_capability( "visualization", 0 );
49 set_callbacks( Open, Close );
50 add_shortcut( "galaktos" );
53 /*****************************************************************************
55 *****************************************************************************/
56 typedef struct aout_filter_sys_t
58 galaktos_thread_t *p_thread;
62 static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
65 static void Thread ( vlc_object_t * );
67 static char *TitleGet( vlc_object_t * );
70 extern GLuint RenderTargetTextureID;
72 /*****************************************************************************
73 * Open: open a scope effect plugin
74 *****************************************************************************/
75 static int Open( vlc_object_t *p_this )
77 aout_filter_t *p_filter = (aout_filter_t *)p_this;
78 aout_filter_sys_t *p_sys;
79 galaktos_thread_t *p_thread;
81 if ( p_filter->input.i_format != VLC_FOURCC('f','l','3','2' )
82 || p_filter->output.i_format != VLC_FOURCC('f','l','3','2') )
84 msg_Warn( p_filter, "bad input or output format" );
87 if ( !AOUT_FMTS_SIMILAR( &p_filter->input, &p_filter->output ) )
89 msg_Warn( p_filter, "input and output formats are not similar" );
93 p_filter->pf_do_work = DoWork;
94 p_filter->b_in_place = 1;
96 /* Allocate structure */
97 p_sys = p_filter->p_sys = malloc( sizeof( aout_filter_sys_t ) );
99 /* Create galaktos thread */
100 p_sys->p_thread = p_thread =
101 vlc_object_create( p_filter, sizeof( galaktos_thread_t ) );
102 vlc_object_attach( p_thread, p_this );
105 var_Create( p_thread, "galaktos-width", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
106 var_Get( p_thread, "galaktos-width", &width );
107 var_Create( p_thread, "galaktos-height", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
108 var_Get( p_thread, "galaktos-height", &height );
110 p_thread->i_cur_sample = 0;
111 bzero( p_thread->p_data, 2*2*512 );
113 p_thread->i_width = 600;
114 p_thread->i_height = 600;
115 p_thread->b_fullscreen = 0;
116 galaktos_init( p_thread );
118 p_thread->i_channels = aout_FormatNbChannels( &p_filter->input );
120 p_thread->psz_title = TitleGet( VLC_OBJECT( p_filter ) );
122 if( vlc_thread_create( p_thread, "galaktos update thread", Thread,
123 VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
125 msg_Err( p_filter, "cannot lauch galaktos thread" );
126 if( p_thread->psz_title ) free( p_thread->psz_title );
127 vlc_object_detach( p_thread );
128 vlc_object_destroy( p_thread );
136 /*****************************************************************************
137 * float to s16 conversion
138 *****************************************************************************/
139 static inline int16_t FloatToInt16( float f )
146 return (int16_t)( f * 32768.0 );
149 /*****************************************************************************
150 * DoWork: process samples buffer
151 *****************************************************************************
152 * This function queues the audio buffer to be processed by the galaktos thread
153 *****************************************************************************/
154 static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
155 aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
160 galaktos_thread_t *p_thread = p_filter->p_sys->p_thread;
162 p_float = (float *)p_in_buf->p_buffer;
163 i_channels = p_thread->i_channels;
165 p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
166 p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes;
168 for( i_samples = p_in_buf->i_nb_samples; i_samples > 0; i_samples-- )
170 int i_cur_sample = p_thread->i_cur_sample;
172 p_thread->p_data[0][i_cur_sample] = FloatToInt16( p_float[0] );
175 p_thread->p_data[1][i_cur_sample] = FloatToInt16( p_float[1] );
177 p_float += i_channels;
179 if( ++(p_thread->i_cur_sample) == 512 )
181 addPCM( p_thread->p_data );
182 p_thread->i_cur_sample = 0;
187 /*****************************************************************************
189 *****************************************************************************/
190 static void Thread( vlc_object_t *p_this )
192 galaktos_thread_t *p_thread = (galaktos_thread_t*)p_this;
195 double realfps=0,fpsstart=0;
200 /* Get on OpenGL provider */
202 (vout_thread_t *)vlc_object_create( p_this, VLC_OBJECT_OPENGL );
203 if( p_thread->p_opengl == NULL )
205 msg_Err( p_thread, "out of memory" );
208 vlc_object_attach( p_thread->p_opengl, p_this );
210 /* Initialize vout parameters */
211 vout_InitFormat( &p_thread->p_opengl->fmt_in,
212 VLC_FOURCC('R','V','3','2'),
213 p_thread->i_width, p_thread->i_height, 1 );
214 p_thread->p_opengl->i_window_width = p_thread->i_width;
215 p_thread->p_opengl->i_window_height = p_thread->i_height;
216 p_thread->p_opengl->render.i_width = p_thread->i_width;
217 p_thread->p_opengl->render.i_height = p_thread->i_width;
218 p_thread->p_opengl->render.i_aspect = VOUT_ASPECT_FACTOR;
219 p_thread->p_opengl->b_scale = VLC_TRUE;
220 p_thread->p_opengl->b_fullscreen = VLC_FALSE;
221 p_thread->p_opengl->i_alignment = 0;
222 p_thread->p_opengl->fmt_in.i_sar_num = 1;
223 p_thread->p_opengl->fmt_in.i_sar_den = 1;
224 p_thread->p_opengl->fmt_render = p_thread->p_opengl->fmt_in;
227 module_Need( p_thread->p_opengl, "opengl provider", NULL, 0 );
228 if( p_thread->p_module == NULL )
230 msg_Err( p_thread, "unable to initialize OpenGL" );
231 vlc_object_detach( p_thread->p_opengl );
232 vlc_object_destroy( p_thread->p_opengl );
236 p_thread->p_opengl->pf_init( p_thread->p_opengl );
238 setup_opengl( p_thread->i_width, p_thread->i_height );
239 CreateRenderTarget(512, &RenderTargetTextureID, NULL);
241 timestart=mdate()/1000;
243 while( !p_thread->b_die )
246 if( galaktos_update( p_thread ) == 1 )
248 vlc_object_kill( p_thread );
250 if( p_thread->psz_title )
252 free( p_thread->psz_title );
253 p_thread->psz_title = NULL;
258 realfps=100/((mdate()/1000-fpsstart)/1000);
259 // printf("%f\n",realfps);
260 fpsstart=mdate()/1000;
263 timed=mspf-(mdate()/1000-timestart);
264 // printf("%d,%d\n",time,mspf);
265 if (timed>0) msleep(1000*timed);
266 // printf("Limiter %d\n",(mdate()/1000-timestart));
267 timestart=mdate()/1000;
270 /* Free the openGL provider */
271 module_Unneed( p_thread->p_opengl, p_thread->p_module );
272 vlc_object_detach( p_thread->p_opengl );
273 vlc_object_destroy( p_thread->p_opengl );
276 /*****************************************************************************
277 * Close: close the plugin
278 *****************************************************************************/
279 static void Close( vlc_object_t *p_this )
281 aout_filter_t *p_filter = (aout_filter_t *)p_this;
282 aout_filter_sys_t *p_sys = p_filter->p_sys;
284 /* Stop galaktos Thread */
285 vlc_object_kill( p_sys->p_thread );
287 galaktos_done( p_sys->p_thread );
289 vlc_thread_join( p_sys->p_thread );
292 vlc_object_detach( p_sys->p_thread );
293 vlc_object_destroy( p_sys->p_thread );
298 static char *TitleGet( vlc_object_t *p_this )
300 char *psz_title = NULL;
301 input_thread_t *p_input =
302 vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
306 char *psz_orig = input_item_GetURI( input_GetItem( p_input ) );
307 char *psz = strrchr( psz_orig, '/' );
319 psz_title = strdup( psz );
322 vlc_object_release( p_input );