224
|
225
|
new file mode 100644
|
...
|
...
|
@@ -0,0 +1,551 @@
|
|
0
|
+/*
|
|
1
|
+ * Windows Television (WTV) demuxer
|
|
2
|
+ * Copyright (c) 2010 Peter Ross <pross@xvid.org>
|
|
3
|
+ *
|
|
4
|
+ * This file is part of FFmpeg.
|
|
5
|
+ *
|
|
6
|
+ * FFmpeg is free software; you can redistribute it and/or
|
|
7
|
+ * modify it under the terms of the GNU Lesser General Public
|
|
8
|
+ * License as published by the Free Software Foundation; either
|
|
9
|
+ * version 2.1 of the License, or (at your option) any later version.
|
|
10
|
+ *
|
|
11
|
+ * FFmpeg is distributed in the hope that it will be useful,
|
|
12
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14
|
+ * Lesser General Public License for more details.
|
|
15
|
+ *
|
|
16
|
+ * You should have received a copy of the GNU Lesser General Public
|
|
17
|
+ * License along with FFmpeg; if not, write to the Free Software
|
|
18
|
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19
|
+ */
|
|
20
|
+
|
|
21
|
+/**
|
|
22
|
+ * @file
|
|
23
|
+ * Windows Television (WTV) demuxer
|
|
24
|
+ * @author Peter Ross <pross@xvid.org>
|
|
25
|
+ */
|
|
26
|
+
|
|
27
|
+#include "libavutil/intreadwrite.h"
|
|
28
|
+#include "avformat.h"
|
|
29
|
+#include "riff.h"
|
|
30
|
+#include "asf.h"
|
|
31
|
+
|
|
32
|
+/* Macros for formating GUIDs */
|
|
33
|
+#define PRI_GUID \
|
|
34
|
+ "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
|
|
35
|
+#define ARG_GUID(g) \
|
|
36
|
+ g[0],g[1],g[2],g[3],g[4],g[5],g[6],g[7],g[8],g[9],g[10],g[11],g[12],g[13],g[14],g[15]
|
|
37
|
+
|
|
38
|
+typedef struct WtvContext {
|
|
39
|
+ uint64_t pts;
|
|
40
|
+} WtvContext;
|
|
41
|
+
|
|
42
|
+static int is_zero(uint8_t *v, int n)
|
|
43
|
+{
|
|
44
|
+ int i;
|
|
45
|
+ for (i = 0; i < n; i++)
|
|
46
|
+ if (v[i]) return 0;
|
|
47
|
+ return 1;
|
|
48
|
+}
|
|
49
|
+
|
|
50
|
+typedef struct {
|
|
51
|
+ enum CodecID id;
|
|
52
|
+ ff_asf_guid guid;
|
|
53
|
+} AVCodecGuid;
|
|
54
|
+
|
|
55
|
+static enum CodecID ff_codec_guid_get_id(const AVCodecGuid *guids, ff_asf_guid guid)
|
|
56
|
+{
|
|
57
|
+ int i;
|
|
58
|
+ for (i = 0; guids[i].id != CODEC_ID_NONE; i++) {
|
|
59
|
+ if (!ff_guidcmp(guids[i].guid, guid))
|
|
60
|
+ return guids[i].id;
|
|
61
|
+ }
|
|
62
|
+ return CODEC_ID_NONE;
|
|
63
|
+}
|
|
64
|
+
|
|
65
|
+/* WTV GUIDs */
|
|
66
|
+static const ff_asf_guid wtv_guid =
|
|
67
|
+ {0xB7,0xD8,0x00,0x20,0x37,0x49,0xDA,0x11,0xA6,0x4E,0x00,0x07,0xE9,0x5E,0xAD,0x8D};
|
|
68
|
+static const ff_asf_guid meta_guid =
|
|
69
|
+ {0x5A,0xFE,0xD7,0x6D,0xC8,0x1D,0x8F,0x4A,0x99,0x22,0xFA,0xB1,0x1C,0x38,0x14,0x53};
|
|
70
|
+static const ff_asf_guid timestamp_guid =
|
|
71
|
+ {0x5B,0x05,0xE6,0x1B,0x97,0xA9,0x49,0x43,0x88,0x17,0x1A,0x65,0x5A,0x29,0x8A,0x97};
|
|
72
|
+static const ff_asf_guid data_guid =
|
|
73
|
+ {0x95,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D};
|
|
74
|
+static const ff_asf_guid stream_guid =
|
|
75
|
+ {0xED,0xA4,0x13,0x23,0x2D,0xBF,0x4F,0x45,0xAD,0x8A,0xD9,0x5B,0xA7,0xF9,0x1F,0xEE};
|
|
76
|
+static const ff_asf_guid subtitle_guid =
|
|
77
|
+ {0x48,0xC0,0xCE,0x5D,0xB9,0xD0,0x63,0x41,0x87,0x2C,0x4F,0x32,0x22,0x3B,0xE8,0x8A};
|
|
78
|
+static const ff_asf_guid language_guid =
|
|
79
|
+ {0x6D,0x66,0x92,0xE2,0x02,0x9C,0x8D,0x44,0xAA,0x8D,0x78,0x1A,0x93,0xFD,0xC3,0x95};
|
|
80
|
+
|
|
81
|
+/* Windows media GUIDs */
|
|
82
|
+
|
|
83
|
+#define MEDIASUBTYPE_BASE_GUID \
|
|
84
|
+ 0x00,0x00,0x10,0x00,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71
|
|
85
|
+
|
|
86
|
+/* Media types */
|
|
87
|
+static const ff_asf_guid mediatype_audio =
|
|
88
|
+ {'a','u','d','s',MEDIASUBTYPE_BASE_GUID};
|
|
89
|
+static const ff_asf_guid mediatype_video =
|
|
90
|
+ {'v','i','d','s',MEDIASUBTYPE_BASE_GUID};
|
|
91
|
+static const ff_asf_guid mediasubtype_mpeg1payload =
|
|
92
|
+ {0x81,0xEB,0x36,0xE4,0x4F,0x52,0xCE,0x11,0x9F,0x53,0x00,0x20,0xAF,0x0B,0xA7,0x70};
|
|
93
|
+static const ff_asf_guid mediatype_mpeg2_sections =
|
|
94
|
+ {0x6C,0x17,0x5F,0x45,0x06,0x4B,0xCE,0x47,0x9A,0xEF,0x8C,0xAE,0xF7,0x3D,0xF7,0xB5};
|
|
95
|
+static const ff_asf_guid mediatype_mpeg2_pes =
|
|
96
|
+ {0x20,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA};
|
|
97
|
+static const ff_asf_guid mediatype_mstvcaption =
|
|
98
|
+ {0x89,0x8A,0x8B,0xB8,0x49,0xB0,0x80,0x4C,0xAD,0xCF,0x58,0x98,0x98,0x5E,0x22,0xC1};
|
|
99
|
+
|
|
100
|
+/* Media subtypes */
|
|
101
|
+static const ff_asf_guid mediasubtype_cpfilters_processed =
|
|
102
|
+ {0x28,0xBD,0xAD,0x46,0xD0,0x6F,0x96,0x47,0x93,0xB2,0x15,0x5C,0x51,0xDC,0x04,0x8D};
|
|
103
|
+static const ff_asf_guid mediasubtype_dvb_subtitle =
|
|
104
|
+ {0xC3,0xCB,0xFF,0x34,0xB3,0xD5,0x71,0x41,0x90,0x02,0xD4,0xC6,0x03,0x01,0x69,0x7F};
|
|
105
|
+static const ff_asf_guid mediasubtype_teletext =
|
|
106
|
+ {0xE3,0x76,0x2A,0xF7,0x0A,0xEB,0xD0,0x11,0xAC,0xE4,0x00,0x00,0xC0,0xCC,0x16,0xBA};
|
|
107
|
+static const ff_asf_guid mediasubtype_dtvccdata =
|
|
108
|
+ {0xAA,0xDD,0x2A,0xF5,0xF0,0x36,0xF5,0x43,0x95,0xEA,0x6D,0x86,0x64,0x84,0x26,0x2A};
|
|
109
|
+static const ff_asf_guid mediasubtype_mpeg2_sections =
|
|
110
|
+ {0x79,0x85,0x9F,0x4A,0xF8,0x6B,0x92,0x43,0x8A,0x6D,0xD2,0xDD,0x09,0xFA,0x78,0x61};
|
|
111
|
+
|
|
112
|
+/* Formats */
|
|
113
|
+static const ff_asf_guid format_cpfilters_processed =
|
|
114
|
+ {0x6F,0xB3,0x39,0x67,0x5F,0x1D,0xC2,0x4A,0x81,0x92,0x28,0xBB,0x0E,0x73,0xD1,0x6A};
|
|
115
|
+static const ff_asf_guid format_waveformatex =
|
|
116
|
+ {0x81,0x9F,0x58,0x05,0x56,0xC3,0xCE,0x11,0xBF,0x01,0x00,0xAA,0x00,0x55,0x59,0x5A};
|
|
117
|
+static const ff_asf_guid format_videoinfo2 =
|
|
118
|
+ {0xA0,0x76,0x2A,0xF7,0x0A,0xEB,0xD0,0x11,0xAC,0xE4,0x00,0x00,0xC0,0xCC,0x16,0xBA};
|
|
119
|
+static const ff_asf_guid format_mpeg2_video =
|
|
120
|
+ {0xE3,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA};
|
|
121
|
+static const ff_asf_guid format_none =
|
|
122
|
+ {0xD6,0x17,0x64,0x0F,0x18,0xC3,0xD0,0x11,0xA4,0x3F,0x00,0xA0,0xC9,0x22,0x31,0x96};
|
|
123
|
+
|
|
124
|
+static const AVCodecGuid video_guids[] = {
|
|
125
|
+ {CODEC_ID_MPEG2VIDEO, {0x26,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}},
|
|
126
|
+ {CODEC_ID_NONE}
|
|
127
|
+};
|
|
128
|
+
|
|
129
|
+static const AVCodecGuid audio_guids[] = {
|
|
130
|
+ {CODEC_ID_AC3, {0x2C,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}},
|
|
131
|
+ {CODEC_ID_EAC3, {0xAF,0x87,0xFB,0xA7,0x02,0x2D,0xFB,0x42,0xA4,0xD4,0x05,0xCD,0x93,0x84,0x3B,0xDD}},
|
|
132
|
+ {CODEC_ID_MP2, {0x2B,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}},
|
|
133
|
+ {CODEC_ID_NONE}
|
|
134
|
+};
|
|
135
|
+
|
|
136
|
+static int read_probe(AVProbeData *p)
|
|
137
|
+{
|
|
138
|
+ return ff_guidcmp(p->buf, wtv_guid) ? 0 : AVPROBE_SCORE_MAX;
|
|
139
|
+}
|
|
140
|
+
|
|
141
|
+/**
|
|
142
|
+ * parse VIDEOINFOHEADER2 structure
|
|
143
|
+ * @return bytes consumed
|
|
144
|
+ */
|
|
145
|
+static int parse_videoinfoheader2(AVFormatContext *s, AVStream *st)
|
|
146
|
+{
|
|
147
|
+ ByteIOContext *pb = s->pb;
|
|
148
|
+
|
|
149
|
+ url_fskip(pb, 32);
|
|
150
|
+ st->codec->bit_rate = get_le32(pb);
|
|
151
|
+ url_fskip(pb, 20);
|
|
152
|
+ st->sample_aspect_ratio.num = get_le32(pb);
|
|
153
|
+ st->sample_aspect_ratio.den = get_le32(pb);
|
|
154
|
+ url_fskip(pb, 8);
|
|
155
|
+ ff_get_bmp_header(pb, st);
|
|
156
|
+
|
|
157
|
+ return 72 + 40;
|
|
158
|
+}
|
|
159
|
+
|
|
160
|
+/**
|
|
161
|
+ * Parse MPEG1WAVEFORMATEX extradata structure
|
|
162
|
+ */
|
|
163
|
+static void parse_mpeg1waveformatex(AVStream *st)
|
|
164
|
+{
|
|
165
|
+ /* fwHeadLayer */
|
|
166
|
+ switch (AV_RL16(st->codec->extradata)) {
|
|
167
|
+ case 0x0001 : st->codec->codec_id = CODEC_ID_MP1; break;
|
|
168
|
+ case 0x0002 : st->codec->codec_id = CODEC_ID_MP2; break;
|
|
169
|
+ case 0x0004 : st->codec->codec_id = CODEC_ID_MP3; break;
|
|
170
|
+ }
|
|
171
|
+
|
|
172
|
+ st->codec->bit_rate = AV_RL32(st->codec->extradata + 2); /* dwHeadBitrate */
|
|
173
|
+
|
|
174
|
+ /* dwHeadMode */
|
|
175
|
+ switch (AV_RL16(st->codec->extradata + 6)) {
|
|
176
|
+ case 1 : case 2 : case 4 : st->codec->channels = 2; break;
|
|
177
|
+ case 8 : st->codec->channels = 1; break;
|
|
178
|
+ }
|
|
179
|
+}
|
|
180
|
+
|
|
181
|
+static AVStream * new_stream(AVFormatContext *s, int sid, int codec_type)
|
|
182
|
+{
|
|
183
|
+ AVStream * st = av_new_stream(s, sid);
|
|
184
|
+ if (!st)
|
|
185
|
+ return NULL;
|
|
186
|
+ st->codec->codec_type = codec_type;
|
|
187
|
+ st->need_parsing = AVSTREAM_PARSE_FULL;
|
|
188
|
+ av_set_pts_info(st, 64, 1, 10000000);
|
|
189
|
+ return st;
|
|
190
|
+}
|
|
191
|
+
|
|
192
|
+/**
|
|
193
|
+ * parse Media Type structure and create new streams as required
|
|
194
|
+ * @param mediatype Mediatype GUID
|
|
195
|
+ * @param subtype Subtype GUID
|
|
196
|
+ * @param formattype Format GUID
|
|
197
|
+ * @param size Size of format buffer
|
|
198
|
+ * @return NULL on error
|
|
199
|
+ */
|
|
200
|
+static AVStream * parse_media_type(AVFormatContext *s, int sid,
|
|
201
|
+ ff_asf_guid mediatype, ff_asf_guid subtype,
|
|
202
|
+ ff_asf_guid formattype, int size)
|
|
203
|
+{
|
|
204
|
+ ByteIOContext *pb = s->pb;
|
|
205
|
+ AVStream *st;
|
|
206
|
+ if (!ff_guidcmp(subtype, mediasubtype_cpfilters_processed) &&
|
|
207
|
+ !ff_guidcmp(formattype, format_cpfilters_processed)) {
|
|
208
|
+ ff_asf_guid actual_subtype;
|
|
209
|
+ ff_asf_guid actual_formattype;
|
|
210
|
+
|
|
211
|
+ if (size < 32) {
|
|
212
|
+ av_log(s, AV_LOG_WARNING, "format buffer size underflow\n");
|
|
213
|
+ url_fskip(pb, size);
|
|
214
|
+ return NULL;
|
|
215
|
+ }
|
|
216
|
+
|
|
217
|
+ url_fskip(pb, size - 32);
|
|
218
|
+ ff_get_guid(pb, &actual_subtype);
|
|
219
|
+ ff_get_guid(pb, &actual_formattype);
|
|
220
|
+ url_fseek(pb, -size, SEEK_CUR);
|
|
221
|
+
|
|
222
|
+ st = parse_media_type(s, sid, mediatype, actual_subtype, actual_formattype, size - 32);
|
|
223
|
+ url_fskip(pb, 32);
|
|
224
|
+ return st;
|
|
225
|
+ } else if (!ff_guidcmp(mediatype, mediatype_audio)) {
|
|
226
|
+ st = new_stream(s, sid, AVMEDIA_TYPE_AUDIO);
|
|
227
|
+ if (!st)
|
|
228
|
+ return NULL;
|
|
229
|
+ if (!ff_guidcmp(formattype, format_waveformatex)) {
|
|
230
|
+ ff_get_wav_header(pb, st->codec, size);
|
|
231
|
+ } else {
|
|
232
|
+ if (ff_guidcmp(formattype, format_none))
|
|
233
|
+ av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype));
|
|
234
|
+ url_fskip(pb, size);
|
|
235
|
+ }
|
|
236
|
+
|
|
237
|
+ if (!memcmp(subtype + 4, (const uint8_t[]){MEDIASUBTYPE_BASE_GUID}, 12)) {
|
|
238
|
+ st->codec->codec_id = ff_wav_codec_get_id(AV_RL32(subtype), st->codec->bits_per_coded_sample);
|
|
239
|
+ } else if (!ff_guidcmp(subtype, mediasubtype_mpeg1payload)) {
|
|
240
|
+ if (st->codec->extradata && st->codec->extradata_size >= 22)
|
|
241
|
+ parse_mpeg1waveformatex(st);
|
|
242
|
+ else
|
|
243
|
+ av_log(s, AV_LOG_WARNING, "MPEG1WAVEFORMATEX underflow\n");
|
|
244
|
+ } else {
|
|
245
|
+ st->codec->codec_id = ff_codec_guid_get_id(audio_guids, subtype);
|
|
246
|
+ }
|
|
247
|
+ if (st->codec->codec_id == CODEC_ID_NONE)
|
|
248
|
+ av_log(s, AV_LOG_WARNING, "unknown subtype:"PRI_GUID"\n", ARG_GUID(subtype));
|
|
249
|
+ return st;
|
|
250
|
+ } else if (!ff_guidcmp(mediatype, mediatype_video)) {
|
|
251
|
+ st = new_stream(s, sid, AVMEDIA_TYPE_VIDEO);
|
|
252
|
+ if (!st)
|
|
253
|
+ return NULL;
|
|
254
|
+ if (!ff_guidcmp(formattype, format_videoinfo2)) {
|
|
255
|
+ int consumed = parse_videoinfoheader2(s, st);
|
|
256
|
+ url_fskip(pb, FFMAX(size - consumed, 0));
|
|
257
|
+ } else if (!ff_guidcmp(formattype, format_mpeg2_video)) {
|
|
258
|
+ int consumed = parse_videoinfoheader2(s, st);
|
|
259
|
+ url_fskip(pb, FFMAX(size - consumed, 0));
|
|
260
|
+ } else {
|
|
261
|
+ if (ff_guidcmp(formattype, format_none))
|
|
262
|
+ av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype));
|
|
263
|
+ url_fskip(pb, size);
|
|
264
|
+ }
|
|
265
|
+
|
|
266
|
+ if (!memcmp(subtype + 4, (const uint8_t[]){MEDIASUBTYPE_BASE_GUID}, 12)) {
|
|
267
|
+ st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(subtype));
|
|
268
|
+ } else {
|
|
269
|
+ st->codec->codec_id = ff_codec_guid_get_id(video_guids, subtype);
|
|
270
|
+ }
|
|
271
|
+ if (st->codec->codec_id == CODEC_ID_NONE)
|
|
272
|
+ av_log(s, AV_LOG_WARNING, "unknown subtype:"PRI_GUID"\n", ARG_GUID(subtype));
|
|
273
|
+ return st;
|
|
274
|
+ } else if (!ff_guidcmp(mediatype, mediatype_mpeg2_pes) &&
|
|
275
|
+ !ff_guidcmp(subtype, mediasubtype_dvb_subtitle)) {
|
|
276
|
+ st = new_stream(s, sid, AVMEDIA_TYPE_SUBTITLE);
|
|
277
|
+ if (!st)
|
|
278
|
+ return NULL;
|
|
279
|
+ if (ff_guidcmp(formattype, format_none))
|
|
280
|
+ av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype));
|
|
281
|
+ url_fskip(pb, size);
|
|
282
|
+ st->codec->codec_id = CODEC_ID_DVB_SUBTITLE;
|
|
283
|
+ return st;
|
|
284
|
+ } else if (!ff_guidcmp(mediatype, mediatype_mstvcaption) &&
|
|
285
|
+ (!ff_guidcmp(subtype, mediasubtype_teletext) || !ff_guidcmp(subtype, mediasubtype_dtvccdata))) {
|
|
286
|
+ st = new_stream(s, sid, AVMEDIA_TYPE_SUBTITLE);
|
|
287
|
+ if (!st)
|
|
288
|
+ return NULL;
|
|
289
|
+ if (ff_guidcmp(formattype, format_none))
|
|
290
|
+ av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype));
|
|
291
|
+ url_fskip(pb, size);
|
|
292
|
+ st->codec->codec_id = CODEC_ID_DVB_TELETEXT;
|
|
293
|
+ return st;
|
|
294
|
+ } else if (!ff_guidcmp(mediatype, mediatype_mpeg2_sections) &&
|
|
295
|
+ !ff_guidcmp(subtype, mediasubtype_mpeg2_sections)) {
|
|
296
|
+ if (ff_guidcmp(formattype, format_none))
|
|
297
|
+ av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype));
|
|
298
|
+ url_fskip(pb, size);
|
|
299
|
+ return NULL;
|
|
300
|
+ }
|
|
301
|
+
|
|
302
|
+ av_log(s, AV_LOG_WARNING, "unknown media type, mediatype:"PRI_GUID
|
|
303
|
+ ", subtype:"PRI_GUID", formattype:"PRI_GUID"\n",
|
|
304
|
+ ARG_GUID(mediatype), ARG_GUID(subtype), ARG_GUID(formattype));
|
|
305
|
+ url_fskip(pb, size);
|
|
306
|
+ return NULL;
|
|
307
|
+}
|
|
308
|
+
|
|
309
|
+/**
|
|
310
|
+ * Read three byte language code
|
|
311
|
+ */
|
|
312
|
+static void get_language(ByteIOContext *pb, AVStream *st)
|
|
313
|
+{
|
|
314
|
+ uint8_t language[4];
|
|
315
|
+ get_buffer(pb, language, 3);
|
|
316
|
+ if (language[0]) {
|
|
317
|
+ language[3] = 0;
|
|
318
|
+ av_metadata_set2(&st->metadata, "language", language, 0);
|
|
319
|
+ }
|
|
320
|
+}
|
|
321
|
+
|
|
322
|
+enum {
|
|
323
|
+ SEEK_TO_DATA = 0,
|
|
324
|
+ SEEK_TO_BYTE,
|
|
325
|
+ SEEK_TO_PTS,
|
|
326
|
+};
|
|
327
|
+
|
|
328
|
+/**
|
|
329
|
+ * Parse WTV chunks
|
|
330
|
+ * @param mode SEEK_TO_DATA, SEEK_TO_BYTE, SEEK_TO_PTS
|
|
331
|
+ * @param seekts either byte position or timestamp
|
|
332
|
+ * @param[out] len Length of data chunk
|
|
333
|
+ * @return stream index of data chunk, or <0 on error
|
|
334
|
+ */
|
|
335
|
+static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_ptr)
|
|
336
|
+{
|
|
337
|
+ WtvContext *wtv = s->priv_data;
|
|
338
|
+ ByteIOContext *pb = s->pb;
|
|
339
|
+ while (!url_feof(pb)) {
|
|
340
|
+ ff_asf_guid g;
|
|
341
|
+ int len, sid, consumed;
|
|
342
|
+
|
|
343
|
+ if (mode == SEEK_TO_BYTE && url_ftell(pb) >= seekts)
|
|
344
|
+ return 0;
|
|
345
|
+
|
|
346
|
+ ff_get_guid(pb, &g);
|
|
347
|
+ if (is_zero(g, sizeof(ff_asf_guid)))
|
|
348
|
+ return AVERROR_EOF;
|
|
349
|
+
|
|
350
|
+ len = get_le32(pb);
|
|
351
|
+ sid = get_le32(pb) & 0x7FFF;
|
|
352
|
+ url_fskip(pb, 8);
|
|
353
|
+ consumed = 32;
|
|
354
|
+
|
|
355
|
+ if (!ff_guidcmp(g, stream_guid)) {
|
|
356
|
+ if (ff_find_stream_index(s, sid) < 0) {
|
|
357
|
+ ff_asf_guid mediatype, subtype, formattype;
|
|
358
|
+ int size;
|
|
359
|
+ consumed += 20;
|
|
360
|
+ url_fskip(pb, 16);
|
|
361
|
+ if (get_le32(pb)) {
|
|
362
|
+ url_fskip(pb, 8);
|
|
363
|
+ ff_get_guid(pb, &mediatype);
|
|
364
|
+ ff_get_guid(pb, &subtype);
|
|
365
|
+ url_fskip(pb, 12);
|
|
366
|
+ ff_get_guid(pb, &formattype);
|
|
367
|
+ size = get_le32(pb);
|
|
368
|
+ parse_media_type(s, sid, mediatype, subtype, formattype, size);
|
|
369
|
+ consumed += 72 + size;
|
|
370
|
+ }
|
|
371
|
+ }
|
|
372
|
+ } else if (!ff_guidcmp(g, subtitle_guid)) {
|
|
373
|
+ int stream_index = ff_find_stream_index(s, sid);
|
|
374
|
+ if (stream_index >= 0) {
|
|
375
|
+ AVStream *st = s->streams[stream_index];
|
|
376
|
+
|
|
377
|
+ url_fskip(pb, 10);
|
|
378
|
+ get_language(pb, st);
|
|
379
|
+ url_fskip(pb, 1);
|
|
380
|
+
|
|
381
|
+ st->codec->extradata = av_malloc(4);
|
|
382
|
+ if (!st->codec->extradata)
|
|
383
|
+ return AVERROR(ENOMEM);
|
|
384
|
+ st->codec->extradata_size = get_buffer(pb, st->codec->extradata, 4);
|
|
385
|
+ consumed += 18;
|
|
386
|
+ }
|
|
387
|
+ } else if (!ff_guidcmp(g, language_guid)) {
|
|
388
|
+ int stream_index = ff_find_stream_index(s, sid);
|
|
389
|
+ if (stream_index >= 0) {
|
|
390
|
+ AVStream *st = s->streams[stream_index];
|
|
391
|
+ url_fskip(pb, 12);
|
|
392
|
+ get_language(pb, st);
|
|
393
|
+ consumed += 15;
|
|
394
|
+ }
|
|
395
|
+ } else if (!ff_guidcmp(g, timestamp_guid)) {
|
|
396
|
+ url_fskip(pb, 8);
|
|
397
|
+ wtv->pts = get_le64(pb);
|
|
398
|
+ consumed += 16;
|
|
399
|
+ if (wtv->pts == -1)
|
|
400
|
+ wtv->pts = AV_NOPTS_VALUE;
|
|
401
|
+ if (mode == SEEK_TO_PTS && wtv->pts >= seekts) {
|
|
402
|
+#define WTV_PAD8(x) (((x) + 7) & ~7)
|
|
403
|
+ url_fskip(pb, WTV_PAD8(len) - consumed);
|
|
404
|
+ return 0;
|
|
405
|
+ }
|
|
406
|
+ } else if (!ff_guidcmp(g, data_guid)) {
|
|
407
|
+ int stream_index = ff_find_stream_index(s, sid);
|
|
408
|
+ if (mode == SEEK_TO_DATA && stream_index >= 0) {
|
|
409
|
+ if (len_ptr) {
|
|
410
|
+ *len_ptr = len;
|
|
411
|
+ }
|
|
412
|
+ if (wtv->pts != AV_NOPTS_VALUE)
|
|
413
|
+ av_add_index_entry(s->streams[stream_index], url_ftell(pb) - consumed, wtv->pts, 0, 0, AVINDEX_KEYFRAME);
|
|
414
|
+ return stream_index;
|
|
415
|
+ }
|
|
416
|
+ } else if (
|
|
417
|
+ !ff_guidcmp(g, /* DSATTRIB_CAPTURE_STREAMTIME */ (const ff_asf_guid){0x14,0x56,0x1A,0x0C,0xCD,0x30,0x40,0x4F,0xBC,0xBF,0xD0,0x3E,0x52,0x30,0x62,0x07}) ||
|
|
418
|
+ !ff_guidcmp(g, /* DSATTRIB_PicSampleSeq */ (const ff_asf_guid){0x02,0xAE,0x5B,0x2F,0x8F,0x7B,0x60,0x4F,0x82,0xD6,0xE4,0xEA,0x2F,0x1F,0x4C,0x99}) ||
|
|
419
|
+ !ff_guidcmp(g, /* DSATTRIB_TRANSPORT_PROPERTIES */ (const ff_asf_guid){0x12,0xF6,0x22,0xB6,0xAD,0x47,0x71,0x46,0xAD,0x6C,0x05,0xA9,0x8E,0x65,0xDE,0x3A}) ||
|
|
420
|
+ !ff_guidcmp(g, /* dvr_ms_vid_frame_rep_data */ (const ff_asf_guid){0xCC,0x32,0x64,0xDD,0x29,0xE2,0xDB,0x40,0x80,0xF6,0xD2,0x63,0x28,0xD2,0x76,0x1F}) ||
|
|
421
|
+ !ff_guidcmp(g, /* EVENTID_AudioDescriptorSpanningEvent */ (const ff_asf_guid){0x1C,0xD4,0x7B,0x10,0xDA,0xA6,0x91,0x46,0x83,0x69,0x11,0xB2,0xCD,0xAA,0x28,0x8E}) ||
|
|
422
|
+ !ff_guidcmp(g, /* EVENTID_AudioTypeSpanningEvent */ (const ff_asf_guid){0xBE,0xBF,0x1C,0x50,0x49,0xB8,0xCE,0x42,0x9B,0xE9,0x3D,0xB8,0x69,0xFB,0x82,0xB3}) ||
|
|
423
|
+ !ff_guidcmp(g, /* EVENTID_ChannelChangeSpanningEvent */ (const ff_asf_guid){0xE5,0xC5,0x67,0x90,0x5C,0x4C,0x05,0x42,0x86,0xC8,0x7A,0xFE,0x20,0xFE,0x1E,0xFA}) ||
|
|
424
|
+ !ff_guidcmp(g, /* EVENTID_ChannelInfoSpanningEvent */ (const ff_asf_guid){0x80,0x6D,0xF3,0x41,0x32,0x41,0xC2,0x4C,0xB1,0x21,0x01,0xA4,0x32,0x19,0xD8,0x1B}) ||
|
|
425
|
+ !ff_guidcmp(g, /* EVENTID_ChannelTypeSpanningEvent */ (const ff_asf_guid){0x51,0x1D,0xAB,0x72,0xD2,0x87,0x9B,0x48,0xBA,0x11,0x0E,0x08,0xDC,0x21,0x02,0x43}) ||
|
|
426
|
+ !ff_guidcmp(g, /* EVENTID_CtxADescriptorSpanningEvent */ (const ff_asf_guid){0xE6,0xA2,0xB4,0x3A,0x47,0x42,0x34,0x4B,0x89,0x6C,0x30,0xAF,0xA5,0xD2,0x1C,0x24}) ||
|
|
427
|
+ !ff_guidcmp(g, /* EVENTID_DVBScramblingControlSpanningEvent */ (const ff_asf_guid){0xC4,0xE1,0xD4,0x4B,0xA1,0x90,0x09,0x41,0x82,0x36,0x27,0xF0,0x0E,0x7D,0xCC,0x5B}) ||
|
|
428
|
+ !ff_guidcmp(g, /* EVENTID_PIDListSpanningEvent */ (const ff_asf_guid){0x65,0x8F,0xFC,0x47,0xBB,0xE2,0x34,0x46,0x9C,0xEF,0xFD,0xBF,0xE6,0x26,0x1D,0x5C}) ||
|
|
429
|
+ !ff_guidcmp(g, /* EVENTID_SignalAndServiceStatusSpanningEvent */ (const ff_asf_guid){0xCB,0xC5,0x68,0x80,0x04,0x3C,0x2B,0x49,0xB4,0x7D,0x03,0x08,0x82,0x0D,0xCE,0x51}) ||
|
|
430
|
+ !ff_guidcmp(g, /* EVENTID_StreamIDSpanningEvent */ (const ff_asf_guid){0x68,0xAB,0xF1,0xCA,0x53,0xE1,0x41,0x4D,0xA6,0xB3,0xA7,0xC9,0x98,0xDB,0x75,0xEE}) ||
|
|
431
|
+ !ff_guidcmp(g, /* EVENTID_StreamTypeSpanningEvent */ (const ff_asf_guid){0xBC,0x2E,0xAF,0x82,0xA6,0x30,0x64,0x42,0xA8,0x0B,0xAD,0x2E,0x13,0x72,0xAC,0x60}) ||
|
|
432
|
+ !ff_guidcmp(g, /* EVENTID_TeletextSpanningEvent */ (const ff_asf_guid){0x50,0xD9,0x99,0x95,0x33,0x5F,0x17,0x46,0xAF,0x7C,0x1E,0x54,0xB5,0x10,0xDA,0xA3}) ||
|
|
433
|
+ !ff_guidcmp(g, (const ff_asf_guid){0x1E,0xBE,0xC3,0xC5,0x43,0x92,0xDC,0x11,0x85,0xE5,0x00,0x12,0x3F,0x6F,0x73,0xB9}) ||
|
|
434
|
+ !ff_guidcmp(g, (const ff_asf_guid){0x3B,0x86,0xA2,0xB1,0xEB,0x1E,0xC3,0x44,0x8C,0x88,0x1C,0xA3,0xFF,0xE3,0xE7,0x6A}) ||
|
|
435
|
+ !ff_guidcmp(g, (const ff_asf_guid){0x4E,0x7F,0x4C,0x5B,0xC4,0xD0,0x38,0x4B,0xA8,0x3E,0x21,0x7F,0x7B,0xBF,0x52,0xE7}) ||
|
|
436
|
+ !ff_guidcmp(g, (const ff_asf_guid){0x63,0x36,0xEB,0xFE,0xA1,0x7E,0xD9,0x11,0x83,0x08,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) ||
|
|
437
|
+ !ff_guidcmp(g, (const ff_asf_guid){0x70,0xE9,0xF1,0xF8,0x89,0xA4,0x4C,0x4D,0x83,0x73,0xB8,0x12,0xE0,0xD5,0xF8,0x1E}) ||
|
|
438
|
+ !ff_guidcmp(g, (const ff_asf_guid){0x96,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) ||
|
|
439
|
+ !ff_guidcmp(g, (const ff_asf_guid){0x97,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) ||
|
|
440
|
+ !ff_guidcmp(g, (const ff_asf_guid){0xA1,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) ||
|
|
441
|
+ !ff_guidcmp(g, (const ff_asf_guid){0xA2,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D})) {
|
|
442
|
+ //ignore known guids
|
|
443
|
+ } else
|
|
444
|
+ av_log(s, AV_LOG_WARNING, "unsuported chunk:"PRI_GUID"\n", ARG_GUID(g));
|
|
445
|
+
|
|
446
|
+ url_fskip(pb, WTV_PAD8(len) - consumed);
|
|
447
|
+ }
|
|
448
|
+ return AVERROR_EOF;
|
|
449
|
+}
|
|
450
|
+
|
|
451
|
+#define WTV_CHUNK_START 0x40000
|
|
452
|
+
|
|
453
|
+static int read_header(AVFormatContext *s, AVFormatParameters *ap)
|
|
454
|
+{
|
|
455
|
+ ByteIOContext *pb = s->pb;
|
|
456
|
+ int ret;
|
|
457
|
+
|
|
458
|
+ url_fseek(pb, WTV_CHUNK_START, SEEK_SET);
|
|
459
|
+ ret = parse_chunks(s, SEEK_TO_DATA, 0, 0);
|
|
460
|
+ if (ret < 0)
|
|
461
|
+ return ret;
|
|
462
|
+
|
|
463
|
+ url_fseek(pb, -32, SEEK_CUR);
|
|
464
|
+ return 0;
|
|
465
|
+}
|
|
466
|
+
|
|
467
|
+static int read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
468
|
+{
|
|
469
|
+ WtvContext *wtv = s->priv_data;
|
|
470
|
+ ByteIOContext *pb = s->pb;
|
|
471
|
+ int stream_index, len, ret;
|
|
472
|
+
|
|
473
|
+ stream_index = parse_chunks(s, SEEK_TO_DATA, 0, &len);
|
|
474
|
+ if (stream_index < 0)
|
|
475
|
+ return stream_index;
|
|
476
|
+
|
|
477
|
+ ret = av_get_packet(pb, pkt, len - 32);
|
|
478
|
+ if (ret < 0)
|
|
479
|
+ return ret;
|
|
480
|
+ pkt->stream_index = stream_index;
|
|
481
|
+ pkt->pts = wtv->pts;
|
|
482
|
+ url_fskip(pb, WTV_PAD8(len) - len);
|
|
483
|
+ return 0;
|
|
484
|
+}
|
|
485
|
+
|
|
486
|
+static int read_seek2(AVFormatContext *s, int stream_index,
|
|
487
|
+ int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
|
|
488
|
+{
|
|
489
|
+ WtvContext *wtv = s->priv_data;
|
|
490
|
+ ByteIOContext *pb = s->pb;
|
|
491
|
+ AVStream *st;
|
|
492
|
+ int i;
|
|
493
|
+
|
|
494
|
+ if (stream_index < 0) {
|
|
495
|
+ stream_index = av_find_default_stream_index(s);
|
|
496
|
+ if (stream_index < 0)
|
|
497
|
+ return -1;
|
|
498
|
+ }
|
|
499
|
+ st = s->streams[stream_index];
|
|
500
|
+
|
|
501
|
+ if ((flags & AVSEEK_FLAG_FRAME)) {
|
|
502
|
+ return AVERROR_NOTSUPP;
|
|
503
|
+ } else if ((flags & AVSEEK_FLAG_BYTE)) {
|
|
504
|
+ if (ts < url_ftell(pb)) {
|
|
505
|
+ for (i = st->nb_index_entries - 1; i >= 0; i--) {
|
|
506
|
+ if (st->index_entries[i].pos <= ts) {
|
|
507
|
+ wtv->pts = st->index_entries[i].timestamp;
|
|
508
|
+ url_fseek(pb, st->index_entries[i].pos, SEEK_SET);
|
|
509
|
+ break;
|
|
510
|
+ }
|
|
511
|
+ }
|
|
512
|
+ if (i < 0) {
|
|
513
|
+ wtv->pts = 0;
|
|
514
|
+ url_fseek(pb, WTV_CHUNK_START, SEEK_SET);
|
|
515
|
+ }
|
|
516
|
+ }
|
|
517
|
+ if (parse_chunks(s, SEEK_TO_BYTE, ts, 0) < 0)
|
|
518
|
+ return AVERROR(ERANGE);
|
|
519
|
+ return 0;
|
|
520
|
+ } else {
|
|
521
|
+ ts *= 10;
|
|
522
|
+ i = av_index_search_timestamp(st, ts, flags);
|
|
523
|
+ if (i < 0) {
|
|
524
|
+ if (st->nb_index_entries > 0) {
|
|
525
|
+ wtv->pts = st->index_entries[st->nb_index_entries - 1].timestamp;
|
|
526
|
+ url_fseek(pb, st->index_entries[st->nb_index_entries - 1].pos, SEEK_SET);
|
|
527
|
+ } else {
|
|
528
|
+ wtv->pts = 0;
|
|
529
|
+ url_fseek(pb, WTV_CHUNK_START, SEEK_SET);
|
|
530
|
+ }
|
|
531
|
+ if (parse_chunks(s, SEEK_TO_PTS, ts, 0) < 0)
|
|
532
|
+ return AVERROR(ERANGE);
|
|
533
|
+ return 0;
|
|
534
|
+ }
|
|
535
|
+ wtv->pts = st->index_entries[i].timestamp;
|
|
536
|
+ url_fseek(pb, st->index_entries[i].pos, SEEK_SET);
|
|
537
|
+ return 0;
|
|
538
|
+ }
|
|
539
|
+}
|
|
540
|
+
|
|
541
|
+AVInputFormat wtv_demuxer = {
|
|
542
|
+ .name = "wtv",
|
|
543
|
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Television (WTV)"),
|
|
544
|
+ .priv_data_size = sizeof(WtvContext),
|
|
545
|
+ .read_probe = read_probe,
|
|
546
|
+ .read_header = read_header,
|
|
547
|
+ .read_packet = read_packet,
|
|
548
|
+ .read_seek2 = read_seek2,
|
|
549
|
+ .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT,
|
|
550
|
+};
|