2010-03-11 07:17:40 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 David Conrad
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libavcodec/bytestream.h"
|
|
|
|
#include "avformat.h"
|
2011-11-29 18:28:15 +00:00
|
|
|
#include "internal.h"
|
2010-03-11 07:17:40 +00:00
|
|
|
#include "oggdec.h"
|
|
|
|
|
|
|
|
static int skeleton_header(AVFormatContext *s, int idx)
|
|
|
|
{
|
|
|
|
struct ogg *ogg = s->priv_data;
|
|
|
|
struct ogg_stream *os = ogg->streams + idx;
|
|
|
|
AVStream *st = s->streams[idx];
|
|
|
|
uint8_t *buf = os->buf + os->pstart;
|
|
|
|
int version_major, version_minor;
|
2012-09-19 23:07:09 +00:00
|
|
|
int64_t start_num, start_den;
|
|
|
|
uint64_t start_granule;
|
2010-03-11 07:17:40 +00:00
|
|
|
int target_idx, start_time;
|
|
|
|
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 18:42:52 +00:00
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
|
2010-03-11 07:17:40 +00:00
|
|
|
|
2013-07-06 21:53:19 +00:00
|
|
|
if ((os->flags & OGG_FLAG_EOS) && os->psize == 0)
|
|
|
|
return 1;
|
|
|
|
|
2010-03-11 07:17:40 +00:00
|
|
|
if (os->psize < 8)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!strncmp(buf, "fishead", 8)) {
|
|
|
|
if (os->psize < 64)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
version_major = AV_RL16(buf+8);
|
|
|
|
version_minor = AV_RL16(buf+10);
|
|
|
|
|
2012-02-04 19:15:55 +00:00
|
|
|
if (version_major != 3 && version_major != 4) {
|
2010-03-11 07:17:40 +00:00
|
|
|
av_log(s, AV_LOG_WARNING, "Unknown skeleton version %d.%d\n",
|
|
|
|
version_major, version_minor);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is the overall start time. We use it for the start time of
|
|
|
|
// of the skeleton stream since if left unset lavf assumes 0,
|
|
|
|
// which we don't want since skeleton is timeless
|
|
|
|
// FIXME: the real meaning of this field is "start playback at
|
|
|
|
// this time which can be in the middle of a packet
|
|
|
|
start_num = AV_RL64(buf+12);
|
|
|
|
start_den = AV_RL64(buf+20);
|
|
|
|
|
2013-01-08 01:52:15 +00:00
|
|
|
if (start_den > 0 && start_num > 0) {
|
2011-02-07 01:33:53 +00:00
|
|
|
int base_den;
|
2011-01-31 19:08:56 +00:00
|
|
|
av_reduce(&start_time, &base_den, start_num, start_den, INT_MAX);
|
2011-11-29 18:28:15 +00:00
|
|
|
avpriv_set_pts_info(st, 64, 1, base_den);
|
2010-03-28 01:15:08 +00:00
|
|
|
os->lastpts =
|
2010-03-11 07:17:40 +00:00
|
|
|
st->start_time = start_time;
|
|
|
|
}
|
|
|
|
} else if (!strncmp(buf, "fisbone", 8)) {
|
|
|
|
if (os->psize < 52)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
target_idx = ogg_find_stream(ogg, AV_RL32(buf+12));
|
|
|
|
start_granule = AV_RL64(buf+36);
|
2013-07-06 07:34:13 +00:00
|
|
|
if (target_idx < 0) {
|
|
|
|
av_log(s, AV_LOG_WARNING, "Serial number in fisbone doesn't match any stream\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
os = ogg->streams + target_idx;
|
2012-09-19 23:07:09 +00:00
|
|
|
if (os->start_granule != OGG_NOGRANULE_VALUE) {
|
2013-07-06 07:34:13 +00:00
|
|
|
av_log(s, AV_LOG_WARNING, "Multiple fisbone for the same stream\n");
|
2012-09-19 23:07:09 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2013-07-06 07:34:13 +00:00
|
|
|
if (start_granule != OGG_NOGRANULE_VALUE) {
|
2012-09-19 23:07:09 +00:00
|
|
|
os->start_granule = start_granule;
|
2010-03-11 07:17:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct ogg_codec ff_skeleton_codec = {
|
|
|
|
.magic = "fishead",
|
|
|
|
.magicsize = 8,
|
|
|
|
.header = skeleton_header,
|
2012-09-19 23:01:43 +00:00
|
|
|
.nb_header = 0,
|
2010-03-11 07:17:40 +00:00
|
|
|
};
|