dynamicoverlay_commands.c 28.4 KB
Newer Older
1
2
3
4
5
6
/*****************************************************************************
 * dynamicoverlay_commands.c : dynamic overlay plugin commands
 *****************************************************************************
 * Copyright (C) 2008 the VideoLAN team
 * $Id$
 *
ivoire's avatar
ivoire committed
7
 * Author: Søren Bøg <avacore@videolan.org>
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 *         Jean-Paul Saman <jpsaman@videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

29
#include <vlc_common.h>
30
31
32
33
34
35
36
#include <vlc_arrays.h>
#include <vlc_vout.h>
#include <vlc_filter.h>
#include <vlc_osd.h>

#include <string.h>
#include <ctype.h>
37
38

#if defined(HAVE_SYS_SHM_H)
39
#include <sys/shm.h>
40
#endif
41
42
43
44
45
46
47
48
49
50

#include "dynamicoverlay.h"


/*****************************************************************************
 * overlay_t: Overlay descriptor
 *****************************************************************************/

overlay_t *OverlayCreate( void )
{
51
    overlay_t *p_ovl = calloc( 1, sizeof( overlay_t ) );
52
53
54
55
56
    if( p_ovl == NULL )
       return NULL;

    p_ovl->i_x = p_ovl->i_y = 0;
    p_ovl->i_alpha = 0xFF;
57
    p_ovl->b_active = false;
58
59
    video_format_Setup( &p_ovl->format, VLC_FOURCC( '\0','\0','\0','\0') , 0, 0,
                        VOUT_ASPECT_FACTOR );
basOS G's avatar
basOS G committed
60
    p_ovl->p_fontstyle = text_style_New();
61
62
63
64
65
66
67
    p_ovl->data.p_text = NULL;

    return p_ovl;
}

int OverlayDestroy( overlay_t *p_ovl )
{
68
    free( p_ovl->data.p_text );
basOS G's avatar
basOS G committed
69
    text_style_Delete( p_ovl->p_fontstyle );
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

    return VLC_SUCCESS;
}

/*****************************************************************************
 * Command parsers
 *****************************************************************************/
static int skip_space( char **psz_command )
{
    char *psz_temp = *psz_command;

    while( isspace( *psz_temp ) )
    {
        ++psz_temp;
    }
    if( psz_temp == *psz_command )
    {
        return VLC_EGENERIC;
    }
    *psz_command = psz_temp;
    return VLC_SUCCESS;
}

static int parse_digit( char **psz_command, int32_t *value )
{
    char *psz_temp;
    *value = strtol( *psz_command, &psz_temp, 10 );
    if( psz_temp == *psz_command )
    {
        return VLC_EGENERIC;
    }
    *psz_command = psz_temp;
    return VLC_SUCCESS;
}

static int parse_char( char **psz_command, char **psz_end,
                       int count, char *psz_value )
{
    if( *psz_end - *psz_command < count )
    {
        return VLC_EGENERIC;
    }
    memcpy( psz_value, *psz_command, count );
    *psz_command += count;
    return VLC_SUCCESS;
}

static int parser_DataSharedMem( char *psz_command,
                                 char *psz_end,
                                 commandparams_t *p_params )
{
    /* Parse: 0 128 128 RGBA 9404459 */
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->i_width ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->i_height ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    skip_space( &psz_command );
    if( isascii( *psz_command ) )
    {
        if( parse_char( &psz_command, &psz_end, 4, (char*)&p_params->fourcc )
            == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->i_shmid ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    return VLC_SUCCESS;
}

static int parser_Id( char *psz_command, char *psz_end,
                      commandparams_t *p_params )
{
159
    VLC_UNUSED(psz_end);
160
161
162
163
164
165
166
167
168
169
170
171
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    return VLC_SUCCESS;
}

static int parser_None( char *psz_command, char *psz_end,
                        commandparams_t *p_params )
{
172
173
174
    VLC_UNUSED(psz_command);
    VLC_UNUSED(psz_end);
    VLC_UNUSED(p_params);
175
176
177
178
179
180
    return VLC_SUCCESS;
}

static int parser_SetAlpha( char *psz_command, char *psz_end,
                            commandparams_t *p_params )
{
181
    VLC_UNUSED(psz_end);
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC  )
            return VLC_EGENERIC;
    }
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->i_alpha ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    return VLC_SUCCESS;
}

