Originally committed as revision 24301 to svn://svn.ffmpeg.org/ffmpeg/trunk
Peter Ross authored on 2010/07/18 17:06:55... | ... |
@@ -228,6 +228,7 @@ library: |
228 | 228 |
@item Sony Wave64 (W64) @tab @tab X |
229 | 229 |
@item SoX native format @tab X @tab X |
230 | 230 |
@item SUN AU format @tab X @tab X |
231 |
+@item Text files @tab @tab X |
|
231 | 232 |
@item THP @tab @tab X |
232 | 233 |
@tab Used on the Nintendo GameCube. |
233 | 234 |
@item Tiertex Limited SEQ @tab @tab X |
... | ... |
@@ -316,6 +317,7 @@ following image formats are supported: |
316 | 316 |
@tab Used in games like Mad Dog McCree. |
317 | 317 |
@item AMV Video @tab @tab X |
318 | 318 |
@tab Used in Chinese MP3 players. |
319 |
+@item ANSI/ASCII art @tab @tab X |
|
319 | 320 |
@item Apple MJPEG-B @tab @tab X |
320 | 321 |
@item Apple QuickDraw @tab @tab X |
321 | 322 |
@tab fourcc: qdrw |
... | ... |
@@ -249,6 +249,7 @@ OBJS-$(CONFIG_TMV_DEMUXER) += tmv.o |
249 | 249 |
OBJS-$(CONFIG_TRUEHD_DEMUXER) += raw.o |
250 | 250 |
OBJS-$(CONFIG_TRUEHD_MUXER) += raw.o |
251 | 251 |
OBJS-$(CONFIG_TTA_DEMUXER) += tta.o id3v1.o id3v2.o |
252 |
+OBJS-$(CONFIG_TTY_DEMUXER) += tty.o sauce.o |
|
252 | 253 |
OBJS-$(CONFIG_TXD_DEMUXER) += txd.o |
253 | 254 |
OBJS-$(CONFIG_VC1_DEMUXER) += raw.o |
254 | 255 |
OBJS-$(CONFIG_VC1T_DEMUXER) += vc1test.o |
... | ... |
@@ -198,6 +198,7 @@ void av_register_all(void) |
198 | 198 |
REGISTER_MUXDEMUX (TRUEHD, truehd); |
199 | 199 |
REGISTER_DEMUXER (TTA, tta); |
200 | 200 |
REGISTER_DEMUXER (TXD, txd); |
201 |
+ REGISTER_DEMUXER (TTY, tty); |
|
201 | 202 |
REGISTER_DEMUXER (VC1, vc1); |
202 | 203 |
REGISTER_MUXDEMUX (VC1T, vc1t); |
203 | 204 |
REGISTER_DEMUXER (VMD, vmd); |
... | ... |
@@ -22,7 +22,7 @@ |
22 | 22 |
#define AVFORMAT_AVFORMAT_H |
23 | 23 |
|
24 | 24 |
#define LIBAVFORMAT_VERSION_MAJOR 52 |
25 |
-#define LIBAVFORMAT_VERSION_MINOR 74 |
|
25 |
+#define LIBAVFORMAT_VERSION_MINOR 75 |
|
26 | 26 |
#define LIBAVFORMAT_VERSION_MICRO 0 |
27 | 27 |
|
28 | 28 |
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |
29 | 29 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,131 @@ |
0 |
+/* |
|
1 |
+ * @file |
|
2 |
+ * Tele-typewriter demuxer |
|
3 |
+ * Copyright (c) 2010 Peter Ross <pross@xvid.org> |
|
4 |
+ * |
|
5 |
+ * This file is part of FFmpeg. |
|
6 |
+ * |
|
7 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
8 |
+ * modify it under the terms of the GNU Lesser General Public |
|
9 |
+ * License as published by the Free Software Foundation; either |
|
10 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
11 |
+ * |
|
12 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
13 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 |
+ * Lesser General Public License for more details. |
|
16 |
+ * |
|
17 |
+ * You should have received a copy of the GNU Lesser General Public |
|
18 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
19 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
20 |
+ */ |
|
21 |
+ |
|
22 |
+#include "libavutil/intreadwrite.h" |
|
23 |
+#include "libavutil/avstring.h" |
|
24 |
+#include "avformat.h" |
|
25 |
+#include "sauce.h" |
|
26 |
+#include <strings.h> |
|
27 |
+ |
|
28 |
+#define LINE_RATE 6000 /* characters per second */ |
|
29 |
+ |
|
30 |
+typedef struct { |
|
31 |
+ int chars_per_frame; |
|
32 |
+ uint64_t fsize; /** file size less metadata buffer */ |
|
33 |
+} TtyDemuxContext; |
|
34 |
+ |
|
35 |
+/** |
|
36 |
+ * Parse EFI header |
|
37 |
+ */ |
|
38 |
+static int efi_read(AVFormatContext *avctx, uint64_t start_pos) |
|
39 |
+{ |
|
40 |
+ TtyDemuxContext *s = avctx->priv_data; |
|
41 |
+ ByteIOContext *pb = avctx->pb; |
|
42 |
+ char buf[37]; |
|
43 |
+ int len; |
|
44 |
+ |
|
45 |
+ url_fseek(pb, start_pos, SEEK_SET); |
|
46 |
+ if (get_byte(pb) != 0x1A) |
|
47 |
+ return -1; |
|
48 |
+ |
|
49 |
+#define GET_EFI_META(name,size) \ |
|
50 |
+ len = get_byte(pb); \ |
|
51 |
+ if (len < 1 || len > size) \ |
|
52 |
+ return -1; \ |
|
53 |
+ if (get_buffer(pb, buf, size) == size) { \ |
|
54 |
+ buf[len] = 0; \ |
|
55 |
+ av_metadata_set2(&avctx->metadata, name, buf, 0); \ |
|
56 |
+ } |
|
57 |
+ |
|
58 |
+ GET_EFI_META("filename", 12) |
|
59 |
+ GET_EFI_META("title", 36) |
|
60 |
+ |
|
61 |
+ s->fsize = start_pos; |
|
62 |
+ return 0; |
|
63 |
+} |
|
64 |
+ |
|
65 |
+static int read_header(AVFormatContext *avctx, |
|
66 |
+ AVFormatParameters *ap) |
|
67 |
+{ |
|
68 |
+ TtyDemuxContext *s = avctx->priv_data; |
|
69 |
+ AVStream *st = av_new_stream(avctx, 0); |
|
70 |
+ if (!st) |
|
71 |
+ return AVERROR(ENOMEM); |
|
72 |
+ st->codec->codec_tag = 0; |
|
73 |
+ st->codec->codec_type = CODEC_TYPE_VIDEO; |
|
74 |
+ st->codec->codec_id = CODEC_ID_ANSI; |
|
75 |
+ if (ap->width) st->codec->width = ap->width; |
|
76 |
+ if (ap->height) st->codec->height = ap->height; |
|
77 |
+ |
|
78 |
+ if (!ap->time_base.num) { |
|
79 |
+ av_set_pts_info(st, 60, 1, 25); |
|
80 |
+ } else { |
|
81 |
+ av_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den); |
|
82 |
+ } |
|
83 |
+ |
|
84 |
+ /* simulate tty display speed */ |
|
85 |
+ s->chars_per_frame = FFMAX(av_q2d(st->time_base) * (ap->sample_rate ? ap->sample_rate : LINE_RATE), 1); |
|
86 |
+ |
|
87 |
+ if (!url_is_streamed(avctx->pb)) { |
|
88 |
+ s->fsize = url_fsize(avctx->pb); |
|
89 |
+ st->duration = (s->fsize + s->chars_per_frame - 1) / s->chars_per_frame; |
|
90 |
+ |
|
91 |
+ if (ff_sauce_read(avctx, &s->fsize, 0, 0) < 0) |
|
92 |
+ efi_read(avctx, s->fsize - 51); |
|
93 |
+ |
|
94 |
+ url_fseek(avctx->pb, 0, SEEK_SET); |
|
95 |
+ } |
|
96 |
+ |
|
97 |
+ return 0; |
|
98 |
+} |
|
99 |
+ |
|
100 |
+static int read_packet(AVFormatContext *avctx, AVPacket *pkt) |
|
101 |
+{ |
|
102 |
+ TtyDemuxContext *s = avctx->priv_data; |
|
103 |
+ int n; |
|
104 |
+ |
|
105 |
+ if (url_feof(avctx->pb)) |
|
106 |
+ return AVERROR_EOF; |
|
107 |
+ |
|
108 |
+ n = s->chars_per_frame; |
|
109 |
+ if (s->fsize) { |
|
110 |
+ // ignore metadata buffer |
|
111 |
+ uint64_t p = url_ftell(avctx->pb); |
|
112 |
+ if (p + s->chars_per_frame > s->fsize) |
|
113 |
+ n = s->fsize - p; |
|
114 |
+ } |
|
115 |
+ |
|
116 |
+ pkt->size = av_get_packet(avctx->pb, pkt, n); |
|
117 |
+ if (pkt->size <= 0) |
|
118 |
+ return AVERROR(EIO); |
|
119 |
+ pkt->flags |= PKT_FLAG_KEY; |
|
120 |
+ return 0; |
|
121 |
+} |
|
122 |
+ |
|
123 |
+AVInputFormat tty_demuxer = { |
|
124 |
+ .name = "tty", |
|
125 |
+ .long_name = NULL_IF_CONFIG_SMALL("Tele-typewriter"), |
|
126 |
+ .priv_data_size = sizeof(TtyDemuxContext), |
|
127 |
+ .read_header = read_header, |
|
128 |
+ .read_packet = read_packet, |
|
129 |
+ .extensions = "ans,art,asc,diz,ice,nfo,txt,vt", |
|
130 |
+}; |