annotate msnwc_tcp.c @ 6196:a2e2f11f6124 libavformat

Reindent Patch by Josh Allmann, joshua dot allmann at gmail
author mstorsjo
date Mon, 28 Jun 2010 20:37:16 +0000
parents 08cd1179a20d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3148
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
1 /*
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
2 * Copyright (C) 2008 Ramiro Polla <ramiro@lisha.ufsc.br>
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
3 *
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
4 * This file is part of FFmpeg.
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
5 *
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
10 *
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
14 * Lesser General Public License for more details.
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
15 *
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
19 */
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
20
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3148
diff changeset
21 #include "libavcodec/bytestream.h"
3148
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
22 #include "avformat.h"
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
23
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
24 #define HEADER_SIZE 24
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
25
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
26 /*
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
27 * Header structure:
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
28 * uint16_t ss; // struct size
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
29 * uint16_t width; // frame width
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
30 * uint16_t height; // frame height
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
31 * uint16_t ff; // keyframe + some other info(???)
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
32 * uint32_t size; // size of data
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
33 * uint32_t fourcc; // ML20
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
34 * uint32_t u3; // ?
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
35 * uint32_t ts; // time
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
36 */
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
37
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
38 static int msnwc_tcp_probe(AVProbeData *p)
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
39 {
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
40 int i;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
41
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
42 for(i = 0 ; i + HEADER_SIZE <= p->buf_size ; i++) {
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
43 uint16_t width, height;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
44 uint32_t fourcc;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
45 const uint8_t *bytestream = p->buf+i;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
46
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
47 if(bytestream_get_le16(&bytestream) != HEADER_SIZE)
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
48 continue;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
49 width = bytestream_get_le16(&bytestream);
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
50 height = bytestream_get_le16(&bytestream);
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
51 if(!(width==320 && height==240) && !(width==160 && height==120))
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
52 continue;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
53 bytestream += 2; // keyframe
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
54 bytestream += 4; // size
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
55 fourcc = bytestream_get_le32(&bytestream);
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
56 if(fourcc != MKTAG('M', 'L', '2', '0'))
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
57 continue;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
58
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
59 if(i) {
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
60 if(i < 14) /* starts with SwitchBoard connection info */
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
61 return AVPROBE_SCORE_MAX / 2;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
62 else /* starts in the middle of stream */
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
63 return AVPROBE_SCORE_MAX / 3;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
64 } else {
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
65 return AVPROBE_SCORE_MAX;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
66 }
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
67 }
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
68
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
69 return -1;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
70 }
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
71
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
72 static int msnwc_tcp_read_header(AVFormatContext *ctx, AVFormatParameters *ap)
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
73 {
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
74 ByteIOContext *pb = ctx->pb;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
75 AVCodecContext *codec;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
76 AVStream *st;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
77
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
78 st = av_new_stream(ctx, 0);
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
79 if(!st)
5930
08cd1179a20d Replace all remaining occurrences of AVERROR_NOMEM with
stefano
parents: 5913
diff changeset
80 return AVERROR(ENOMEM);
3148
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
81
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
82 codec = st->codec;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 3424
diff changeset
83 codec->codec_type = AVMEDIA_TYPE_VIDEO;
3148
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
84 codec->codec_id = CODEC_ID_MIMIC;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
85 codec->codec_tag = MKTAG('M', 'L', '2', '0');
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
86
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
87 av_set_pts_info(st, 32, 1, 1000);
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
88
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
89 /* Some files start with "connected\r\n\r\n".
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
90 * So skip until we find the first byte of struct size */
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
91 while(get_byte(pb) != HEADER_SIZE && !url_feof(pb));
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
92
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
93 if(url_feof(pb)) {
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
94 av_log(ctx, AV_LOG_ERROR, "Could not find valid start.");
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
95 return -1;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
96 }
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
97
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
98 return 0;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
99 }
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
100
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
101 static int msnwc_tcp_read_packet(AVFormatContext *ctx, AVPacket *pkt)
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
102 {
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
103 ByteIOContext *pb = ctx->pb;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
104 uint16_t keyframe;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
105 uint32_t size, timestamp;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
106
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
107 url_fskip(pb, 1); /* one byte has been read ahead */
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
108 url_fskip(pb, 2);
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
109 url_fskip(pb, 2);
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
110 keyframe = get_le16(pb);
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
111 size = get_le32(pb);
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
112 url_fskip(pb, 4);
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
113 url_fskip(pb, 4);
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
114 timestamp = get_le32(pb);
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
115
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
116 if(!size || av_get_packet(pb, pkt, size) != size)
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
117 return -1;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
118
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
119 url_fskip(pb, 1); /* Read ahead one byte of struct size like read_header */
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
120
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
121 pkt->pts = timestamp;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
122 pkt->dts = timestamp;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
123 pkt->stream_index = 0;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
124
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
125 /* Some aMsn generated videos (or was it Mercury Messenger?) don't set
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
126 * this bit and rely on the codec to get keyframe information */
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
127 if(keyframe&1)
5913
11bb10c37225 Replace all occurences of PKT_FLAG_KEY with AV_PKT_FLAG_KEY.
cehoyos
parents: 5910
diff changeset
128 pkt->flags |= AV_PKT_FLAG_KEY;
3148
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
129
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
130 return HEADER_SIZE + size;
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
131 }
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
132
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
133 AVInputFormat msnwc_tcp_demuxer = {
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
134 "msnwctcp",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3286
diff changeset
135 NULL_IF_CONFIG_SMALL("MSN TCP Webcam stream"),
3148
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
136 0,
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
137 msnwc_tcp_probe,
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
138 msnwc_tcp_read_header,
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
139 msnwc_tcp_read_packet,
f00aeedea66a MSN TCP Webcam stream demuxer.
ramiro
parents:
diff changeset
140 };