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 *****************************************************************************/
32 #include <sys/fcntl.h>
37 /*****************************************************************************
39 *****************************************************************************/
46 void ImagesCreate( void ) {
47 char *p_data = p_imageRGBA;
48 for( size_t i = 0; i < HEIGHT; ++i ) {
49 for( size_t j = 0; j < HEIGHT; ++j ) {
50 *(p_data++) = i * 4 & 0xFF;
53 *(p_data++) = j * 4 & 0xFF;
58 /*****************************************************************************
60 *****************************************************************************/
62 int IsFailure( char *psz_text ) {
63 return strncmp( psz_text, "SUCCESS:", 8 );
66 /*****************************************************************************
68 *****************************************************************************/
70 int main( int i_argc, char *ppsz_argv[] ) {
72 printf( "Incorrect number of parameters.\n"
73 "Usage is: %s command-fifo response-fifo\n", ppsz_argv[0] );
77 printf( "Creating shared memory..." );
78 int i_shmRGBA = shmget( IPC_PRIVATE, WIDTH * HEIGHT * 4, S_IRWXU );
79 if( i_shmRGBA == -1 ) {
80 printf( " failed\n" );
83 printf( " done. ID is %d\n", i_shmRGBA );
85 printf( "Attaching shared memory..." );
86 p_imageRGBA = shmat( i_shmRGBA, NULL, 0 );
87 if( p_imageRGBA == -1 ) {
88 printf( " failed\n" );
93 printf( "Queueing shared memory for destruction..." );
94 if( shmctl( i_shmRGBA, IPC_RMID, 0 ) == -1 ) {
95 printf( " failed\n" );
100 printf( "Generating images..." );
104 printf( "Please make sure vlc is running.\n"
105 "You should append parameters similar to the following:\n"
106 "--sub-filter overlay --overlay-input %s --overlay-output %s\n",
107 ppsz_argv[1], ppsz_argv[2] );
109 printf( "Opening FIFOs..." );
110 FILE *f_cmd = fopen( ppsz_argv[1], "w" );
111 if( f_cmd == NULL ) {
112 printf( " failed\n" );
115 FILE *f_res = fopen( ppsz_argv[2], "r" );
116 if( f_res == NULL ) {
117 printf( " failed\n" );
122 printf( "Getting an overlay..." );
125 fprintf( f_cmd, "GenImage\n" );
127 fscanf( f_res, "%8s", &psz_resp );
128 if( IsFailure( psz_resp ) ) {
129 printf( " failed\n" );
132 fscanf( f_res, "%d", &i_overlay );
133 printf( " done. Overlay is %d\n", i_overlay );
135 printf( "Sending data..." );
136 fprintf( f_cmd, "DataSharedMem %d %d %d RGBA %d\n", i_overlay, WIDTH,
139 fscanf( f_res, "%8s", &psz_resp );
140 if( IsFailure( psz_resp ) ) {
141 printf( " failed\n" );
146 printf( "Activating overlay..." );
147 fprintf( f_cmd, "SetVisibility %d 1\n", i_overlay );
149 fscanf( f_res, "%8s", &psz_resp );
150 if( IsFailure( psz_resp ) ) {
151 printf( " failed\n" );
156 printf( "Sweeping alpha..." );
157 for( int i_alpha = 0xFF; i_alpha >= -0xFF ; i_alpha -= 8 ) {
158 fprintf( f_cmd, "SetAlpha %d %d\n", i_overlay, abs( i_alpha ) );
160 fscanf( f_res, "%8s", &psz_resp );
161 if( IsFailure( psz_resp ) ) {
162 printf( " failed\n" );
167 fprintf( f_cmd, "SetAlpha %d 255\n", i_overlay );
169 fscanf( f_res, "%8s", &psz_resp );
170 if( IsFailure( psz_resp ) ) {
171 printf( " failed\n" );
176 printf( "Circle motion..." );
177 for( float f_theta = 0; f_theta <= 2 * M_PI ; f_theta += M_PI / 64.0 ) {
178 fprintf( f_cmd, "SetPosition %d %d %d\n", i_overlay,
179 (int)( - cos( f_theta ) * 100.0 + 100.0 ),
180 (int)( - sin( f_theta ) * 100.0 + 100.0 ) );
182 fscanf( f_res, "%8s", &psz_resp );
183 if( IsFailure( psz_resp ) ) {
184 printf( " failed\n" );
189 fprintf( f_cmd, "SetPosition %d 0 0\n", i_overlay );
191 fscanf( f_res, "%8s", &psz_resp );
192 if( IsFailure( psz_resp ) ) {
193 printf( " failed\n" );
198 printf( "Removing image..." );
199 fprintf( f_cmd, "DeleteImage %d\n", i_overlay );
201 fscanf( f_res, "%8s", &psz_resp );
202 if( IsFailure( psz_resp ) ) {
203 printf( " failed\n" );