yading@11
|
1 /*
|
yading@11
|
2 * Copyright (C) 2010 David Conrad
|
yading@11
|
3 *
|
yading@11
|
4 * This file is part of FFmpeg.
|
yading@11
|
5 *
|
yading@11
|
6 * FFmpeg is free software; you can redistribute it and/or
|
yading@11
|
7 * modify it under the terms of the GNU Lesser General Public
|
yading@11
|
8 * License as published by the Free Software Foundation; either
|
yading@11
|
9 * version 2.1 of the License, or (at your option) any later version.
|
yading@11
|
10 *
|
yading@11
|
11 * FFmpeg is distributed in the hope that it will be useful,
|
yading@11
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@11
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@11
|
14 * Lesser General Public License for more details.
|
yading@11
|
15 *
|
yading@11
|
16 * You should have received a copy of the GNU Lesser General Public
|
yading@11
|
17 * License along with FFmpeg; if not, write to the Free Software
|
yading@11
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@11
|
19 */
|
yading@11
|
20
|
yading@11
|
21 #include "libavcodec/bytestream.h"
|
yading@11
|
22 #include "avformat.h"
|
yading@11
|
23 #include "internal.h"
|
yading@11
|
24 #include "oggdec.h"
|
yading@11
|
25
|
yading@11
|
26 static int skeleton_header(AVFormatContext *s, int idx)
|
yading@11
|
27 {
|
yading@11
|
28 struct ogg *ogg = s->priv_data;
|
yading@11
|
29 struct ogg_stream *os = ogg->streams + idx;
|
yading@11
|
30 AVStream *st = s->streams[idx];
|
yading@11
|
31 uint8_t *buf = os->buf + os->pstart;
|
yading@11
|
32 int version_major, version_minor;
|
yading@11
|
33 int64_t start_num, start_den;
|
yading@11
|
34 uint64_t start_granule;
|
yading@11
|
35 int target_idx, start_time;
|
yading@11
|
36
|
yading@11
|
37 strcpy(st->codec->codec_name, "skeleton");
|
yading@11
|
38 st->codec->codec_type = AVMEDIA_TYPE_DATA;
|
yading@11
|
39
|
yading@11
|
40 if (os->psize < 8)
|
yading@11
|
41 return -1;
|
yading@11
|
42
|
yading@11
|
43 if (!strncmp(buf, "fishead", 8)) {
|
yading@11
|
44 if (os->psize < 64)
|
yading@11
|
45 return -1;
|
yading@11
|
46
|
yading@11
|
47 version_major = AV_RL16(buf+8);
|
yading@11
|
48 version_minor = AV_RL16(buf+10);
|
yading@11
|
49
|
yading@11
|
50 if (version_major != 3 && version_major != 4) {
|
yading@11
|
51 av_log(s, AV_LOG_WARNING, "Unknown skeleton version %d.%d\n",
|
yading@11
|
52 version_major, version_minor);
|
yading@11
|
53 return -1;
|
yading@11
|
54 }
|
yading@11
|
55
|
yading@11
|
56 // This is the overall start time. We use it for the start time of
|
yading@11
|
57 // of the skeleton stream since if left unset lavf assumes 0,
|
yading@11
|
58 // which we don't want since skeleton is timeless
|
yading@11
|
59 // FIXME: the real meaning of this field is "start playback at
|
yading@11
|
60 // this time which can be in the middle of a packet
|
yading@11
|
61 start_num = AV_RL64(buf+12);
|
yading@11
|
62 start_den = AV_RL64(buf+20);
|
yading@11
|
63
|
yading@11
|
64 if (start_den > 0 && start_num > 0) {
|
yading@11
|
65 int base_den;
|
yading@11
|
66 av_reduce(&start_time, &base_den, start_num, start_den, INT_MAX);
|
yading@11
|
67 avpriv_set_pts_info(st, 64, 1, base_den);
|
yading@11
|
68 os->lastpts =
|
yading@11
|
69 st->start_time = start_time;
|
yading@11
|
70 }
|
yading@11
|
71 } else if (!strncmp(buf, "fisbone", 8)) {
|
yading@11
|
72 if (os->psize < 52)
|
yading@11
|
73 return -1;
|
yading@11
|
74
|
yading@11
|
75 target_idx = ogg_find_stream(ogg, AV_RL32(buf+12));
|
yading@11
|
76 start_granule = AV_RL64(buf+36);
|
yading@11
|
77 if (os->start_granule != OGG_NOGRANULE_VALUE) {
|
yading@11
|
78 avpriv_report_missing_feature(s,
|
yading@11
|
79 "Multiple fisbone for the same stream");
|
yading@11
|
80 return 1;
|
yading@11
|
81 }
|
yading@11
|
82 if (target_idx >= 0 && start_granule != OGG_NOGRANULE_VALUE) {
|
yading@11
|
83 os->start_granule = start_granule;
|
yading@11
|
84 }
|
yading@11
|
85 }
|
yading@11
|
86
|
yading@11
|
87 return 1;
|
yading@11
|
88 }
|
yading@11
|
89
|
yading@11
|
90 const struct ogg_codec ff_skeleton_codec = {
|
yading@11
|
91 .magic = "fishead",
|
yading@11
|
92 .magicsize = 8,
|
yading@11
|
93 .header = skeleton_header,
|
yading@11
|
94 .nb_header = 0,
|
yading@11
|
95 };
|