From ba0b957330e7524790d7a2566b9f6bd50633ca69 Mon Sep 17 00:00:00 2001 From: Jean-Paul Saman Date: Wed, 26 Mar 2008 11:39:03 +0100 Subject: [PATCH] =?utf8?q?Patch=20from=20S=C3=B8ren=20B=C3=B8g=20=20GSoC=202007?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Overlay - Basic test/demonstration program --- extras/misc/overlay-test.c | 207 +++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 extras/misc/overlay-test.c diff --git a/extras/misc/overlay-test.c b/extras/misc/overlay-test.c new file mode 100644 index 0000000000..ec66683e9a --- /dev/null +++ b/extras/misc/overlay-test.c @@ -0,0 +1,207 @@ +/***************************************************************************** + * overlay-test.c : test program for the dynamic overlay plugin + ***************************************************************************** + * Copyright (C) 2007 the VideoLAN team + * $Id$ + * + * Author: Søren Bøg + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +/***************************************************************************** + * Preamble + *****************************************************************************/ +#include +#include +#include +#include + +#include +#include +#include +#include + +/***************************************************************************** + * Images + *****************************************************************************/ + +#define WIDTH 128 +#define HEIGHT 128 + +char *p_imageRGBA; + +void ImagesCreate( void ) { + char *p_data = p_imageRGBA; + for( size_t i = 0; i < HEIGHT; ++i ) { + for( size_t j = 0; j < HEIGHT; ++j ) { + *(p_data++) = i * 4 & 0xFF; + *(p_data++) = 0xFF; + *(p_data++) = 0x00; + *(p_data++) = j * 4 & 0xFF; + } + } +} + +/***************************************************************************** + * I/O Helpers + *****************************************************************************/ + +int IsFailure( char *psz_text ) { + return strncmp( psz_text, "SUCCESS:", 8 ); +} + +/***************************************************************************** + * main + *****************************************************************************/ + +int main( int i_argc, char *ppsz_argv[] ) { + if( i_argc != 3 ) { + printf( "Incorrect number of parameters.\n" + "Usage is: %s command-fifo response-fifo\n", ppsz_argv[0] ); + exit( -2 ); + } + + printf( "Creating shared memory..." ); + int i_shmRGBA = shmget( IPC_PRIVATE, WIDTH * HEIGHT * 4, S_IRWXU ); + if( i_shmRGBA == -1 ) { + printf( " failed\n" ); + exit( -1 ); + } + printf( " done. ID is %d\n", i_shmRGBA ); + + printf( "Attaching shared memory..." ); + p_imageRGBA = shmat( i_shmRGBA, NULL, 0 ); + if( p_imageRGBA == -1 ) { + printf( " failed\n" ); + exit( -1 ); + } + printf( " done\n" ); + + printf( "Queueing shared memory for destruction..." ); + if( shmctl( i_shmRGBA, IPC_RMID, 0 ) == -1 ) { + printf( " failed\n" ); + exit( -1 ); + } + printf( " done\n" ); + + printf( "Generating images..." ); + ImagesCreate(); + printf( " done\n" ); + + printf( "Please make sure vlc is running.\n" + "You should append parameters similar to the following:\n" + "--sub-filter overlay --overlay-input %s --overlay-output %s\n", + ppsz_argv[1], ppsz_argv[2] ); + + printf( "Opening FIFOs..." ); + FILE *f_cmd = fopen( ppsz_argv[1], "w" ); + if( f_cmd == NULL ) { + printf( " failed\n" ); + exit( -1 ); + } + FILE *f_res = fopen( ppsz_argv[2], "r" ); + if( f_res == NULL ) { + printf( " failed\n" ); + exit( -1 ); + } + printf( " done\n" ); + + printf( "Getting an overlay..." ); + int i_overlay; + char psz_resp[9]; + fprintf( f_cmd, "GenImage\n" ); + fflush( f_cmd ); + fscanf( f_res, "%8s", &psz_resp ); + if( IsFailure( psz_resp ) ) { + printf( " failed\n" ); + exit( -1 ); + } + fscanf( f_res, "%d", &i_overlay ); + printf( " done. Overlay is %d\n", i_overlay ); + + printf( "Sending data..." ); + fprintf( f_cmd, "DataSharedMem %d %d %d RGBA %d\n", i_overlay, WIDTH, + HEIGHT, i_shmRGBA ); + fflush( f_cmd ); + fscanf( f_res, "%8s", &psz_resp ); + if( IsFailure( psz_resp ) ) { + printf( " failed\n" ); + exit( -1 ); + } + printf( " done\n" ); + + printf( "Activating overlay..." ); + fprintf( f_cmd, "SetVisibility %d 1\n", i_overlay ); + fflush( f_cmd ); + fscanf( f_res, "%8s", &psz_resp ); + if( IsFailure( psz_resp ) ) { + printf( " failed\n" ); + exit( -1 ); + } + printf( " done\n" ); + + printf( "Sweeping alpha..." ); + for( int i_alpha = 0xFF; i_alpha >= -0xFF ; i_alpha -= 8 ) { + fprintf( f_cmd, "SetAlpha %d %d\n", i_overlay, abs( i_alpha ) ); + fflush( f_cmd ); + fscanf( f_res, "%8s", &psz_resp ); + if( IsFailure( psz_resp ) ) { + printf( " failed\n" ); + exit( -1 ); + } + usleep( 20000 ); + } + fprintf( f_cmd, "SetAlpha %d 255\n", i_overlay ); + fflush( f_cmd ); + fscanf( f_res, "%8s", &psz_resp ); + if( IsFailure( psz_resp ) ) { + printf( " failed\n" ); + exit( -1 ); + } + printf( " done\n" ); + + printf( "Circle motion..." ); + for( float f_theta = 0; f_theta <= 2 * M_PI ; f_theta += M_PI / 64.0 ) { + fprintf( f_cmd, "SetPosition %d %d %d\n", i_overlay, + (int)( - cos( f_theta ) * 100.0 + 100.0 ), + (int)( - sin( f_theta ) * 100.0 + 100.0 ) ); + fflush( f_cmd ); + fscanf( f_res, "%8s", &psz_resp ); + if( IsFailure( psz_resp ) ) { + printf( " failed\n" ); + exit( -1 ); + } + usleep( 20000 ); + } + fprintf( f_cmd, "SetPosition %d 0 0\n", i_overlay ); + fflush( f_cmd ); + fscanf( f_res, "%8s", &psz_resp ); + if( IsFailure( psz_resp ) ) { + printf( " failed\n" ); + exit( -1 ); + } + printf( " done\n" ); + + printf( "Removing image..." ); + fprintf( f_cmd, "DeleteImage %d\n", i_overlay ); + fflush( f_cmd ); + fscanf( f_res, "%8s", &psz_resp ); + if( IsFailure( psz_resp ) ) { + printf( " failed\n" ); + exit( -1 ); + } + printf( " done\n" ); +} -- 2.39.2