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
40
43 int chars_per_frame;
/**< characters to send decoder per frame;
44 set by private options as characters per second, and then
45 converted to characters per frame at runtime */
46 int width,
height;
/**< video size (WxH pixels) (private option) */
48 uint64_t
fsize;
/**< file size less metadata buffer */
50
52 {
55 if (!st)
59
63 }
64
66
67 /* simulate tty display speed */
69
70 return st;
71 }
72
73 #if CONFIG_BINTEXT_DEMUXER | CONFIG_ADF_DEMUXER | CONFIG_IDF_DEMUXER
74 /**
75 * Given filesize and width, calculate height (assume font_height of 16)
76 */
77 static void calculate_height(
AVCodecContext *avctx, uint64_t fsize)
78 {
79 avctx->
height = (fsize / ((avctx->
width>>3)*2)) << 4;
80 }
81 #endif
82
83 #if CONFIG_BINTEXT_DEMUXER
84 static const uint8_t next_magic[]={
85 0x1A, 0x1B, '[', '0', ';', '3', '0', ';', '4', '0', 'm', 'N', 'E', 'X', 'T', 0x00
86 };
87
89 {
94
96 if (
avio_read(pb, buf,
sizeof(next_magic)) !=
sizeof(next_magic))
97 return -1;
98 if (memcmp(buf, next_magic, sizeof(next_magic)))
99 return -1;
101 return -1;
102
103 *fsize -= 256;
104
105 #define GET_EFI2_META(name,size) \
106 len = avio_r8(pb); \
107 if (len < 1 || len > size) \
108 return -1; \
109 if (avio_read(pb, buf, size) == size && *buf) { \
110 buf[len] = 0; \
111 av_dict_set(&avctx->metadata, name, buf, 0); \
112 }
113
114 GET_EFI2_META("filename", 12)
115 GET_EFI2_META("author", 20)
116 GET_EFI2_META("publisher", 20)
117 GET_EFI2_META("title", 35)
118
120 }
121
122 static
void predict_width(
AVCodecContext *avctx, uint64_t fsize,
int got_width)
123 {
124 /** attempt to guess width */
125 if (!got_width)
126 avctx->width = fsize > 4000 ? (160<<3) : (80<<3);
127 }
128
130 {
133
135 if (!st)
138
143
145 int got_width = 0;
148 next_tag_read(s, &bin->
fsize);
150 predict_width(st->
codec, bin->
fsize, got_width);
152 }
154 }
155 return 0;
156 }
157 #endif /* CONFIG_BINTEXT_DEMUXER */
158
159 #if CONFIG_XBIN_DEMUXER
161 {
163
164 if (
AV_RL32(d) ==
MKTAG(
'X',
'B',
'I',
'N') && d[4] == 0x1A &&
166 d[9] > 0 && d[9] <= 32)
168 return 0;
169 }
170
172 {
175 char fontheight,
flags;
176
178 if (!st)
180
187
194
201
206 }
207
208 return 0;
209 }
210 #endif /* CONFIG_XBIN_DEMUXER */
211
212 #if CONFIG_ADF_DEMUXER
214 {
218
221
223 if (!st)
226
231
239
241 int got_width = 0;
248 }
249 return 0;
250 }
251 #endif /* CONFIG_ADF_DEMUXER */
252
253 #if CONFIG_IDF_DEMUXER
254 static const uint8_t idf_magic[] = {
255 0x04, 0x31, 0x2e, 0x34, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x15, 0x00
256 };
257
259 {
260 if (p->
buf_size <
sizeof(idf_magic))
261 return 0;
262 if (!memcmp(p->
buf, idf_magic,
sizeof(idf_magic)))
264 return 0;
265 }
266
268 {
272 int got_width = 0;
273
276
278 if (!st)
281
286
288
293
299 return 0;
300 }
301 #endif /* CONFIG_IDF_DEMUXER */
302
305 {
307
308 if (bin->
fsize > 0) {
311 bin->
fsize = -1;
/* done */
312 }
else if (!bin->
fsize) {
317 } else {
319 }
320
322 return 0;
323 }
324
325 #define OFFSET(x) offsetof(BinDemuxContext, x)
331 };
332
333 #define CLASS(name) \
334 (const AVClass[1]){{ \
335 .class_name = name, \
336 .item_name = av_default_item_name, \
337 .option = options, \
338 .version = LIBAVUTIL_VERSION_INT, \
339 }}
340
341 #if CONFIG_BINTEXT_DEMUXER
348 .extensions = "bin",
349 .priv_class =
CLASS(
"Binary text demuxer"),
350 };
351 #endif
352
353 #if CONFIG_XBIN_DEMUXER
361 .priv_class =
CLASS(
"eXtended BINary text (XBIN) demuxer"),
362 };
363 #endif
364
365 #if CONFIG_ADF_DEMUXER
372 .extensions = "adf",
373 .priv_class =
CLASS(
"Artworx Data Format demuxer"),
374 };
375 #endif
376
377 #if CONFIG_IDF_DEMUXER
385 .extensions = "idf",
386 .priv_class =
CLASS(
"iCE Draw File demuxer"),
387 };
388 #endif