yading@11: /* yading@11: * Copyright (C) 2010 David Conrad yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #include "libavcodec/bytestream.h" yading@11: #include "avformat.h" yading@11: #include "internal.h" yading@11: #include "oggdec.h" yading@11: yading@11: static int skeleton_header(AVFormatContext *s, int idx) yading@11: { yading@11: struct ogg *ogg = s->priv_data; yading@11: struct ogg_stream *os = ogg->streams + idx; yading@11: AVStream *st = s->streams[idx]; yading@11: uint8_t *buf = os->buf + os->pstart; yading@11: int version_major, version_minor; yading@11: int64_t start_num, start_den; yading@11: uint64_t start_granule; yading@11: int target_idx, start_time; yading@11: yading@11: strcpy(st->codec->codec_name, "skeleton"); yading@11: st->codec->codec_type = AVMEDIA_TYPE_DATA; yading@11: yading@11: if (os->psize < 8) yading@11: return -1; yading@11: yading@11: if (!strncmp(buf, "fishead", 8)) { yading@11: if (os->psize < 64) yading@11: return -1; yading@11: yading@11: version_major = AV_RL16(buf+8); yading@11: version_minor = AV_RL16(buf+10); yading@11: yading@11: if (version_major != 3 && version_major != 4) { yading@11: av_log(s, AV_LOG_WARNING, "Unknown skeleton version %d.%d\n", yading@11: version_major, version_minor); yading@11: return -1; yading@11: } yading@11: yading@11: // This is the overall start time. We use it for the start time of yading@11: // of the skeleton stream since if left unset lavf assumes 0, yading@11: // which we don't want since skeleton is timeless yading@11: // FIXME: the real meaning of this field is "start playback at yading@11: // this time which can be in the middle of a packet yading@11: start_num = AV_RL64(buf+12); yading@11: start_den = AV_RL64(buf+20); yading@11: yading@11: if (start_den > 0 && start_num > 0) { yading@11: int base_den; yading@11: av_reduce(&start_time, &base_den, start_num, start_den, INT_MAX); yading@11: avpriv_set_pts_info(st, 64, 1, base_den); yading@11: os->lastpts = yading@11: st->start_time = start_time; yading@11: } yading@11: } else if (!strncmp(buf, "fisbone", 8)) { yading@11: if (os->psize < 52) yading@11: return -1; yading@11: yading@11: target_idx = ogg_find_stream(ogg, AV_RL32(buf+12)); yading@11: start_granule = AV_RL64(buf+36); yading@11: if (os->start_granule != OGG_NOGRANULE_VALUE) { yading@11: avpriv_report_missing_feature(s, yading@11: "Multiple fisbone for the same stream"); yading@11: return 1; yading@11: } yading@11: if (target_idx >= 0 && start_granule != OGG_NOGRANULE_VALUE) { yading@11: os->start_granule = start_granule; yading@11: } yading@11: } yading@11: yading@11: return 1; yading@11: } yading@11: yading@11: const struct ogg_codec ff_skeleton_codec = { yading@11: .magic = "fishead", yading@11: .magicsize = 8, yading@11: .header = skeleton_header, yading@11: .nb_header = 0, yading@11: };