1 /*****************************************************************************
2 * overlay-test.c : test program for the dynamic overlay plugin
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
6 * Author: Søren Bøg <avacore@videolan.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
37 /*****************************************************************************
39 *****************************************************************************/
44 #define TEXT "Hello world!"
45 #define TEXTSIZE sizeof( TEXT )
50 void DataCreate( void ) {
51 char *p_data
= p_imageRGBA
;
52 for( size_t i
= 0; i
< HEIGHT
; ++i
) {
53 for( size_t j
= 0; j
< HEIGHT
; ++j
) {
54 *(p_data
++) = i
* 4 & 0xFF;
57 *(p_data
++) = j
* 4 & 0xFF;
61 memcpy( p_text
, TEXT
, TEXTSIZE
);
64 /*****************************************************************************
66 *****************************************************************************/
68 int IsFailure( char *psz_text
) {
69 return strncmp( psz_text
, "SUCCESS:", 8 );
72 void CheckResult( FILE *p_res
) {
75 fscanf( p_res
, "%8s", &psz_resp
);
76 if( IsFailure( psz_resp
) ) {
77 printf( " failed\n" );
82 void CheckedCommand( FILE *p_cmd
, FILE *p_res
, char *p_format
, ... ) {
84 va_start( ap
, p_format
);
86 vfprintf( p_cmd
, p_format
, ap
);
94 int GenImage( FILE *p_cmd
, FILE *p_res
) {
97 printf( "Getting an overlay..." );
98 CheckedCommand( p_cmd
, p_res
, "GenImage\n" );
99 fscanf( p_res
, "%d", &i_overlay
);
100 printf( " done. Overlay is %d\n", i_overlay
);
105 void DeleteImage( FILE *p_cmd
, FILE *p_res
, int i_overlay
) {
106 printf( "Removing image..." );
107 CheckedCommand( p_cmd
, p_res
, "DeleteImage %d\n", i_overlay
);
111 void StartAtomic( FILE *p_cmd
, FILE *p_res
) {
112 CheckedCommand( p_cmd
, p_res
, "StartAtomic\n" );
115 void EndAtomic( FILE *p_cmd
, FILE *p_res
) {
116 CheckedCommand( p_cmd
, p_res
, "EndAtomic\n" );
119 void DataSharedMem( FILE *p_cmd
, FILE *p_res
, int i_overlay
, int i_width
,
120 int i_height
, char *psz_format
, int i_shmid
) {
122 printf( "Sending data via shared memory..." );
123 CheckedCommand( p_cmd
, p_res
, "DataSharedMem %d %d %d %s %d\n", i_overlay
,
124 i_width
, i_height
, psz_format
, i_shmid
);
128 void SetAlpha( FILE *p_cmd
, FILE *p_res
, int i_overlay
, int i_alpha
) {
129 CheckedCommand( p_cmd
, p_res
, "SetAlpha %d %d\n", i_overlay
, i_alpha
);
132 void SetPosition( FILE *p_cmd
, FILE *p_res
, int i_overlay
, int i_x
, int i_y
) {
133 CheckedCommand( p_cmd
, p_res
, "SetPosition %d %d %d\n", i_overlay
, i_x
,
137 void SetVisibility( FILE *p_cmd
, FILE *p_res
, int i_overlay
, int i_visible
) {
138 CheckedCommand( p_cmd
, p_res
, "SetVisibility %d %d\n", i_overlay
,
142 void SetTextAlpha( FILE *p_cmd
, FILE *p_res
, int i_overlay
, int i_alpha
) {
143 CheckedCommand( p_cmd
, p_res
, "SetTextAlpha %d %d\n", i_overlay
, i_alpha
);
146 void SetTextColor( FILE *p_cmd
, FILE *p_res
, int i_overlay
, int i_red
,
147 int i_green
, int i_blue
) {
148 CheckedCommand( p_cmd
, p_res
, "SetTextColor %d %d %d %d\n", i_overlay
,
149 i_red
, i_green
, i_blue
);
152 void SetTextSize( FILE *p_cmd
, FILE *p_res
, int i_overlay
, int i_size
) {
153 CheckedCommand( p_cmd
, p_res
, "SetTextSize %d %d\n", i_overlay
, i_size
);
156 int GetTextSize( FILE *p_cmd
, FILE *p_res
, int i_overlay
) {
159 CheckedCommand( p_cmd
, p_res
, "GetTextSize %d\n", i_overlay
);
160 fscanf( p_res
, "%d", &i_size
);
165 /*****************************************************************************
167 *****************************************************************************/
169 void BasicTest( FILE *p_cmd
, FILE *p_res
, int i_overlay
) {
170 printf( "Activating overlay..." );
171 SetVisibility( p_cmd
, p_res
, i_overlay
, 1 );
174 printf( "Sweeping alpha..." );
175 for( int i_alpha
= 0xFF; i_alpha
>= -0xFF ; i_alpha
-= 8 ) {
176 SetAlpha( p_cmd
, p_res
, i_overlay
, abs( i_alpha
) );
179 SetAlpha( p_cmd
, p_res
, i_overlay
, 255 );
182 printf( "Circle motion..." );
183 for( float f_theta
= 0; f_theta
<= 2 * M_PI
; f_theta
+= M_PI
/ 64.0 ) {
184 SetPosition( p_cmd
, p_res
, i_overlay
,
185 (int)( - cos( f_theta
) * 100.0 + 100.0 ),
186 (int)( - sin( f_theta
) * 100.0 + 100.0 ) );
189 SetPosition( p_cmd
, p_res
, i_overlay
, 0, 100 );
192 printf( "Atomic motion..." );
193 StartAtomic( p_cmd
, p_res
);
194 SetPosition( p_cmd
, NULL
, i_overlay
, 200, 50 );
196 SetPosition( p_cmd
, NULL
, i_overlay
, 0, 0 );
197 EndAtomic( p_cmd
, p_res
);
198 CheckResult( p_res
);
199 CheckResult( p_res
);
205 void TextTest( FILE *p_cmd
, FILE *p_res
, int i_overlay
) {
206 printf( "Sweeping (text) alpha..." );
207 for( int i_alpha
= 0xFF; i_alpha
>= -0xFF ; i_alpha
-= 8 ) {
208 SetTextAlpha( p_cmd
, p_res
, i_overlay
, abs( i_alpha
) );
211 SetTextAlpha( p_cmd
, p_res
, i_overlay
, 255 );
214 printf( "Sweeping colors..." );
215 for( int i_red
= 0xFF; i_red
>= 0x00 ; i_red
-= 8 ) {
216 SetTextColor( p_cmd
, p_res
, i_overlay
, i_red
, 0xFF, 0xFF );
219 for( int i_green
= 0xFF; i_green
>= 0x00 ; i_green
-= 8 ) {
220 SetTextColor( p_cmd
, p_res
, i_overlay
, 0x00, i_green
, 0xFF );
223 for( int i_blue
= 0xFF; i_blue
>= 0x00 ; i_blue
-= 8 ) {
224 SetTextColor( p_cmd
, p_res
, i_overlay
, 0x00, 0x00, i_blue
);
227 SetTextColor( p_cmd
, p_res
, i_overlay
, 0x00, 0x00, 0x00 );
230 printf( "Getting size..." );
231 int i_basesize
= GetTextSize( p_cmd
, p_res
, i_overlay
);
232 printf( " done. Size is %d\n", i_basesize
);
234 printf( "Sweeping size..." );
235 for( float f_theta
= 0; f_theta
<= M_PI
; f_theta
+= M_PI
/ 128.0 ) {
236 SetTextSize( p_cmd
, p_res
, i_overlay
,
237 i_basesize
* ( 1 + 3 * sin( f_theta
) ) );
240 SetTextSize( p_cmd
, p_res
, i_overlay
, i_basesize
);
246 /*****************************************************************************
248 *****************************************************************************/
250 int main( int i_argc
, char *ppsz_argv
[] ) {
252 printf( "Incorrect number of parameters.\n"
253 "Usage is: %s command-fifo response-fifo\n", ppsz_argv
[0] );
257 printf( "Creating shared memory for RGBA..." );
258 int i_shmRGBA
= shmget( IPC_PRIVATE
, WIDTH
* HEIGHT
* 4, S_IRWXU
);
259 if( i_shmRGBA
== -1 ) {
260 printf( " failed\n" );
263 printf( " done, ID is %d. Text...", i_shmRGBA
);
264 int i_shmText
= shmget( IPC_PRIVATE
, TEXTSIZE
, S_IRWXU
);
265 if( i_shmText
== -1 ) {
266 printf( " failed\n" );
269 printf( " done, ID is %d\n", i_shmText
);
271 printf( "Attaching shared memory for RGBA..." );
272 p_imageRGBA
= shmat( i_shmRGBA
, NULL
, 0 );
273 if( p_imageRGBA
== (void*)-1 ) {
274 printf( " failed\n" );
277 printf( " done. Text..." );
278 p_text
= shmat( i_shmText
, NULL
, 0 );
279 if( p_text
== (void*)-1 ) {
280 printf( " failed\n" );
285 printf( "Queueing shared memory for destruction, RGBA..." );
286 if( shmctl( i_shmRGBA
, IPC_RMID
, 0 ) == -1 ) {
287 printf( " failed\n" );
290 printf( " done. Text..." );
291 if( shmctl( i_shmText
, IPC_RMID
, 0 ) == -1 ) {
292 printf( " failed\n" );
297 printf( "Generating data..." );
301 printf( "Making FIFOs..." );
302 if( mkfifo( ppsz_argv
[1], S_IRWXU
) ) {
303 if( errno
!= EEXIST
) {
304 printf( " failed\n" );
307 printf( " input already exists..." );
309 if( mkfifo( ppsz_argv
[2], S_IRWXU
) ) {
310 if( errno
!= EEXIST
) {
311 printf( " failed\n" );
314 printf( " output already exists..." );
318 printf( "Please make sure vlc is running.\n"
319 "You should append parameters similar to the following:\n"
320 "--sub-source overlay{input=%s,output=%s}\n",
321 ppsz_argv
[1], ppsz_argv
[2] );
323 printf( "Opening FIFOs..." );
324 FILE *p_cmd
= fopen( ppsz_argv
[1], "w" );
325 if( p_cmd
== NULL
) {
326 printf( " failed\n" );
329 FILE *p_res
= fopen( ppsz_argv
[2], "r" );
330 if( p_res
== NULL
) {
331 printf( " failed\n" );
336 int i_overlay_image
= GenImage( p_cmd
, p_res
);
337 int i_overlay_text
= GenImage( p_cmd
, p_res
);
338 DataSharedMem( p_cmd
, p_res
, i_overlay_image
, WIDTH
, HEIGHT
, "RGBA",
340 DataSharedMem( p_cmd
, p_res
, i_overlay_text
, TEXTSIZE
, 1, "TEXT",
343 BasicTest( p_cmd
, p_res
, i_overlay_image
);
344 BasicTest( p_cmd
, p_res
, i_overlay_text
);
345 TextTest( p_cmd
, p_res
, i_overlay_text
);
347 DeleteImage( p_cmd
, p_res
, i_overlay_image
);
348 DeleteImage( p_cmd
, p_res
, i_overlay_text
);