]> git.sesse.net Git - vlc/blob - plugins/fx/scope.c
* ./plugins/gtk/gtk_menu.c: fixed a compile issue on IA64.
[vlc] / plugins / fx / scope.c
1 /*****************************************************************************
2  * scope.c : Scope effect module
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: scope.c,v 1.1 2002/02/25 04:30:03 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>                                              /* strdup() */
29 #include <errno.h>
30
31 #include <videolan/vlc.h>
32
33 #include "video.h"
34 #include "video_output.h"
35
36 #include "audio_output.h"                                   /* aout_thread_t */
37
38 #define SCOPE_WIDTH 640
39 #define SCOPE_HEIGHT 200
40 #define SCOPE_ASPECT (VOUT_ASPECT_FACTOR*SCOPE_WIDTH/SCOPE_HEIGHT)
41
42 /*****************************************************************************
43  * Capabilities defined in the other files.
44  *****************************************************************************/
45 static void aout_getfunctions( function_list_t * p_function_list );
46
47 /*****************************************************************************
48  * aout_sys_t: scope audio output method descriptor
49  *****************************************************************************
50  * This structure is part of the audio output thread descriptor.
51  * It describes some scope specific variables.
52  *****************************************************************************/
53 typedef struct aout_sys_s
54 {
55     struct aout_fifo_s *p_aout_fifo; /* XXX: unused yet */
56     struct vout_thread_s *p_vout;
57
58 } aout_sys_t;
59
60 /*****************************************************************************
61  * Build configuration tree.
62  *****************************************************************************/
63 MODULE_CONFIG_START
64 MODULE_CONFIG_STOP
65
66 MODULE_INIT_START
67     SET_DESCRIPTION( "scope effect module" )
68     ADD_CAPABILITY( AOUT, 0 )
69     ADD_SHORTCUT( "scope" )
70 MODULE_INIT_STOP
71
72 MODULE_ACTIVATE_START
73     aout_getfunctions( &p_module->p_functions->aout );
74 MODULE_ACTIVATE_STOP
75
76 MODULE_DEACTIVATE_START
77 MODULE_DEACTIVATE_STOP
78
79 /*****************************************************************************
80  * Local prototypes.
81  *****************************************************************************/
82 static int     aout_Open        ( aout_thread_t *p_aout );
83 static int     aout_SetFormat   ( aout_thread_t *p_aout );
84 static int     aout_GetBufInfo  ( aout_thread_t *p_aout, int i_buffer_info );
85 static void    aout_Play        ( aout_thread_t *p_aout,
86                                   byte_t *buffer, int i_size );
87 static void    aout_Close       ( aout_thread_t *p_aout );
88
89 /*****************************************************************************
90  * Functions exported as capabilities. They are declared as static so that
91  * we don't pollute the namespace too much.
92  *****************************************************************************/
93 static void aout_getfunctions( function_list_t * p_function_list )
94 {
95     p_function_list->functions.aout.pf_open = aout_Open;
96     p_function_list->functions.aout.pf_setformat = aout_SetFormat;
97     p_function_list->functions.aout.pf_getbufinfo = aout_GetBufInfo;
98     p_function_list->functions.aout.pf_play = aout_Play;
99     p_function_list->functions.aout.pf_close = aout_Close;
100 }
101
102 /*****************************************************************************
103  * aout_Open: open a scope effect plugin
104  *****************************************************************************/
105 static int aout_Open( aout_thread_t *p_aout )
106 {
107     /* Allocate structure */
108     p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
109     if( p_aout->p_sys == NULL )
110     {
111         intf_ErrMsg("error: %s", strerror(ENOMEM) );
112         return( 1 );
113     }
114
115     p_aout->p_sys->p_vout =
116         vout_CreateThread( NULL, SCOPE_WIDTH, SCOPE_HEIGHT,
117                            FOURCC_I420, SCOPE_ASPECT );
118
119     return( 0 );
120 }
121
122 /*****************************************************************************
123  * aout_SetFormat: set the output format
124  *****************************************************************************/
125 static int aout_SetFormat( aout_thread_t *p_aout )
126 {
127     /* Force the output method */
128     p_aout->i_format = AOUT_FMT_U16_LE;
129     p_aout->i_channels = 2;
130
131     return( 0 );
132 }
133
134 /*****************************************************************************
135  * aout_GetBufInfo: buffer status query
136  *****************************************************************************/
137 static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
138 {
139     /* arbitrary value that should be changed */
140     return( i_buffer_limit );
141 }
142
143 /*****************************************************************************
144  * aout_Play: play a sound samples buffer
145  *****************************************************************************
146  * This function writes a buffer of i_length bytes in the socket
147  *****************************************************************************/
148 static void aout_Play( aout_thread_t *p_aout, byte_t *p_buffer, int i_size )
149 {
150     picture_t *p_outpic;
151     int i_index;
152     u8 *p_pixel;
153     u16 *p_sample;
154
155     /* This is a new frame. Get a structure from the video_output. */
156     while( ( p_outpic = vout_CreatePicture( p_aout->p_sys->p_vout, 0, 0, 0 ) )
157               == NULL )
158     {
159         if( p_aout->b_die )
160         {
161             return;
162         }
163         msleep( VOUT_OUTMEM_SLEEP );
164     }
165
166     /* Blank the picture */
167     for( i_index = 0 ; i_index < p_outpic->i_planes ; i_index++ )
168     {
169         memset( p_outpic->p[i_index].p_pixels, i_index ? 0x80 : 0x00,
170                 p_outpic->p[i_index].i_lines * p_outpic->p[i_index].i_pitch );
171     }
172
173     /* Left channel */
174     for( i_index = 0, p_sample = (u16*)p_buffer;
175          i_index < SCOPE_WIDTH && i_index < i_size / 2;
176          i_index++ )
177     {
178         int i;
179         u8 i_value = *p_sample / 256;
180
181         for( i = 0 ; i < 8 ; i++ )
182         {
183             p_pixel = p_outpic->p[0].p_pixels + (p_outpic->p[0].i_pitch * i_index) / SCOPE_WIDTH + p_outpic->p[0].i_lines * (u8)(i_value+128) / 512 * p_outpic->p[0].i_pitch;
184             *p_pixel = 0x9f;
185             p_pixel = p_outpic->p[1].p_pixels + (p_outpic->p[1].i_pitch * i_index) / SCOPE_WIDTH + p_outpic->p[1].i_lines * (u8)(i_value+128) / 512 * p_outpic->p[1].i_pitch;
186             *p_pixel = 0x00;
187             p_sample += 2;
188         }
189     }
190
191     /* Right channel */
192     for( i_index = 0, p_sample = (u16*)p_buffer + 1;
193          i_index < SCOPE_WIDTH && i_index < i_size / 2;
194          i_index++ )
195     {
196         int i;
197         u8 i_value = *p_sample / 256;
198
199         for( i = 0 ; i < 8 ; i++ )
200         {
201             p_pixel = p_outpic->p[0].p_pixels + (p_outpic->p[0].i_pitch * i_index) / SCOPE_WIDTH + (p_outpic->p[0].i_lines * (u8)(i_value+128) / 512 + p_outpic->p[0].i_lines / 2) * p_outpic->p[0].i_pitch;
202             *p_pixel = 0x7f;
203             p_pixel = p_outpic->p[2].p_pixels + (p_outpic->p[2].i_pitch * i_index) / SCOPE_WIDTH + (p_outpic->p[2].i_lines * (u8)(i_value+128) / 512 + p_outpic->p[2].i_lines / 2) * p_outpic->p[2].i_pitch;
204             *p_pixel = 0xdd;
205             p_sample += 2;
206         }
207     }
208
209     /* Display the picture */
210     vout_DatePicture( p_aout->p_sys->p_vout, p_outpic, p_aout->date );
211     vout_DisplayPicture( p_aout->p_sys->p_vout, p_outpic );
212 }
213
214 /*****************************************************************************
215  * aout_Close: close the Esound socket
216  *****************************************************************************/
217 static void aout_Close( aout_thread_t *p_aout )
218 {
219     vout_DestroyThread( p_aout->p_sys->p_vout, NULL );
220     free( p_aout->p_sys );
221 }
222