1 /*
2 * Binary text demuxer
3 * eXtended BINary text (XBIN) demuxer
4 * Artworx Data Format demuxer
5 * iCEDraw File demuxer
6 * Copyright (c) 2010 Peter Ross <pross@xvid.org>
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg 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 GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 /**
26 * @file
27 * Binary text demuxer
28 * eXtended BINary text (XBIN) demuxer
29 * Artworx Data Format demuxer
30 * iCEDraw File demuxer
31 */
32
33 #include "config_components.h"
34
43
47 set by private options as characters per second, and then
48 converted to characters per frame at runtime */
49 int width,
height;
/**< video size (WxH pixels) (private option) */
51 uint64_t
fsize;
/**< file size less metadata buffer */
53
55 {
58 if (!st)
62
66 }
67
69
70 /* simulate tty display speed */
72
73 return st;
74 }
75
76 #if CONFIG_BINTEXT_DEMUXER | CONFIG_ADF_DEMUXER | CONFIG_IDF_DEMUXER
77 /**
78 * Given filesize and width, calculate height (assume font_height of 16)
79 */
81 {
83 }
84 #endif
85
86 #if CONFIG_BINTEXT_DEMUXER
87 static const uint8_t next_magic[]={
88 0x1A, 0x1B, '[', '0', ';', '3', '0', ';', '4', '0', 'm', 'N', 'E', 'X', 'T', 0x00
89 };
90
92 {
94 char buf[36];
97
98 if (start_pos < 256)
100
101 avio_seek(pb, start_pos - 256, SEEK_SET);
102 if (
avio_read(pb, buf,
sizeof(next_magic)) !=
sizeof(next_magic))
103 return -1;
104 if (memcmp(buf, next_magic, sizeof(next_magic)))
105 return -1;
107 return -1;
108
110
111 #define GET_EFI2_META(name,size) \
112 len = avio_r8(pb); \
113 if (len < 1 || len > size) \
114 return -1; \
115 if (avio_read(pb, buf, size) == size && *buf) { \
116 buf[len] = 0; \
117 av_dict_set(&avctx->metadata, name, buf, 0); \
118 }
119
120 GET_EFI2_META("filename", 12)
121 GET_EFI2_META("author", 20)
122 GET_EFI2_META("publisher", 20)
123 GET_EFI2_META("title", 35)
124
126 }
127
129 {
130 /** attempt to guess width */
131 if (!got_width)
132 par->width =
fsize > 4000 ? (160<<3) : (80<<3);
133 }
134
136 {
137 const uint8_t *d =
p->buf;
138 int magic = 0, sauce = 0;
139
140 if (
p->buf_size > 256)
141 magic = !memcmp(d +
p->buf_size - 256, next_magic,
sizeof(next_magic));
142 if (
p->buf_size > 128)
143 sauce = !memcmp(d +
p->buf_size - 128,
"SAUCE00", 7);
144
145 if (magic)
147
150 int got_width = 0;
152 if (sauce)
154
155 predict_width(&par,
p->buf_size, got_width);
157 return 0;
158 calculate_height(&par,
p->buf_size);
160 return 0;
161
164 return 0;
165 }
166
167 if (sauce)
168 return 1;
169
170 return 0;
171 }
172
173
175 {
180 if (!st)
183
188
190 int got_width = 0;
193 next_tag_read(
s, &bin->
fsize);
199 }
201 }
202 return 0;
203 }
204 #endif /* CONFIG_BINTEXT_DEMUXER */
205
206 #if CONFIG_XBIN_DEMUXER
208 {
209 const uint8_t *d =
p->buf;
210
211 if (
AV_RL32(d) ==
MKTAG(
'X',
'B',
'I',
'N') && d[4] == 0x1A &&
213 d[9] > 0 && d[9] <= 32)
215 return 0;
216 }
217
219 {
222 char fontheight,
flags;
225 if (!st)
227
234
241
249
252 if (fsize < 9 + st->codecpar->extradata_size)
253 return 0;
257 }
258
259 return 0;
260 }
261 #endif /* CONFIG_XBIN_DEMUXER */
262
263 #if CONFIG_ADF_DEMUXER
265 {
270
273
275 if (!st)
278
283
291
293 int got_width = 0;
295 if (
fsize < 1 + 192 + 4096)
296 return 0;
305 }
306 return 0;
307 }
308 #endif /* CONFIG_ADF_DEMUXER */
309
310 #if CONFIG_IDF_DEMUXER
311 static const uint8_t idf_magic[] = {
312 0x04, 0x31, 0x2e, 0x34, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x15, 0x00
313 };
314
316 {
317 if (
p->buf_size <
sizeof(idf_magic))
318 return 0;
319 if (!memcmp(
p->buf, idf_magic,
sizeof(idf_magic)))
321 return 0;
322 }
323
325 {
329 int got_width = 0,
ret;
331
334
336 if (!st)
339
344
346 if (
fsize < 12 + 4096 + 48)
349
351
356
363 return 0;
364 }
365 #endif /* CONFIG_IDF_DEMUXER */
366
369 {
371
372 if (bin->
fsize > 0) {
375 bin->
fsize = -1;
/* done */
376 }
else if (!bin->
fsize) {
381 } else {
383 }
384
386 return 0;
387 }
388
389 #define OFFSET(x) offsetof(BinDemuxContext, x)
395 };
396
397 #define CLASS(name) \
398 (const AVClass[1]){{ \
399 .class_name = name, \
400 .item_name = av_default_item_name, \
401 .option = options, \
402 .version = LIBAVUTIL_VERSION_INT, \
403 }}
404
405 #if CONFIG_BINTEXT_DEMUXER
409 .p.priv_class =
CLASS(
"Binary text demuxer"),
414 };
415 #endif
416
417 #if CONFIG_XBIN_DEMUXER
421 .p.priv_class =
CLASS(
"eXtended BINary text (XBIN) demuxer"),
426 };
427 #endif
428
429 #if CONFIG_ADF_DEMUXER
433 .p.extensions = "adf",
434 .p.priv_class =
CLASS(
"Artworx Data Format demuxer"),
438 };
439 #endif
440
441 #if CONFIG_IDF_DEMUXER
445 .p.extensions = "idf",
446 .p.priv_class =
CLASS(
"iCE Draw File demuxer"),
451 };
452 #endif