summaryrefslogtreecommitdiffstats
path: root/mpvcore
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 /mpvcore
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 'mpvcore')
-rw-r--r--mpvcore/av_common.c25
-rw-r--r--mpvcore/av_common.h1
-rw-r--r--mpvcore/player/video.c3
3 files changed, 25 insertions, 4 deletions
diff --git a/mpvcore/av_common.c b/mpvcore/av_common.c
index 11d1090146..d4fa6d426f 100644
--- a/mpvcore/av_common.c
+++ b/mpvcore/av_common.c
@@ -20,7 +20,7 @@
#include <libavutil/common.h>
#include <libavcodec/avcodec.h>
-#include "mpvcore/mp_talloc.h"
+#include "mpvcore/mp_common.h"
#include "demux/packet.h"
#include "av_common.h"
#include "codecs.h"
@@ -60,11 +60,19 @@ void mp_copy_lav_codec_headers(AVCodecContext *avctx, AVCodecContext *st)
avctx->bits_per_coded_sample = st->bits_per_coded_sample;
}
+// We merely pass-through our PTS/DTS as an int64_t; libavcodec won't use it.
+union pts { int64_t i; double d; };
+
// Set dst from mpkt. Note that dst is not refcountable.
// mpkt can be NULL to generate empty packets (used to flush delayed data).
-// Does not set pts or duration fields.
+// Sets pts/dts to reinterpret-casted mpv values - these are useful for
+// reading back via mp_get_av_frame_okt_pdts(), but they will be non-sense for
+// libavcodec itself. (And normally, libavcodec won't interpret them.)
+// Does not set duration field.
void mp_set_av_packet(AVPacket *dst, struct demux_packet *mpkt)
{
+ assert(sizeof(int64_t) >= sizeof(double));
+
av_init_packet(dst);
dst->data = mpkt ? mpkt->buffer : NULL;
dst->size = mpkt ? mpkt->len : 0;
@@ -76,6 +84,19 @@ void mp_set_av_packet(AVPacket *dst, struct demux_packet *mpkt)
dst->side_data = mpkt->avpacket->side_data;
dst->side_data_elems = mpkt->avpacket->side_data_elems;
}
+ dst->pts = (union pts){.d = mpkt ? mpkt->pts : MP_NOPTS_VALUE}.i;
+ dst->dts = (union pts){.d = mpkt ? mpkt->dts : MP_NOPTS_VALUE}.i;
+}
+
+// Return the pts/dts from a frame returned by libavcodec. Note that this
+// assumes libavcodec was fed a packet setup with mp_set_av_packet()! If not,
+// the timestamps might contain garbage.
+// Normally, this returns the pts. If the pts is unknown, return dts instead.
+double mp_get_av_frame_pkt_pdts(AVFrame *frame)
+{
+ double pts = (union pts){.i = frame->pkt_pts}.d;
+ double dts = (union pts){.i = frame->pkt_dts}.d;
+ return pts == MP_NOPTS_VALUE ? dts : pts;
}
void mp_add_lavc_decoders(struct mp_decoder_list *list, enum AVMediaType type)
diff --git a/mpvcore/av_common.h b/mpvcore/av_common.h
index 2fa8f127b0..683570971d 100644
--- a/mpvcore/av_common.h
+++ b/mpvcore/av_common.h
@@ -26,6 +26,7 @@ struct demux_packet;
void mp_copy_lav_codec_headers(AVCodecContext *avctx, AVCodecContext *st);
void mp_set_av_packet(AVPacket *dst, struct demux_packet *mpkt);
+double mp_get_av_frame_pkt_pdts(AVFrame *frame);
void mp_add_lavc_decoders(struct mp_decoder_list *list, enum AVMediaType type);
int mp_codec_to_av_codec_id(const char *codec);
const char *mp_codec_from_av_codec_id(int codec_id);
diff --git a/mpvcore/player/video.c b/mpvcore/player/video.c
index c162cfa51a..a1585e560d 100644
--- a/mpvcore/player/video.c
+++ b/mpvcore/player/video.c
@@ -302,8 +302,7 @@ static void determine_frame_pts(struct MPContext *mpctx)
if (opts->user_pts_assoc_mode)
d_video->pts_assoc_mode = opts->user_pts_assoc_mode;
else if (d_video->pts_assoc_mode == 0) {
- if (d_video->header->demuxer->timestamp_type == TIMESTAMP_TYPE_PTS
- && d_video->codec_reordered_pts != MP_NOPTS_VALUE)
+ if (d_video->codec_reordered_pts != MP_NOPTS_VALUE)
d_video->pts_assoc_mode = 1;
else
d_video->pts_assoc_mode = 2;