annotate oggparseskeleton.c @ 6171:240beb8a3072 libavformat

asfdec: ensure number of streams is within bounds; remove VLA in asf_read_pts()
author mru
date Thu, 24 Jun 2010 15:10:06 +0000
parents 536e5527c1e0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5812
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
1 /*
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
2 * Copyright (C) 2010 David Conrad
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
3 *
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
4 * This file is part of FFmpeg.
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
5 *
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
10 *
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
14 * Lesser General Public License for more details.
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
15 *
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
19 */
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
20
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
21 #include "libavcodec/bytestream.h"
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
22 #include "avformat.h"
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
23 #include "oggdec.h"
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
24
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
25 static int skeleton_header(AVFormatContext *s, int idx)
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
26 {
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
27 struct ogg *ogg = s->priv_data;
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
28 struct ogg_stream *os = ogg->streams + idx;
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
29 AVStream *st = s->streams[idx];
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
30 uint8_t *buf = os->buf + os->pstart;
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
31 int version_major, version_minor;
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
32 int64_t start_num, start_den, start_granule;
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
33 int target_idx, start_time;
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
34
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
35 strcpy(st->codec->codec_name, "skeleton");
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5900
diff changeset
36 st->codec->codec_type = AVMEDIA_TYPE_DATA;
5812
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
37
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
38 if (os->psize < 8)
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
39 return -1;
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
40
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
41 if (!strncmp(buf, "fishead", 8)) {
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
42 if (os->psize < 64)
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
43 return -1;
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
44
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
45 version_major = AV_RL16(buf+8);
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
46 version_minor = AV_RL16(buf+10);
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
47
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
48 if (version_major != 3) {
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
49 av_log(s, AV_LOG_WARNING, "Unknown skeleton version %d.%d\n",
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
50 version_major, version_minor);
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
51 return -1;
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
52 }
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
53
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
54 // This is the overall start time. We use it for the start time of
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
55 // of the skeleton stream since if left unset lavf assumes 0,
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
56 // which we don't want since skeleton is timeless
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
57 // FIXME: the real meaning of this field is "start playback at
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
58 // this time which can be in the middle of a packet
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
59 start_num = AV_RL64(buf+12);
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
60 start_den = AV_RL64(buf+20);
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
61
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
62 if (start_den) {
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
63 av_reduce(&start_time, &st->time_base.den, start_num, start_den, INT_MAX);
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
64 st->time_base.num = 1;
5900
79084b40586c correct first pts for ogg skeleton
aurel
parents: 5812
diff changeset
65 os->lastpts =
5812
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
66 st->start_time = start_time;
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
67 }
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
68 } else if (!strncmp(buf, "fisbone", 8)) {
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
69 if (os->psize < 52)
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
70 return -1;
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
71
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
72 target_idx = ogg_find_stream(ogg, AV_RL32(buf+12));
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
73 start_granule = AV_RL64(buf+36);
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
74 if (target_idx >= 0 && start_granule != -1) {
5900
79084b40586c correct first pts for ogg skeleton
aurel
parents: 5812
diff changeset
75 ogg->streams[target_idx].lastpts =
5812
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
76 s->streams[target_idx]->start_time = ogg_gptopts(s, target_idx, start_granule, NULL);
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
77 }
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
78 }
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
79
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
80 return 1;
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
81 }
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
82
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
83 const struct ogg_codec ff_skeleton_codec = {
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
84 .magic = "fishead",
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
85 .magicsize = 8,
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
86 .header = skeleton_header,
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents:
diff changeset
87 };