1 /*****************************************************************************
2 * overlay-test.c : test program for the dynamic overlay plugin
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
7 * Author: Søren Bøg <avacore@videolan.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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
34 #include <sys/fcntl.h>
39 /*****************************************************************************
41 *****************************************************************************/
46 #define TEXT "Hello world!"
47 #define TEXTSIZE sizeof( TEXT )
52 void DataCreate( void ) {
53 char *p_data = p_imageRGBA;
54 for( size_t i = 0; i < HEIGHT; ++i ) {
55 for( size_t j = 0; j < HEIGHT; ++j ) {
56 *(p_data++) = i * 4 & 0xFF;
59 *(p_data++) = j * 4 & 0xFF;
63 memcpy( p_text, TEXT, TEXTSIZE );
66 /*****************************************************************************
68 *****************************************************************************/
70 int IsFailure( char *psz_text ) {
71 return strncmp( psz_text, "SUCCESS:", 8 );
74 void CheckResult( FILE *p_res ) {
77 fscanf( p_res, "%8s", &psz_resp );
78 if( IsFailure( psz_resp ) ) {
79 printf( " failed\n" );
84 void CheckedCommand( FILE *p_cmd, FILE *p_res, char *p_format, ... ) {
86 va_start( ap, p_format );
88 vfprintf( p_cmd, p_format, ap );
96 int GenImage( FILE *p_cmd, FILE *p_res ) {
99 printf( "Getting an overlay..." );
100 CheckedCommand( p_cmd, p_res, "GenImage\n" );
101 fscanf( p_res, "%d", &i_overlay );
102 printf( " done. Overlay is %d\n", i_overlay );
107 void DeleteImage( FILE *p_cmd, FILE *p_res, int i_overlay ) {
108 printf( "Removing image..." );
109 CheckedCommand( p_cmd, p_res, "DeleteImage %d\n", i_overlay );
113 void StartAtomic( FILE *p_cmd, FILE *p_res ) {
114 CheckedCommand( p_cmd, p_res, "StartAtomic\n" );
117 void EndAtomic( FILE *p_cmd, FILE *p_res ) {
118 CheckedCommand( p_cmd, p_res, "EndAtomic\n" );
121 void DataSharedMem( FILE *p_cmd, FILE *p_res, int i_overlay, int i_width,
122 int i_height, char *psz_format, int i_shmid ) {
124 printf( "Sending data via shared memory..." );
125 CheckedCommand( p_cmd, p_res, "DataSharedMem %d %d %d %s %d\n", i_overlay,
126 i_width, i_height, psz_format, i_shmid );
130 void SetAlpha( FILE *p_cmd, FILE *p_res, int i_overlay, int i_alpha ) {
131 CheckedCommand( p_cmd, p_res, "SetAlpha %d %d\n", i_overlay, i_alpha );
134 void SetPosition( FILE *p_cmd, FILE *p_res, int i_overlay, int i_x, int i_y ) {
135 CheckedCommand( p_cmd, p_res, "SetPosition %d %d %d\n", i_overlay, i_x,
139 void SetVisibility( FILE *p_cmd, FILE *p_res, int i_overlay, int i_visible ) {
140 CheckedCommand( p_cmd, p_res, "SetVisibility %d %d\n", i_overlay,
144 void SetTextAlpha( FILE *p_cmd, FILE *p_res, int i_overlay, int i_alpha ) {
145 CheckedCommand( p_cmd, p_res, "SetTextAlpha %d %d\n", i_overlay, i_alpha );
148 void SetTextColor( FILE *p_cmd, FILE *p_res, int i_overlay, int i_red,
149 int i_green, int i_blue ) {
150 CheckedCommand( p_cmd, p_res, "SetTextColor %d %d %d %d\n", i_overlay,
151 i_red, i_green, i_blue );
154 void SetTextSize( FILE *p_cmd, FILE *p_res, int i_overlay, int i_size ) {
155 CheckedCommand( p_cmd, p_res, "SetTextSize %d %d\n", i_overlay, i_size );
158 int GetTextSize( FILE *p_cmd, FILE *p_res, int i_overlay ) {
161 CheckedCommand( p_cmd, p_res, "GetTextSize %d\n", i_overlay );
162 fscanf( p_res, "%d", &i_size );
167 /*****************************************************************************
169 *****************************************************************************/
171 void BasicTest( FILE *p_cmd, FILE *p_res, int i_overlay ) {
172 printf( "Activating overlay..." );
173 SetVisibility( p_cmd, p_res, i_overlay, 1 );
176 printf( "Sweeping alpha..." );
177 for( int i_alpha = 0xFF; i_alpha >= -0xFF ; i_alpha -= 8 ) {
178 SetAlpha( p_cmd, p_res, i_overlay, abs( i_alpha ) );
181 SetAlpha( p_cmd, p_res, i_overlay, 255 );
184 printf( "Circle motion..." );
185 for( float f_theta = 0; f_theta <= 2 * M_PI ; f_theta += M_PI / 64.0 ) {
186 SetPosition( p_cmd, p_res, i_overlay,
187 (int)( - cos( f_theta ) * 100.0 + 100.0 ),
188 (int)( - sin( f_theta ) * 100.0 + 100.0 ) );
191 SetPosition( p_cmd, p_res, i_overlay, 0, 100 );
194 printf( "Atomic motion..." );
195 StartAtomic( p_cmd, p_res );
196 SetPosition( p_cmd, NULL, i_overlay, 200, 50 );
198 SetPosition( p_cmd, NULL, i_overlay, 0, 0 );
199 EndAtomic( p_cmd, p_res );
200 CheckResult( p_res );
201 CheckResult( p_res );
207 void TextTest( FILE *p_cmd, FILE *p_res, int i_overlay ) {
208 printf( "Sweeping (text) alpha..." );
209 for( int i_alpha = 0xFF; i_alpha >= -0xFF ; i_alpha -= 8 ) {
210 SetTextAlpha( p_cmd, p_res, i_overlay, abs( i_alpha ) );
213 SetTextAlpha( p_cmd, p_res, i_overlay, 255 );
216 printf( "Sweeping colors..." );
217 for( int i_red = 0xFF; i_red >= 0x00 ; i_red -= 8 ) {
218 SetTextColor( p_cmd, p_res, i_overlay, i_red, 0xFF, 0xFF );
221 for( int i_green = 0xFF; i_green >= 0x00 ; i_green -= 8 ) {
222 SetTextColor( p_cmd, p_res, i_overlay, 0x00, i_green, 0xFF );
225 for( int i_blue = 0xFF; i_blue >= 0x00 ; i_blue -= 8 ) {
226 SetTextColor( p_cmd, p_res, i_overlay, 0x00, 0x00, i_blue );
229 SetTextColor( p_cmd, p_res, i_overlay, 0x00, 0x00, 0x00 );
232 printf( "Getting size..." );
233 int i_basesize = GetTextSize( p_cmd, p_res, i_overlay );
234 printf( " done. Size is %d\n", i_basesize );
236 printf( "Sweeping size..." );
237 for( float f_theta = 0; f_theta <= M_PI ; f_theta += M_PI / 128.0 ) {
238 SetTextSize( p_cmd, p_res, i_overlay,
239 i_basesize * ( 1 + 3 * sin( f_theta ) ) );
242 SetTextSize( p_cmd, p_res, i_overlay, i_basesize );
248 /*****************************************************************************
250 *****************************************************************************/
252 int main( int i_argc, char *ppsz_argv[] ) {
254 printf( "Incorrect number of parameters.\n"
255 "Usage is: %s command-fifo response-fifo\n", ppsz_argv[0] );
259 printf( "Creating shared memory for RGBA..." );
260 int i_shmRGBA = shmget( IPC_PRIVATE, WIDTH * HEIGHT * 4, S_IRWXU );
261 if( i_shmRGBA == -1 ) {
262 printf( " failed\n" );
265 printf( " done, ID is %d. Text...", i_shmRGBA );
266 int i_shmText = shmget( IPC_PRIVATE, TEXTSIZE, S_IRWXU );
267 if( i_shmText == -1 ) {
268 printf( " failed\n" );
271 printf( " done, ID is %d\n", i_shmText );
273 printf( "Attaching shared memory for RGBA..." );
274 p_imageRGBA = shmat( i_shmRGBA, NULL, 0 );
275 if( p_imageRGBA == (void*)-1 ) {
276 printf( " failed\n" );
279 printf( " done. Text..." );
280 p_text = shmat( i_shmText, NULL, 0 );
281 if( p_text == (void*)-1 ) {
282 printf( " failed\n" );
287 printf( "Queueing shared memory for destruction, RGBA..." );
288 if( shmctl( i_shmRGBA, IPC_RMID, 0 ) == -1 ) {
289 printf( " failed\n" );
292 printf( " done. Text..." );
293 if( shmctl( i_shmText, IPC_RMID, 0 ) == -1 ) {
294 printf( " failed\n" );
299 printf( "Generating data..." );
303 printf( "Making FIFOs..." );
304 if( mkfifo( ppsz_argv[1], S_IRWXU ) ) {
305 if( errno != EEXIST ) {
306 printf( " failed\n" );
309 printf( " input already exists..." );
311 if( mkfifo( ppsz_argv[2], S_IRWXU ) ) {
312 if( errno != EEXIST ) {
313 printf( " failed\n" );
316 printf( " output already exists..." );
320 printf( "Please make sure vlc is running.\n"
321 "You should append parameters similar to the following:\n"
322 "--sub-filter overlay{input=%s,output=%s}\n",
323 ppsz_argv[1], ppsz_argv[2] );
325 printf( "Opening FIFOs..." );
326 FILE *p_cmd = fopen( ppsz_argv[1], "w" );
327 if( p_cmd == NULL ) {
328 printf( " failed\n" );
331 FILE *p_res = fopen( ppsz_argv[2], "r" );
332 if( p_res == NULL ) {
333 printf( " failed\n" );
338 int i_overlay_image = GenImage( p_cmd, p_res );
339 int i_overlay_text = GenImage( p_cmd, p_res );
340 DataSharedMem( p_cmd, p_res, i_overlay_image, WIDTH, HEIGHT, "RGBA",
342 DataSharedMem( p_cmd, p_res, i_overlay_text, TEXTSIZE, 1, "TEXT",
345 BasicTest( p_cmd, p_res, i_overlay_image );
346 BasicTest( p_cmd, p_res, i_overlay_text );
347 TextTest( p_cmd, p_res, i_overlay_text );
349 DeleteImage( p_cmd, p_res, i_overlay_image );
350 DeleteImage( p_cmd, p_res, i_overlay_text );