1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
35 #include "video_init.h"
38 #include <vlc/input.h>
40 #include "aout_internal.h"
42 /*****************************************************************************
44 *****************************************************************************/
45 static int Open ( vlc_object_t * );
46 static void Close ( vlc_object_t * );
49 set_description( _("GaLaktos visualization plugin") );
50 set_capability( "audio filter", 0 );
51 set_callbacks( Open, Close );
52 add_shortcut( "galaktos" );
55 /*****************************************************************************
57 *****************************************************************************/
58 typedef struct aout_filter_sys_t
60 galaktos_thread_t *p_thread;
64 static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
67 static void Thread ( vlc_object_t * );
69 static char *TitleGet( vlc_object_t * );
72 extern GLuint RenderTargetTextureID;
74 /*****************************************************************************
75 * Open: open a scope effect plugin
76 *****************************************************************************/
77 static int Open( vlc_object_t *p_this )
79 aout_filter_t *p_filter = (aout_filter_t *)p_this;
80 aout_filter_sys_t *p_sys;
81 galaktos_thread_t *p_thread;
82 vlc_value_t width, height;
84 if ( p_filter->input.i_format != VLC_FOURCC('f','l','3','2' )
85 || p_filter->output.i_format != VLC_FOURCC('f','l','3','2') )
87 msg_Warn( p_filter, "Bad input or output format" );
90 if ( !AOUT_FMTS_SIMILAR( &p_filter->input, &p_filter->output ) )
92 msg_Warn( p_filter, "input and output formats are not similar" );
96 p_filter->pf_do_work = DoWork;
97 p_filter->b_in_place = 1;
99 /* Allocate structure */
100 p_sys = p_filter->p_sys = malloc( sizeof( aout_filter_sys_t ) );
102 /* Create galaktos thread */
103 p_sys->p_thread = p_thread =
104 vlc_object_create( p_filter, sizeof( galaktos_thread_t ) );
105 vlc_object_attach( p_thread, p_this );
108 var_Create( p_thread, "galaktos-width", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
109 var_Get( p_thread, "galaktos-width", &width );
110 var_Create( p_thread, "galaktos-height", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
111 var_Get( p_thread, "galaktos-height", &height );
113 p_thread->i_cur_sample = 0;
114 bzero( p_thread->p_data, 2*2*512 );
116 p_thread->i_width = 600;
117 p_thread->i_height = 600;
118 p_thread->b_fullscreen = 0;
119 galaktos_glx_init( p_thread );
120 galaktos_init( p_thread );
122 p_thread->i_channels = aout_FormatNbChannels( &p_filter->input );
124 p_thread->psz_title = TitleGet( VLC_OBJECT( p_filter ) );
126 if( vlc_thread_create( p_thread, "galaktos update thread", Thread,
127 VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
129 msg_Err( p_filter, "cannot lauch galaktos thread" );
130 if( p_thread->psz_title ) free( p_thread->psz_title );
131 vlc_object_detach( p_thread );
132 vlc_object_destroy( p_thread );
141 /*****************************************************************************
142 * float to s16 conversion
143 *****************************************************************************/
144 static inline int16_t FloatToInt16( float f )
151 return (int16_t)( f * 32768.0 );
155 /*****************************************************************************
156 * DoWork: process samples buffer
157 *****************************************************************************
158 * This function queues the audio buffer to be processed by the galaktos thread
159 *****************************************************************************/
160 static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
161 aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
166 galaktos_thread_t *p_thread = p_filter->p_sys->p_thread;
168 p_float = (float *)p_in_buf->p_buffer;
169 i_channels = p_thread->i_channels;
171 p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
172 p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes;
174 for( i_samples = p_in_buf->i_nb_samples; i_samples > 0; i_samples-- )
176 int i_cur_sample = p_thread->i_cur_sample;
178 p_thread->p_data[0][i_cur_sample] = FloatToInt16( p_float[0] );
181 p_thread->p_data[1][i_cur_sample] = FloatToInt16( p_float[1] );
183 p_float += i_channels;
185 if( ++(p_thread->i_cur_sample) == 512 )
187 addPCM( p_thread->p_data );
188 p_thread->i_cur_sample = 0;
193 /*****************************************************************************
195 *****************************************************************************/
196 static void Thread( vlc_object_t *p_this )
198 galaktos_thread_t *p_thread = (galaktos_thread_t*)p_this;
201 double realfps=0,fpsstart=0;
206 galaktos_glx_activate_window( p_thread );
207 setup_opengl( p_thread->i_width, p_thread->i_height );
208 CreateRenderTarget(512, &RenderTargetTextureID, NULL);
210 timestart=mdate()/1000;
212 while( !p_thread->b_die )
215 if( galaktos_update( p_thread ) == 1 )
219 if( p_thread->psz_title )
221 free( p_thread->psz_title );
222 p_thread->psz_title = NULL;
227 realfps=100/((mdate()/1000-fpsstart)/1000);
228 // printf("%f\n",realfps);
229 fpsstart=mdate()/1000;
232 timed=mspf-(mdate()/1000-timestart);
233 // printf("%d,%d\n",time,mspf);
234 if (timed>0) msleep(1000*timed);
235 // printf("Limiter %d\n",(mdate()/1000-timestart));
236 timestart=mdate()/1000;
239 galaktos_glx_done( p_thread );
242 /*****************************************************************************
243 * Close: close the plugin
244 *****************************************************************************/
245 static void Close( vlc_object_t *p_this )
247 aout_filter_t *p_filter = (aout_filter_t *)p_this;
248 aout_filter_sys_t *p_sys = p_filter->p_sys;
250 /* Stop galaktos Thread */
251 p_sys->p_thread->b_die = VLC_TRUE;
253 galaktos_done( p_sys->p_thread );
255 vlc_thread_join( p_sys->p_thread );
258 vlc_object_detach( p_sys->p_thread );
260 vlc_object_destroy( p_sys->p_thread );
265 static char *TitleGet( vlc_object_t *p_this )
267 char *psz_title = NULL;
268 input_thread_t *p_input =
269 vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
273 char *psz = strrchr( p_input->input.p_item->psz_uri, '/' );
281 psz = p_input->input.p_item->psz_uri;
285 psz_title = strdup( psz );
287 vlc_object_release( p_input );