1 /*****************************************************************************
2 * scope.c : Scope effect module
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: scope.c,v 1.11 2002/07/31 20:56:51 sam Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <string.h> /* strdup() */
35 #define SCOPE_WIDTH 320
36 #define SCOPE_HEIGHT 240
37 #define SCOPE_ASPECT (VOUT_ASPECT_FACTOR*SCOPE_WIDTH/SCOPE_HEIGHT)
39 /*****************************************************************************
40 * aout_sys_t: scope audio output method descriptor
41 *****************************************************************************
42 * This structure is part of the audio output thread descriptor.
43 * It describes some scope specific variables.
44 *****************************************************************************/
47 aout_fifo_t *p_aout_fifo;
49 aout_thread_t *p_aout;
50 vout_thread_t *p_vout;
53 /*****************************************************************************
55 *****************************************************************************/
56 static int Open ( vlc_object_t * );
57 static void Close ( vlc_object_t * );
59 static int SetFormat ( aout_thread_t * );
60 static int GetBufInfo ( aout_thread_t *, int );
61 static void Play ( aout_thread_t *, byte_t *, int );
63 /*****************************************************************************
65 *****************************************************************************/
67 set_description( _("scope effect") );
68 set_capability( "audio output", 0 );
69 set_callbacks( Open, Close );
70 add_shortcut( "scope" );
73 /*****************************************************************************
74 * Open: open a scope effect plugin
75 *****************************************************************************/
76 static int Open( vlc_object_t *p_this )
78 aout_thread_t *p_aout = (aout_thread_t *)p_this;
81 /* Allocate structure */
82 p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
83 if( p_aout->p_sys == NULL )
85 msg_Err( p_aout, "out of memory" );
89 psz_method = config_GetPsz( p_aout, "aout" );
103 /* Open video output */
104 p_aout->p_sys->p_vout =
105 vout_CreateThread( p_aout, SCOPE_WIDTH, SCOPE_HEIGHT,
106 VLC_FOURCC('I','4','2','0'), SCOPE_ASPECT );
108 if( p_aout->p_sys->p_vout == NULL )
110 msg_Err( p_aout, "no suitable vout module" );
111 free( p_aout->p_sys );
115 /* Open audio output */
116 p_aout->p_sys->p_aout = vlc_object_create( p_aout, VLC_OBJECT_AOUT );
118 p_aout->p_sys->p_aout->i_format = p_aout->i_format;
119 p_aout->p_sys->p_aout->i_rate = p_aout->i_rate;
120 p_aout->p_sys->p_aout->i_channels = p_aout->i_channels;
122 p_aout->p_sys->p_aout->p_module =
123 module_Need( p_aout->p_sys->p_aout, "audio output", "" );
124 if( p_aout->p_sys->p_aout->p_module == NULL )
126 msg_Err( p_aout, "no suitable aout module" );
127 vlc_object_destroy( p_aout->p_sys->p_aout );
128 vout_DestroyThread( p_aout->p_sys->p_vout );
129 free( p_aout->p_sys );
133 vlc_object_attach( p_aout->p_sys->p_aout, p_aout );
135 p_aout->pf_setformat = SetFormat;
136 p_aout->pf_getbufinfo = GetBufInfo;
137 p_aout->pf_play = Play;
142 /*****************************************************************************
143 * SetFormat: set the output format
144 *****************************************************************************/
145 static int SetFormat( aout_thread_t *p_aout )
149 /* Force the output method */
150 p_aout->p_sys->p_aout->i_format = p_aout->i_format;
151 p_aout->p_sys->p_aout->i_channels = p_aout->i_channels;
152 p_aout->p_sys->p_aout->i_rate = p_aout->i_rate;
155 * Initialize audio device
157 i_ret = p_aout->p_sys->p_aout->pf_setformat( p_aout->p_sys->p_aout );
164 if( p_aout->p_sys->p_aout->i_format != p_aout->i_format
165 || p_aout->p_sys->p_aout->i_channels != p_aout->i_channels )
167 msg_Err( p_aout, "plugin is not very cooperative" );
171 p_aout->i_channels = p_aout->p_sys->p_aout->i_channels;
172 p_aout->i_format = p_aout->p_sys->p_aout->i_format;
173 p_aout->i_rate = p_aout->p_sys->p_aout->i_rate;
178 /*****************************************************************************
179 * GetBufInfo: buffer status query
180 *****************************************************************************/
181 static int GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
183 return p_aout->p_sys->p_aout->pf_getbufinfo( p_aout->p_sys->p_aout,
187 /*****************************************************************************
188 * Play: play a sound samples buffer
189 *****************************************************************************
190 * This function writes a buffer of i_length bytes in the socket
191 *****************************************************************************/
192 static void Play( aout_thread_t *p_aout, byte_t *p_buffer, int i_size )
195 int i_index, i_image;
199 /* Play the real sound */
200 p_aout->p_sys->p_aout->pf_play( p_aout->p_sys->p_aout, p_buffer, i_size );
202 for( i_image = 0; (i_image + 1) * SCOPE_WIDTH * 8 < i_size ; i_image++ )
204 /* Don't stay here forever */
205 if( mdate() >= p_aout->date - 10000 )
210 /* This is a new frame. Get a structure from the video_output. */
211 while( ( p_outpic = vout_CreatePicture( p_aout->p_sys->p_vout, 0, 0, 0 ) )
218 msleep( VOUT_OUTMEM_SLEEP );
221 /* Blank the picture */
222 for( i_index = 0 ; i_index < p_outpic->i_planes ; i_index++ )
224 memset( p_outpic->p[i_index].p_pixels, i_index ? 0x80 : 0x00,
225 p_outpic->p[i_index].i_lines * p_outpic->p[i_index].i_pitch );
228 /* We only support 2 channels for now */
229 for( i_index = 0 ; i_index < 2 ; i_index++ )
232 for( j = 0 ; j < 3 ; j++ )
234 ppp_area[i_index][j] =
235 p_outpic->p[j].p_pixels + i_index * p_outpic->p[j].i_lines
236 / p_aout->i_channels * p_outpic->p[j].i_pitch;
240 for( i_index = 0, p_sample = (u16*)p_buffer;
241 i_index < SCOPE_WIDTH;
247 for( i = 0 ; i < 2 ; i++ )
250 i_value = *p_sample++ / 256 + 128;
252 + p_outpic->p[0].i_pitch * i_index / SCOPE_WIDTH
253 + p_outpic->p[0].i_lines * i_value / 512
254 * p_outpic->p[0].i_pitch) = 0xbf;
256 + p_outpic->p[1].i_pitch * i_index / SCOPE_WIDTH
257 + p_outpic->p[1].i_lines * i_value / 512
258 * p_outpic->p[1].i_pitch) = 0xff;
261 i_value = *p_sample++ / 256 + 128;
263 + p_outpic->p[0].i_pitch * i_index / SCOPE_WIDTH
264 + p_outpic->p[0].i_lines * i_value / 512
265 * p_outpic->p[0].i_pitch) = 0x9f;
267 + p_outpic->p[2].i_pitch * i_index / SCOPE_WIDTH
268 + p_outpic->p[2].i_lines * i_value / 512
269 * p_outpic->p[2].i_pitch) = 0xdd;
273 /* Display the picture - FIXME: find a better date :-) */
274 vout_DatePicture( p_aout->p_sys->p_vout, p_outpic,
275 p_aout->date + i_image * 20000 );
276 vout_DisplayPicture( p_aout->p_sys->p_vout, p_outpic );
278 p_buffer += SCOPE_WIDTH * 4;
282 /*****************************************************************************
283 * Close: close the plugin
284 *****************************************************************************/
285 static void Close( vlc_object_t *p_this )
287 aout_thread_t *p_aout = (aout_thread_t *)p_this;
289 /* Kill audio output */
290 module_Unneed( p_aout->p_sys->p_aout, p_aout->p_sys->p_aout->p_module );
291 vlc_object_detach_all( p_aout->p_sys->p_aout );
292 vlc_object_destroy( p_aout->p_sys->p_aout );
294 /* Kill video output */
295 vout_DestroyThread( p_aout->p_sys->p_vout );
297 free( p_aout->p_sys );