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 *****************************************************************************/
28 #include <vlc_common.h>
29 #include <vlc_arrays.h>
31 #include <vlc_filter.h>
37 #if defined(HAVE_SYS_SHM_H)
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
) );
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,
59 p_ovl
->p_fontstyle
= text_style_Create( STYLE_NO_DEFAULTS
);
60 p_ovl
->data
.p_text
= NULL
;
65 int OverlayDestroy( overlay_t
*p_ovl
)
67 free( p_ovl
->data
.p_text
);
68 text_style_Delete( p_ovl
->p_fontstyle
);
73 /*****************************************************************************
75 *****************************************************************************/
76 static int skip_space( char **psz_command
)
78 char *psz_temp
= *psz_command
;
80 while( isspace( (unsigned char)*psz_temp
) )
84 if( psz_temp
== *psz_command
)
88 *psz_command
= psz_temp
;
92 static int parse_digit( char **psz_command
, int32_t *value
)
95 long l
= strtol( *psz_command
, &psz_temp
, 10 );
97 if( psz_temp
== *psz_command
)
101 #if LONG_MAX > INT32_MAX
102 if( l
> INT32_MAX
|| l
< INT32_MIN
)
106 *psz_command
= psz_temp
;
110 static int parse_char( char **psz_command
, char **psz_end
,
111 int count
, char *psz_value
)
113 if( *psz_end
- *psz_command
< count
)
117 memcpy( psz_value
, *psz_command
, count
);
118 *psz_command
+= count
;
122 static int parser_DataSharedMem( char *psz_command
,
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
)
133 skip_space( &psz_command
);
134 if( isdigit( (unsigned char)*psz_command
) )
136 if( parse_digit( &psz_command
, &p_params
->i_width
) == 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
)
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
)
152 skip_space( &psz_command
);
153 if( isdigit( (unsigned char)*psz_command
) )
155 if( parse_digit( &psz_command
, &p_params
->i_shmid
) == VLC_EGENERIC
)
161 static int parser_Id( char *psz_command
, char *psz_end
,
162 commandparams_t
*p_params
)
165 skip_space( &psz_command
);
166 if( isdigit( (unsigned char)*psz_command
) )
168 if( parse_digit( &psz_command
, &p_params
->i_id
) == VLC_EGENERIC
)
174 static int parser_None( char *psz_command
, char *psz_end
,
175 commandparams_t
*p_params
)
177 VLC_UNUSED(psz_command
);
179 VLC_UNUSED(p_params
);
183 static int parser_SetAlpha( char *psz_command
, char *psz_end
,
184 commandparams_t
*p_params
)
187 skip_space( &psz_command
);
188 if( isdigit( (unsigned char)*psz_command
) )
190 if( parse_digit( &psz_command
, &p_params
->i_id
) == 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
)
202 static int parser_SetPosition( char *psz_command
, char *psz_end
,
203 commandparams_t
*p_params
)
206 skip_space( &psz_command
);
207 if( isdigit( (unsigned char)*psz_command
) )
209 if( parse_digit( &psz_command
, &p_params
->i_id
) == 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
)
218 skip_space( &psz_command
);
219 if( isdigit( (unsigned char)*psz_command
) )
221 if( parse_digit( &psz_command
, &p_params
->i_y
) == VLC_EGENERIC
)
227 static int parser_SetTextAlpha( char *psz_command
, char *psz_end
,
228 commandparams_t
*p_params
)
231 skip_space( &psz_command
);
232 if( isdigit( (unsigned char)*psz_command
) )
234 if( parse_digit( &psz_command
, &p_params
->i_id
) == VLC_EGENERIC
)
237 skip_space( &psz_command
);
238 if( isdigit( (unsigned char)*psz_command
) )
242 if( parse_digit( &psz_command
, &value
) == VLC_EGENERIC
)
245 p_params
->fontstyle
.i_font_alpha
= value
;
250 static int parser_SetTextColor( char *psz_command
, char *psz_end
,
251 commandparams_t
*p_params
)
253 int r
= 0, g
= 0, b
= 0;
256 skip_space( &psz_command
);
257 if( isdigit( (unsigned char)*psz_command
) )
259 if( parse_digit( &psz_command
, &p_params
->i_id
) == VLC_EGENERIC
)
262 skip_space( &psz_command
);
263 if( isdigit( (unsigned char)*psz_command
) )
265 if( parse_digit( &psz_command
, &r
) == VLC_EGENERIC
)
268 skip_space( &psz_command
);
269 if( isdigit( (unsigned char)*psz_command
) )
271 if( parse_digit( &psz_command
, &g
) == VLC_EGENERIC
)
274 skip_space( &psz_command
);
275 if( isdigit( (unsigned char)*psz_command
) )
277 if( parse_digit( &psz_command
, &b
) == VLC_EGENERIC
)
280 p_params
->fontstyle
.i_font_color
= (r
<<16) | (g
<<8) | (b
<<0);
284 static int parser_SetTextSize( char *psz_command
, char *psz_end
,
285 commandparams_t
*p_params
)
288 skip_space( &psz_command
);
289 if( isdigit( (unsigned char)*psz_command
) )
291 if( parse_digit( &psz_command
, &p_params
->i_id
) == 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
)
303 static int parser_SetVisibility( char *psz_command
, char *psz_end
,
304 commandparams_t
*p_params
)
307 skip_space( &psz_command
);
308 if( isdigit( (unsigned char)*psz_command
) )
310 if( parse_digit( &psz_command
, &p_params
->i_id
) == VLC_EGENERIC
)
313 skip_space( &psz_command
);
314 if( isdigit( (unsigned char)*psz_command
) )
317 if( parse_digit( &psz_command
, &i_vis
) == VLC_EGENERIC
)
319 p_params
->b_visible
= (i_vis
== 1) ? true : false;
324 /*****************************************************************************
325 * Command unparser functions
326 *****************************************************************************/
328 static int unparse_default( const commandparams_t
*p_results
,
331 VLC_UNUSED(p_results
);
332 VLC_UNUSED(p_output
);
336 static int unparse_GenImage( const commandparams_t
*p_results
,
339 int ret
= BufferPrintf( p_output
, " %d", p_results
->i_id
);
340 if( ret
!= VLC_SUCCESS
)
346 static int unparse_GetAlpha( const commandparams_t
*p_results
,
349 int ret
= BufferPrintf( p_output
, " %d", p_results
->i_alpha
);
350 if( ret
!= VLC_SUCCESS
)
356 static int unparse_GetPosition( const commandparams_t
*p_results
,
359 int ret
= BufferPrintf( p_output
, " %d", p_results
->i_x
);
360 if( ret
!= VLC_SUCCESS
)
363 ret
= BufferPrintf( p_output
, " %d", p_results
->i_y
);
364 if( ret
!= VLC_SUCCESS
)
370 static int unparse_GetTextAlpha( const commandparams_t
*p_results
,
373 int ret
= BufferPrintf( p_output
, " %d", p_results
->fontstyle
.i_font_alpha
);
374 if( ret
!= VLC_SUCCESS
)
380 static int unparse_GetTextColor( const commandparams_t
*p_results
,
383 int ret
= BufferPrintf( p_output
, " %d", (p_results
->fontstyle
.i_font_color
& 0xff0000)>>16 );
384 if( ret
!= VLC_SUCCESS
)
387 ret
= BufferPrintf( p_output
, " %d", (p_results
->fontstyle
.i_font_color
& 0x00ff00)>>8 );
388 if( ret
!= VLC_SUCCESS
)
391 ret
= BufferPrintf( p_output
, " %d", (p_results
->fontstyle
.i_font_color
& 0x0000ff) );
392 if( ret
!= VLC_SUCCESS
)
398 static int unparse_GetTextSize( const commandparams_t
*p_results
,
401 int ret
= BufferPrintf( p_output
, " %d", p_results
->fontstyle
.i_font_size
);
402 if( ret
!= VLC_SUCCESS
)
408 static int unparse_GetVisibility( const commandparams_t
*p_results
,
411 int ret
= BufferPrintf( p_output
, " %d", (p_results
->b_visible
? 1 : 0) );
412 if( ret
!= VLC_SUCCESS
) {
418 /*****************************************************************************
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
;
431 VLC_UNUSED(p_results
);
433 p_ovl
= ListGet( &p_sys
->overlays
, p_params
->i_id
);
436 msg_Err( p_filter
, "Invalid overlay: %d", p_params
->i_id
);
440 if( shmctl( p_params
->i_shmid
, IPC_STAT
, &shminfo
) == -1 )
442 msg_Err( p_filter
, "Unable to access shared memory" );
445 i_size
= shminfo
.shm_segsz
;
447 if( p_params
->fourcc
== VLC_CODEC_TEXT
)
451 if( (p_params
->i_height
!= 1) || (p_params
->i_width
< 1) )
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" );
460 if( (size_t)p_params
->i_width
> i_size
)
463 "Insufficient data in shared memory. need %d, got %zu",
464 p_params
->i_width
, i_size
);
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" );
475 video_format_Setup( &p_ovl
->format
, VLC_CODEC_TEXT
,
478 p_data
= shmat( p_params
->i_shmid
, NULL
, SHM_RDONLY
);
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
;
486 memcpy( p_ovl
->data
.p_text
, p_data
, p_params
->i_width
);
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
,
498 if( p_ovl
->data
.p_pic
== NULL
)
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
;
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
)
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
;
520 p_data
= shmat( p_params
->i_shmid
, NULL
, SHM_RDONLY
);
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
;
530 for( size_t i_plane
= 0; i_plane
< (size_t)p_ovl
->data
.p_pic
->i_planes
;
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
;
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
;
546 p_sys
->b_updated
= p_ovl
->b_active
;
550 VLC_UNUSED(p_params
);
551 VLC_UNUSED(p_results
);
553 msg_Err( p_filter
, "system doesn't support shared memory" );
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;
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();
592 ssize_t i_idx
= ListAdd( &p_sys
->overlays
, p_ovl
);
596 p_results
->i_id
= i_idx
;
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
);
609 p_results
->i_alpha
= p_ovl
->i_alpha
;
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
);
622 p_results
->i_x
= p_ovl
->i_x
;
623 p_results
->i_y
= p_ovl
->i_y
;
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
);
636 p_results
->fontstyle
.i_font_alpha
= p_ovl
->p_fontstyle
->i_font_alpha
;
637 p_results
->fontstyle
.i_features
|= STYLE_HAS_FONT_ALPHA
;
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
);
650 p_results
->fontstyle
.i_font_color
= p_ovl
->p_fontstyle
->i_font_color
;
651 p_results
->fontstyle
.i_features
|= STYLE_HAS_FONT_COLOR
;
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
);
664 p_results
->fontstyle
.i_font_size
= p_ovl
->p_fontstyle
->i_font_size
;
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
);
678 p_results
->b_visible
= p_ovl
->b_active
? 1 : 0;
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
);
693 p_ovl
->i_alpha
= p_params
->i_alpha
;
694 p_sys
->b_updated
= p_ovl
->b_active
;
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
);
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
;
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
);
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
;
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
);
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
;
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
);
761 p_ovl
->p_fontstyle
->i_font_size
= p_params
->fontstyle
.i_font_size
;
762 p_sys
->b_updated
= p_ovl
->b_active
;
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
);
777 p_ovl
->b_active
= p_params
->b_visible
;// ? false : true;
778 p_sys
->b_updated
= true;
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;
794 /*****************************************************************************
796 *****************************************************************************/
797 static const commanddesc_static_t p_commands
[] =
799 { .psz_command
= "DataSharedMem",
801 .pf_parser
= parser_DataSharedMem
,
802 .pf_execute
= exec_DataSharedMem
,
803 .pf_unparse
= unparse_default
,
805 { .psz_command
= "DeleteImage",
807 .pf_parser
= parser_Id
,
808 .pf_execute
= exec_DeleteImage
,
809 .pf_unparse
= unparse_default
,
811 { .psz_command
= "EndAtomic",
813 .pf_parser
= parser_None
,
814 .pf_execute
= exec_EndAtomic
,
815 .pf_unparse
= unparse_default
,
817 { .psz_command
= "GenImage",
819 .pf_parser
= parser_None
,
820 .pf_execute
= exec_GenImage
,
821 .pf_unparse
= unparse_GenImage
,
823 { .psz_command
= "GetAlpha",
825 .pf_parser
= parser_Id
,
826 .pf_execute
= exec_GetAlpha
,
827 .pf_unparse
= unparse_GetAlpha
,
829 { .psz_command
= "GetPosition",
831 .pf_parser
= parser_Id
,
832 .pf_execute
= exec_GetPosition
,
833 .pf_unparse
= unparse_GetPosition
,
835 { .psz_command
= "GetTextAlpha",
837 .pf_parser
= parser_Id
,
838 .pf_execute
= exec_GetTextAlpha
,
839 .pf_unparse
= unparse_GetTextAlpha
,
841 { .psz_command
= "GetTextColor",
843 .pf_parser
= parser_Id
,
844 .pf_execute
= exec_GetTextColor
,
845 .pf_unparse
= unparse_GetTextColor
,
847 { .psz_command
= "GetTextSize",
849 .pf_parser
= parser_Id
,
850 .pf_execute
= exec_GetTextSize
,
851 .pf_unparse
= unparse_GetTextSize
,
853 { .psz_command
= "GetVisibility",
855 .pf_parser
= parser_Id
,
856 .pf_execute
= exec_GetVisibility
,
857 .pf_unparse
= unparse_GetVisibility
,
859 { .psz_command
= "SetAlpha",
861 .pf_parser
= parser_SetAlpha
,
862 .pf_execute
= exec_SetAlpha
,
863 .pf_unparse
= unparse_default
,
865 { .psz_command
= "SetPosition",
867 .pf_parser
= parser_SetPosition
,
868 .pf_execute
= exec_SetPosition
,
869 .pf_unparse
= unparse_default
,
871 { .psz_command
= "SetTextAlpha",
873 .pf_parser
= parser_SetTextAlpha
,
874 .pf_execute
= exec_SetTextAlpha
,
875 .pf_unparse
= unparse_default
,
877 { .psz_command
= "SetTextColor",
879 .pf_parser
= parser_SetTextColor
,
880 .pf_execute
= exec_SetTextColor
,
881 .pf_unparse
= unparse_default
,
883 { .psz_command
= "SetTextSize",
885 .pf_parser
= parser_SetTextSize
,
886 .pf_execute
= exec_SetTextSize
,
887 .pf_unparse
= unparse_default
,
889 { .psz_command
= "SetVisibility",
891 .pf_parser
= parser_SetVisibility
,
892 .pf_execute
= exec_SetVisibility
,
893 .pf_unparse
= unparse_default
,
895 { .psz_command
= "StartAtomic",
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
;
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;