]> git.sesse.net Git - vlc/blob - modules/video_filter/dynamicoverlay/dynamicoverlay_commands.c
Use var_InheritString for --decklink-video-connection.
[vlc] / modules / video_filter / dynamicoverlay / dynamicoverlay_commands.c
1 /*****************************************************************************
2  * dynamicoverlay_commands.c : dynamic overlay plugin commands
3  *****************************************************************************
4  * Copyright (C) 2008 the VideoLAN team
5  * $Id$
6  *
7  * Author: Søren Bøg <avacore@videolan.org>
8  *         Jean-Paul Saman <jpsaman@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <vlc_common.h>
30 #include <vlc_arrays.h>
31 #include <vlc_vout.h>
32 #include <vlc_filter.h>
33 #include <vlc_osd.h>
34
35 #include <string.h>
36 #include <ctype.h>
37
38 #if defined(HAVE_SYS_SHM_H)
39 #include <sys/shm.h>
40 #endif
41
42 #include "dynamicoverlay.h"
43
44
45 /*****************************************************************************
46  * overlay_t: Overlay descriptor
47  *****************************************************************************/
48
49 overlay_t *OverlayCreate( void )
50 {
51     overlay_t *p_ovl = calloc( 1, sizeof( overlay_t ) );
52     if( p_ovl == NULL )
53        return NULL;
54
55     p_ovl->i_x = p_ovl->i_y = 0;
56     p_ovl->i_alpha = 0xFF;
57     p_ovl->b_active = false;
58     video_format_Setup( &p_ovl->format, VLC_FOURCC( '\0','\0','\0','\0') , 0, 0,
59                         1, 1 );
60     p_ovl->p_fontstyle = text_style_New();
61     p_ovl->data.p_text = NULL;
62
63     return p_ovl;
64 }
65
66 int OverlayDestroy( overlay_t *p_ovl )
67 {
68     free( p_ovl->data.p_text );
69     text_style_Delete( p_ovl->p_fontstyle );
70
71     return VLC_SUCCESS;
72 }
73
74 /*****************************************************************************
75  * Command parsers
76  *****************************************************************************/
77 static int skip_space( char **psz_command )
78 {
79     char *psz_temp = *psz_command;
80
81     while( isspace( *psz_temp ) )
82     {
83         ++psz_temp;
84     }
85     if( psz_temp == *psz_command )
86     {
87         return VLC_EGENERIC;
88     }
89     *psz_command = psz_temp;
90     return VLC_SUCCESS;
91 }
92
93 static int parse_digit( char **psz_command, int32_t *value )
94 {
95     char *psz_temp;
96     *value = strtol( *psz_command, &psz_temp, 10 );
97     if( psz_temp == *psz_command )
98     {
99         return VLC_EGENERIC;
100     }
101     *psz_command = psz_temp;
102     return VLC_SUCCESS;
103 }
104
105 static int parse_char( char **psz_command, char **psz_end,
106                        int count, char *psz_value )
107 {
108     if( *psz_end - *psz_command < count )
109     {
110         return VLC_EGENERIC;
111     }
112     memcpy( psz_value, *psz_command, count );
113     *psz_command += count;
114     return VLC_SUCCESS;
115 }
116
117 static int parser_DataSharedMem( char *psz_command,
118                                  char *psz_end,
119                                  commandparams_t *p_params )
120 {
121     /* Parse: 0 128 128 RGBA 9404459 */
122     skip_space( &psz_command );
123     if( isdigit( *psz_command ) )
124     {
125         if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
126             return VLC_EGENERIC;
127     }
128     skip_space( &psz_command );
129     if( isdigit( *psz_command ) )
130     {
131         if( parse_digit( &psz_command, &p_params->i_width ) == VLC_EGENERIC )
132             return VLC_EGENERIC;
133     }
134     skip_space( &psz_command );
135     if( isdigit( *psz_command ) )
136     {
137         if( parse_digit( &psz_command, &p_params->i_height ) == VLC_EGENERIC )
138             return VLC_EGENERIC;
139     }
140     skip_space( &psz_command );
141     if( isascii( *psz_command ) )
142     {
143         if( parse_char( &psz_command, &psz_end, 4, (char*)&p_params->fourcc )
144             == VLC_EGENERIC )
145             return VLC_EGENERIC;
146     }
147     skip_space( &psz_command );
148     if( isdigit( *psz_command ) )
149     {
150         if( parse_digit( &psz_command, &p_params->i_shmid ) == VLC_EGENERIC )
151             return VLC_EGENERIC;
152     }
153     return VLC_SUCCESS;
154 }
155
156 static int parser_Id( char *psz_command, char *psz_end,
157                       commandparams_t *p_params )
158 {
159     VLC_UNUSED(psz_end);
160     skip_space( &psz_command );
161     if( isdigit( *psz_command ) )
162     {
163         if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
164             return VLC_EGENERIC;
165     }
166     return VLC_SUCCESS;
167 }
168
169 static int parser_None( char *psz_command, char *psz_end,
170                         commandparams_t *p_params )
171 {
172     VLC_UNUSED(psz_command);
173     VLC_UNUSED(psz_end);
174     VLC_UNUSED(p_params);
175     return VLC_SUCCESS;
176 }
177
178 static int parser_SetAlpha( char *psz_command, char *psz_end,
179                             commandparams_t *p_params )
180 {
181     VLC_UNUSED(psz_end);
182     skip_space( &psz_command );
183     if( isdigit( *psz_command ) )
184     {
185         if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC  )
186             return VLC_EGENERIC;
187     }
188     skip_space( &psz_command );
189     if( isdigit( *psz_command ) )
190     {
191         if( parse_digit( &psz_command, &p_params->i_alpha ) == VLC_EGENERIC )
192             return VLC_EGENERIC;
193     }
194     return VLC_SUCCESS;
195 }
196
197 static int parser_SetPosition( char *psz_command, char *psz_end,
198                                commandparams_t *p_params )
199 {
200     VLC_UNUSED(psz_end);
201     skip_space( &psz_command );
202     if( isdigit( *psz_command ) )
203     {
204         if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
205             return VLC_EGENERIC;
206     }
207     skip_space( &psz_command );
208     if( isdigit( *psz_command ) )
209     {
210         if( parse_digit( &psz_command, &p_params->i_x ) == VLC_EGENERIC )
211             return VLC_EGENERIC;
212     }
213     skip_space( &psz_command );
214     if( isdigit( *psz_command ) )
215     {
216         if( parse_digit( &psz_command, &p_params->i_y ) == VLC_EGENERIC )
217             return VLC_EGENERIC;
218     }
219     return VLC_SUCCESS;
220 }
221
222 static int parser_SetTextAlpha( char *psz_command, char *psz_end,
223                                 commandparams_t *p_params )
224 {
225     VLC_UNUSED(psz_end);
226     skip_space( &psz_command );
227     if( isdigit( *psz_command ) )
228     {
229         if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
230             return VLC_EGENERIC;
231     }
232     skip_space( &psz_command );
233     if( isdigit( *psz_command ) )
234     {
235         if( parse_digit( &psz_command, &p_params->fontstyle.i_font_alpha ) == VLC_EGENERIC )
236             return VLC_EGENERIC;
237     }
238     return VLC_SUCCESS;
239 }
240
241 static int parser_SetTextColor( char *psz_command, char *psz_end,
242                                 commandparams_t *p_params )
243 {
244     int r = 0, g = 0, b = 0;
245     VLC_UNUSED(psz_end);
246
247     skip_space( &psz_command );
248     if( isdigit( *psz_command ) )
249     {
250         if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
251             return VLC_EGENERIC;
252     }
253     skip_space( &psz_command );
254     if( isdigit( *psz_command ) )
255     {
256         if( parse_digit( &psz_command, &r ) == VLC_EGENERIC )
257             return VLC_EGENERIC;
258     }
259     skip_space( &psz_command );
260     if( isdigit( *psz_command ) )
261     {
262         if( parse_digit( &psz_command, &g ) == VLC_EGENERIC )
263             return VLC_EGENERIC;
264     }
265     skip_space( &psz_command );
266     if( isdigit( *psz_command ) )
267     {
268         if( parse_digit( &psz_command, &b ) == VLC_EGENERIC )
269             return VLC_EGENERIC;
270     }
271     p_params->fontstyle.i_font_color = (r<<16) | (g<<8) | (b<<0);
272     return VLC_SUCCESS;
273 }
274
275 static int parser_SetTextSize( char *psz_command, char *psz_end,
276                                commandparams_t *p_params )
277 {
278     VLC_UNUSED(psz_end);
279     skip_space( &psz_command );
280     if( isdigit( *psz_command ) )
281     {
282         if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
283             return VLC_EGENERIC;
284     }
285     skip_space( &psz_command );
286     if( isdigit( *psz_command ) )
287     {
288         if( parse_digit( &psz_command, &p_params->fontstyle.i_font_size ) == VLC_EGENERIC )
289             return VLC_EGENERIC;
290     }
291     return VLC_SUCCESS;
292 }
293
294 static int parser_SetVisibility( char *psz_command, char *psz_end,
295                                  commandparams_t *p_params )
296 {
297     VLC_UNUSED(psz_end);
298     skip_space( &psz_command );
299     if( isdigit( *psz_command ) )
300     {
301         if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
302             return VLC_EGENERIC;
303     }
304     skip_space( &psz_command );
305     if( isdigit( *psz_command ) )
306     {
307         int32_t i_vis = 0;
308         if( parse_digit( &psz_command, &i_vis ) == VLC_EGENERIC )
309             return VLC_EGENERIC;
310         p_params->b_visible = (i_vis == 1) ? true : false;
311     }
312     return VLC_SUCCESS;
313 }
314
315 /*****************************************************************************
316  * Command unparser functions
317  *****************************************************************************/
318
319 static int unparse_default( const commandparams_t *p_results,
320                             buffer_t *p_output )
321 {
322     VLC_UNUSED(p_results);
323     VLC_UNUSED(p_output);
324     return VLC_SUCCESS;
325 }
326
327 static int unparse_GenImage( const commandparams_t *p_results,
328                              buffer_t *p_output )
329 {
330     int ret = BufferPrintf( p_output, " %d", p_results->i_id );
331     if( ret != VLC_SUCCESS )
332         return ret;
333
334     return VLC_SUCCESS;
335 }
336
337 static int unparse_GetAlpha( const commandparams_t *p_results,
338                              buffer_t *p_output )
339 {
340     int ret = BufferPrintf( p_output, " %d", p_results->i_alpha );
341     if( ret != VLC_SUCCESS )
342         return ret;
343
344     return VLC_SUCCESS;
345 }
346
347 static int unparse_GetPosition( const commandparams_t *p_results,
348                                 buffer_t *p_output )
349 {
350     int ret = BufferPrintf( p_output, " %d", p_results->i_x );
351     if( ret != VLC_SUCCESS )
352         return ret;
353
354     ret = BufferPrintf( p_output, " %d", p_results->i_y );
355     if( ret != VLC_SUCCESS )
356         return ret;
357
358     return VLC_SUCCESS;
359 }
360
361 static int unparse_GetTextAlpha( const commandparams_t *p_results,
362                                  buffer_t *p_output )
363 {
364     int ret = BufferPrintf( p_output, " %d", p_results->fontstyle.i_font_alpha );
365     if( ret != VLC_SUCCESS )
366         return ret;
367
368     return VLC_SUCCESS;
369 }
370
371 static int unparse_GetTextColor( const commandparams_t *p_results,
372                                  buffer_t *p_output )
373 {
374     int ret = BufferPrintf( p_output, " %d", (p_results->fontstyle.i_font_color & 0xff0000)>>16 );
375     if( ret != VLC_SUCCESS )
376         return ret;
377
378     ret = BufferPrintf( p_output, " %d", (p_results->fontstyle.i_font_color & 0x00ff00)>>8 );
379     if( ret != VLC_SUCCESS )
380         return ret;
381
382     ret = BufferPrintf( p_output, " %d", (p_results->fontstyle.i_font_color & 0x0000ff) );
383     if( ret != VLC_SUCCESS )
384         return ret;
385
386     return VLC_SUCCESS;
387 }
388
389 static int unparse_GetTextSize( const commandparams_t *p_results,
390                                 buffer_t *p_output )
391 {
392     int ret = BufferPrintf( p_output, " %d", p_results->fontstyle.i_font_size );
393     if( ret != VLC_SUCCESS )
394         return ret;
395
396     return VLC_SUCCESS;
397 }
398
399 static int unparse_GetVisibility( const commandparams_t *p_results,
400                              buffer_t *p_output )
401 {
402     int ret = BufferPrintf( p_output, " %d", (p_results->b_visible ? 1 : 0) );
403     if( ret != VLC_SUCCESS ) {
404         return ret;
405     }
406     return VLC_SUCCESS;
407 }
408
409 /*****************************************************************************
410  * Command functions
411  *****************************************************************************/
412 static int exec_DataSharedMem( filter_t *p_filter,
413                                const commandparams_t *p_params,
414                                commandparams_t *p_results )
415 {
416 #if defined(HAVE_SYS_SHM_H)
417     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
418     struct shmid_ds shminfo;
419     overlay_t *p_ovl;
420     size_t i_size;
421
422     VLC_UNUSED(p_results);
423
424     p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
425     if( p_ovl == NULL )
426     {
427         msg_Err( p_filter, "Invalid overlay: %d", p_params->i_id );
428         return VLC_EGENERIC;
429     }
430
431     if( shmctl( p_params->i_shmid, IPC_STAT, &shminfo ) == -1 )
432     {
433         msg_Err( p_filter, "Unable to access shared memory" );
434         return VLC_EGENERIC;
435     }
436     i_size = shminfo.shm_segsz;
437
438     if( p_params->fourcc == VLC_CODEC_TEXT )
439     {
440         char *p_data;
441
442         if( (p_params->i_height != 1) || (p_params->i_width < 1) )
443         {
444             msg_Err( p_filter,
445                      "Invalid width and/or height. when specifying text height "
446                      "must be 1 and width the number of bytes in the string, "
447                      "including the null terminator" );
448             return VLC_EGENERIC;
449         }
450
451         if( (size_t)p_params->i_width > i_size )
452         {
453             msg_Err( p_filter,
454                      "Insufficient data in shared memory. need %d, got %zu",
455                      p_params->i_width, i_size );
456             return VLC_EGENERIC;
457         }
458
459         p_ovl->data.p_text = malloc( p_params->i_width );
460         if( p_ovl->data.p_text == NULL )
461         {
462             msg_Err( p_filter, "Unable to allocate string storage" );
463             return VLC_ENOMEM;
464         }
465
466         video_format_Setup( &p_ovl->format, VLC_CODEC_TEXT,
467                             0, 0, 0, 1 );
468
469         p_data = shmat( p_params->i_shmid, NULL, SHM_RDONLY );
470         if( p_data == NULL )
471         {
472             msg_Err( p_filter, "Unable to attach to shared memory" );
473             free( p_ovl->data.p_text );
474             p_ovl->data.p_text = NULL;
475             return VLC_ENOMEM;
476         }
477         memcpy( p_ovl->data.p_text, p_data, p_params->i_width );
478
479         shmdt( p_data );
480     }
481     else
482     {
483         uint8_t *p_data, *p_in;
484         size_t i_neededsize = 0;
485
486         p_ovl->data.p_pic = picture_New( p_params->fourcc,
487                                          p_params->i_width, p_params->i_height,
488                                          1, 1 );
489         if( p_ovl->data.p_pic == NULL )
490             return VLC_ENOMEM;
491
492         p_ovl->format = p_ovl->data.p_pic->format;
493
494         for( size_t i_plane = 0; i_plane < (size_t)p_ovl->data.p_pic->i_planes;
495              ++i_plane )
496         {
497             i_neededsize += p_ovl->data.p_pic->p[i_plane].i_visible_lines *
498                             p_ovl->data.p_pic->p[i_plane].i_visible_pitch;
499         }
500
501         if( i_neededsize > i_size )
502         {
503             msg_Err( p_filter,
504                      "Insufficient data in shared memory. need %zu, got %zu",
505                      i_neededsize, i_size );
506             picture_Release( p_ovl->data.p_pic );
507             p_ovl->data.p_pic = NULL;
508             return VLC_EGENERIC;
509         }
510
511         p_data = shmat( p_params->i_shmid, NULL, SHM_RDONLY );
512         if( p_data == NULL )
513         {
514             msg_Err( p_filter, "Unable to attach to shared memory" );
515             picture_Release( p_ovl->data.p_pic );
516             p_ovl->data.p_pic = NULL;
517             return VLC_ENOMEM;
518         }
519
520         p_in = p_data;
521         for( size_t i_plane = 0; i_plane < (size_t)p_ovl->data.p_pic->i_planes;
522              ++i_plane )
523         {
524             uint8_t *p_out = p_ovl->data.p_pic->p[i_plane].p_pixels;
525             for( size_t i_line = 0;
526                  i_line < (size_t)p_ovl->data.p_pic->p[i_plane].i_visible_lines;
527                  ++i_line )
528             {
529                 vlc_memcpy( p_out, p_in,
530                             p_ovl->data.p_pic->p[i_plane].i_visible_pitch );
531                 p_out += p_ovl->data.p_pic->p[i_plane].i_pitch;
532                 p_in += p_ovl->data.p_pic->p[i_plane].i_visible_pitch;
533             }
534         }
535         shmdt( p_data );
536     }
537     p_sys->b_updated = p_ovl->b_active;
538
539     return VLC_SUCCESS;
540 #else
541     VLC_UNUSED(p_params);
542     VLC_UNUSED(p_results);
543
544     msg_Err( p_filter, "system doesn't support shared memory" );
545     return VLC_EGENERIC;
546 #endif
547 }
548
549 static int exec_DeleteImage( filter_t *p_filter,
550                              const commandparams_t *p_params,
551                              commandparams_t *p_results )
552 {
553     VLC_UNUSED(p_results);
554     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
555     p_sys->b_updated = true;
556
557     return ListRemove( &p_sys->overlays, p_params->i_id );
558 }
559
560 static int exec_EndAtomic( filter_t *p_filter,
561                            const commandparams_t *p_params,
562                            commandparams_t *p_results )
563 {
564     VLC_UNUSED(p_params);
565     VLC_UNUSED(p_results);
566     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
567     QueueTransfer( &p_sys->pending, &p_sys->atomic );
568     p_sys->b_atomic = false;
569     return VLC_SUCCESS;
570 }
571
572 static int exec_GenImage( filter_t *p_filter,
573                           const commandparams_t *p_params,
574                           commandparams_t *p_results )
575 {
576     VLC_UNUSED(p_params);
577     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
578
579     overlay_t *p_ovl = OverlayCreate();
580     if( p_ovl == NULL )
581         return VLC_ENOMEM;
582
583     ssize_t i_idx = ListAdd( &p_sys->overlays, p_ovl );
584     if( i_idx < 0 )
585         return i_idx;
586
587     p_results->i_id = i_idx;
588     return VLC_SUCCESS;
589 }
590
591 static int exec_GetAlpha( filter_t *p_filter,
592                           const commandparams_t *p_params,
593                           commandparams_t *p_results )
594 {
595     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
596     overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
597     if( p_ovl == NULL )
598         return VLC_EGENERIC;
599
600     p_results->i_alpha = p_ovl->i_alpha;
601     return VLC_SUCCESS;
602 }
603
604 static int exec_GetPosition( filter_t *p_filter,
605                              const commandparams_t *p_params,
606                              commandparams_t *p_results )
607 {
608     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
609     overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
610     if( p_ovl == NULL )
611         return VLC_EGENERIC;
612
613     p_results->i_x = p_ovl->i_x;
614     p_results->i_y = p_ovl->i_y;
615     return VLC_SUCCESS;
616 }
617
618 static int exec_GetTextAlpha( filter_t *p_filter,
619                               const commandparams_t *p_params,
620                               commandparams_t *p_results )
621 {
622     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
623     overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
624     if( p_ovl == NULL )
625         return VLC_EGENERIC;
626
627     p_results->fontstyle.i_font_alpha = p_ovl->p_fontstyle->i_font_alpha;
628     return VLC_SUCCESS;
629 }
630
631 static int exec_GetTextColor( filter_t *p_filter,
632                               const commandparams_t *p_params,
633                               commandparams_t *p_results )
634 {
635     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
636     overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
637     if( p_ovl == NULL )
638         return VLC_EGENERIC;
639
640     p_results->fontstyle.i_font_color = p_ovl->p_fontstyle->i_font_color;
641     return VLC_SUCCESS;
642 }
643
644 static int exec_GetTextSize( filter_t *p_filter,
645                              const commandparams_t *p_params,
646                              commandparams_t *p_results )
647 {
648     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
649     overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
650     if( p_ovl == NULL )
651         return VLC_EGENERIC;
652
653     p_results->fontstyle.i_font_size = p_ovl->p_fontstyle->i_font_size;
654     return VLC_SUCCESS;
655 }
656
657 static int exec_GetVisibility( filter_t *p_filter,
658                                const commandparams_t *p_params,
659                                commandparams_t *p_results )
660 {
661     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
662
663     overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
664     if( p_ovl == NULL )
665         return VLC_EGENERIC;
666
667     p_results->b_visible = ( p_ovl->b_active == true ) ? 1 : 0;
668     return VLC_SUCCESS;
669 }
670
671 static int exec_SetAlpha( filter_t *p_filter,
672                           const commandparams_t *p_params,
673                           commandparams_t *p_results )
674 {
675     VLC_UNUSED(p_results);
676     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
677
678     overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
679     if( p_ovl == NULL )
680         return VLC_EGENERIC;
681
682     p_ovl->i_alpha = p_params->i_alpha;
683     p_sys->b_updated = p_ovl->b_active;
684     return VLC_SUCCESS;
685 }
686
687 static int exec_SetPosition( filter_t *p_filter,
688                              const commandparams_t *p_params,
689                              commandparams_t *p_results )
690 {
691     VLC_UNUSED(p_results);
692     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
693
694     overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
695     if( p_ovl == NULL )
696         return VLC_EGENERIC;
697
698     p_ovl->i_x = p_params->i_x;
699     p_ovl->i_y = p_params->i_y;
700
701     p_sys->b_updated = p_ovl->b_active;
702     return VLC_SUCCESS;
703 }
704
705 static int exec_SetTextAlpha( filter_t *p_filter,
706                               const commandparams_t *p_params,
707                               commandparams_t *p_results )
708 {
709     VLC_UNUSED(p_results);
710     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
711
712     overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
713     if( p_ovl == NULL )
714         return VLC_EGENERIC;
715
716     p_ovl->p_fontstyle->i_font_alpha = p_params->fontstyle.i_font_alpha;
717     p_sys->b_updated = p_ovl->b_active;
718     return VLC_SUCCESS;
719 }
720
721 static int exec_SetTextColor( filter_t *p_filter,
722                               const commandparams_t *p_params,
723                               commandparams_t *p_results )
724 {
725     VLC_UNUSED(p_results);
726     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
727
728     overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
729     if( p_ovl == NULL )
730         return VLC_EGENERIC;
731
732     p_ovl->p_fontstyle->i_font_color = p_params->fontstyle.i_font_color;
733     p_sys->b_updated = p_ovl->b_active;
734     return VLC_SUCCESS;
735 }
736
737 static int exec_SetTextSize( filter_t *p_filter,
738                               const commandparams_t *p_params,
739                               commandparams_t *p_results )
740 {
741     VLC_UNUSED(p_results);
742     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
743
744     overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
745     if( p_ovl == NULL )
746         return VLC_EGENERIC;
747
748     p_ovl->p_fontstyle->i_font_size = p_params->fontstyle.i_font_size;
749     p_sys->b_updated = p_ovl->b_active;
750     return VLC_SUCCESS;
751 }
752
753 static int exec_SetVisibility( filter_t *p_filter,
754                                const commandparams_t *p_params,
755                                commandparams_t *p_results )
756 {
757     VLC_UNUSED(p_results);
758     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
759
760     overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
761     if( p_ovl == NULL )
762         return VLC_EGENERIC;
763
764     p_ovl->b_active = p_params->b_visible;// ? false : true;
765     p_sys->b_updated = true;
766     return VLC_SUCCESS;
767 }
768
769 static int exec_StartAtomic( filter_t *p_filter,
770                              const commandparams_t *p_params,
771                              commandparams_t *p_results )
772 {
773     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
774     VLC_UNUSED(p_params);
775     VLC_UNUSED(p_results);
776
777     p_sys->b_atomic = true;
778     return VLC_SUCCESS;
779 }
780
781 /*****************************************************************************
782  * Command functions
783  *****************************************************************************/
784 static const commanddesc_static_t p_commands[] =
785 {
786     {   .psz_command = "DataSharedMem",
787         .b_atomic = true,
788         .pf_parser = parser_DataSharedMem,
789         .pf_execute = exec_DataSharedMem,
790         .pf_unparse = unparse_default,
791     },
792     {   .psz_command = "DeleteImage",
793         .b_atomic = true,
794         .pf_parser = parser_Id,
795         .pf_execute = exec_DeleteImage,
796         .pf_unparse = unparse_default,
797     },
798     {   .psz_command = "EndAtomic",
799         .b_atomic = false,
800         .pf_parser = parser_None,
801         .pf_execute = exec_EndAtomic,
802         .pf_unparse = unparse_default,
803     },
804     {   .psz_command = "GenImage",
805         .b_atomic = false,
806         .pf_parser = parser_None,
807         .pf_execute = exec_GenImage,
808         .pf_unparse = unparse_GenImage,
809     },
810     {   .psz_command = "GetAlpha",
811         .b_atomic = false,
812         .pf_parser = parser_Id,
813         .pf_execute = exec_GetAlpha,
814         .pf_unparse = unparse_GetAlpha,
815     },
816     {   .psz_command = "GetPosition",
817         .b_atomic = false,
818         .pf_parser = parser_Id,
819         .pf_execute = exec_GetPosition,
820         .pf_unparse = unparse_GetPosition,
821     },
822     {   .psz_command = "GetTextAlpha",
823         .b_atomic = false,
824         .pf_parser = parser_Id,
825         .pf_execute = exec_GetTextAlpha,
826         .pf_unparse = unparse_GetTextAlpha,
827     },
828     {   .psz_command = "GetTextColor",
829         .b_atomic = false,
830         .pf_parser = parser_Id,
831         .pf_execute = exec_GetTextColor,
832         .pf_unparse = unparse_GetTextColor,
833     },
834     {   .psz_command = "GetTextSize",
835         .b_atomic = true,
836         .pf_parser = parser_Id,
837         .pf_execute = exec_GetTextSize,
838         .pf_unparse = unparse_GetTextSize,
839     },
840     {   .psz_command = "GetVisibility",
841         .b_atomic = false,
842         .pf_parser = parser_Id,
843         .pf_execute = exec_GetVisibility,
844         .pf_unparse = unparse_GetVisibility,
845     },
846     {   .psz_command = "SetAlpha",
847         .b_atomic = true,
848         .pf_parser = parser_SetAlpha,
849         .pf_execute = exec_SetAlpha,
850         .pf_unparse = unparse_default,
851     },
852     {   .psz_command = "SetPosition",
853         .b_atomic = true,
854         .pf_parser = parser_SetPosition,
855         .pf_execute = exec_SetPosition,
856         .pf_unparse = unparse_default,
857     },
858     {   .psz_command = "SetTextAlpha",
859         .b_atomic = true,
860         .pf_parser = parser_SetTextAlpha,
861         .pf_execute = exec_SetTextAlpha,
862         .pf_unparse = unparse_default,
863     },
864     {   .psz_command = "SetTextColor",
865         .b_atomic = true,
866         .pf_parser = parser_SetTextColor,
867         .pf_execute = exec_SetTextColor,
868         .pf_unparse = unparse_default,
869     },
870     {   .psz_command = "SetTextSize",
871         .b_atomic = true,
872         .pf_parser = parser_SetTextSize,
873         .pf_execute = exec_SetTextSize,
874         .pf_unparse = unparse_default,
875     },
876     {   .psz_command = "SetVisibility",
877         .b_atomic = true,
878         .pf_parser = parser_SetVisibility,
879         .pf_execute = exec_SetVisibility,
880         .pf_unparse = unparse_default,
881     },
882     {   .psz_command = "StartAtomic",
883         .b_atomic = true,
884         .pf_parser = parser_None,
885         .pf_execute = exec_StartAtomic,
886         .pf_unparse = unparse_default,
887     }
888 };
889
890 void RegisterCommand( filter_t *p_filter )
891 {
892     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
893     size_t i_index = 0;
894
895     p_sys->i_commands = ARRAY_SIZE(p_commands);
896     p_sys->pp_commands = (commanddesc_t **) calloc( p_sys->i_commands, sizeof(commanddesc_t*) );
897     if( !p_sys->pp_commands ) return;
898     for( i_index = 0; i_index < p_sys->i_commands; i_index ++ )
899     {
900         p_sys->pp_commands[i_index] = (commanddesc_t *) malloc( sizeof(commanddesc_t) );
901         if( !p_sys->pp_commands[i_index] ) return;
902         p_sys->pp_commands[i_index]->psz_command = strdup( p_commands[i_index].psz_command );
903         p_sys->pp_commands[i_index]->b_atomic = p_commands[i_index].b_atomic;
904         p_sys->pp_commands[i_index]->pf_parser = p_commands[i_index].pf_parser;
905         p_sys->pp_commands[i_index]->pf_execute = p_commands[i_index].pf_execute;
906         p_sys->pp_commands[i_index]->pf_unparse = p_commands[i_index].pf_unparse;
907     }
908
909     msg_Dbg( p_filter, "%zu commands are available", p_sys->i_commands );
910     for( size_t i_index = 0; i_index < p_sys->i_commands; i_index++ )
911         msg_Dbg( p_filter, "    %s", p_sys->pp_commands[i_index]->psz_command );
912 }
913
914 void UnregisterCommand( filter_t *p_filter )
915 {
916     filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
917     size_t i_index = 0;
918
919     for( i_index = 0; i_index < p_sys->i_commands; i_index++ )
920     {
921         free( p_sys->pp_commands[i_index]->psz_command );
922         free( p_sys->pp_commands[i_index] );
923     }
924     free( p_sys->pp_commands );
925     p_sys->pp_commands = NULL;
926     p_sys->i_commands = 0;
927 }