]> git.sesse.net Git - vlc/blob - modules/video_filter/dynamicoverlay/dynamicoverlay.h
Merge branch 'master' into lpcm_encoder
[vlc] / modules / video_filter / dynamicoverlay / dynamicoverlay.h
1 /*****************************************************************************
2  * dynamicoverlay.h : dynamic overlay plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2008 the VideoLAN team
5  * $Id$
6  *
7  * Author: Jean-Paul Saman <jpsaman@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef DYNAMIC_OVERLAY_H
25 #define DYNAMIC_OVERLAY_H   1
26
27 #include <vlc_common.h>
28 #include <vlc_filter.h>
29 #include <vlc_text_style.h>
30
31 /*****************************************************************************
32  * buffer_t: Command and response buffer
33  *****************************************************************************/
34
35 typedef struct buffer_t
36 {
37     size_t i_size;                         /**< Size of the allocated memory */
38     size_t i_length;                          /**< Length of the stored data */
39
40     char *p_memory;                       /**< Start of the allocated memory */
41     char *p_begin;                             /**< Start of the stored data */
42 } buffer_t;
43
44 int BufferInit( buffer_t *p_buffer );
45 int BufferDestroy( buffer_t *p_buffer );
46 int BufferAdd( buffer_t *p_buffer, const char *p_data, size_t i_len );
47 int BufferPrintf( buffer_t *p_buffer, const char *p_fmt, ... );
48 int BufferDel( buffer_t *p_buffer, int i_len );
49 char *BufferGetToken( buffer_t *p_buffer );
50
51 /*****************************************************************************
52  * Command structures
53  *****************************************************************************/
54
55 /** struct commandparams_t - command params structure */
56 typedef struct commandparams_t
57 {
58     int32_t i_id;       /*< overlay id */
59     int32_t i_shmid;    /*< shared memory identifier */
60
61     vlc_fourcc_t fourcc;/*< chroma */
62
63     int32_t i_x;        /*< x position of overlay */
64     int32_t i_y;        /*< y position of overlay */
65     int32_t i_width;    /*< width of overlay */
66     int32_t i_height;   /*< height of overlay */
67
68     int32_t i_alpha;    /*< alpha value of overlay */
69
70     text_style_t fontstyle; /*< text style */
71
72     bool b_visible; /*< visibility flag of overlay */
73 } commandparams_t;
74
75 typedef int (*parser_func_t)(char *psz_command, char *psz_end, commandparams_t *p_params );
76 typedef int (*execute_func_t)( filter_t *p_filter, const commandparams_t *p_params, commandparams_t *p_results );
77 typedef int (*unparse_func_t)( const commandparams_t *p_results, buffer_t *p_output );
78
79 typedef struct commanddesc_t
80 {
81     char *psz_command;
82     bool b_atomic;
83     parser_func_t pf_parser;
84     execute_func_t pf_execute;
85     unparse_func_t pf_unparse;
86 } commanddesc_t;
87
88 typedef struct commanddesc_static_t
89 {
90     const char *psz_command;
91     bool b_atomic;
92     parser_func_t pf_parser;
93     execute_func_t pf_execute;
94     unparse_func_t pf_unparse;
95 } commanddesc_static_t;
96
97
98 typedef struct command_t
99 {
100     struct commanddesc_t *p_command;
101     int i_status;
102     commandparams_t params;
103     commandparams_t results;
104     struct command_t *p_next;
105 } command_t;
106
107 void RegisterCommand( filter_t *p_filter );
108 void UnregisterCommand( filter_t *p_filter );
109
110 /*****************************************************************************
111  * queue_t: Command queue
112  *****************************************************************************/
113
114 typedef struct queue_t
115 {
116     command_t *p_head;                  /**< Head (first entry) of the queue */
117     command_t *p_tail;                   /**< Tail (last entry) of the queue */
118 } queue_t;
119
120 int QueueInit( queue_t *p_queue );
121 int QueueDestroy( queue_t *p_queue );
122 int QueueEnqueue( queue_t *p_queue, command_t *p_cmd );
123 command_t *QueueDequeue( queue_t *p_queue );
124 int QueueTransfer( queue_t *p_sink, queue_t *p_source );
125
126 /*****************************************************************************
127  * overlay_t: Overlay descriptor
128  *****************************************************************************/
129
130 typedef struct overlay_t
131 {
132     int i_x, i_y;
133     int i_alpha;
134     bool b_active;
135
136     video_format_t format;
137     text_style_t *p_fontstyle;
138     union {
139         picture_t *p_pic;
140         char *p_text;
141     } data;
142 } overlay_t;
143
144 overlay_t *OverlayCreate( void );
145 int OverlayDestroy( overlay_t *p_ovl );
146
147 /*****************************************************************************
148  * list_t: Command queue
149  *****************************************************************************/
150
151 typedef struct list_t
152 {
153     overlay_t **pp_head, **pp_tail;
154 } list_t;
155
156 int ListInit( list_t *p_list );
157 int ListDestroy( list_t *p_list );
158 ssize_t ListAdd( list_t *p_list, overlay_t *p_new );
159 int ListRemove( list_t *p_list, size_t i_idx );
160 overlay_t *ListGet( list_t *p_list, size_t i_idx );
161 overlay_t *ListWalk( list_t *p_list );
162
163 /*****************************************************************************
164  * filter_sys_t: adjust filter method descriptor
165  *****************************************************************************/
166
167 struct filter_sys_t
168 {
169     buffer_t input, output;
170
171     int i_inputfd, i_outputfd;
172     char *psz_inputfile, *psz_outputfile;
173
174     commanddesc_t **pp_commands; /* array of commands */
175     size_t i_commands;
176
177     bool b_updated, b_atomic;
178     queue_t atomic, pending, processed;
179     list_t overlays;
180
181     vlc_mutex_t lock;   /* lock to protect psz_inputfile and psz_outputfile */
182 };
183
184 #endif