Originally committed as revision 12492 to svn://svn.ffmpeg.org/ffmpeg/trunk
Ramiro Polla authored on 2008/03/19 04:54:47... | ... |
@@ -249,6 +249,7 @@ Muxers/Demuxers: |
249 | 249 |
movenc.c Michael Niedermayer, Baptiste Coudurier |
250 | 250 |
mpc.c Kostya Shishkov |
251 | 251 |
mpegts* Mans Rullgard |
252 |
+ msnwc_tcp.c Ramiro Polla |
|
252 | 253 |
mtv.c Reynaldo H. Verdejo Pinochet |
253 | 254 |
mxf.c Baptiste Coudurier |
254 | 255 |
nsvdec.c Francois Revol |
... | ... |
@@ -102,6 +102,7 @@ OBJS-$(CONFIG_MPEGTSRAW_DEMUXER) += mpegts.o |
102 | 102 |
OBJS-$(CONFIG_MPEGTS_MUXER) += mpegtsenc.o |
103 | 103 |
OBJS-$(CONFIG_MPEGVIDEO_DEMUXER) += raw.o |
104 | 104 |
OBJS-$(CONFIG_MPJPEG_MUXER) += mpjpeg.o |
105 |
+OBJS-$(CONFIG_MSNWC_TCP_DEMUXER) += msnwc_tcp.o |
|
105 | 106 |
OBJS-$(CONFIG_MTV_DEMUXER) += mtv.o |
106 | 107 |
OBJS-$(CONFIG_MXF_DEMUXER) += mxf.o |
107 | 108 |
OBJS-$(CONFIG_NSV_DEMUXER) += nsvdec.o |
... | ... |
@@ -116,6 +116,7 @@ void av_register_all(void) |
116 | 116 |
REGISTER_DEMUXER (MPEGTSRAW, mpegtsraw); |
117 | 117 |
REGISTER_DEMUXER (MPEGVIDEO, mpegvideo); |
118 | 118 |
REGISTER_MUXER (MPJPEG, mpjpeg); |
119 |
+ REGISTER_DEMUXER (MSNWC_TCP, msnwc_tcp); |
|
119 | 120 |
REGISTER_DEMUXER (MTV, mtv); |
120 | 121 |
REGISTER_DEMUXER (MXF, mxf); |
121 | 122 |
REGISTER_DEMUXER (NSV, nsv); |
... | ... |
@@ -22,7 +22,7 @@ |
22 | 22 |
#define FFMPEG_AVFORMAT_H |
23 | 23 |
|
24 | 24 |
#define LIBAVFORMAT_VERSION_MAJOR 52 |
25 |
-#define LIBAVFORMAT_VERSION_MINOR 10 |
|
25 |
+#define LIBAVFORMAT_VERSION_MINOR 11 |
|
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,140 @@ |
0 |
+/* |
|
1 |
+ * Copyright (C) 2008 Ramiro Polla <ramiro@lisha.ufsc.br> |
|
2 |
+ * |
|
3 |
+ * This file is part of FFmpeg. |
|
4 |
+ * |
|
5 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
6 |
+ * modify it under the terms of the GNU Lesser General Public |
|
7 |
+ * License as published by the Free Software Foundation; either |
|
8 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
9 |
+ * |
|
10 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
11 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 |
+ * Lesser General Public License for more details. |
|
14 |
+ * |
|
15 |
+ * You should have received a copy of the GNU Lesser General Public |
|
16 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
17 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
18 |
+ */ |
|
19 |
+ |
|
20 |
+#include "avformat.h" |
|
21 |
+#include "bytestream.h" |
|
22 |
+ |
|
23 |
+#define HEADER_SIZE 24 |
|
24 |
+ |
|
25 |
+/* |
|
26 |
+ * Header structure: |
|
27 |
+ * uint16_t ss; // struct size |
|
28 |
+ * uint16_t width; // frame width |
|
29 |
+ * uint16_t height; // frame height |
|
30 |
+ * uint16_t ff; // keyframe + some other info(???) |
|
31 |
+ * uint32_t size; // size of data |
|
32 |
+ * uint32_t fourcc; // ML20 |
|
33 |
+ * uint32_t u3; // ? |
|
34 |
+ * uint32_t ts; // time |
|
35 |
+ */ |
|
36 |
+ |
|
37 |
+static int msnwc_tcp_probe(AVProbeData *p) |
|
38 |
+{ |
|
39 |
+ int i; |
|
40 |
+ |
|
41 |
+ for(i = 0 ; i + HEADER_SIZE <= p->buf_size ; i++) { |
|
42 |
+ uint16_t width, height; |
|
43 |
+ uint32_t fourcc; |
|
44 |
+ const uint8_t *bytestream = p->buf+i; |
|
45 |
+ |
|
46 |
+ if(bytestream_get_le16(&bytestream) != HEADER_SIZE) |
|
47 |
+ continue; |
|
48 |
+ width = bytestream_get_le16(&bytestream); |
|
49 |
+ height = bytestream_get_le16(&bytestream); |
|
50 |
+ if(!(width==320 && height==240) && !(width==160 && height==120)) |
|
51 |
+ continue; |
|
52 |
+ bytestream += 2; // keyframe |
|
53 |
+ bytestream += 4; // size |
|
54 |
+ fourcc = bytestream_get_le32(&bytestream); |
|
55 |
+ if(fourcc != MKTAG('M', 'L', '2', '0')) |
|
56 |
+ continue; |
|
57 |
+ |
|
58 |
+ if(i) { |
|
59 |
+ if(i < 14) /* starts with SwitchBoard connection info */ |
|
60 |
+ return AVPROBE_SCORE_MAX / 2; |
|
61 |
+ else /* starts in the middle of stream */ |
|
62 |
+ return AVPROBE_SCORE_MAX / 3; |
|
63 |
+ } else { |
|
64 |
+ return AVPROBE_SCORE_MAX; |
|
65 |
+ } |
|
66 |
+ } |
|
67 |
+ |
|
68 |
+ return -1; |
|
69 |
+} |
|
70 |
+ |
|
71 |
+static int msnwc_tcp_read_header(AVFormatContext *ctx, AVFormatParameters *ap) |
|
72 |
+{ |
|
73 |
+ ByteIOContext *pb = ctx->pb; |
|
74 |
+ AVCodecContext *codec; |
|
75 |
+ AVStream *st; |
|
76 |
+ |
|
77 |
+ st = av_new_stream(ctx, 0); |
|
78 |
+ if(!st) |
|
79 |
+ return AVERROR_NOMEM; |
|
80 |
+ |
|
81 |
+ codec = st->codec; |
|
82 |
+ codec->codec_type = CODEC_TYPE_VIDEO; |
|
83 |
+ codec->codec_id = CODEC_ID_MIMIC; |
|
84 |
+ codec->codec_tag = MKTAG('M', 'L', '2', '0'); |
|
85 |
+ |
|
86 |
+ av_set_pts_info(st, 32, 1, 1000); |
|
87 |
+ |
|
88 |
+ /* Some files start with "connected\r\n\r\n". |
|
89 |
+ * So skip until we find the first byte of struct size */ |
|
90 |
+ while(get_byte(pb) != HEADER_SIZE && !url_feof(pb)); |
|
91 |
+ |
|
92 |
+ if(url_feof(pb)) { |
|
93 |
+ av_log(ctx, AV_LOG_ERROR, "Could not find valid start."); |
|
94 |
+ return -1; |
|
95 |
+ } |
|
96 |
+ |
|
97 |
+ return 0; |
|
98 |
+} |
|
99 |
+ |
|
100 |
+static int msnwc_tcp_read_packet(AVFormatContext *ctx, AVPacket *pkt) |
|
101 |
+{ |
|
102 |
+ ByteIOContext *pb = ctx->pb; |
|
103 |
+ uint16_t keyframe; |
|
104 |
+ uint32_t size, timestamp; |
|
105 |
+ |
|
106 |
+ url_fskip(pb, 1); /* one byte has been read ahead */ |
|
107 |
+ url_fskip(pb, 2); |
|
108 |
+ url_fskip(pb, 2); |
|
109 |
+ keyframe = get_le16(pb); |
|
110 |
+ size = get_le32(pb); |
|
111 |
+ url_fskip(pb, 4); |
|
112 |
+ url_fskip(pb, 4); |
|
113 |
+ timestamp = get_le32(pb); |
|
114 |
+ |
|
115 |
+ if(!size || av_get_packet(pb, pkt, size) != size) |
|
116 |
+ return -1; |
|
117 |
+ |
|
118 |
+ url_fskip(pb, 1); /* Read ahead one byte of struct size like read_header */ |
|
119 |
+ |
|
120 |
+ pkt->pts = timestamp; |
|
121 |
+ pkt->dts = timestamp; |
|
122 |
+ pkt->stream_index = 0; |
|
123 |
+ |
|
124 |
+ /* Some aMsn generated videos (or was it Mercury Messenger?) don't set |
|
125 |
+ * this bit and rely on the codec to get keyframe information */ |
|
126 |
+ if(keyframe&1) |
|
127 |
+ pkt->flags |= PKT_FLAG_KEY; |
|
128 |
+ |
|
129 |
+ return HEADER_SIZE + size; |
|
130 |
+} |
|
131 |
+ |
|
132 |
+AVInputFormat msnwc_tcp_demuxer = { |
|
133 |
+ "msnwctcp", |
|
134 |
+ "MSN TCP Webcam stream", |
|
135 |
+ 0, |
|
136 |
+ msnwc_tcp_probe, |
|
137 |
+ msnwc_tcp_read_header, |
|
138 |
+ msnwc_tcp_read_packet, |
|
139 |
+}; |