static int parser_SetPosition( char *psz_command, char *psz_end,
                               commandparams_t *p_params )
{
200
    VLC_UNUSED(psz_end);
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->i_x ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->i_y ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    return VLC_SUCCESS;
}

static int parser_SetTextAlpha( char *psz_command, char *psz_end,
                                commandparams_t *p_params )
{
225
    VLC_UNUSED(psz_end);
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->fontstyle.i_font_alpha ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    return VLC_SUCCESS;
}

static int parser_SetTextColor( char *psz_command, char *psz_end,
                                commandparams_t *p_params )
{
244
    int r = 0, g = 0, b = 0;
245
    VLC_UNUSED(psz_end);
246

247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &r ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &g ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &b ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
271
    p_params->fontstyle.i_font_color = (r<<16) | (g<<8) | (b<<0);
272
273
274
275
276
277
    return VLC_SUCCESS;
}

static int parser_SetTextSize( char *psz_command, char *psz_end,
                               commandparams_t *p_params )
{
278
    VLC_UNUSED(psz_end);
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->fontstyle.i_font_size ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    return VLC_SUCCESS;
}

static int parser_SetVisibility( char *psz_command, char *psz_end,
                                 commandparams_t *p_params )
{
297
    VLC_UNUSED(psz_end);
298
299
300
301
302
303
304
305
306
307
308
309
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )
            return VLC_EGENERIC;
    }
    skip_space( &psz_command );
    if( isdigit( *psz_command ) )
    {
        int32_t i_vis = 0;
        if( parse_digit( &psz_command, &i_vis ) == VLC_EGENERIC )
            return VLC_EGENERIC;
310
        p_params->b_visible = (i_vis == 1) ? true : false;
311
312
313
314
315
316
317
318
319
320
321
    }
    return VLC_SUCCESS;
}

/*****************************************************************************
 * Command unparser functions
 *****************************************************************************/

static int unparse_default( const commandparams_t *p_results,
                            buffer_t *p_output )
{
322
    VLC_UNUSED(p_results);
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
    VLC_UNUSED(p_output);
    return VLC_SUCCESS;
}

static int unparse_GenImage( const commandparams_t *p_results,
                             buffer_t *p_output )
{
    int ret = BufferPrintf( p_output, " %d", p_results->i_id );
    if( ret != VLC_SUCCESS )
        return ret;

    return VLC_SUCCESS;
}

static int unparse_GetAlpha( const commandparams_t *p_results,
                             buffer_t *p_output )
{
    int ret = BufferPrintf( p_output, " %d", p_results->i_alpha );
    if( ret != VLC_SUCCESS )
        return ret;

    return VLC_SUCCESS;
}

static int unparse_GetPosition( const commandparams_t *p_results,
                                buffer_t *p_output )
{
    int ret = BufferPrintf( p_output, " %d", p_results->i_x );
    if( ret != VLC_SUCCESS )
        return ret;

    ret = BufferPrintf( p_output, " %d", p_results->i_y );
    if( ret != VLC_SUCCESS )
        return ret;

    return VLC_SUCCESS;
}

static int unparse_GetTextAlpha( const commandparams_t *p_results,
                                 buffer_t *p_output )
{
    int ret = BufferPrintf( p_output, " %d", p_results->fontstyle.i_font_alpha );
    if( ret != VLC_SUCCESS )
        return ret;

    return VLC_SUCCESS;
}

