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