Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Peter Ross authored on 2011/09/16 11:50:26... | ... |
@@ -51,6 +51,7 @@ library: |
51 | 51 |
@tab Multimedia format used in games like Mad Dog McCree. |
52 | 52 |
@item 3GPP AMR @tab X @tab X |
53 | 53 |
@item Apple HTTP Live Streaming @tab @tab X |
54 |
+@item Artworx Data Format @tab @tab X |
|
54 | 55 |
@item ASF @tab X @tab X |
55 | 56 |
@item AVI @tab X @tab X |
56 | 57 |
@item AVISynth @tab @tab X |
... | ... |
@@ -60,6 +61,7 @@ library: |
60 | 60 |
@tab Audio and video format used in some games by Beam Software. |
61 | 61 |
@item Bethesda Softworks VID @tab @tab X |
62 | 62 |
@tab Used in some games from Bethesda Softworks. |
63 |
+@item Binary text @tab @tab C |
|
63 | 64 |
@item Bink @tab @tab X |
64 | 65 |
@tab Multimedia format used by many games. |
65 | 66 |
@item Bitmap Brothers JV @tab @tab X |
... | ... |
@@ -106,6 +108,7 @@ library: |
106 | 106 |
@item GXF @tab X @tab X |
107 | 107 |
@tab General eXchange Format SMPTE 360M, used by Thomson Grass Valley |
108 | 108 |
playout servers. |
109 |
+@item iCEDraw File @tab @tab X |
|
109 | 110 |
@item id Quake II CIN video @tab @tab X |
110 | 111 |
@item id RoQ @tab X @tab X |
111 | 112 |
@tab Used in Quake III, Jedi Knight 2, other computer games. |
... | ... |
@@ -267,6 +270,7 @@ library: |
267 | 267 |
@tab Microsoft video container used in Xbox games. |
268 | 268 |
@item xWMA @tab @tab X |
269 | 269 |
@tab Microsoft audio container used by XAudio 2. |
270 |
+@item eXtended BINary text (XBIN) @tab @tab X |
|
270 | 271 |
@item YUV4MPEG pipe @tab X @tab X |
271 | 272 |
@item Psygnosis YOP @tab @tab X |
272 | 273 |
@end multitable |
... | ... |
@@ -96,6 +96,7 @@ OBJS-$(CONFIG_BFI_DECODER) += bfi.o |
96 | 96 |
OBJS-$(CONFIG_BINK_DECODER) += bink.o binkdsp.o |
97 | 97 |
OBJS-$(CONFIG_BINKAUDIO_DCT_DECODER) += binkaudio.o wma.o |
98 | 98 |
OBJS-$(CONFIG_BINKAUDIO_RDFT_DECODER) += binkaudio.o wma.o |
99 |
+OBJS-$(CONFIG_BINTEXT_DECODER) += bintext.o cga_data.o |
|
99 | 100 |
OBJS-$(CONFIG_BMP_DECODER) += bmp.o msrledec.o |
100 | 101 |
OBJS-$(CONFIG_BMP_ENCODER) += bmpenc.o |
101 | 102 |
OBJS-$(CONFIG_C93_DECODER) += c93.o |
... | ... |
@@ -188,6 +189,7 @@ OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o |
188 | 188 |
OBJS-$(CONFIG_HUFFYUV_DECODER) += huffyuv.o |
189 | 189 |
OBJS-$(CONFIG_HUFFYUV_ENCODER) += huffyuv.o |
190 | 190 |
OBJS-$(CONFIG_IDCIN_DECODER) += idcinvideo.o |
191 |
+OBJS-$(CONFIG_IDF_DECODER) += bintext.o cga_data.o |
|
191 | 192 |
OBJS-$(CONFIG_IFF_BYTERUN1_DECODER) += iff.o |
192 | 193 |
OBJS-$(CONFIG_IFF_ILBM_DECODER) += iff.o |
193 | 194 |
OBJS-$(CONFIG_IMC_DECODER) += imc.o |
... | ... |
@@ -440,6 +442,7 @@ OBJS-$(CONFIG_WS_SND1_DECODER) += ws-snd1.o |
440 | 440 |
OBJS-$(CONFIG_XAN_DPCM_DECODER) += dpcm.o |
441 | 441 |
OBJS-$(CONFIG_XAN_WC3_DECODER) += xan.o |
442 | 442 |
OBJS-$(CONFIG_XAN_WC4_DECODER) += xxan.o |
443 |
+OBJS-$(CONFIG_XBIN_DECODER) += bintext.o cga_data.o |
|
443 | 444 |
OBJS-$(CONFIG_XL_DECODER) += xl.o |
444 | 445 |
OBJS-$(CONFIG_XSUB_DECODER) += xsubdec.o |
445 | 446 |
OBJS-$(CONFIG_XSUB_ENCODER) += xsubenc.o |
... | ... |
@@ -393,6 +393,11 @@ void avcodec_register_all(void) |
393 | 393 |
REGISTER_ENCODER (LIBXAVS, libxavs); |
394 | 394 |
REGISTER_ENCODER (LIBXVID, libxvid); |
395 | 395 |
|
396 |
+ /* text */ |
|
397 |
+ REGISTER_DECODER (BINTEXT, bintext); |
|
398 |
+ REGISTER_DECODER (XBIN, xbin); |
|
399 |
+ REGISTER_DECODER (IDF, idf); |
|
400 |
+ |
|
396 | 401 |
/* parsers */ |
397 | 402 |
REGISTER_PARSER (AAC, aac); |
398 | 403 |
REGISTER_PARSER (AAC_LATM, aac_latm); |
... | ... |
@@ -361,6 +361,9 @@ enum CodecID { |
361 | 361 |
/* other specific kind of codecs (generally used for attachments) */ |
362 | 362 |
CODEC_ID_FIRST_UNKNOWN = 0x18000, ///< A dummy ID pointing at the start of various fake codecs. |
363 | 363 |
CODEC_ID_TTF= 0x18000, |
364 |
+ CODEC_ID_BINTEXT, |
|
365 |
+ CODEC_ID_XBIN, |
|
366 |
+ CODEC_ID_IDF, |
|
364 | 367 |
|
365 | 368 |
CODEC_ID_PROBE= 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it |
366 | 369 |
|
367 | 370 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,252 @@ |
0 |
+/* |
|
1 |
+ * Binary text decoder |
|
2 |
+ * eXtended BINary text (XBIN) decoder |
|
3 |
+ * iCEDraw File decoder |
|
4 |
+ * Copyright (c) 2010 Peter Ross (pross@xvid.org) |
|
5 |
+ * |
|
6 |
+ * This file is part of FFmpeg. |
|
7 |
+ * |
|
8 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
9 |
+ * modify it under the terms of the GNU Lesser General Public |
|
10 |
+ * License as published by the Free Software Foundation; either |
|
11 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
12 |
+ * |
|
13 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
14 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 |
+ * Lesser General Public License for more details. |
|
17 |
+ * |
|
18 |
+ * You should have received a copy of the GNU Lesser General Public |
|
19 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
20 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
21 |
+ */ |
|
22 |
+ |
|
23 |
+/** |
|
24 |
+ * @file libavcodec/xbin.c |
|
25 |
+ * Binary text decoder |
|
26 |
+ * eXtended BINary text (XBIN) decoder |
|
27 |
+ * iCEDraw File decoder |
|
28 |
+ */ |
|
29 |
+ |
|
30 |
+#include "libavutil/intreadwrite.h" |
|
31 |
+#include "avcodec.h" |
|
32 |
+#include "cga_data.h" |
|
33 |
+#include "bintext.h" |
|
34 |
+ |
|
35 |
+typedef struct XbinContext { |
|
36 |
+ AVFrame frame; |
|
37 |
+ int palette[16]; |
|
38 |
+ int flags; |
|
39 |
+ int font_height; |
|
40 |
+ const uint8_t *font; |
|
41 |
+ int x, y; |
|
42 |
+} XbinContext; |
|
43 |
+ |
|
44 |
+static av_cold int decode_init(AVCodecContext *avctx) |
|
45 |
+{ |
|
46 |
+ XbinContext *s = avctx->priv_data; |
|
47 |
+ uint8_t *p; |
|
48 |
+ int i; |
|
49 |
+ |
|
50 |
+ avctx->pix_fmt = PIX_FMT_PAL8; |
|
51 |
+ s->frame.reference = 1; |
|
52 |
+ if (avctx->get_buffer(avctx, &s->frame)) { |
|
53 |
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
|
54 |
+ return -1; |
|
55 |
+ } |
|
56 |
+ |
|
57 |
+ p = avctx->extradata; |
|
58 |
+ if (p) { |
|
59 |
+ s->font_height = p[0]; |
|
60 |
+ s->flags = p[1]; |
|
61 |
+ p += 2; |
|
62 |
+ } else { |
|
63 |
+ s->font_height = 8; |
|
64 |
+ s->flags = 0; |
|
65 |
+ } |
|
66 |
+ |
|
67 |
+ if ((s->flags & BINTEXT_PALETTE)) { |
|
68 |
+ for (i = 0; i < 16; i++) { |
|
69 |
+ s->palette[i] = 0xFF000000 | (AV_RB24(p) << 2); |
|
70 |
+ p += 3; |
|
71 |
+ } |
|
72 |
+ } else { |
|
73 |
+ for (i = 0; i < 16; i++) |
|
74 |
+ s->palette[i] = 0xFF000000 | ff_cga_palette[i]; |
|
75 |
+ } |
|
76 |
+ |
|
77 |
+ if ((s->flags & BINTEXT_FONT)) { |
|
78 |
+ s->font = p; |
|
79 |
+ } else { |
|
80 |
+ switch(s->font_height) { |
|
81 |
+ default: |
|
82 |
+ av_log(avctx, AV_LOG_WARNING, "font height %i not support\n", s->font_height); |
|
83 |
+ s->font_height = 8; |
|
84 |
+ case 8: |
|
85 |
+ s->font = ff_cga_font; |
|
86 |
+ break; |
|
87 |
+ case 16: |
|
88 |
+ s->font = ff_vga16_font; |
|
89 |
+ break; |
|
90 |
+ } |
|
91 |
+ } |
|
92 |
+ |
|
93 |
+ return 0; |
|
94 |
+} |
|
95 |
+ |
|
96 |
+#define DEFAULT_BG_COLOR 0 |
|
97 |
+static void hscroll(AVCodecContext *avctx) |
|
98 |
+{ |
|
99 |
+ XbinContext *s = avctx->priv_data; |
|
100 |
+ if (s->y < avctx->height - s->font_height) { |
|
101 |
+ s->y += s->font_height; |
|
102 |
+ } else { |
|
103 |
+ memmove(s->frame.data[0], s->frame.data[0] + s->font_height*s->frame.linesize[0], |
|
104 |
+ (avctx->height - s->font_height)*s->frame.linesize[0]); |
|
105 |
+ memset(s->frame.data[0] + (avctx->height - s->font_height)*s->frame.linesize[0], |
|
106 |
+ DEFAULT_BG_COLOR, s->font_height * s->frame.linesize[0]); |
|
107 |
+ } |
|
108 |
+} |
|
109 |
+ |
|
110 |
+#define FONT_WIDTH 8 |
|
111 |
+ |
|
112 |
+/** |
|
113 |
+ * Draw character to screen |
|
114 |
+ */ |
|
115 |
+static void draw_char(AVCodecContext *avctx, int c, int a) |
|
116 |
+{ |
|
117 |
+ XbinContext *s = avctx->priv_data; |
|
118 |
+ if (s->y > avctx->height - s->font_height) |
|
119 |
+ return; |
|
120 |
+ ff_draw_pc_font(s->frame.data[0] + s->y * s->frame.linesize[0] + s->x, |
|
121 |
+ s->frame.linesize[0], s->font, s->font_height, c, |
|
122 |
+ a & 0x0F, a >> 4); |
|
123 |
+ s->x += FONT_WIDTH; |
|
124 |
+ if (s->x >= avctx->width) { |
|
125 |
+ s->x = 0; |
|
126 |
+ s->y += s->font_height; |
|
127 |
+ } |
|
128 |
+} |
|
129 |
+ |
|
130 |
+static int decode_frame(AVCodecContext *avctx, |
|
131 |
+ void *data, int *data_size, |
|
132 |
+ AVPacket *avpkt) |
|
133 |
+{ |
|
134 |
+ XbinContext *s = avctx->priv_data; |
|
135 |
+ const uint8_t *buf = avpkt->data; |
|
136 |
+ int buf_size = avpkt->size; |
|
137 |
+ const uint8_t *buf_end = buf+buf_size; |
|
138 |
+ |
|
139 |
+ if (avctx->reget_buffer(avctx, &s->frame)) { |
|
140 |
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
|
141 |
+ return -1; |
|
142 |
+ } |
|
143 |
+ s->frame.pict_type = FF_I_TYPE; |
|
144 |
+ s->frame.palette_has_changed = 1; |
|
145 |
+ memcpy(s->frame.data[1], s->palette, 16 * 4); |
|
146 |
+ |
|
147 |
+ if (avctx->codec_id == CODEC_ID_XBIN) { |
|
148 |
+ while (buf + 2 < buf_end) { |
|
149 |
+ int i,c,a; |
|
150 |
+ int type = *buf >> 6; |
|
151 |
+ int count = (*buf & 0x3F) + 1; |
|
152 |
+ buf++; |
|
153 |
+ switch (type) { |
|
154 |
+ case 0: //no compression |
|
155 |
+ for (i = 0; i < count && buf + 1 < buf_end; i++) { |
|
156 |
+ draw_char(avctx, buf[0], buf[1]); |
|
157 |
+ buf += 2; |
|
158 |
+ } |
|
159 |
+ break; |
|
160 |
+ case 1: //character compression |
|
161 |
+ c = *buf++; |
|
162 |
+ for (i = 0; i < count && buf < buf_end; i++) |
|
163 |
+ draw_char(avctx, c, *buf++); |
|
164 |
+ break; |
|
165 |
+ case 2: //attribute compression |
|
166 |
+ a = *buf++; |
|
167 |
+ for (i = 0; i < count && buf < buf_end; i++) |
|
168 |
+ draw_char(avctx, *buf++, a); |
|
169 |
+ break; |
|
170 |
+ case 3: //character/attribute compression |
|
171 |
+ c = *buf++; |
|
172 |
+ a = *buf++; |
|
173 |
+ for (i = 0; i < count && buf < buf_end; i++) |
|
174 |
+ draw_char(avctx, c, a); |
|
175 |
+ break; |
|
176 |
+ } |
|
177 |
+ } |
|
178 |
+ } else if (avctx->codec_id == CODEC_ID_IDF) { |
|
179 |
+ while (buf + 2 < buf_end) { |
|
180 |
+ if (AV_RL16(buf) == 1) { |
|
181 |
+ int i; |
|
182 |
+ if (buf + 6 > buf_end) |
|
183 |
+ break; |
|
184 |
+ for (i = 0; i < buf[2]; i++) |
|
185 |
+ draw_char(avctx, buf[4], buf[5]); |
|
186 |
+ buf += 6; |
|
187 |
+ } else { |
|
188 |
+ draw_char(avctx, buf[0], buf[1]); |
|
189 |
+ buf += 2; |
|
190 |
+ } |
|
191 |
+ } |
|
192 |
+ } else { |
|
193 |
+ while (buf + 1 < buf_end) { |
|
194 |
+ draw_char(avctx, buf[0], buf[1]); |
|
195 |
+ buf += 2; |
|
196 |
+ } |
|
197 |
+ } |
|
198 |
+ |
|
199 |
+ *data_size = sizeof(AVFrame); |
|
200 |
+ *(AVFrame*)data = s->frame; |
|
201 |
+ return buf_size; |
|
202 |
+} |
|
203 |
+ |
|
204 |
+static av_cold int decode_end(AVCodecContext *avctx) |
|
205 |
+{ |
|
206 |
+ XbinContext *s = avctx->priv_data; |
|
207 |
+ |
|
208 |
+ if (s->frame.data[0]) |
|
209 |
+ avctx->release_buffer(avctx, &s->frame); |
|
210 |
+ |
|
211 |
+ return 0; |
|
212 |
+} |
|
213 |
+ |
|
214 |
+AVCodec ff_bintext_decoder = { |
|
215 |
+ "xbin", |
|
216 |
+ AVMEDIA_TYPE_VIDEO, |
|
217 |
+ CODEC_ID_BINTEXT, |
|
218 |
+ sizeof(XbinContext), |
|
219 |
+ decode_init, |
|
220 |
+ NULL, |
|
221 |
+ decode_end, |
|
222 |
+ decode_frame, |
|
223 |
+ CODEC_CAP_DR1, |
|
224 |
+ .long_name = NULL_IF_CONFIG_SMALL("Binary text"), |
|
225 |
+}; |
|
226 |
+ |
|
227 |
+AVCodec ff_xbin_decoder = { |
|
228 |
+ "xbin", |
|
229 |
+ AVMEDIA_TYPE_VIDEO, |
|
230 |
+ CODEC_ID_XBIN, |
|
231 |
+ sizeof(XbinContext), |
|
232 |
+ decode_init, |
|
233 |
+ NULL, |
|
234 |
+ decode_end, |
|
235 |
+ decode_frame, |
|
236 |
+ CODEC_CAP_DR1, |
|
237 |
+ .long_name = NULL_IF_CONFIG_SMALL("eXtended BINary text"), |
|
238 |
+}; |
|
239 |
+ |
|
240 |
+AVCodec ff_idf_decoder = { |
|
241 |
+ "idf", |
|
242 |
+ AVMEDIA_TYPE_VIDEO, |
|
243 |
+ CODEC_ID_IDF, |
|
244 |
+ sizeof(XbinContext), |
|
245 |
+ decode_init, |
|
246 |
+ NULL, |
|
247 |
+ decode_end, |
|
248 |
+ decode_frame, |
|
249 |
+ CODEC_CAP_DR1, |
|
250 |
+ .long_name = NULL_IF_CONFIG_SMALL("iCEDraw text"), |
|
251 |
+}; |
0 | 252 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,37 @@ |
0 |
+/* |
|
1 |
+ * Binary text decoder |
|
2 |
+ * Copyright (c) 2010 Peter Ross (pross@xvid.org) |
|
3 |
+ * |
|
4 |
+ * This file is part of FFmpeg. |
|
5 |
+ * |
|
6 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+/** |
|
22 |
+ * @file |
|
23 |
+ * Binary text decoder |
|
24 |
+ */ |
|
25 |
+ |
|
26 |
+#ifndef AVCODEC_BINTEXT_H |
|
27 |
+#define AVCODEC_BINTEXT_H |
|
28 |
+ |
|
29 |
+/* flag values passed between avformat and avcodec; |
|
30 |
+ * while these are identical to the XBIN flags, they are are also used |
|
31 |
+ * for the BINTEXT and IDF decoders. |
|
32 |
+ */ |
|
33 |
+#define BINTEXT_PALETTE 0x1 |
|
34 |
+#define BINTEXT_FONT 0x2 |
|
35 |
+ |
|
36 |
+#endif /* AVCODEC_BINTEXT_H */ |
... | ... |
@@ -21,6 +21,7 @@ OBJS-$(CONFIG_A64_MUXER) += a64.o |
21 | 21 |
OBJS-$(CONFIG_AAC_DEMUXER) += aacdec.o rawdec.o |
22 | 22 |
OBJS-$(CONFIG_AC3_DEMUXER) += ac3dec.o rawdec.o |
23 | 23 |
OBJS-$(CONFIG_AC3_MUXER) += rawenc.o |
24 |
+OBJS-$(CONFIG_ADF_DEMUXER) += bintext.o sauce.o |
|
24 | 25 |
OBJS-$(CONFIG_ADTS_MUXER) += adtsenc.o |
25 | 26 |
OBJS-$(CONFIG_AEA_DEMUXER) += aea.o pcm.o |
26 | 27 |
OBJS-$(CONFIG_AIFF_DEMUXER) += aiffdec.o riff.o pcm.o isom.o |
... | ... |
@@ -46,6 +47,7 @@ OBJS-$(CONFIG_AVS_DEMUXER) += avs.o vocdec.o voc.o |
46 | 46 |
OBJS-$(CONFIG_BETHSOFTVID_DEMUXER) += bethsoftvid.o |
47 | 47 |
OBJS-$(CONFIG_BFI_DEMUXER) += bfi.o |
48 | 48 |
OBJS-$(CONFIG_BINK_DEMUXER) += bink.o |
49 |
+OBJS-$(CONFIG_BINTEXT_DEMUXER) += bintext.o sauce.o |
|
49 | 50 |
OBJS-$(CONFIG_C93_DEMUXER) += c93.o vocdec.o voc.o |
50 | 51 |
OBJS-$(CONFIG_CAF_DEMUXER) += cafdec.o caf.o mov.o riff.o isom.o |
51 | 52 |
OBJS-$(CONFIG_CAF_MUXER) += cafenc.o caf.o riff.o isom.o |
... | ... |
@@ -100,6 +102,7 @@ OBJS-$(CONFIG_H263_MUXER) += rawenc.o |
100 | 100 |
OBJS-$(CONFIG_H264_DEMUXER) += h264dec.o rawdec.o |
101 | 101 |
OBJS-$(CONFIG_H264_MUXER) += rawenc.o |
102 | 102 |
OBJS-$(CONFIG_IDCIN_DEMUXER) += idcin.o |
103 |
+OBJS-$(CONFIG_IDF_DEMUXER) += bintext.o |
|
103 | 104 |
OBJS-$(CONFIG_IFF_DEMUXER) += iff.o |
104 | 105 |
OBJS-$(CONFIG_IMAGE2_DEMUXER) += img2.o |
105 | 106 |
OBJS-$(CONFIG_IMAGE2_MUXER) += img2.o |
... | ... |
@@ -308,6 +311,7 @@ OBJS-$(CONFIG_WTV_DEMUXER) += wtvdec.o wtv.o asfdec.o asf.o asfcry |
308 | 308 |
OBJS-$(CONFIG_WTV_MUXER) += wtvenc.o wtv.o asf.o riff.o |
309 | 309 |
OBJS-$(CONFIG_WV_DEMUXER) += wv.o apetag.o |
310 | 310 |
OBJS-$(CONFIG_XA_DEMUXER) += xa.o |
311 |
+OBJS-$(CONFIG_XBIN_DEMUXER) += bintext.o sauce.o |
|
311 | 312 |
OBJS-$(CONFIG_XMV_DEMUXER) += xmv.o |
312 | 313 |
OBJS-$(CONFIG_XWMA_DEMUXER) += xwma.o riff.o |
313 | 314 |
OBJS-$(CONFIG_YOP_DEMUXER) += yop.o |
... | ... |
@@ -51,6 +51,7 @@ void av_register_all(void) |
51 | 51 |
REGISTER_MUXER (A64, a64); |
52 | 52 |
REGISTER_DEMUXER (AAC, aac); |
53 | 53 |
REGISTER_MUXDEMUX (AC3, ac3); |
54 |
+ REGISTER_DEMUXER (ADF, adf); |
|
54 | 55 |
REGISTER_MUXER (ADTS, adts); |
55 | 56 |
REGISTER_DEMUXER (AEA, aea); |
56 | 57 |
REGISTER_MUXDEMUX (AIFF, aiff); |
... | ... |
@@ -69,6 +70,7 @@ void av_register_all(void) |
69 | 69 |
REGISTER_DEMUXER (AVS, avs); |
70 | 70 |
REGISTER_DEMUXER (BETHSOFTVID, bethsoftvid); |
71 | 71 |
REGISTER_DEMUXER (BFI, bfi); |
72 |
+ REGISTER_DEMUXER (BINTEXT, bintext); |
|
72 | 73 |
REGISTER_DEMUXER (BINK, bink); |
73 | 74 |
REGISTER_DEMUXER (C93, c93); |
74 | 75 |
REGISTER_MUXDEMUX (CAF, caf); |
... | ... |
@@ -103,6 +105,7 @@ void av_register_all(void) |
103 | 103 |
REGISTER_MUXDEMUX (H263, h263); |
104 | 104 |
REGISTER_MUXDEMUX (H264, h264); |
105 | 105 |
REGISTER_DEMUXER (IDCIN, idcin); |
106 |
+ REGISTER_DEMUXER (IDF, idf); |
|
106 | 107 |
REGISTER_DEMUXER (IFF, iff); |
107 | 108 |
REGISTER_MUXDEMUX (IMAGE2, image2); |
108 | 109 |
REGISTER_MUXDEMUX (IMAGE2PIPE, image2pipe); |
... | ... |
@@ -229,6 +232,7 @@ void av_register_all(void) |
229 | 229 |
REGISTER_MUXDEMUX (WTV, wtv); |
230 | 230 |
REGISTER_DEMUXER (WV, wv); |
231 | 231 |
REGISTER_DEMUXER (XA, xa); |
232 |
+ REGISTER_DEMUXER (XBIN, xbin); |
|
232 | 233 |
REGISTER_DEMUXER (XMV, xmv); |
233 | 234 |
REGISTER_DEMUXER (XWMA, xwma); |
234 | 235 |
REGISTER_DEMUXER (YOP, yop); |
235 | 236 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,376 @@ |
0 |
+/* |
|
1 |
+ * Binary text demuxer |
|
2 |
+ * eXtended BINary text (XBIN) demuxer |
|
3 |
+ * Artworx Data Format demuxer |
|
4 |
+ * iCEDraw File demuxer |
|
5 |
+ * Copyright (c) 2010 Peter Ross <pross@xvid.org> |
|
6 |
+ * |
|
7 |
+ * This file is part of FFmpeg. |
|
8 |
+ * |
|
9 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
10 |
+ * modify it under the terms of the GNU Lesser General Public |
|
11 |
+ * License as published by the Free Software Foundation; either |
|
12 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
13 |
+ * |
|
14 |
+ * FFmpeg 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 GNU |
|
17 |
+ * Lesser General Public License for more details. |
|
18 |
+ * |
|
19 |
+ * You should have received a copy of the GNU Lesser General Public |
|
20 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
21 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
22 |
+ */ |
|
23 |
+ |
|
24 |
+/** |
|
25 |
+ * @file |
|
26 |
+ * Binary text demuxer |
|
27 |
+ * eXtended BINary text (XBIN) demuxer |
|
28 |
+ * Artworx Data Format demuxer |
|
29 |
+ * iCEDraw File demuxer |
|
30 |
+ */ |
|
31 |
+ |
|
32 |
+#include "libavutil/intreadwrite.h" |
|
33 |
+#include "avformat.h" |
|
34 |
+#include "sauce.h" |
|
35 |
+#include "libavcodec/bintext.h" |
|
36 |
+ |
|
37 |
+#define LINE_RATE 6000 /** characters per second */ |
|
38 |
+ |
|
39 |
+typedef struct { |
|
40 |
+ int chars_per_frame; |
|
41 |
+ uint64_t fsize; /**< file size less metadata buffer */ |
|
42 |
+} BinDemuxContext; |
|
43 |
+ |
|
44 |
+#if CONFIG_BINTEXT_DEMUXER | CONFIG_ADF_DEMUXER | CONFIG_IDF_DEMUXER |
|
45 |
+/** |
|
46 |
+ * Given filesize and width, calculate height (assume font_height of 16) |
|
47 |
+ */ |
|
48 |
+static void calculate_height(AVCodecContext *avctx, uint64_t fsize) |
|
49 |
+{ |
|
50 |
+ avctx->height = (fsize / ((avctx->width>>3)*2)) << 4; |
|
51 |
+} |
|
52 |
+#endif |
|
53 |
+ |
|
54 |
+#if CONFIG_BINTEXT_DEMUXER |
|
55 |
+static const uint8_t next_magic[]={ |
|
56 |
+ 0x1A, 0x1B, '[', '0', ';', '3', '0', ';', '4', '0', 'm', 'N', 'E', 'X', 'T', 0x00 |
|
57 |
+}; |
|
58 |
+ |
|
59 |
+static int next_tag_read(AVFormatContext *avctx, uint64_t *fsize) |
|
60 |
+{ |
|
61 |
+ ByteIOContext *pb = avctx->pb; |
|
62 |
+ char buf[36]; |
|
63 |
+ int len; |
|
64 |
+ uint64_t start_pos = url_fsize(pb) - 256; |
|
65 |
+ |
|
66 |
+ url_fseek(pb, start_pos, SEEK_SET); |
|
67 |
+ if (get_buffer(pb, buf, sizeof(next_magic)) != sizeof(next_magic)) |
|
68 |
+ return -1; |
|
69 |
+ if (memcmp(buf, next_magic, sizeof(next_magic))) |
|
70 |
+ return -1; |
|
71 |
+ if (get_byte(pb) != 0x01) |
|
72 |
+ return -1; |
|
73 |
+ |
|
74 |
+ *fsize -= 256; |
|
75 |
+ |
|
76 |
+#define GET_EFI2_META(name,size) \ |
|
77 |
+ len = get_byte(pb); \ |
|
78 |
+ if (len < 1 || len > size) \ |
|
79 |
+ return -1; \ |
|
80 |
+ if (get_buffer(pb, buf, size) == size && *buf) { \ |
|
81 |
+ buf[len] = 0; \ |
|
82 |
+ av_metadata_set2(&avctx->metadata, name, buf, 0); \ |
|
83 |
+ } |
|
84 |
+ |
|
85 |
+ GET_EFI2_META("filename", 12) |
|
86 |
+ GET_EFI2_META("author", 20) |
|
87 |
+ GET_EFI2_META("publisher", 20) |
|
88 |
+ GET_EFI2_META("title", 35) |
|
89 |
+ |
|
90 |
+ return 0; |
|
91 |
+} |
|
92 |
+ |
|
93 |
+static void predict_width(AVCodecContext *avctx, uint64_t fsize, int got_width) |
|
94 |
+{ |
|
95 |
+ /** attempt to guess width */ |
|
96 |
+ if (!got_width) |
|
97 |
+ avctx->width = fsize > 4000 ? (160<<3) : (80<<3); |
|
98 |
+} |
|
99 |
+ |
|
100 |
+static AVStream * init_stream(AVFormatContext *s, |
|
101 |
+ AVFormatParameters *ap) |
|
102 |
+{ |
|
103 |
+ BinDemuxContext *bin = s->priv_data; |
|
104 |
+ AVStream *st = av_new_stream(s, 0); |
|
105 |
+ if (!st) |
|
106 |
+ return NULL; |
|
107 |
+ st->codec->codec_tag = 0; |
|
108 |
+ st->codec->codec_type = AVMEDIA_TYPE_VIDEO; |
|
109 |
+ |
|
110 |
+ if (!ap->time_base.num) { |
|
111 |
+ av_set_pts_info(st, 60, 1, 25); |
|
112 |
+ } else { |
|
113 |
+ av_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den); |
|
114 |
+ } |
|
115 |
+ |
|
116 |
+ /* simulate tty display speed */ |
|
117 |
+ bin->chars_per_frame = FFMAX(av_q2d(st->time_base) * (ap->sample_rate ? ap->sample_rate : LINE_RATE), 1); |
|
118 |
+ |
|
119 |
+ st->codec->width = ap->width ? ap->width : (80<<3); |
|
120 |
+ st->codec->height = ap->height ? ap->height : (25<<4); |
|
121 |
+ return st; |
|
122 |
+} |
|
123 |
+ |
|
124 |
+static int bintext_read_header(AVFormatContext *s, |
|
125 |
+ AVFormatParameters *ap) |
|
126 |
+{ |
|
127 |
+ BinDemuxContext *bin = s->priv_data; |
|
128 |
+ ByteIOContext *pb = s->pb; |
|
129 |
+ |
|
130 |
+ AVStream *st = init_stream(s, ap); |
|
131 |
+ if (!st) |
|
132 |
+ return AVERROR(ENOMEM); |
|
133 |
+ st->codec->codec_id = CODEC_ID_BINTEXT; |
|
134 |
+ |
|
135 |
+ st->codec->extradata_size = 2; |
|
136 |
+ st->codec->extradata = av_malloc(st->codec->extradata_size); |
|
137 |
+ if (!st->codec->extradata) |
|
138 |
+ return AVERROR(ENOMEM); |
|
139 |
+ st->codec->extradata[0] = 16; |
|
140 |
+ st->codec->extradata[1] = 0; |
|
141 |
+ |
|
142 |
+ if (!url_is_streamed(pb)) { |
|
143 |
+ int got_width = 0; |
|
144 |
+ bin->fsize = url_fsize(pb); |
|
145 |
+ if (ff_sauce_read(s, &bin->fsize, &got_width, 0) < 0) |
|
146 |
+ next_tag_read(s, &bin->fsize); |
|
147 |
+ if (!ap->width) |
|
148 |
+ predict_width(st->codec, bin->fsize, got_width); |
|
149 |
+ if (!ap->height) |
|
150 |
+ calculate_height(st->codec, bin->fsize); |
|
151 |
+ url_fseek(pb, 0, SEEK_SET); |
|
152 |
+ } |
|
153 |
+ return 0; |
|
154 |
+}; |
|
155 |
+#endif /* CONFIG_BINTEXT_DEMUXER */ |
|
156 |
+ |
|
157 |
+#if CONFIG_XBIN_DEMUXER |
|
158 |
+static int xbin_probe(AVProbeData *p) |
|
159 |
+{ |
|
160 |
+ const uint8_t *d = p->buf; |
|
161 |
+ |
|
162 |
+ if (AV_RL32(d) == MKTAG('X','B','I','N') && d[4] == 0x1A && |
|
163 |
+ AV_RL16(d+5) > 0 && AV_RL16(d+5) <= 160 && |
|
164 |
+ d[9] > 0 && d[9] <= 32) |
|
165 |
+ return AVPROBE_SCORE_MAX; |
|
166 |
+ return 0; |
|
167 |
+} |
|
168 |
+ |
|
169 |
+static int xbin_read_header(AVFormatContext *s, |
|
170 |
+ AVFormatParameters *ap) |
|
171 |
+{ |
|
172 |
+ BinDemuxContext *bin = s->priv_data; |
|
173 |
+ ByteIOContext *pb = s->pb; |
|
174 |
+ char fontheight, flags; |
|
175 |
+ uint8_t *h; |
|
176 |
+ |
|
177 |
+ AVStream *st = init_stream(s, ap); |
|
178 |
+ if (!st) |
|
179 |
+ return AVERROR(ENOMEM); |
|
180 |
+ |
|
181 |
+ url_fskip(pb, 5); |
|
182 |
+ st->codec->width = get_le16(pb)<<3; |
|
183 |
+ st->codec->height = get_le16(pb); |
|
184 |
+ fontheight = get_byte(pb); |
|
185 |
+ st->codec->height *= fontheight; |
|
186 |
+ flags = get_byte(pb); |
|
187 |
+ |
|
188 |
+ st->codec->extradata_size = 2; |
|
189 |
+ if ((flags & BINTEXT_PALETTE)) |
|
190 |
+ st->codec->extradata_size += 48; |
|
191 |
+ if ((flags & BINTEXT_FONT)) |
|
192 |
+ st->codec->extradata_size += fontheight * (flags & 0x10 ? 512 : 256); |
|
193 |
+ st->codec->codec_id = flags & 4 ? CODEC_ID_XBIN : CODEC_ID_BINTEXT; |
|
194 |
+ |
|
195 |
+ h = st->codec->extradata = av_malloc(st->codec->extradata_size); |
|
196 |
+ if (!st->codec->extradata) |
|
197 |
+ return AVERROR(ENOMEM); |
|
198 |
+ st->codec->extradata[0] = fontheight; |
|
199 |
+ st->codec->extradata[1] = flags; |
|
200 |
+ if (get_buffer(pb, st->codec->extradata + 2, st->codec->extradata_size - 2) < 0) |
|
201 |
+ return AVERROR(EIO); |
|
202 |
+ |
|
203 |
+ if (!url_is_streamed(pb)) { |
|
204 |
+ bin->fsize = url_fsize(pb) - 9 - st->codec->extradata_size; |
|
205 |
+ ff_sauce_read(s, &bin->fsize, NULL, 0); |
|
206 |
+ url_fseek(pb, 9 + st->codec->extradata_size, SEEK_SET); |
|
207 |
+ } |
|
208 |
+ |
|
209 |
+ return 0; |
|
210 |
+} |
|
211 |
+#endif /* CONFIG_XBIN_DEMUXER */ |
|
212 |
+ |
|
213 |
+#if CONFIG_ADF_DEMUXER |
|
214 |
+static int adf_read_header(AVFormatContext *s, |
|
215 |
+ AVFormatParameters *ap) |
|
216 |
+{ |
|
217 |
+ BinDemuxContext *bin = s->priv_data; |
|
218 |
+ ByteIOContext *pb = s->pb; |
|
219 |
+ AVStream *st; |
|
220 |
+ |
|
221 |
+ if (get_byte(pb) != 1) |
|
222 |
+ return AVERROR_INVALIDDATA; |
|
223 |
+ |
|
224 |
+ st = init_stream(s, ap); |
|
225 |
+ if (!st) |
|
226 |
+ return AVERROR(ENOMEM); |
|
227 |
+ st->codec->codec_id = CODEC_ID_BINTEXT; |
|
228 |
+ |
|
229 |
+ st->codec->extradata_size = 2 + 48 + 4096; |
|
230 |
+ st->codec->extradata = av_malloc(st->codec->extradata_size); |
|
231 |
+ if (!st->codec->extradata) |
|
232 |
+ return AVERROR(ENOMEM); |
|
233 |
+ st->codec->extradata[0] = 16; |
|
234 |
+ st->codec->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT; |
|
235 |
+ |
|
236 |
+ if (get_buffer(pb, st->codec->extradata + 2, 24) < 0) |
|
237 |
+ return AVERROR(EIO); |
|
238 |
+ url_fskip(pb, 144); |
|
239 |
+ if (get_buffer(pb, st->codec->extradata + 2 + 24, 24) < 0) |
|
240 |
+ return AVERROR(EIO); |
|
241 |
+ if (get_buffer(pb, st->codec->extradata + 2 + 48, 4096) < 0) |
|
242 |
+ return AVERROR(EIO); |
|
243 |
+ |
|
244 |
+ if (!url_is_streamed(pb)) { |
|
245 |
+ int got_width = 0; |
|
246 |
+ bin->fsize = url_fsize(pb) - 1 - 192 - 4096; |
|
247 |
+ st->codec->width = 80<<3; |
|
248 |
+ ff_sauce_read(s, &bin->fsize, &got_width, 0); |
|
249 |
+ if (!ap->height) |
|
250 |
+ calculate_height(st->codec, bin->fsize); |
|
251 |
+ url_fseek(pb, 1 + 192 + 4096, SEEK_SET); |
|
252 |
+ } |
|
253 |
+ return 0; |
|
254 |
+} |
|
255 |
+#endif /* CONFIG_ADF_DEMUXER */ |
|
256 |
+ |
|
257 |
+#if CONFIG_IDF_DEMUXER |
|
258 |
+static const uint8_t idf_magic[] = { |
|
259 |
+ 0x04, 0x31, 0x2e, 0x34, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x15, 0x00 |
|
260 |
+}; |
|
261 |
+ |
|
262 |
+static int idf_probe(AVProbeData *p) |
|
263 |
+{ |
|
264 |
+ if (!memcmp(p->buf, idf_magic, FFMIN(sizeof(idf_magic), p->buf_size))) |
|
265 |
+ return AVPROBE_SCORE_MAX; |
|
266 |
+ return 0; |
|
267 |
+} |
|
268 |
+ |
|
269 |
+static int idf_read_header(AVFormatContext *s, |
|
270 |
+ AVFormatParameters *ap) |
|
271 |
+{ |
|
272 |
+ BinDemuxContext *bin = s->priv_data; |
|
273 |
+ ByteIOContext *pb = s->pb; |
|
274 |
+ AVStream *st; |
|
275 |
+ int got_width = 0; |
|
276 |
+ |
|
277 |
+ if (url_is_streamed(pb)) |
|
278 |
+ return AVERROR(EIO); |
|
279 |
+ |
|
280 |
+ st = init_stream(s, ap); |
|
281 |
+ if (!st) |
|
282 |
+ return AVERROR(ENOMEM); |
|
283 |
+ st->codec->codec_id = CODEC_ID_IDF; |
|
284 |
+ |
|
285 |
+ st->codec->extradata_size = 2 + 48 + 4096; |
|
286 |
+ st->codec->extradata = av_malloc(st->codec->extradata_size); |
|
287 |
+ if (!st->codec->extradata) |
|
288 |
+ return AVERROR(ENOMEM); |
|
289 |
+ st->codec->extradata[0] = 16; |
|
290 |
+ st->codec->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT; |
|
291 |
+ |
|
292 |
+ url_fseek(pb, url_fsize(pb) - 4096 - 48, SEEK_SET); |
|
293 |
+ |
|
294 |
+ if (get_buffer(pb, st->codec->extradata + 2 + 48, 4096) < 0) |
|
295 |
+ return AVERROR(EIO); |
|
296 |
+ if (get_buffer(pb, st->codec->extradata + 2, 48) < 0) |
|
297 |
+ return AVERROR(EIO); |
|
298 |
+ |
|
299 |
+ bin->fsize = url_fsize(pb) - 12 - 4096 - 48; |
|
300 |
+ ff_sauce_read(s, &bin->fsize, &got_width, 0); |
|
301 |
+ if (!ap->height) |
|
302 |
+ calculate_height(st->codec, bin->fsize); |
|
303 |
+ url_fseek(pb, 12, SEEK_SET); |
|
304 |
+ return 0; |
|
305 |
+} |
|
306 |
+#endif /* CONFIG_IDF_DEMUXER */ |
|
307 |
+ |
|
308 |
+static int read_packet(AVFormatContext *s, |
|
309 |
+ AVPacket *pkt) |
|
310 |
+{ |
|
311 |
+ BinDemuxContext *bin = s->priv_data; |
|
312 |
+ |
|
313 |
+ if (bin->fsize > 0) { |
|
314 |
+ if (av_get_packet(s->pb, pkt, bin->fsize) < 0) |
|
315 |
+ return AVERROR(EIO); |
|
316 |
+ bin->fsize = -1; /* done */ |
|
317 |
+ } else if (!bin->fsize) { |
|
318 |
+ if (url_feof(s->pb)) |
|
319 |
+ return AVERROR(EIO); |
|
320 |
+ if (av_get_packet(s->pb, pkt, bin->chars_per_frame) < 0) |
|
321 |
+ return AVERROR(EIO); |
|
322 |
+ } else { |
|
323 |
+ return AVERROR(EIO); |
|
324 |
+ } |
|
325 |
+ |
|
326 |
+ pkt->flags |= AV_PKT_FLAG_KEY; |
|
327 |
+ return 0; |
|
328 |
+} |
|
329 |
+ |
|
330 |
+#if CONFIG_BINTEXT_DEMUXER |
|
331 |
+AVInputFormat ff_bintext_demuxer = { |
|
332 |
+ "bin", |
|
333 |
+ NULL_IF_CONFIG_SMALL("Binary text"), |
|
334 |
+ sizeof(BinDemuxContext), |
|
335 |
+ NULL, |
|
336 |
+ bintext_read_header, |
|
337 |
+ read_packet, |
|
338 |
+ .extensions = "bin", |
|
339 |
+}; |
|
340 |
+#endif |
|
341 |
+ |
|
342 |
+#if CONFIG_XBIN_DEMUXER |
|
343 |
+AVInputFormat ff_xbin_demuxer = { |
|
344 |
+ "xbin", |
|
345 |
+ NULL_IF_CONFIG_SMALL("eXtended BINary text (XBIN)"), |
|
346 |
+ sizeof(BinDemuxContext), |
|
347 |
+ xbin_probe, |
|
348 |
+ xbin_read_header, |
|
349 |
+ read_packet, |
|
350 |
+}; |
|
351 |
+#endif |
|
352 |
+ |
|
353 |
+#if CONFIG_ADF_DEMUXER |
|
354 |
+AVInputFormat ff_adf_demuxer = { |
|
355 |
+ "adf", |
|
356 |
+ NULL_IF_CONFIG_SMALL("Artworx Data Format"), |
|
357 |
+ sizeof(BinDemuxContext), |
|
358 |
+ NULL, |
|
359 |
+ adf_read_header, |
|
360 |
+ read_packet, |
|
361 |
+ .extensions = "adf", |
|
362 |
+}; |
|
363 |
+#endif |
|
364 |
+ |
|
365 |
+#if CONFIG_IDF_DEMUXER |
|
366 |
+AVInputFormat ff_idf_demuxer = { |
|
367 |
+ "idf", |
|
368 |
+ NULL_IF_CONFIG_SMALL("iCE Draw File"), |
|
369 |
+ sizeof(BinDemuxContext), |
|
370 |
+ idf_probe, |
|
371 |
+ idf_read_header, |
|
372 |
+ read_packet, |
|
373 |
+ .extensions = "idf", |
|
374 |
+}; |
|
375 |
+#endif |