static int unparse_GetTextColor( const commandparams_t *p_results,
                                 buffer_t *p_output )
{
374
    int ret = BufferPrintf( p_output, " %d", (p_results->fontstyle.i_font_color & 0xff0000)>>16 );
375
376
377
    if( ret != VLC_SUCCESS )
        return ret;

378
    ret = BufferPrintf( p_output, " %d", (p_results->fontstyle.i_font_color & 0x00ff00)>>8 );
379
380
381
    if( ret != VLC_SUCCESS )
        return ret;

382
    ret = BufferPrintf( p_output, " %d", (p_results->fontstyle.i_font_color & 0x0000ff) );
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
    if( ret != VLC_SUCCESS )
        return ret;

    return VLC_SUCCESS;
}

static int unparse_GetTextSize( const commandparams_t *p_results,
                                buffer_t *p_output )
{
    int ret = BufferPrintf( p_output, " %d", p_results->fontstyle.i_font_size );
    if( ret != VLC_SUCCESS )
        return ret;

    return VLC_SUCCESS;
}

static int unparse_GetVisibility( const commandparams_t *p_results,
                             buffer_t *p_output )
{
    int ret = BufferPrintf( p_output, " %d", (p_results->b_visible ? 1 : 0) );
    if( ret != VLC_SUCCESS ) {
        return ret;
    }
    return VLC_SUCCESS;
}

/*****************************************************************************
 * Command functions
 *****************************************************************************/
static int exec_DataSharedMem( filter_t *p_filter,
                               const commandparams_t *p_params,
                               commandparams_t *p_results )
{
416
#if defined(HAVE_SYS_SHM_H)
417
418
419
420
421
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
    struct shmid_ds shminfo;
    overlay_t *p_ovl;
    size_t i_size;

422
    VLC_UNUSED(p_results);
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437

    p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
    if( p_ovl == NULL )
    {
        msg_Err( p_filter, "Invalid overlay: %d", p_params->i_id );
        return VLC_EGENERIC;
    }

    if( shmctl( p_params->i_shmid, IPC_STAT, &shminfo ) == -1 )
    {
        msg_Err( p_filter, "Unable to access shared memory" );
        return VLC_EGENERIC;
    }
    i_size = shminfo.shm_segsz;

438
    if( p_params->fourcc == VLC_CODEC_TEXT )
439
440
441
442
443
444
    {
        char *p_data;

        if( (p_params->i_height != 1) || (p_params->i_width < 1) )
        {
            msg_Err( p_filter,
Christophe Mutricy's avatar
Typos    
Christophe Mutricy committed
445
                     "Invalid width and/or height. when specifying text height "
446
447
448
449
450
451
452
453
                     "must be 1 and width the number of bytes in the string, "
                     "including the null terminator" );
            return VLC_EGENERIC;
        }

        if( (size_t)p_params->i_width > i_size )
        {
            msg_Err( p_filter,
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
454
                     "Insufficient data in shared memory. need %d, got %zu",
455
456
457
458
459
460
461
462
463
464
465
                     p_params->i_width, i_size );
            return VLC_EGENERIC;
        }

        p_ovl->data.p_text = malloc( p_params->i_width );
        if( p_ovl->data.p_text == NULL )
        {
            msg_Err( p_filter, "Unable to allocate string storage" );
            return VLC_ENOMEM;
        }

466
467
        video_format_Setup( &p_ovl->format, VLC_CODEC_TEXT,
                            0, 0, 0 );
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489

        p_data = shmat( p_params->i_shmid, NULL, SHM_RDONLY );
        if( p_data == NULL )
        {
            msg_Err( p_filter, "Unable to attach to shared memory" );
            free( p_ovl->data.p_text );
            p_ovl->data.p_text = NULL;
            return VLC_ENOMEM;
        }
        memcpy( p_ovl->data.p_text, p_data, p_params->i_width );

        shmdt( p_data );
    }
    else
    {
        uint8_t *p_data, *p_in;
        size_t i_neededsize = 0;

        p_ovl->data.p_pic = malloc( sizeof( picture_t ) );
        if( p_ovl->data.p_pic == NULL )
            return VLC_ENOMEM;

490
491
492
        video_format_Setup( &p_ovl->format, p_params->fourcc,
                            p_params->i_width, p_params->i_height,
                            VOUT_ASPECT_FACTOR );
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
        if( vout_AllocatePicture( p_filter, p_ovl->data.p_pic,
                                  p_ovl->format.i_chroma, p_params->i_width,
                                  p_params->i_height, p_ovl->format.i_aspect ) )
        {
            msg_Err( p_filter, "Unable to allocate picture" );
            free( p_ovl->data.p_pic );
            p_ovl->data.p_pic = NULL;
            return VLC_ENOMEM;
        }

        for( size_t i_plane = 0; i_plane < (size_t)p_ovl->data.p_pic->i_planes;
             ++i_plane )
        {
            i_neededsize += p_ovl->data.p_pic->p[i_plane].i_visible_lines *
                            p_ovl->data.p_pic->p[i_plane].i_visible_pitch;
        }

        if( i_neededsize > i_size )
        {
            msg_Err( p_filter,
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
513
                     "Insufficient data in shared memory. need %zu, got %zu",
514
                     i_neededsize, i_size );
515
            picture_Release( p_ovl->data.p_pic );
516
517
518
519
520
521
522
523
524
            free( p_ovl->data.p_pic );
            p_ovl->data.p_pic = NULL;
            return VLC_EGENERIC;
        }

        p_data = shmat( p_params->i_shmid, NULL, SHM_RDONLY );
        if( p_data == NULL )
        {
            msg_Err( p_filter, "Unable to attach to shared memory" );
525
            picture_Release( p_ovl->data.p_pic );
526
527
528
529
530
531
532
533
534
535
536
537
538
539
            free( p_ovl->data.p_pic );
            p_ovl->data.p_pic = NULL;
            return VLC_ENOMEM;
        }

        p_in = p_data;
        for( size_t i_plane = 0; i_plane < (size_t)p_ovl->data.p_pic->i_planes;
             ++i_plane )
        {
            uint8_t *p_out = p_ovl->data.p_pic->p[i_plane].p_pixels;
            for( size_t i_line = 0;
                 i_line < (size_t)p_ovl->data.p_pic->p[i_plane].i_visible_lines;
                 ++i_line )
            {
540
541
                vlc_memcpy( p_out, p_in,
                            p_ovl->data.p_pic->p[i_plane].i_visible_pitch );
542
543
544
545
546
547
548
549
550
                p_out += p_ovl->data.p_pic->p[i_plane].i_pitch;
                p_in += p_ovl->data.p_pic->p[i_plane].i_visible_pitch;
            }
        }
        shmdt( p_data );
    }
    p_sys->b_updated = p_ovl->b_active;

    return VLC_SUCCESS;
551
552
553
554
555
556
557
#else
    VLC_UNUSED(p_params);
    VLC_UNUSED(p_results);

    msg_Err( p_filter, "system doesn't support shared memory" );
    return VLC_EGENERIC;
#endif
558
559
560
561
562
563
}

static int exec_DeleteImage( filter_t *p_filter,
                             const commandparams_t *p_params,
                             commandparams_t *p_results )
{
564
    VLC_UNUSED(p_results);
565
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
566
    p_sys->b_updated = true;
567
568
569
570
571
572
573
574

    return ListRemove( &p_sys->overlays, p_params->i_id );
}

static int exec_EndAtomic( filter_t *p_filter,
                           const commandparams_t *p_params,
                           commandparams_t *p_results )
{
575
576
    VLC_UNUSED(p_params);
    VLC_UNUSED(p_results);
577
578
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
    QueueTransfer( &p_sys->pending, &p_sys->atomic );
579
    p_sys->b_atomic = false;
580
581
582
583
584
585
586
    return VLC_SUCCESS;
}

static int exec_GenImage( filter_t *p_filter,
                          const commandparams_t *p_params,
                          commandparams_t *p_results )
{
587
    VLC_UNUSED(p_params);
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;

    overlay_t *p_ovl = OverlayCreate();
    if( p_ovl == NULL )
        return VLC_ENOMEM;

    ssize_t i_idx = ListAdd( &p_sys->overlays, p_ovl );
    if( i_idx < 0 )
        return i_idx;

    p_results->i_id = i_idx;
    return VLC_SUCCESS;
}

