Mercurial > libavformat.hg
changeset 5514:52c7b29eca31 libavformat
oggdec: Set dts when known
author | conrad |
---|---|
date | Mon, 11 Jan 2010 05:51:09 +0000 |
parents | f4eceb1eb100 |
children | fa3115c9b043 |
files | oggdec.c oggdec.h oggparsedirac.c oggparsetheora.c |
diffstat | 4 files changed, 31 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/oggdec.c Mon Jan 11 00:31:55 2010 +0000 +++ b/oggdec.c Mon Jan 11 05:51:09 2010 +0000 @@ -119,6 +119,7 @@ os->psize = 0; os->granule = -1; os->lastpts = AV_NOPTS_VALUE; + os->lastdts = AV_NOPTS_VALUE; os->nsegs = 0; os->segp = 0; } @@ -428,16 +429,18 @@ } static uint64_t -ogg_gptopts (AVFormatContext * s, int i, uint64_t gp) +ogg_gptopts (AVFormatContext * s, int i, uint64_t gp, int64_t *dts) { struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + i; uint64_t pts = AV_NOPTS_VALUE; if(os->codec->gptopts){ - pts = os->codec->gptopts(s, i, gp); + pts = os->codec->gptopts(s, i, gp, dts); } else { pts = gp; + if (dts) + *dts = pts; } return pts; @@ -474,7 +477,7 @@ if (idx != -1){ s->streams[idx]->duration = - ogg_gptopts (s, idx, ogg->streams[idx].granule); + ogg_gptopts (s, idx, ogg->streams[idx].granule, NULL); } ogg->size = size; @@ -534,12 +537,16 @@ pkt->pts = os->lastpts; os->lastpts = AV_NOPTS_VALUE; } + if (os->lastdts != AV_NOPTS_VALUE) { + pkt->dts = os->lastdts; + os->lastdts = AV_NOPTS_VALUE; + } if (os->page_end) { if (os->granule != -1LL) { if (os->codec && os->codec->granule_is_start) - pkt->pts = ogg_gptopts(s, idx, os->granule); + pkt->pts = ogg_gptopts(s, idx, os->granule, &pkt->dts); else - os->lastpts = ogg_gptopts(s, idx, os->granule); + os->lastpts = ogg_gptopts(s, idx, os->granule, &os->lastdts); os->granule = -1LL; } else av_log(s, AV_LOG_WARNING, "Packet is missing granule\n"); @@ -579,7 +586,7 @@ while (url_ftell(bc) < pos_limit && !ogg_read_page (s, &i)) { if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 && ogg->streams[i].codec && i == stream_index) { - pts = ogg_gptopts(s, i, ogg->streams[i].granule); + pts = ogg_gptopts(s, i, ogg->streams[i].granule, NULL); // FIXME: this is the position of the packet after the one with above // pts. *pos_arg = url_ftell(bc);
--- a/oggdec.h Mon Jan 11 00:31:55 2010 +0000 +++ b/oggdec.h Mon Jan 11 05:51:09 2010 +0000 @@ -40,7 +40,12 @@ */ int (*header)(AVFormatContext *, int); int (*packet)(AVFormatContext *, int); - uint64_t (*gptopts)(AVFormatContext *, int, uint64_t); + /** + * Translate a granule into a timestamp. + * Will set dts if non-null and known. + * @return pts + */ + uint64_t (*gptopts)(AVFormatContext *, int, uint64_t, int64_t *dts); /** * 1 if granule is the start time of the associated packet. * 0 if granule is the end time of the associated packet. @@ -60,6 +65,7 @@ uint32_t seq; uint64_t granule; int64_t lastpts; + int64_t lastdts; int flags; const struct ogg_codec *codec; int header;
--- a/oggparsedirac.c Mon Jan 11 00:31:55 2010 +0000 +++ b/oggparsedirac.c Mon Jan 11 05:51:09 2010 +0000 @@ -47,7 +47,8 @@ } // various undocument things: granule is signed (only for dirac!) -static uint64_t dirac_gptopts(AVFormatContext *s, int idx, int64_t gp) +static uint64_t dirac_gptopts(AVFormatContext *s, int idx, int64_t gp, + int64_t *dts_out) { struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx; @@ -59,6 +60,9 @@ if (!dist) os->pflags |= PKT_FLAG_KEY; + if (dts_out) + *dts_out = dts; + return pts; } @@ -79,7 +83,8 @@ return 1; } -static uint64_t old_dirac_gptopts(AVFormatContext *s, int idx, uint64_t gp) +static uint64_t old_dirac_gptopts(AVFormatContext *s, int idx, uint64_t gp, + int64_t *dts) { struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx;
--- a/oggparsetheora.c Mon Jan 11 00:31:55 2010 +0000 +++ b/oggparsetheora.c Mon Jan 11 05:51:09 2010 +0000 @@ -123,7 +123,7 @@ } static uint64_t -theora_gptopts(AVFormatContext *ctx, int idx, uint64_t gp) +theora_gptopts(AVFormatContext *ctx, int idx, uint64_t gp, int64_t *dts) { struct ogg *ogg = ctx->priv_data; struct ogg_stream *os = ogg->streams + idx; @@ -137,6 +137,9 @@ if(!pframe) os->pflags |= PKT_FLAG_KEY; + if (dts) + *dts = iframe + pframe; + return iframe + pframe; }