]> git.sesse.net Git - vlc/blob - modules/demux/asademux.h
dvb_scan: fix memleak.
[vlc] / modules / demux / asademux.h
1 /*****************************************************************************
2  * asademux.c: asa demuxer VM
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  *
6  * Originated from asa: portable digital subtitle renderer
7  *
8  * Authors: David Lamparter <equinox at diac24 dot net>
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 St, Fifth Floor, Boston, MA  02110-1301  USA
23  ****************************************************************************/
24
25 /****************************************************************************
26  * Changes from asa version:
27  *  - headers adapted
28  *  - external definition file support dropped
29  *  - integer timestamps
30  ****************************************************************************
31  * Please retain Linux kernel CodingStyle for sync.
32  * base commit d8c269b0fae9a8f8904e16e92313da165d664c74
33  ****************************************************************************/
34
35 #ifndef _ASADEMUX_H
36 #define _ASADEMUX_H
37
38 #include <pcre.h>
39
40 /** parser reuse. imports-to-C uses char *, real VM uses pcre * */
41 typedef union {
42         pcre *pcre;
43         char *str;
44 } asa_pcre;
45
46 /** pcre_compile wrapper.
47  * used to allow loading differently for imports-to-C conversion.
48  * @param out output (parsed pcre)
49  * @param str regular expression string
50  * @return 0 on success, any other on error
51  */
52 extern int asa_pcre_compile(asa_pcre *out, const char *str);
53
54 /** import instruction code */
55 enum asa_import_insn_type {
56         ASAI_COMMIT = 0,        /**< put current buffer as line */
57         ASAI_DISCARD,           /**< discard current buffer */
58         ASAI_BREAK,             /**< leave child group */
59
60         ASAI_SELECT,            /**< select source matchgroup */
61         ASAI_SG,                /**< execute search & replace on selected */
62         ASAI_SGU,               /**< like ASAI_SG, but update matchgroups */
63         ASAI_APPEND,            /**< append selected source to buffer */
64
65         ASAI_FPS,               /**< set fixed fps */
66         ASAI_SHOW,              /**< set start time */
67         ASAI_HIDE,              /**< set end time */
68
69         ASAI_CHILD              /**< child regex match */
70 };
71
72 /** replacement element for ASAI_SG / ASAI_SGU */
73 struct asa_repl {
74         struct asa_repl *next;  /**< next element */
75
76         int group;              /**< -1 if fixed string, else source group */
77         char *text;             /**< fixed string for group == -1 */
78 };
79
80 /** time specification element */
81 struct asa_tspec {
82         struct asa_tspec *next; /**< next element */
83
84         int group;              /**< source matchgroup */
85         double  mult,           /**< ts multiplier. 1.0 = 1 second */
86                 fps_mult;       /**< fps multiplier. probably 0.0 or 1.0 */
87 };
88
89 /** single import instruction */
90 struct asa_import_insn {
91         struct asa_import_insn
92                 *parent,        /**< owner insn, NULL if format child */
93                 *next;          /**< next instruction */
94
95         enum asa_import_insn_type insn; /**< instruction code */
96         /** instruction parameters */
97         union {
98                 int break_depth;                /**< depth to break out */
99                 int select;                     /**< matchgroup to select */
100                 /** search-replace parameters */
101                 struct {
102                         asa_pcre regex;         /**< search for */
103                         struct asa_repl *repl;  /**< replace by */
104                 } sg;
105                 /** time specification */
106                 struct {
107                         struct asa_tspec *tsp;  /**< sources to sum up */
108                         int delta_select;       /**< -1 or delta index */
109                 } tspec;
110                 /** child instructions */
111                 struct {
112                         asa_pcre regex;         /** <if this matches... */
113                         struct asa_import_insn *insns;  /**< do this. */
114                 } child;
115                 double fps_value;               /**< fixed fps value */
116         } v;
117 };
118
119 /** destination format of import rules */
120 enum asa_import_target {
121         ASAI_TARGET_TEXT = (1 << 0),            /**< plain text packets */
122         ASAI_TARGET_SSA = (1 << 1)              /**< MKV ASS packets */
123 };
124
125 /** importing instructions for format */
126 struct asa_import_format {
127         struct asa_import_format *next,         /**< next format */
128                 *prevtgt,                       /**< previous target */
129                 *nexttgt;                       /**< next target of this*/
130
131         char *name;                             /**< format name */
132
133         enum asa_import_target target;          /**< target */
134         struct asa_import_insn *insns;          /**< instructions */
135 };
136
137 /** format detection rules */
138 struct asa_import_detect {
139         struct asa_import_detect *next;         /**< next rule */
140
141         asa_pcre re;                            /**< if this matches... */
142
143         char *name;                             /**< use this format */
144         struct asa_import_format *fmt;          /**< through this pointer */
145
146 };
147
148 extern struct asa_import_detect *asa_det_first, **asa_det_last;
149 extern struct asa_import_format *asa_fmt_first, **asa_fmt_last;
150
151 typedef int (asa_import_callback)(demux_t *demux, void *arg,
152         int64_t start, int64_t stop,
153         const char *buffer, size_t buffer_length);
154
155 extern struct asa_import_detect *asa_imports_detect(const void *data,
156         size_t dlen);
157 extern int asa_import(demux_t *d, const void *data, size_t dlen,
158         int64_t usecperframe, struct asa_import_detect *det,
159         asa_import_callback *callback, void *arg);
160 extern void asa_init_import(void);
161
162 #endif