static int exec_GetAlpha( filter_t *p_filter,
                          const commandparams_t *p_params,
                          commandparams_t *p_results )
{
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
    overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
    if( p_ovl == NULL )
        return VLC_EGENERIC;

    p_results->i_alpha = p_ovl->i_alpha;
    return VLC_SUCCESS;
}

static int exec_GetPosition( filter_t *p_filter,
                             const commandparams_t *p_params,
                             commandparams_t *p_results )
{
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
    overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
    if( p_ovl == NULL )
        return VLC_EGENERIC;

    p_results->i_x = p_ovl->i_x;
    p_results->i_y = p_ovl->i_y;
    return VLC_SUCCESS;
}

static int exec_GetTextAlpha( filter_t *p_filter,
                              const commandparams_t *p_params,
                              commandparams_t *p_results )
{
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
    overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
    if( p_ovl == NULL )
        return VLC_EGENERIC;

basOS G's avatar
basOS G committed
638
    p_results->fontstyle.i_font_alpha = p_ovl->p_fontstyle->i_font_alpha;
639
640
641
642
643
644
645
646
647
648
649
650
    return VLC_SUCCESS;
}

static int exec_GetTextColor( filter_t *p_filter,
                              const commandparams_t *p_params,
                              commandparams_t *p_results )
{
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
    overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
    if( p_ovl == NULL )
        return VLC_EGENERIC;

basOS G's avatar
basOS G committed
651
    p_results->fontstyle.i_font_color = p_ovl->p_fontstyle->i_font_color;
652
653
654
655
656
657
658
659
660
661
662
663
    return VLC_SUCCESS;
}

static int exec_GetTextSize( filter_t *p_filter,
                             const commandparams_t *p_params,
                             commandparams_t *p_results )
{
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
    overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
    if( p_ovl == NULL )
        return VLC_EGENERIC;

basOS G's avatar
basOS G committed
664
    p_results->fontstyle.i_font_size = p_ovl->p_fontstyle->i_font_size;
665
666
667
668
669
670
671
672
673
674
675
676
677
    return VLC_SUCCESS;
}

static int exec_GetVisibility( filter_t *p_filter,
                               const commandparams_t *p_params,
                               commandparams_t *p_results )
{
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;

    overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
    if( p_ovl == NULL )
        return VLC_EGENERIC;

678
    p_results->b_visible = ( p_ovl->b_active == true ) ? 1 : 0;
679
680
681
682
683
684
685
    return VLC_SUCCESS;
}

static int exec_SetAlpha( filter_t *p_filter,
                          const commandparams_t *p_params,
                          commandparams_t *p_results )
{
686
    VLC_UNUSED(p_results);
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;

    overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
    if( p_ovl == NULL )
        return VLC_EGENERIC;

    p_ovl->i_alpha = p_params->i_alpha;
    p_sys->b_updated = p_ovl->b_active;
    return VLC_SUCCESS;
}

static int exec_SetPosition( filter_t *p_filter,
                             const commandparams_t *p_params,
                             commandparams_t *p_results )
{
702
    VLC_UNUSED(p_results);
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;

    overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
    if( p_ovl == NULL )
        return VLC_EGENERIC;

    p_ovl->i_x = p_params->i_x;
    p_ovl->i_y = p_params->i_y;

    p_sys->b_updated = p_ovl->b_active;
    return VLC_SUCCESS;
}

static int exec_SetTextAlpha( filter_t *p_filter,
                              const commandparams_t *p_params,
                              commandparams_t *p_results )
{
720
    VLC_UNUSED(p_results);
721
722
723
724
725
726
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;

    overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
    if( p_ovl == NULL )
        return VLC_EGENERIC;

basOS G's avatar
basOS G committed
727
    p_ovl->p_fontstyle->i_font_alpha = p_params->fontstyle.i_font_alpha;
728
729
730
731
732
733
734
735
    p_sys->b_updated = p_ovl->b_active;
    return VLC_SUCCESS;
}

