1 /*****************************************************************************
2 * asademux.c: asa demuxer VM
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
6 * Originated from asa: portable digital subtitle renderer
8 * Authors: David Lamparter <equinox at diac24 dot net>
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.
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.
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 ****************************************************************************/
25 /****************************************************************************
26 * Changes from asa version:
28 * - external definition file support dropped
29 * - integer timestamps
30 ****************************************************************************
31 * Please retain Linux kernel CodingStyle for sync.
32 * base commit d8c269b0fae9a8f8904e16e92313da165d664c74
33 ****************************************************************************/
40 /** parser reuse. imports-to-C uses char *, real VM uses pcre * */
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
52 extern int asa_pcre_compile(asa_pcre *out, const char *str);
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 */
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 */
65 ASAI_FPS, /**< set fixed fps */
66 ASAI_SHOW, /**< set start time */
67 ASAI_HIDE, /**< set end time */
69 ASAI_CHILD /**< child regex match */
72 /** replacement element for ASAI_SG / ASAI_SGU */
74 struct asa_repl *next; /**< next element */
76 int group; /**< -1 if fixed string, else source group */
77 char *text; /**< fixed string for group == -1 */
80 /** time specification element */
82 struct asa_tspec *next; /**< next element */
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 */
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 */
95 enum asa_import_insn_type insn; /**< instruction code */
96 /** instruction parameters */
98 int break_depth; /**< depth to break out */
99 int select; /**< matchgroup to select */
100 /** search-replace parameters */
102 asa_pcre regex; /**< search for */
103 struct asa_repl *repl; /**< replace by */
105 /** time specification */
107 struct asa_tspec *tsp; /**< sources to sum up */
108 int delta_select; /**< -1 or delta index */
110 /** child instructions */
112 asa_pcre regex; /** <if this matches... */
113 struct asa_import_insn *insns; /**< do this. */
115 double fps_value; /**< fixed fps value */
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 */
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*/
131 char *name; /**< format name */
133 enum asa_import_target target; /**< target */
134 struct asa_import_insn *insns; /**< instructions */
137 /** format detection rules */
138 struct asa_import_detect {
139 struct asa_import_detect *next; /**< next rule */
141 asa_pcre re; /**< if this matches... */
143 char *name; /**< use this format */
144 struct asa_import_format *fmt; /**< through this pointer */
148 extern struct asa_import_detect *asa_det_first, **asa_det_last;
149 extern struct asa_import_format *asa_fmt_first, **asa_fmt_last;
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);
155 extern struct asa_import_detect *asa_imports_detect(const void *data,
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);