summaryrefslogtreecommitdiffstats
path: root/mpvcore
diff options
context:
space:
mode:
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;