static int exec_SetTextColor( filter_t *p_filter,
                              const commandparams_t *p_params,
                              commandparams_t *p_results )
{
736
    VLC_UNUSED(p_results);
737
738
739
740
741
742
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;

    overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
    if( p_ovl == NULL )
        return VLC_EGENERIC;

basOS G's avatar
basOS G committed
743
    p_ovl->p_fontstyle->i_font_color = p_params->fontstyle.i_font_color;
744
745
746
747
748
749
750
751
    p_sys->b_updated = p_ovl->b_active;
    return VLC_SUCCESS;
}

static int exec_SetTextSize( filter_t *p_filter,
                              const commandparams_t *p_params,
                              commandparams_t *p_results )
{
752
    VLC_UNUSED(p_results);
753
754
755
756
757
758
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;

    overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
    if( p_ovl == NULL )
        return VLC_EGENERIC;

basOS G's avatar
basOS G committed
759
    p_ovl->p_fontstyle->i_font_size = p_params->fontstyle.i_font_size;
760
761
762
763
764
765
766
767
    p_sys->b_updated = p_ovl->b_active;
    return VLC_SUCCESS;
}

static int exec_SetVisibility( filter_t *p_filter,
                               const commandparams_t *p_params,
                               commandparams_t *p_results )
{
768
    VLC_UNUSED(p_results);
769
770
771
772
773
774
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;

    overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
    if( p_ovl == NULL )
        return VLC_EGENERIC;

775
776
    p_ovl->b_active = p_params->b_visible;// ? false : true;
    p_sys->b_updated = true;
777
778
779
780
781
782
783
784
    return VLC_SUCCESS;
}

static int exec_StartAtomic( filter_t *p_filter,
                             const commandparams_t *p_params,
                             commandparams_t *p_results )
{
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
785
786
    VLC_UNUSED(p_params);
    VLC_UNUSED(p_results);
787

788
    p_sys->b_atomic = true;
789
790
791
792
793
794
    return VLC_SUCCESS;
}

/*****************************************************************************
 * Command functions
 *****************************************************************************/
