Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 167 lines (143 sloc) 5.026 kb
5a71709 Tele-typewriter demuxer
Peter Ross authored
1 /*
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
07e6384 Add doxygen @file comment block
Peter Ross authored
22 /**
23 * @file
24 * Tele-typewriter demuxer
25 */
26
5a71709 Tele-typewriter demuxer
Peter Ross authored
27 #include "libavutil/intreadwrite.h"
28 #include "libavutil/avstring.h"
67540af @elenril tty: replace AVFormatParameters.sample_rate abuse with a private option.
elenril authored
29 #include "libavutil/log.h"
d2d67e4 @elenril Remove all uses of now deprecated metadata functions.
elenril authored
30 #include "libavutil/dict.h"
67540af @elenril tty: replace AVFormatParameters.sample_rate abuse with a private option.
elenril authored
31 #include "libavutil/opt.h"
06d8c9e @elenril tty: add video_size private option.
elenril authored
32 #include "libavutil/parseutils.h"
5a71709 Tele-typewriter demuxer
Peter Ross authored
33 #include "avformat.h"
c3f9ebf @elenril lavf: make av_set_pts_info private.
elenril authored
34 #include "internal.h"
5a71709 Tele-typewriter demuxer
Peter Ross authored
35 #include "sauce.h"
36
37 typedef struct {
67540af @elenril tty: replace AVFormatParameters.sample_rate abuse with a private option.
elenril authored
38 AVClass *class;
5a71709 Tele-typewriter demuxer
Peter Ross authored
39 int chars_per_frame;
a20df85 @michaelni Fix doxy that refers to the wrong variable.
michaelni authored
40 uint64_t fsize; /**< file size less metadata buffer */
06d8c9e @elenril tty: add video_size private option.
elenril authored
41 char *video_size;/**< A string describing video size, set by a private option. */
c1dcbfd @elenril tty: add framerate private option.
elenril authored
42 char *framerate; /**< Set by a private option. */
5a71709 Tele-typewriter demuxer
Peter Ross authored
43 } TtyDemuxContext;
44
45 /**
46 * Parse EFI header
47 */
48 static int efi_read(AVFormatContext *avctx, uint64_t start_pos)
49 {
50 TtyDemuxContext *s = avctx->priv_data;
471fe57 @elenril avio: rename ByteIOContext to AVIOContext.
elenril authored
51 AVIOContext *pb = avctx->pb;
5a71709 Tele-typewriter demuxer
Peter Ross authored
52 char buf[37];
53 int len;
54
f59d8ff @elenril avio: avio_ prefix for url_fseek
elenril authored
55 avio_seek(pb, start_pos, SEEK_SET);
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
56 if (avio_r8(pb) != 0x1A)
5a71709 Tele-typewriter demuxer
Peter Ross authored
57 return -1;
58
59 #define GET_EFI_META(name,size) \
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
60 len = avio_r8(pb); \
5a71709 Tele-typewriter demuxer
Peter Ross authored
61 if (len < 1 || len > size) \
62 return -1; \
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
63 if (avio_read(pb, buf, size) == size) { \
5a71709 Tele-typewriter demuxer
Peter Ross authored
64 buf[len] = 0; \
d2d67e4 @elenril Remove all uses of now deprecated metadata functions.
elenril authored
65 av_dict_set(&avctx->metadata, name, buf, 0); \
5a71709 Tele-typewriter demuxer
Peter Ross authored
66 }
67
68 GET_EFI_META("filename", 12)
69 GET_EFI_META("title", 36)
70
71 s->fsize = start_pos;
72 return 0;
73 }
74
6e9651d @elenril lavf: remove AVFormatParameters from AVFormatContext.read_header sign…
elenril authored
75 static int read_header(AVFormatContext *avctx)
5a71709 Tele-typewriter demuxer
Peter Ross authored
76 {
77 TtyDemuxContext *s = avctx->priv_data;
8346f60 @elenril tty: factorise returning error codes.
elenril authored
78 int width = 0, height = 0, ret = 0;
3b3bbdd @elenril lavf,lavd: replace av_new_stream->avformat_new_stream part I.
elenril authored
79 AVStream *st = avformat_new_stream(avctx, NULL);
c1dcbfd @elenril tty: add framerate private option.
elenril authored
80 AVRational framerate;
8346f60 @elenril tty: factorise returning error codes.
elenril authored
81
82 if (!st) {
83 ret = AVERROR(ENOMEM);
84 goto fail;
85 }
5a71709 Tele-typewriter demuxer
Peter Ross authored
86 st->codec->codec_tag = 0;
b9f9e59 Replace deprecated CODEC_TYPE_AUDIO and CODEC_TYPE_VIDEO with the
Stefano Sabatini authored
87 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
5a71709 Tele-typewriter demuxer
Peter Ross authored
88 st->codec->codec_id = CODEC_ID_ANSI;
06d8c9e @elenril tty: add video_size private option.
elenril authored
89
8346f60 @elenril tty: factorise returning error codes.
elenril authored
90 if (s->video_size && (ret = av_parse_video_size(&width, &height, s->video_size)) < 0) {
91 av_log (avctx, AV_LOG_ERROR, "Couldn't parse video size.\n");
92 goto fail;
06d8c9e @elenril tty: add video_size private option.
elenril authored
93 }
c1dcbfd @elenril tty: add framerate private option.
elenril authored
94 if ((ret = av_parse_video_rate(&framerate, s->framerate)) < 0) {
95 av_log(avctx, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s->framerate);
96 goto fail;
97 }
06d8c9e @elenril tty: add video_size private option.
elenril authored
98 st->codec->width = width;
99 st->codec->height = height;
c3f9ebf @elenril lavf: make av_set_pts_info private.
elenril authored
100 avpriv_set_pts_info(st, 60, framerate.den, framerate.num);
5a71709 Tele-typewriter demuxer
Peter Ross authored
101
102 /* simulate tty display speed */
67540af @elenril tty: replace AVFormatParameters.sample_rate abuse with a private option.
elenril authored
103 s->chars_per_frame = FFMAX(av_q2d(st->time_base)*s->chars_per_frame, 1);
5a71709 Tele-typewriter demuxer
Peter Ross authored
104
8978fed @elenril avio: introduce an AVIOContext.seekable field
elenril authored
105 if (avctx->pb->seekable) {
db44ea9 @elenril avio: avio_ prefix for url_fsize
elenril authored
106 s->fsize = avio_size(avctx->pb);
5a71709 Tele-typewriter demuxer
Peter Ross authored
107 st->duration = (s->fsize + s->chars_per_frame - 1) / s->chars_per_frame;
108
109 if (ff_sauce_read(avctx, &s->fsize, 0, 0) < 0)
110 efi_read(avctx, s->fsize - 51);
111
f59d8ff @elenril avio: avio_ prefix for url_fseek
elenril authored
112 avio_seek(avctx->pb, 0, SEEK_SET);
5a71709 Tele-typewriter demuxer
Peter Ross authored
113 }
114
8346f60 @elenril tty: factorise returning error codes.
elenril authored
115 fail:
116 return ret;
5a71709 Tele-typewriter demuxer
Peter Ross authored
117 }
118
119 static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
120 {
121 TtyDemuxContext *s = avctx->priv_data;
122 int n;
123
124 if (url_feof(avctx->pb))
125 return AVERROR_EOF;
126
127 n = s->chars_per_frame;
128 if (s->fsize) {
129 // ignore metadata buffer
384c9c2 @elenril avio: add avio_tell macro as a replacement for url_ftell
elenril authored
130 uint64_t p = avio_tell(avctx->pb);
5a71709 Tele-typewriter demuxer
Peter Ross authored
131 if (p + s->chars_per_frame > s->fsize)
132 n = s->fsize - p;
133 }
134
135 pkt->size = av_get_packet(avctx->pb, pkt, n);
136 if (pkt->size <= 0)
137 return AVERROR(EIO);
d947bce @elenril tty.c: rename PKT_FLAG_KEY to AV_PKT_FLAG_KEY.
elenril authored
138 pkt->flags |= AV_PKT_FLAG_KEY;
5a71709 Tele-typewriter demuxer
Peter Ross authored
139 return 0;
140 }
141
06d8c9e @elenril tty: add video_size private option.
elenril authored
142 #define OFFSET(x) offsetof(TtyDemuxContext, x)
143 #define DEC AV_OPT_FLAG_DECODING_PARAM
67540af @elenril tty: replace AVFormatParameters.sample_rate abuse with a private option.
elenril authored
144 static const AVOption options[] = {
145f741 @elenril AVOptions: rename FF_OPT_TYPE_* => AV_OPT_TYPE_*
elenril authored
145 { "chars_per_frame", "", offsetof(TtyDemuxContext, chars_per_frame), AV_OPT_TYPE_INT, {.dbl = 6000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM},
146 { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
147 { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
67540af @elenril tty: replace AVFormatParameters.sample_rate abuse with a private option.
elenril authored
148 { NULL },
149 };
150
151 static const AVClass tty_demuxer_class = {
152 .class_name = "TTY demuxer",
153 .item_name = av_default_item_name,
154 .option = options,
155 .version = LIBAVUTIL_VERSION_INT,
156 };
157
66355be @Flameeyes Prefix all _demuxer, _muxer, _protocol from libavformat and libavdevice.
Flameeyes authored
158 AVInputFormat ff_tty_demuxer = {
5a71709 Tele-typewriter demuxer
Peter Ross authored
159 .name = "tty",
160 .long_name = NULL_IF_CONFIG_SMALL("Tele-typewriter"),
161 .priv_data_size = sizeof(TtyDemuxContext),
162 .read_header = read_header,
163 .read_packet = read_packet,
164 .extensions = "ans,art,asc,diz,ice,nfo,txt,vt",
67540af @elenril tty: replace AVFormatParameters.sample_rate abuse with a private option.
elenril authored
165 .priv_class = &tty_demuxer_class,
5a71709 Tele-typewriter demuxer
Peter Ross authored
166 };
Something went wrong with that request. Please try again.