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 /*****************************************************************************
146 *****************************************************************************/
148 void BasicTest( FILE *p_cmd, FILE *p_res, int i_overlay ) {
149 printf( "Activating overlay..." );
150 SetVisibility( p_cmd, p_res, i_overlay, 1 );
153 printf( "Sweeping alpha..." );
154 for( int i_alpha = 0xFF; i_alpha >= -0xFF ; i_alpha -= 8 ) {
155 SetAlpha( p_cmd, p_res, i_overlay, abs( i_alpha ) );
158 SetAlpha( p_cmd, p_res, i_overlay, 255 );
161 printf( "Circle motion..." );
162 for( float f_theta = 0; f_theta <= 2 * M_PI ; f_theta += M_PI / 64.0 ) {
163 SetPosition( p_cmd, p_res, i_overlay,
164 (int)( - cos( f_theta ) * 100.0 + 100.0 ),
165 (int)( - sin( f_theta ) * 100.0 + 100.0 ) );
168 SetPosition( p_cmd, p_res, i_overlay, 0, 100 );
171 printf( "Atomic motion..." );
172 StartAtomic( p_cmd, p_res );
173 SetPosition( p_cmd, NULL, i_overlay, 200, 50 );
175 SetPosition( p_cmd, NULL, i_overlay, 0, 0 );
176 EndAtomic( p_cmd, p_res );
177 CheckResult( p_res );
178 CheckResult( p_res );
184 /*****************************************************************************
186 *****************************************************************************/
188 int main( int i_argc, char *ppsz_argv[] ) {
190 printf( "Incorrect number of parameters.\n"
191 "Usage is: %s command-fifo response-fifo\n", ppsz_argv[0] );
195 printf( "Creating shared memory for RGBA..." );
196 int i_shmRGBA = shmget( IPC_PRIVATE, WIDTH * HEIGHT * 4, S_IRWXU );
197 if( i_shmRGBA == -1 ) {
198 printf( " failed\n" );
201 printf( " done, ID is %d. Text...", i_shmRGBA );
202 int i_shmText = shmget( IPC_PRIVATE, TEXTSIZE, S_IRWXU );
203 if( i_shmText == -1 ) {
204 printf( " failed\n" );
207 printf( " done, ID is %d\n", i_shmText );
209 printf( "Attaching shared memory for RGBA..." );
210 p_imageRGBA = shmat( i_shmRGBA, NULL, 0 );
211 if( p_imageRGBA == -1 ) {
212 printf( " failed\n" );
215 printf( " done. Text..." );
216 p_text = shmat( i_shmText, NULL, 0 );
218 printf( " failed\n" );
223 printf( "Queueing shared memory for destruction, RGBA..." );
224 if( shmctl( i_shmRGBA, IPC_RMID, 0 ) == -1 ) {
225 printf( " failed\n" );
228 printf( " done. Text..." );
229 if( shmctl( i_shmText, IPC_RMID, 0 ) == -1 ) {
230 printf( " failed\n" );
235 printf( "Generating data..." );
239 printf( "Making FIFOs..." );
240 if( mkfifo( ppsz_argv[1], S_IRWXU ) ) {
241 if( errno != EEXIST ) {
242 printf( " failed\n" );
245 printf( " input already exists..." );
247 if( mkfifo( ppsz_argv[2], S_IRWXU ) ) {
248 if( errno != EEXIST ) {
249 printf( " failed\n" );
252 printf( " output already exists..." );
256 printf( "Please make sure vlc is running.\n"
257 "You should append parameters similar to the following:\n"
258 "--sub-filter overlay{input=%s,output=%s}\n",
259 ppsz_argv[1], ppsz_argv[2] );
261 printf( "Opening FIFOs..." );
262 FILE *p_cmd = fopen( ppsz_argv[1], "w" );
263 if( p_cmd == NULL ) {
264 printf( " failed\n" );
267 FILE *p_res = fopen( ppsz_argv[2], "r" );
268 if( p_res == NULL ) {
269 printf( " failed\n" );
274 int i_overlay_image = GenImage( p_cmd, p_res );
275 int i_overlay_text = GenImage( p_cmd, p_res );
276 DataSharedMem( p_cmd, p_res, i_overlay_image, WIDTH, HEIGHT, "RGBA",
278 DataSharedMem( p_cmd, p_res, i_overlay_text, TEXTSIZE, 1, "TEXT",
281 BasicTest( p_cmd, p_res, i_overlay_image );
282 BasicTest( p_cmd, p_res, i_overlay_text );
284 DeleteImage( p_cmd, p_res, i_overlay_image );
285 DeleteImage( p_cmd, p_res, i_overlay_text );