795
static const commanddesc_static_t p_commands[] =
796
797
{
    {   .psz_command = "DataSharedMem",
798
        .b_atomic = true,
799
800
801
802
803
        .pf_parser = parser_DataSharedMem,
        .pf_execute = exec_DataSharedMem,
        .pf_unparse = unparse_default,
    },
    {   .psz_command = "DeleteImage",
804
        .b_atomic = true,
805
806
807
808
809
        .pf_parser = parser_Id,
        .pf_execute = exec_DeleteImage,
        .pf_unparse = unparse_default,
    },
    {   .psz_command = "EndAtomic",
810
        .b_atomic = false,
811
812
813
814
815
        .pf_parser = parser_None,
        .pf_execute = exec_EndAtomic,
        .pf_unparse = unparse_default,
    },
    {   .psz_command = "GenImage",
816
        .b_atomic = false,
817
818
819
820
821
        .pf_parser = parser_None,
        .pf_execute = exec_GenImage,
        .pf_unparse = unparse_GenImage,
    },
    {   .psz_command = "GetAlpha",
822
        .b_atomic = false,
823
824
825
826
827
        .pf_parser = parser_Id,
        .pf_execute = exec_GetAlpha,
        .pf_unparse = unparse_GetAlpha,
    },
    {   .psz_command = "GetPosition",
828
        .b_atomic = false,
829
830
831
832
833
        .pf_parser = parser_Id,
        .pf_execute = exec_GetPosition,
        .pf_unparse = unparse_GetPosition,
    },
    {   .psz_command = "GetTextAlpha",
834
        .b_atomic = false,
835
836
837
838
839
        .pf_parser = parser_Id,
        .pf_execute = exec_GetTextAlpha,
        .pf_unparse = unparse_GetTextAlpha,
    },
    {   .psz_command = "GetTextColor",
840
        .b_atomic = false,
841
842
843
844
845
        .pf_parser = parser_Id,
        .pf_execute = exec_GetTextColor,
        .pf_unparse = unparse_GetTextColor,
    },
    {   .psz_command = "GetTextSize",
846
        .b_atomic = true,
847
848
849
850
851
        .pf_parser = parser_Id,
        .pf_execute = exec_GetTextSize,
        .pf_unparse = unparse_GetTextSize,
    },
    {   .psz_command = "GetVisibility",
852
        .b_atomic = false,
853
854
855
856
857
        .pf_parser = parser_Id,
        .pf_execute = exec_GetVisibility,
        .pf_unparse = unparse_GetVisibility,
    },
    {   .psz_command = "SetAlpha",
858
        .b_atomic = true,
859
860
861
862
863
        .pf_parser = parser_SetAlpha,
        .pf_execute = exec_SetAlpha,
        .pf_unparse = unparse_default,
    },
    {   .psz_command = "SetPosition",
864
        .b_atomic = true,
865
866
867
868
869
        .pf_parser = parser_SetPosition,
        .pf_execute = exec_SetPosition,
        .pf_unparse = unparse_default,
    },
    {   .psz_command = "SetTextAlpha",
870
        .b_atomic = true,
871
872
873
874
875
        .pf_parser = parser_SetTextAlpha,
        .pf_execute = exec_SetTextAlpha,
        .pf_unparse = unparse_default,
    },
    {   .psz_command = "SetTextColor",
876
        .b_atomic = true,
877
878
879
880
881
        .pf_parser = parser_SetTextColor,
        .pf_execute = exec_SetTextColor,
        .pf_unparse = unparse_default,
    },
    {   .psz_command = "SetTextSize",
882
        .b_atomic = true,
883
884
885
886
887
        .pf_parser = parser_SetTextSize,
        .pf_execute = exec_SetTextSize,
        .pf_unparse = unparse_default,
    },
    {   .psz_command = "SetVisibility",
888
        .b_atomic = true,
889
890
891
892
893
        .pf_parser = parser_SetVisibility,
        .pf_execute = exec_SetVisibility,
        .pf_unparse = unparse_default,
    },
    {   .psz_command = "StartAtomic",
894
        .b_atomic = true,
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
        .pf_parser = parser_None,
        .pf_execute = exec_StartAtomic,
        .pf_unparse = unparse_default,
    }
};

void RegisterCommand( filter_t *p_filter )
{
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
    size_t i_index = 0;

    p_sys->i_commands = ARRAY_SIZE(p_commands);
    p_sys->pp_commands = (commanddesc_t **) calloc( p_sys->i_commands, sizeof(commanddesc_t*) );
    if( !p_sys->pp_commands ) return;
    for( i_index = 0; i_index < p_sys->i_commands; i_index ++ )
    {
        p_sys->pp_commands[i_index] = (commanddesc_t *) malloc( sizeof(commanddesc_t) );
        if( !p_sys->pp_commands[i_index] ) return;
        p_sys->pp_commands[i_index]->psz_command = strdup( p_commands[i_index].psz_command );
        p_sys->pp_commands[i_index]->b_atomic = p_commands[i_index].b_atomic;
        p_sys->pp_commands[i_index]->pf_parser = p_commands[i_index].pf_parser;
        p_sys->pp_commands[i_index]->pf_execute = p_commands[i_index].pf_execute;
        p_sys->pp_commands[i_index]->pf_unparse = p_commands[i_index].pf_unparse;
    }

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
920
    msg_Dbg( p_filter, "%zu commands are available", p_sys->i_commands );
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
    for( size_t i_index = 0; i_index < p_sys->i_commands; i_index++ )
        msg_Dbg( p_filter, "    %s", p_sys->pp_commands[i_index]->psz_command );
}

void UnregisterCommand( filter_t *p_filter )
{
    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;
    size_t i_index = 0;

    for( i_index = 0; i_index < p_sys->i_commands; i_index++ )
    {
        free( p_sys->pp_commands[i_index]->psz_command );
        free( p_sys->pp_commands[i_index] );
    }
    free( p_sys->pp_commands );
    p_sys->pp_commands = NULL;
    p_sys->i_commands = 0;
}