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 *****************************************************************************/
33 #include <sys/fcntl.h>
38 /*****************************************************************************
40 *****************************************************************************/
45 #define TEXT "Hello world!"
46 #define TEXTSIZE sizeof( TEXT )
51 void DataCreate( void ) {
52 char *p_data = p_imageRGBA;
53 for( size_t i = 0; i < HEIGHT; ++i ) {
54 for( size_t j = 0; j < HEIGHT; ++j ) {
55 *(p_data++) = i * 4 & 0xFF;
58 *(p_data++) = j * 4 & 0xFF;
62 memcpy( p_text, TEXT, TEXTSIZE );
65 /*****************************************************************************
67 *****************************************************************************/
69 int IsFailure( char *psz_text ) {
70 return strncmp( psz_text, "SUCCESS:", 8 );
73 void CheckResult( FILE *p_res ) {
76 fscanf( p_res, "%8s", &psz_resp );
77 if( IsFailure( psz_resp ) ) {
78 printf( " failed\n" );
83 void CheckedCommand( FILE *p_cmd, FILE *p_res, char *p_format, ... ) {
85 va_start( ap, p_format );
87 vfprintf( p_cmd, p_format, ap );
95 int GenImage( FILE *p_cmd, FILE *p_res ) {
98 printf( "Getting an overlay..." );
99 CheckedCommand( p_cmd, p_res, "GenImage\n" );
100 fscanf( p_res, "%d", &i_overlay );
101 printf( " done. Overlay is %d\n", i_overlay );
106 void DeleteImage( FILE *p_cmd, FILE *p_res, int i_overlay ) {
107 printf( "Removing image..." );
108 CheckedCommand( p_cmd, p_res, "DeleteImage %d\n", i_overlay );
112 void StartAtomic( FILE *p_cmd, FILE *p_res ) {
113 CheckedCommand( p_cmd, p_res, "StartAtomic\n" );
116 void EndAtomic( FILE *p_cmd, FILE *p_res ) {
117 CheckedCommand( p_cmd, p_res, "EndAtomic\n" );
120 void DataSharedMem( FILE *p_cmd, FILE *p_res, int i_overlay, int i_width,
121 int i_height, char *psz_format, int i_shmid ) {
123 printf( "Sending data via shared memory..." );
124 CheckedCommand( p_cmd, p_res, "DataSharedMem %d %d %d %s %d\n", i_overlay,
125 i_width, i_height, psz_format, i_shmid );
129 void SetAlpha( FILE *p_cmd, FILE *p_res, int i_overlay, int i_alpha ) {
130 CheckedCommand( p_cmd, p_res, "SetAlpha %d %d\n", i_overlay, i_alpha );
133 void SetPosition( FILE *p_cmd, FILE *p_res, int i_overlay, int i_x, int i_y ) {
134 CheckedCommand( p_cmd, p_res, "SetPosition %d %d %d\n", i_overlay, i_x,
138 void SetVisibility( FILE *p_cmd, FILE *p_res, int i_overlay, int i_visible ) {
139 CheckedCommand( p_cmd, p_res, "SetVisibility %d %d\n", i_overlay,
143 /*****************************************************************************
145 *****************************************************************************/
147 void BasicTest( FILE *p_cmd, FILE *p_res, int i_overlay ) {
148 printf( "Activating overlay..." );
149 SetVisibility( p_cmd, p_res, i_overlay, 1 );
152 printf( "Sweeping alpha..." );
153 for( int i_alpha = 0xFF; i_alpha >= -0xFF ; i_alpha -= 8 ) {
154 SetAlpha( p_cmd, p_res, i_overlay, abs( i_alpha ) );
157 SetAlpha( p_cmd, p_res, i_overlay, 255 );
160 printf( "Circle motion..." );
161 for( float f_theta = 0; f_theta <= 2 * M_PI ; f_theta += M_PI / 64.0 ) {
162 SetPosition( p_cmd, p_res, i_overlay,
163 (int)( - cos( f_theta ) * 100.0 + 100.0 ),
164 (int)( - sin( f_theta ) * 100.0 + 100.0 ) );
167 SetPosition( p_cmd, p_res, i_overlay, 0, 100 );
170 printf( "Atomic motion..." );
171 StartAtomic( p_cmd, p_res );
172 SetPosition( p_cmd, NULL, i_overlay, 200, 50 );
174 SetPosition( p_cmd, NULL, i_overlay, 0, 0 );
175 EndAtomic( p_cmd, p_res );
176 CheckResult( p_res );
177 CheckResult( p_res );
183 /*****************************************************************************
185 *****************************************************************************/
187 int main( int i_argc, char *ppsz_argv[] ) {
189 printf( "Incorrect number of parameters.\n"
190 "Usage is: %s command-fifo response-fifo\n", ppsz_argv[0] );
194 printf( "Creating shared memory for RGBA..." );
195 int i_shmRGBA = shmget( IPC_PRIVATE, WIDTH * HEIGHT * 4, S_IRWXU );
196 if( i_shmRGBA == -1 ) {
197 printf( " failed\n" );
200 printf( " done, ID is %d. Text...", i_shmRGBA );
201 int i_shmText = shmget( IPC_PRIVATE, TEXTSIZE, S_IRWXU );
202 if( i_shmText == -1 ) {
203 printf( " failed\n" );
206 printf( " done, ID is %d\n", i_shmText );
208 printf( "Attaching shared memory for RGBA..." );
209 p_imageRGBA = shmat( i_shmRGBA, NULL, 0 );
210 if( p_imageRGBA == -1 ) {
211 printf( " failed\n" );
214 printf( " done. Text..." );
215 p_text = shmat( i_shmText, NULL, 0 );
217 printf( " failed\n" );
222 printf( "Queueing shared memory for destruction, RGBA..." );
223 if( shmctl( i_shmRGBA, IPC_RMID, 0 ) == -1 ) {
224 printf( " failed\n" );
227 printf( " done. Text..." );
228 if( shmctl( i_shmText, IPC_RMID, 0 ) == -1 ) {
229 printf( " failed\n" );
234 printf( "Generating data..." );
238 printf( "Please make sure vlc is running.\n"
239 "You should append parameters similar to the following:\n"
240 "--sub-filter overlay --overlay-input %s --overlay-output %s\n",
241 ppsz_argv[1], ppsz_argv[2] );
243 printf( "Opening FIFOs..." );
244 FILE *p_cmd = fopen( ppsz_argv[1], "w" );
245 if( p_cmd == NULL ) {
246 printf( " failed\n" );
249 FILE *p_res = fopen( ppsz_argv[2], "r" );
250 if( p_res == NULL ) {
251 printf( " failed\n" );
256 int i_overlay_image = GenImage( p_cmd, p_res );
257 int i_overlay_text = GenImage( p_cmd, p_res );
258 DataSharedMem( p_cmd, p_res, i_overlay_image, WIDTH, HEIGHT, "RGBA",
260 DataSharedMem( p_cmd, p_res, i_overlay_text, TEXTSIZE, 1, "TEXT",
263 BasicTest( p_cmd, p_res, i_overlay_image );
264 BasicTest( p_cmd, p_res, i_overlay_text );
266 DeleteImage( p_cmd, p_res, i_overlay_image );
267 DeleteImage( p_cmd, p_res, i_overlay_text );