annotate tty.c @ 6326:a7040617f568 libavformat

Document existing rules for AVInputFormat.name.
author alexc
date Tue, 27 Jul 2010 14:13:24 +0000
parents 5f0bde61870e
children c4ff37db69e1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6271
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
1 /*
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
2 * Tele-typewriter demuxer
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
3 * Copyright (c) 2010 Peter Ross <pross@xvid.org>
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
4 *
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
5 * This file is part of FFmpeg.
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
6 *
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
11 *
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
15 * Lesser General Public License for more details.
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
16 *
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
20 */
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
21
6278
5f0bde61870e Add doxygen @file comment block
pross
parents: 6271
diff changeset
22 /**
5f0bde61870e Add doxygen @file comment block
pross
parents: 6271
diff changeset
23 * @file
5f0bde61870e Add doxygen @file comment block
pross
parents: 6271
diff changeset
24 * Tele-typewriter demuxer
5f0bde61870e Add doxygen @file comment block
pross
parents: 6271
diff changeset
25 */
5f0bde61870e Add doxygen @file comment block
pross
parents: 6271
diff changeset
26
6271
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
27 #include "libavutil/intreadwrite.h"
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
28 #include "libavutil/avstring.h"
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
29 #include "avformat.h"
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
30 #include "sauce.h"
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
31 #include <strings.h>
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
32
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
33 #define LINE_RATE 6000 /* characters per second */
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
34
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
35 typedef struct {
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
36 int chars_per_frame;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
37 uint64_t fsize; /** file size less metadata buffer */
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
38 } TtyDemuxContext;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
39
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
40 /**
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
41 * Parse EFI header
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
42 */
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
43 static int efi_read(AVFormatContext *avctx, uint64_t start_pos)
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
44 {
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
45 TtyDemuxContext *s = avctx->priv_data;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
46 ByteIOContext *pb = avctx->pb;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
47 char buf[37];
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
48 int len;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
49
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
50 url_fseek(pb, start_pos, SEEK_SET);
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
51 if (get_byte(pb) != 0x1A)
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
52 return -1;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
53
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
54 #define GET_EFI_META(name,size) \
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
55 len = get_byte(pb); \
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
56 if (len < 1 || len > size) \
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
57 return -1; \
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
58 if (get_buffer(pb, buf, size) == size) { \
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
59 buf[len] = 0; \
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
60 av_metadata_set2(&avctx->metadata, name, buf, 0); \
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
61 }
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
62
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
63 GET_EFI_META("filename", 12)
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
64 GET_EFI_META("title", 36)
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
65
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
66 s->fsize = start_pos;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
67 return 0;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
68 }
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
69
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
70 static int read_header(AVFormatContext *avctx,
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
71 AVFormatParameters *ap)
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
72 {
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
73 TtyDemuxContext *s = avctx->priv_data;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
74 AVStream *st = av_new_stream(avctx, 0);
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
75 if (!st)
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
76 return AVERROR(ENOMEM);
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
77 st->codec->codec_tag = 0;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
78 st->codec->codec_type = CODEC_TYPE_VIDEO;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
79 st->codec->codec_id = CODEC_ID_ANSI;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
80 if (ap->width) st->codec->width = ap->width;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
81 if (ap->height) st->codec->height = ap->height;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
82
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
83 if (!ap->time_base.num) {
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
84 av_set_pts_info(st, 60, 1, 25);
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
85 } else {
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
86 av_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den);
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
87 }
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
88
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
89 /* simulate tty display speed */
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
90 s->chars_per_frame = FFMAX(av_q2d(st->time_base) * (ap->sample_rate ? ap->sample_rate : LINE_RATE), 1);
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
91
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
92 if (!url_is_streamed(avctx->pb)) {
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
93 s->fsize = url_fsize(avctx->pb);
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
94 st->duration = (s->fsize + s->chars_per_frame - 1) / s->chars_per_frame;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
95
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
96 if (ff_sauce_read(avctx, &s->fsize, 0, 0) < 0)
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
97 efi_read(avctx, s->fsize - 51);
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
98
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
99 url_fseek(avctx->pb, 0, SEEK_SET);
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
100 }
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
101
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
102 return 0;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
103 }
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
104
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
105 static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
106 {
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
107 TtyDemuxContext *s = avctx->priv_data;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
108 int n;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
109
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
110 if (url_feof(avctx->pb))
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
111 return AVERROR_EOF;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
112
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
113 n = s->chars_per_frame;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
114 if (s->fsize) {
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
115 // ignore metadata buffer
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
116 uint64_t p = url_ftell(avctx->pb);
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
117 if (p + s->chars_per_frame > s->fsize)
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
118 n = s->fsize - p;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
119 }
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
120
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
121 pkt->size = av_get_packet(avctx->pb, pkt, n);
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
122 if (pkt->size <= 0)
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
123 return AVERROR(EIO);
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
124 pkt->flags |= PKT_FLAG_KEY;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
125 return 0;
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
126 }
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
127
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
128 AVInputFormat tty_demuxer = {
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
129 .name = "tty",
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
130 .long_name = NULL_IF_CONFIG_SMALL("Tele-typewriter"),
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
131 .priv_data_size = sizeof(TtyDemuxContext),
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
132 .read_header = read_header,
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
133 .read_packet = read_packet,
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
134 .extensions = "ans,art,asc,diz,ice,nfo,txt,vt",
21b8d2334030 Tele-typewriter demuxer
pross
parents:
diff changeset
135 };