player: include other selected tracks(if any) in osd_message when unselecting an es
[vlc.git] / modules / spu / dynamicoverlay / dynamicoverlay_commands.c
blob31160d2ec8a171fa3e7481dada0ca98cc0bb1c5e
1 /*****************************************************************************
2 * dynamicoverlay_commands.c : dynamic overlay plugin commands
3 *****************************************************************************
4 * Copyright (C) 2008 VLC authors and VideoLAN
6 * Author: Søren Bøg <avacore@videolan.org>
7 * Jean-Paul Saman <jpsaman@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #include <vlc_common.h>
29 #include <vlc_arrays.h>
30 #include <vlc_vout.h>
31 #include <vlc_filter.h>
33 #include <limits.h>
34 #include <string.h>
35 #include <ctype.h>
37 #if defined(HAVE_SYS_SHM_H)
38 #include <sys/shm.h>
39 #endif
41 #include "dynamicoverlay.h"
44 /*****************************************************************************
45 * overlay_t: Overlay descriptor
46 *****************************************************************************/
48 overlay_t *OverlayCreate( void )
50 overlay_t *p_ovl = calloc( 1, sizeof( overlay_t ) );
51 if( p_ovl == NULL )
52 return NULL;
54 p_ovl->i_x = p_ovl->i_y = 0;
55 p_ovl->i_alpha = 0xFF;
56 p_ovl->b_active = false;
57 video_format_Setup( &p_ovl->format, VLC_FOURCC( '\0','\0','\0','\0') , 0, 0,
58 0, 0, 1, 1 );
59 p_ovl->p_fontstyle = text_style_Create( STYLE_NO_DEFAULTS );
60 p_ovl->data.p_text = NULL;
62 return p_ovl;
65 int OverlayDestroy( overlay_t *p_ovl )
67 free( p_ovl->data.p_text );
68 text_style_Delete( p_ovl->p_fontstyle );
70 return VLC_SUCCESS;
73 /*****************************************************************************
74 * Command parsers
75 *****************************************************************************/
76 static int skip_space( char **psz_command )
78 char *psz_temp = *psz_command;
80 while( isspace( (unsigned char)*psz_temp ) )
82 ++psz_temp;
84 if( psz_temp == *psz_command )
86 return VLC_EGENERIC;
88 *psz_command = psz_temp;
89 return VLC_SUCCESS;
92 static int parse_digit( char **psz_command, int32_t *value )
94 char *psz_temp;
95 long l = strtol( *psz_command, &psz_temp, 10 );
97 if( psz_temp == *psz_command )
99 return VLC_EGENERIC;
101 #if LONG_MAX > INT32_MAX
102 if( l > INT32_MAX || l < INT32_MIN )
103 return VLC_EGENERIC;
104 #endif
105 *value = l;
106 *psz_command = psz_temp;
107 return VLC_SUCCESS;
110 static int parse_char( char **psz_command, char **psz_end,
111 int count, char *psz_value )
113 if( *psz_end - *psz_command < count )
115 return VLC_EGENERIC;
117 memcpy( psz_value, *psz_command, count );
118 *psz_command += count;
119 return VLC_SUCCESS;
122 static int parser_DataSharedMem( char *psz_command,
123 char *psz_end,
124 commandparams_t *p_params )
126 /* Parse: 0 128 128 RGBA 9404459 */
127 skip_space( &psz_command );
128 if( isdigit( (unsigned char)*psz_command ) )
130 if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
131 return VLC_EGENERIC;
133 skip_space( &psz_command );
134 if( isdigit( (unsigned char)*psz_command ) )
136 if( parse_digit( &psz_command, &p_params->i_width ) == VLC_EGENERIC )
137 return VLC_EGENERIC;
139 skip_space( &psz_command );
140 if( isdigit( (unsigned char)*psz_command ) )
142 if( parse_digit( &psz_command, &p_params->i_height ) == VLC_EGENERIC )
143 return VLC_EGENERIC;
145 skip_space( &psz_command );
146 if( isascii( (unsigned char)*psz_command ) )
148 if( parse_char( &psz_command, &psz_end, 4, (char*)&p_params->fourcc )
149 == VLC_EGENERIC )
150 return VLC_EGENERIC;
152 skip_space( &psz_command );
153 if( isdigit( (unsigned char)*psz_command ) )
155 if( parse_digit( &psz_command, &p_params->i_shmid ) == VLC_EGENERIC )
156 return VLC_EGENERIC;
158 return VLC_SUCCESS;
161 static int parser_Id( char *psz_command, char *psz_end,
162 commandparams_t *p_params )
164 VLC_UNUSED(psz_end);
165 skip_space( &psz_command );
166 if( isdigit( (unsigned char)*psz_command ) )
168 if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
169 return VLC_EGENERIC;
171 return VLC_SUCCESS;
174 static int parser_None( char *psz_command, char *psz_end,
175 commandparams_t *p_params )
177 VLC_UNUSED(psz_command);
178 VLC_UNUSED(psz_end);
179 VLC_UNUSED(p_params);
180 return VLC_SUCCESS;
183 static int parser_SetAlpha( char *psz_command, char *psz_end,
184 commandparams_t *p_params )
186 VLC_UNUSED(psz_end);
187 skip_space( &psz_command );
188 if( isdigit( (unsigned char)*psz_command ) )
190 if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
191 return VLC_EGENERIC;
193 skip_space( &psz_command );
194 if( isdigit( (unsigned char)*psz_command ) )
196 if( parse_digit( &psz_command, &p_params->i_alpha ) == VLC_EGENERIC )
197 return VLC_EGENERIC;
199 return VLC_SUCCESS;
202 static int parser_SetPosition( char *psz_command, char *psz_end,
203 commandparams_t *p_params )
205 VLC_UNUSED(psz_end);
206 skip_space( &psz_command );
207 if( isdigit( (unsigned char)*psz_command ) )
209 if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
210 return VLC_EGENERIC;
212 skip_space( &psz_command );
213 if( isdigit( (unsigned char)*psz_command ) )
215 if( parse_digit( &psz_command, &p_params->i_x ) == VLC_EGENERIC )
216 return VLC_EGENERIC;
218 skip_space( &psz_command );
219 if( isdigit( (unsigned char)*psz_command ) )
221 if( parse_digit( &psz_command, &p_params->i_y ) == VLC_EGENERIC )
222 return VLC_EGENERIC;
224 return VLC_SUCCESS;
227 static int parser_SetTextAlpha( char *psz_command, char *psz_end,
228 commandparams_t *p_params )
230 VLC_UNUSED(psz_end);
231 skip_space( &psz_command );
232 if( isdigit( (unsigned char)*psz_command ) )
234 if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
235 return VLC_EGENERIC;
237 skip_space( &psz_command );
238 if( isdigit( (unsigned char)*psz_command ) )
240 int32_t value;
242 if( parse_digit( &psz_command, &value ) == VLC_EGENERIC )
243 return VLC_EGENERIC;
245 p_params->fontstyle.i_font_alpha = value;
247 return VLC_SUCCESS;
250 static int parser_SetTextColor( char *psz_command, char *psz_end,
251 commandparams_t *p_params )
253 int r = 0, g = 0, b = 0;
254 VLC_UNUSED(psz_end);
256 skip_space( &psz_command );
257 if( isdigit( (unsigned char)*psz_command ) )
259 if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
260 return VLC_EGENERIC;
262 skip_space( &psz_command );
263 if( isdigit( (unsigned char)*psz_command ) )
265 if( parse_digit( &psz_command, &r ) == VLC_EGENERIC )
266 return VLC_EGENERIC;
268 skip_space( &psz_command );
269 if( isdigit( (unsigned char)*psz_command ) )
271 if( parse_digit( &psz_command, &g ) == VLC_EGENERIC )
272 return VLC_EGENERIC;
274 skip_space( &psz_command );
275 if( isdigit( (unsigned char)*psz_command ) )
277 if( parse_digit( &psz_command, &b ) == VLC_EGENERIC )
278 return VLC_EGENERIC;
280 p_params->fontstyle.i_font_color = (r<<16) | (g<<8) | (b<<0);
281 return VLC_SUCCESS;
284 static int parser_SetTextSize( char *psz_command, char *psz_end,
285 commandparams_t *p_params )
287 VLC_UNUSED(psz_end);
288 skip_space( &psz_command );
289 if( isdigit( (unsigned char)*psz_command ) )
291 if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
292 return VLC_EGENERIC;
294 skip_space( &psz_command );
295 if( isdigit( (unsigned char)*psz_command ) )
297 if( parse_digit( &psz_command, &p_params->fontstyle.i_font_size ) == VLC_EGENERIC )
298 return VLC_EGENERIC;
300 return VLC_SUCCESS;
303 static int parser_SetVisibility( char *psz_command, char *psz_end,
304 commandparams_t *p_params )
306 VLC_UNUSED(psz_end);
307 skip_space( &psz_command );
308 if( isdigit( (unsigned char)*psz_command ) )
310 if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
311 return VLC_EGENERIC;
313 skip_space( &psz_command );
314 if( isdigit( (unsigned char)*psz_command ) )
316 int32_t i_vis = 0;
317 if( parse_digit( &psz_command, &i_vis ) == VLC_EGENERIC )
318 return VLC_EGENERIC;
319 p_params->b_visible = (i_vis == 1) ? true : false;
321 return VLC_SUCCESS;
324 /*****************************************************************************
325 * Command unparser functions
326 *****************************************************************************/
328 static int unparse_default( const commandparams_t *p_results,
329 buffer_t *p_output )
331 VLC_UNUSED(p_results);
332 VLC_UNUSED(p_output);
333 return VLC_SUCCESS;
336 static int unparse_GenImage( const commandparams_t *p_results,
337 buffer_t *p_output )
339 int ret = BufferPrintf( p_output, " %d", p_results->i_id );
340 if( ret != VLC_SUCCESS )
341 return ret;
343 return VLC_SUCCESS;
346 static int unparse_GetAlpha( const commandparams_t *p_results,
347 buffer_t *p_output )
349 int ret = BufferPrintf( p_output, " %d", p_results->i_alpha );
350 if( ret != VLC_SUCCESS )
351 return ret;
353 return VLC_SUCCESS;
356 static int unparse_GetPosition( const commandparams_t *p_results,
357 buffer_t *p_output )
359 int ret = BufferPrintf( p_output, " %d", p_results->i_x );
360 if( ret != VLC_SUCCESS )
361 return ret;
363 ret = BufferPrintf( p_output, " %d", p_results->i_y );
364 if( ret != VLC_SUCCESS )
365 return ret;
367 return VLC_SUCCESS;
370 static int unparse_GetTextAlpha( const commandparams_t *p_results,
371 buffer_t *p_output )
373 int ret = BufferPrintf( p_output, " %d", p_results->fontstyle.i_font_alpha );
374 if( ret != VLC_SUCCESS )
375 return ret;
377 return VLC_SUCCESS;
380 static int unparse_GetTextColor( const commandparams_t *p_results,
381 buffer_t *p_output )
383 int ret = BufferPrintf( p_output, " %d", (p_results->fontstyle.i_font_color & 0xff0000)>>16 );
384 if( ret != VLC_SUCCESS )
385 return ret;
387 ret = BufferPrintf( p_output, " %d", (p_results->fontstyle.i_font_color & 0x00ff00)>>8 );
388 if( ret != VLC_SUCCESS )
389 return ret;
391 ret = BufferPrintf( p_output, " %d", (p_results->fontstyle.i_font_color & 0x0000ff) );
392 if( ret != VLC_SUCCESS )
393 return ret;
395 return VLC_SUCCESS;
398 static int unparse_GetTextSize( const commandparams_t *p_results,
399 buffer_t *p_output )
401 int ret = BufferPrintf( p_output, " %d", p_results->fontstyle.i_font_size );
402 if( ret != VLC_SUCCESS )
403 return ret;
405 return VLC_SUCCESS;
408 static int unparse_GetVisibility( const commandparams_t *p_results,
409 buffer_t *p_output )
411 int ret = BufferPrintf( p_output, " %d", (p_results->b_visible ? 1 : 0) );
412 if( ret != VLC_SUCCESS ) {
413 return ret;
415 return VLC_SUCCESS;
418 /*****************************************************************************
419 * Command functions
420 *****************************************************************************/
421 static int exec_DataSharedMem( filter_t *p_filter,
422 const commandparams_t *p_params,
423 commandparams_t *p_results )
425 #if defined(HAVE_SYS_SHM_H)
426 filter_sys_t *p_sys = p_filter->p_sys;
427 struct shmid_ds shminfo;
428 overlay_t *p_ovl;
429 size_t i_size;
431 VLC_UNUSED(p_results);
433 p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
434 if( p_ovl == NULL )
436 msg_Err( p_filter, "Invalid overlay: %d", p_params->i_id );
437 return VLC_EGENERIC;
440 if( shmctl( p_params->i_shmid, IPC_STAT, &shminfo ) == -1 )
442 msg_Err( p_filter, "Unable to access shared memory" );
443 return VLC_EGENERIC;
445 i_size = shminfo.shm_segsz;
447 if( p_params->fourcc == VLC_CODEC_TEXT )
449 char *p_data;
451 if( (p_params->i_height != 1) || (p_params->i_width < 1) )
453 msg_Err( p_filter,
454 "Invalid width and/or height. when specifying text height "
455 "must be 1 and width the number of bytes in the string, "
456 "including the null terminator" );
457 return VLC_EGENERIC;
460 if( (size_t)p_params->i_width > i_size )
462 msg_Err( p_filter,
463 "Insufficient data in shared memory. need %d, got %zu",
464 p_params->i_width, i_size );
465 return VLC_EGENERIC;
468 p_ovl->data.p_text = malloc( p_params->i_width );
469 if( p_ovl->data.p_text == NULL )
471 msg_Err( p_filter, "Unable to allocate string storage" );
472 return VLC_ENOMEM;
475 video_format_Setup( &p_ovl->format, VLC_CODEC_TEXT,
476 0, 0, 0, 0, 0, 1 );
478 p_data = shmat( p_params->i_shmid, NULL, SHM_RDONLY );
479 if( p_data == NULL )
481 msg_Err( p_filter, "Unable to attach to shared memory" );
482 free( p_ovl->data.p_text );
483 p_ovl->data.p_text = NULL;
484 return VLC_ENOMEM;
486 memcpy( p_ovl->data.p_text, p_data, p_params->i_width );
488 shmdt( p_data );
490 else
492 uint8_t *p_data, *p_in;
493 size_t i_neededsize = 0;
495 p_ovl->data.p_pic = picture_New( p_params->fourcc,
496 p_params->i_width, p_params->i_height,
497 1, 1 );
498 if( p_ovl->data.p_pic == NULL )
499 return VLC_ENOMEM;
501 p_ovl->format = p_ovl->data.p_pic->format;
503 for( size_t i_plane = 0; i_plane < (size_t)p_ovl->data.p_pic->i_planes;
504 ++i_plane )
506 i_neededsize += p_ovl->data.p_pic->p[i_plane].i_visible_lines *
507 p_ovl->data.p_pic->p[i_plane].i_visible_pitch;
510 if( i_neededsize > i_size )
512 msg_Err( p_filter,
513 "Insufficient data in shared memory. need %zu, got %zu",
514 i_neededsize, i_size );
515 picture_Release( p_ovl->data.p_pic );
516 p_ovl->data.p_pic = NULL;
517 return VLC_EGENERIC;
520 p_data = shmat( p_params->i_shmid, NULL, SHM_RDONLY );
521 if( p_data == NULL )
523 msg_Err( p_filter, "Unable to attach to shared memory" );
524 picture_Release( p_ovl->data.p_pic );
525 p_ovl->data.p_pic = NULL;
526 return VLC_ENOMEM;
529 p_in = p_data;
530 for( size_t i_plane = 0; i_plane < (size_t)p_ovl->data.p_pic->i_planes;
531 ++i_plane )
533 uint8_t *p_out = p_ovl->data.p_pic->p[i_plane].p_pixels;
534 for( size_t i_line = 0;
535 i_line < (size_t)p_ovl->data.p_pic->p[i_plane].i_visible_lines;
536 ++i_line )
538 memcpy( p_out, p_in,
539 p_ovl->data.p_pic->p[i_plane].i_visible_pitch );
540 p_out += p_ovl->data.p_pic->p[i_plane].i_pitch;
541 p_in += p_ovl->data.p_pic->p[i_plane].i_visible_pitch;
544 shmdt( p_data );
546 p_sys->b_updated = p_ovl->b_active;
548 return VLC_SUCCESS;
549 #else
550 VLC_UNUSED(p_params);
551 VLC_UNUSED(p_results);
553 msg_Err( p_filter, "system doesn't support shared memory" );
554 return VLC_EGENERIC;
555 #endif
558 static int exec_DeleteImage( filter_t *p_filter,
559 const commandparams_t *p_params,
560 commandparams_t *p_results )
562 VLC_UNUSED(p_results);
563 filter_sys_t *p_sys = p_filter->p_sys;
564 p_sys->b_updated = true;
566 return ListRemove( &p_sys->overlays, p_params->i_id );
569 static int exec_EndAtomic( filter_t *p_filter,
570 const commandparams_t *p_params,
571 commandparams_t *p_results )
573 VLC_UNUSED(p_params);
574 VLC_UNUSED(p_results);
575 filter_sys_t *p_sys = p_filter->p_sys;
576 QueueTransfer( &p_sys->pending, &p_sys->atomic );
577 p_sys->b_atomic = false;
578 return VLC_SUCCESS;
581 static int exec_GenImage( filter_t *p_filter,
582 const commandparams_t *p_params,
583 commandparams_t *p_results )
585 VLC_UNUSED(p_params);
586 filter_sys_t *p_sys = p_filter->p_sys;
588 overlay_t *p_ovl = OverlayCreate();
589 if( p_ovl == NULL )
590 return VLC_ENOMEM;
592 ssize_t i_idx = ListAdd( &p_sys->overlays, p_ovl );
593 if( i_idx < 0 )
594 return i_idx;
596 p_results->i_id = i_idx;
597 return VLC_SUCCESS;
600 static int exec_GetAlpha( filter_t *p_filter,
601 const commandparams_t *p_params,
602 commandparams_t *p_results )
604 filter_sys_t *p_sys = p_filter->p_sys;
605 overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
606 if( p_ovl == NULL )
607 return VLC_EGENERIC;
609 p_results->i_alpha = p_ovl->i_alpha;
610 return VLC_SUCCESS;
613 static int exec_GetPosition( filter_t *p_filter,
614 const commandparams_t *p_params,
615 commandparams_t *p_results )
617 filter_sys_t *p_sys = p_filter->p_sys;
618 overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
619 if( p_ovl == NULL )
620 return VLC_EGENERIC;
622 p_results->i_x = p_ovl->i_x;
623 p_results->i_y = p_ovl->i_y;
624 return VLC_SUCCESS;
627 static int exec_GetTextAlpha( filter_t *p_filter,
628 const commandparams_t *p_params,
629 commandparams_t *p_results )
631 filter_sys_t *p_sys = p_filter->p_sys;
632 overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
633 if( p_ovl == NULL )
634 return VLC_EGENERIC;
636 p_results->fontstyle.i_font_alpha = p_ovl->p_fontstyle->i_font_alpha;
637 p_results->fontstyle.i_features |= STYLE_HAS_FONT_ALPHA;
638 return VLC_SUCCESS;
641 static int exec_GetTextColor( filter_t *p_filter,
642 const commandparams_t *p_params,
643 commandparams_t *p_results )
645 filter_sys_t *p_sys = p_filter->p_sys;
646 overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
647 if( p_ovl == NULL )
648 return VLC_EGENERIC;
650 p_results->fontstyle.i_font_color = p_ovl->p_fontstyle->i_font_color;
651 p_results->fontstyle.i_features |= STYLE_HAS_FONT_COLOR;
652 return VLC_SUCCESS;
655 static int exec_GetTextSize( filter_t *p_filter,
656 const commandparams_t *p_params,
657 commandparams_t *p_results )
659 filter_sys_t *p_sys = p_filter->p_sys;
660 overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
661 if( p_ovl == NULL )
662 return VLC_EGENERIC;
664 p_results->fontstyle.i_font_size = p_ovl->p_fontstyle->i_font_size;
665 return VLC_SUCCESS;
668 static int exec_GetVisibility( filter_t *p_filter,
669 const commandparams_t *p_params,
670 commandparams_t *p_results )
672 filter_sys_t *p_sys = p_filter->p_sys;
674 overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
675 if( p_ovl == NULL )
676 return VLC_EGENERIC;
678 p_results->b_visible = p_ovl->b_active ? 1 : 0;
679 return VLC_SUCCESS;
682 static int exec_SetAlpha( filter_t *p_filter,
683 const commandparams_t *p_params,
684 commandparams_t *p_results )
686 VLC_UNUSED(p_results);
687 filter_sys_t *p_sys = p_filter->p_sys;
689 overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
690 if( p_ovl == NULL )
691 return VLC_EGENERIC;
693 p_ovl->i_alpha = p_params->i_alpha;
694 p_sys->b_updated = p_ovl->b_active;
695 return VLC_SUCCESS;
698 static int exec_SetPosition( filter_t *p_filter,
699 const commandparams_t *p_params,
700 commandparams_t *p_results )
702 VLC_UNUSED(p_results);
703 filter_sys_t *p_sys = p_filter->p_sys;
705 overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
706 if( p_ovl == NULL )
707 return VLC_EGENERIC;
709 p_ovl->i_x = p_params->i_x;
710 p_ovl->i_y = p_params->i_y;
712 p_sys->b_updated = p_ovl->b_active;
713 return VLC_SUCCESS;
716 static int exec_SetTextAlpha( filter_t *p_filter,
717 const commandparams_t *p_params,
718 commandparams_t *p_results )
720 VLC_UNUSED(p_results);
721 filter_sys_t *p_sys = p_filter->p_sys;
723 overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
724 if( p_ovl == NULL )
725 return VLC_EGENERIC;
727 p_ovl->p_fontstyle->i_font_alpha = p_params->fontstyle.i_font_alpha;
728 p_ovl->p_fontstyle->i_features |= STYLE_HAS_FONT_ALPHA;
729 p_sys->b_updated = p_ovl->b_active;
730 return VLC_SUCCESS;
733 static int exec_SetTextColor( filter_t *p_filter,
734 const commandparams_t *p_params,
735 commandparams_t *p_results )
737 VLC_UNUSED(p_results);
738 filter_sys_t *p_sys = p_filter->p_sys;
740 overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
741 if( p_ovl == NULL )
742 return VLC_EGENERIC;
744 p_ovl->p_fontstyle->i_font_color = p_params->fontstyle.i_font_color;
745 p_ovl->p_fontstyle->i_features |= STYLE_HAS_FONT_COLOR;
746 p_sys->b_updated = p_ovl->b_active;
747 return VLC_SUCCESS;
750 static int exec_SetTextSize( filter_t *p_filter,
751 const commandparams_t *p_params,
752 commandparams_t *p_results )
754 VLC_UNUSED(p_results);
755 filter_sys_t *p_sys = p_filter->p_sys;
757 overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
758 if( p_ovl == NULL )
759 return VLC_EGENERIC;
761 p_ovl->p_fontstyle->i_font_size = p_params->fontstyle.i_font_size;
762 p_sys->b_updated = p_ovl->b_active;
763 return VLC_SUCCESS;
766 static int exec_SetVisibility( filter_t *p_filter,
767 const commandparams_t *p_params,
768 commandparams_t *p_results )
770 VLC_UNUSED(p_results);
771 filter_sys_t *p_sys = p_filter->p_sys;
773 overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
774 if( p_ovl == NULL )
775 return VLC_EGENERIC;
777 p_ovl->b_active = p_params->b_visible;// ? false : true;
778 p_sys->b_updated = true;
779 return VLC_SUCCESS;
782 static int exec_StartAtomic( filter_t *p_filter,
783 const commandparams_t *p_params,
784 commandparams_t *p_results )
786 filter_sys_t *p_sys = p_filter->p_sys;
787 VLC_UNUSED(p_params);
788 VLC_UNUSED(p_results);
790 p_sys->b_atomic = true;
791 return VLC_SUCCESS;
794 /*****************************************************************************
795 * Command functions
796 *****************************************************************************/
797 static const commanddesc_static_t p_commands[] =
799 { .psz_command = "DataSharedMem",
800 .b_atomic = true,
801 .pf_parser = parser_DataSharedMem,
802 .pf_execute = exec_DataSharedMem,
803 .pf_unparse = unparse_default,
805 { .psz_command = "DeleteImage",
806 .b_atomic = true,
807 .pf_parser = parser_Id,
808 .pf_execute = exec_DeleteImage,
809 .pf_unparse = unparse_default,
811 { .psz_command = "EndAtomic",
812 .b_atomic = false,
813 .pf_parser = parser_None,
814 .pf_execute = exec_EndAtomic,
815 .pf_unparse = unparse_default,
817 { .psz_command = "GenImage",
818 .b_atomic = false,
819 .pf_parser = parser_None,
820 .pf_execute = exec_GenImage,
821 .pf_unparse = unparse_GenImage,
823 { .psz_command = "GetAlpha",
824 .b_atomic = false,
825 .pf_parser = parser_Id,
826 .pf_execute = exec_GetAlpha,
827 .pf_unparse = unparse_GetAlpha,
829 { .psz_command = "GetPosition",
830 .b_atomic = false,
831 .pf_parser = parser_Id,
832 .pf_execute = exec_GetPosition,
833 .pf_unparse = unparse_GetPosition,
835 { .psz_command = "GetTextAlpha",
836 .b_atomic = false,
837 .pf_parser = parser_Id,
838 .pf_execute = exec_GetTextAlpha,
839 .pf_unparse = unparse_GetTextAlpha,
841 { .psz_command = "GetTextColor",
842 .b_atomic = false,
843 .pf_parser = parser_Id,
844 .pf_execute = exec_GetTextColor,
845 .pf_unparse = unparse_GetTextColor,
847 { .psz_command = "GetTextSize",
848 .b_atomic = true,
849 .pf_parser = parser_Id,
850 .pf_execute = exec_GetTextSize,
851 .pf_unparse = unparse_GetTextSize,
853 { .psz_command = "GetVisibility",
854 .b_atomic = false,
855 .pf_parser = parser_Id,
856 .pf_execute = exec_GetVisibility,
857 .pf_unparse = unparse_GetVisibility,
859 { .psz_command = "SetAlpha",
860 .b_atomic = true,
861 .pf_parser = parser_SetAlpha,
862 .pf_execute = exec_SetAlpha,
863 .pf_unparse = unparse_default,
865 { .psz_command = "SetPosition",
866 .b_atomic = true,
867 .pf_parser = parser_SetPosition,
868 .pf_execute = exec_SetPosition,
869 .pf_unparse = unparse_default,
871 { .psz_command = "SetTextAlpha",
872 .b_atomic = true,
873 .pf_parser = parser_SetTextAlpha,
874 .pf_execute = exec_SetTextAlpha,
875 .pf_unparse = unparse_default,
877 { .psz_command = "SetTextColor",
878 .b_atomic = true,
879 .pf_parser = parser_SetTextColor,
880 .pf_execute = exec_SetTextColor,
881 .pf_unparse = unparse_default,
883 { .psz_command = "SetTextSize",
884 .b_atomic = true,
885 .pf_parser = parser_SetTextSize,
886 .pf_execute = exec_SetTextSize,
887 .pf_unparse = unparse_default,
889 { .psz_command = "SetVisibility",
890 .b_atomic = true,
891 .pf_parser = parser_SetVisibility,
892 .pf_execute = exec_SetVisibility,
893 .pf_unparse = unparse_default,
895 { .psz_command = "StartAtomic",
896 .b_atomic = true,
897 .pf_parser = parser_None,
898 .pf_execute = exec_StartAtomic,
899 .pf_unparse = unparse_default,
903 void RegisterCommand( filter_t *p_filter )
905 filter_sys_t *p_sys = p_filter->p_sys;
907 p_sys->i_commands = ARRAY_SIZE(p_commands);
908 p_sys->pp_commands = (commanddesc_t **) calloc( p_sys->i_commands, sizeof(commanddesc_t*) );
909 if( !p_sys->pp_commands ) return;
910 for( size_t i_index = 0; i_index < p_sys->i_commands; i_index ++ )
912 p_sys->pp_commands[i_index] = (commanddesc_t *) malloc( sizeof(commanddesc_t) );
913 if( !p_sys->pp_commands[i_index] ) return;
914 p_sys->pp_commands[i_index]->psz_command = strdup( p_commands[i_index].psz_command );
915 p_sys->pp_commands[i_index]->b_atomic = p_commands[i_index].b_atomic;
916 p_sys->pp_commands[i_index]->pf_parser = p_commands[i_index].pf_parser;
917 p_sys->pp_commands[i_index]->pf_execute = p_commands[i_index].pf_execute;
918 p_sys->pp_commands[i_index]->pf_unparse = p_commands[i_index].pf_unparse;
921 msg_Dbg( p_filter, "%zu commands are available", p_sys->i_commands );
922 for( size_t i_index = 0; i_index < p_sys->i_commands; i_index++ )
923 msg_Dbg( p_filter, " %s", p_sys->pp_commands[i_index]->psz_command );
926 void UnregisterCommand( filter_t *p_filter )
928 filter_sys_t *p_sys = p_filter->p_sys;
929 size_t i_index = 0;
931 for( i_index = 0; i_index < p_sys->i_commands; i_index++ )
933 free( p_sys->pp_commands[i_index]->psz_command );
934 free( p_sys->pp_commands[i_index] );
936 free( p_sys->pp_commands );
937 p_sys->pp_commands = NULL;
938 p_sys->i_commands = 0;