Commit d1f05dd1 authored by Luca Barbato's avatar Luca Barbato

ogg: calculate the start position once all the headers are parsed

The fisbone packets can be muxed in any order as long the last one
comes before the first data packet.
parent 7751e469
......@@ -169,6 +169,7 @@ static int ogg_new_stream(AVFormatContext *s, uint32_t serial, int new_avstream)
os->bufsize = DECODER_BUFFER_SIZE;
os->buf = av_malloc(os->bufsize + FF_INPUT_BUFFER_PADDING_SIZE);
os->header = -1;
os->start_granule = OGG_NOGRANULE_VALUE;
if (new_avstream) {
st = avformat_new_stream(s, NULL);
......@@ -463,6 +464,9 @@ static int ogg_get_headers(AVFormatContext *s)
"Headers mismatch for stream %d\n", i);
return AVERROR_INVALIDDATA;
}
if (os->start_granule != OGG_NOGRANULE_VALUE)
os->lastpts = s->streams[i]->start_time =
ogg_gptopts(s, i, os->start_granule, NULL);
}
av_dlog(s, "found headers\n");
......
......@@ -67,6 +67,7 @@ struct ogg_stream {
unsigned int pduration;
uint32_t serial;
uint64_t granule;
uint64_t start_granule;
int64_t lastpts;
int64_t lastdts;
int64_t sync_pos; ///< file offset of the first page needed to reconstruct the current packet
......@@ -103,6 +104,8 @@ struct ogg {
#define OGG_FLAG_BOS 2
#define OGG_FLAG_EOS 4
#define OGG_NOGRANULE_VALUE -1ull
extern const struct ogg_codec ff_celt_codec;
extern const struct ogg_codec ff_dirac_codec;
extern const struct ogg_codec ff_flac_codec;
......
......@@ -30,7 +30,8 @@ static int skeleton_header(AVFormatContext *s, int idx)
AVStream *st = s->streams[idx];
uint8_t *buf = os->buf + os->pstart;
int version_major, version_minor;
int64_t start_num, start_den, start_granule;
int64_t start_num, start_den;
uint64_t start_granule;
int target_idx, start_time;
strcpy(st->codec->codec_name, "skeleton");
......@@ -73,9 +74,13 @@ static int skeleton_header(AVFormatContext *s, int idx)
target_idx = ogg_find_stream(ogg, AV_RL32(buf+12));
start_granule = AV_RL64(buf+36);
if (target_idx >= 0 && start_granule != -1) {
ogg->streams[target_idx].lastpts =
s->streams[target_idx]->start_time = ogg_gptopts(s, target_idx, start_granule, NULL);
if (os->start_granule != OGG_NOGRANULE_VALUE) {
av_log_missing_feature(s, "multiple fisbone for the "
"same stream\n", 0);
return 1;
}
if (target_idx >= 0 && start_granule != OGG_NOGRANULE_VALUE) {
os->start_granule = start_granule;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment