summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-11-25 23:13:01 +0100
committerwm4 <wm4@nowhere>2013-11-25 23:13:01 +0100
commit9f72a9753e68c4064796f2361fb12492a85a8e0b (patch)
tree438a52f708e95ff08be4a686fa7beec937f2fdbf /demux
parentd8b59aa17fda6aff7bf3031abbd716adc1268422 (diff)
downloadmpv-9f72a9753e68c4064796f2361fb12492a85a8e0b.tar.bz2
mpv-9f72a9753e68c4064796f2361fb12492a85a8e0b.tar.xz
demux: export dts from demux_lavf, use it for avi
Having the DTS directly can be useful for restoring PTS values. The avi file format doesn't actually store PTS values, just DTS. An older hack explicitly exported the DTS as PTS (ignoring the [I assume] genpts generated non-sense PTS), which is not necessary anymore due to this change.
Diffstat (limited to 'demux')
-rw-r--r--demux/demux.c7
-rw-r--r--demux/demux.h7
-rw-r--r--demux/demux_lavf.c21
-rw-r--r--demux/packet.h1
4 files changed, 19 insertions, 17 deletions
diff --git a/demux/demux.c b/demux/demux.c
index 00d59af09d..467b016699 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -131,6 +131,7 @@ static struct demux_packet *create_packet(size_t len)
*dp = (struct demux_packet) {
.len = len,
.pts = MP_NOPTS_VALUE,
+ .dts = MP_NOPTS_VALUE,
.duration = -1,
.stream_pts = MP_NOPTS_VALUE,
.pos = -1,
@@ -217,6 +218,7 @@ struct demux_packet *demux_copy_packet(struct demux_packet *dp)
memcpy(new->buffer, dp->buffer, new->len);
}
new->pts = dp->pts;
+ new->dts = dp->dts;
new->duration = dp->duration;
new->stream_pts = dp->stream_pts;
return new;
@@ -340,6 +342,11 @@ int demuxer_add_packet(demuxer_t *demuxer, struct sh_stream *stream,
if (dp->pos >= 0)
demuxer->filepos = dp->pos;
+ // For video, PTS determination is not trivial, but for other media types
+ // distinguishing PTS and DTS is not useful.
+ if (stream->type != STREAM_VIDEO && dp->pts == MP_NOPTS_VALUE)
+ dp->pts = dp->dts;
+
mp_dbg(MSGT_DEMUXER, MSGL_DBG2,
"DEMUX: Append packet to %s, len=%d pts=%5.3f pos=%"PRIu64" "
"[packs: A=%d V=%d S=%d]\n", stream_type_name(stream->type),
diff --git a/demux/demux.h b/demux/demux.h
index e025862bb2..6b08b84e4c 100644
--- a/demux/demux.h
+++ b/demux/demux.h
@@ -43,12 +43,6 @@ enum demuxer_type {
DEMUXER_TYPE_CUE,
};
-enum timestamp_type {
- TIMESTAMP_TYPE_PTS,
- TIMESTAMP_TYPE_SORT,
-};
-
-
// DEMUXER control commands/answers
#define DEMUXER_CTRL_NOTIMPL -1
#define DEMUXER_CTRL_DONTKNOW 0
@@ -174,7 +168,6 @@ typedef struct demuxer {
bool accurate_seek;
// File format allows PTS resets (even if the current file is without)
bool ts_resets_possible;
- enum timestamp_type timestamp_type;
bool warned_queue_overflow;
struct sh_stream **streams;
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index fe0b3efdd2..98efbc32f3 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -82,7 +82,6 @@ typedef struct lavf_priv {
struct sh_stream **streams; // NULL for unknown streams
int num_streams;
int cur_program;
- bool use_dts;
char *mime_type;
bool genpts_hack;
AVPacket *packets[MAX_PKT_QUEUE];
@@ -541,8 +540,6 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check)
if (matches_avinputformat_name(priv, "avi")) {
/* for avi libavformat returns the avi timestamps in .dts,
* some made-up stuff that's not really pts in .pts */
- priv->use_dts = true;
- demuxer->timestamp_type = TIMESTAMP_TYPE_SORT;
} else {
int mode = lavfdopts->genptsmode;
if (mode == 0 && opts->correct_pts)
@@ -785,14 +782,18 @@ static int demux_lavf_fill_buffer(demuxer_t *demux)
dp = new_demux_packet_fromdata(pkt->data, pkt->size);
dp->avpacket = talloc_steal(dp, pkt);
- int64_t ts = priv->use_dts ? pkt->dts : pkt->pts;
- if (ts != AV_NOPTS_VALUE) {
- dp->pts = ts * av_q2d(st->time_base);
- priv->last_pts = dp->pts * AV_TIME_BASE;
- dp->duration = pkt->duration * av_q2d(st->time_base);
- if (pkt->convergence_duration > 0)
- dp->duration = pkt->convergence_duration * av_q2d(st->time_base);
+ if (pkt->pts != AV_NOPTS_VALUE) {
+ dp->pts = pkt->pts * av_q2d(st->time_base);
+ priv->last_pts = dp->pts;
}
+ if (pkt->dts != AV_NOPTS_VALUE) {
+ dp->dts = pkt->dts * av_q2d(st->time_base);
+ if (priv->last_pts == AV_NOPTS_VALUE)
+ priv->last_pts = pkt->dts;
+ }
+ dp->duration = pkt->duration * av_q2d(st->time_base);
+ if (pkt->convergence_duration > 0)
+ dp->duration = pkt->convergence_duration * av_q2d(st->time_base);
dp->pos = pkt->pos;
dp->keyframe = pkt->flags & AV_PKT_FLAG_KEY;
// Use only one stream for stream_pts, otherwise PTS might be jumpy.
diff --git a/demux/packet.h b/demux/packet.h
index 96e3885761..ca57179acb 100644
--- a/demux/packet.h
+++ b/demux/packet.h
@@ -26,6 +26,7 @@
typedef struct demux_packet {
int len;
double pts;
+ double dts;
double duration;
double stream_pts;
int64_t pos; // position in source file byte stream