mirror of
https://github.com/mpv-player/mpv
synced 2025-02-18 05:37:04 +00:00
av_common: remove old/unused timestamp passthrough code
This attempted to pass through double float timestamps in a bit exact way by reinterpret casting them to int64_t. This usually worked, because libavcodec (in decoding mode) is mostly not allowed to interpret timestamps. libavcodec doesn't even know the unit of the timestamps, unless the API user sets a timebase. We've stopped doing this, and always set a timebase. Only ad_spdif.c still used this (indirectly through mp_set_av_packet()), but doesn't actually need timestamps on the packet. In fact, it's already explicitly setting the packet timestamp fields to 0 before passing it to FFmpeg API. This code is unused, and the passthrough method wasn't terribly elegant to begin with. Drop this code. Arbitrarily use AV_TIME_BASE_Q as fallback in situations the passthrough was used.
This commit is contained in:
parent
d16ba1f7f6
commit
f762fc4230
@ -85,37 +85,24 @@ AVRational mp_get_codec_timebase(struct mp_codec_params *c)
|
|||||||
return tb;
|
return tb;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We merely pass-through our PTS/DTS as an int64_t; libavcodec won't use it.
|
static AVRational get_def_tb(AVRational *tb)
|
||||||
union pts { int64_t i; double d; };
|
{
|
||||||
|
return tb && tb->num > 0 && tb->den > 0 ? *tb : AV_TIME_BASE_Q;
|
||||||
|
}
|
||||||
|
|
||||||
// Convert the mpv style timestamp (seconds as double) to a libavcodec style
|
// Convert the mpv style timestamp (seconds as double) to a libavcodec style
|
||||||
// timestamp (integer units in a given timebase).
|
// timestamp (integer units in a given timebase).
|
||||||
//
|
|
||||||
// If the given timebase is NULL or invalid, pass through the mpv timestamp by
|
|
||||||
// reinterpret casting them to int64_t. In this case, the timestamps will be
|
|
||||||
// non-sense for libavcodec, but we expect that it doesn't interpret them,
|
|
||||||
// and treats them as opaque.
|
|
||||||
int64_t mp_pts_to_av(double mp_pts, AVRational *tb)
|
int64_t mp_pts_to_av(double mp_pts, AVRational *tb)
|
||||||
{
|
{
|
||||||
assert(sizeof(int64_t) >= sizeof(double));
|
AVRational b = get_def_tb(tb);
|
||||||
if (tb && tb->num > 0 && tb->den > 0) {
|
return mp_pts == MP_NOPTS_VALUE ? AV_NOPTS_VALUE : llrint(mp_pts / av_q2d(b));
|
||||||
return mp_pts == MP_NOPTS_VALUE ?
|
|
||||||
AV_NOPTS_VALUE : llrint(mp_pts / av_q2d(*tb));
|
|
||||||
}
|
|
||||||
// The + 0.0 is to squash possible negative zero mp_pts, which would
|
|
||||||
// happen to end up as AV_NOPTS_VALUE.
|
|
||||||
return (union pts){.d = mp_pts + 0.0}.i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inverse of mp_pts_to_av(). (The timebases must be exactly the same.)
|
// Inverse of mp_pts_to_av(). (The timebases must be exactly the same.)
|
||||||
double mp_pts_from_av(int64_t av_pts, AVRational *tb)
|
double mp_pts_from_av(int64_t av_pts, AVRational *tb)
|
||||||
{
|
{
|
||||||
assert(sizeof(int64_t) >= sizeof(double));
|
AVRational b = get_def_tb(tb);
|
||||||
if (tb && tb->num > 0 && tb->den > 0)
|
return av_pts == AV_NOPTS_VALUE ? MP_NOPTS_VALUE : av_pts * av_q2d(b);
|
||||||
return av_pts == AV_NOPTS_VALUE ? MP_NOPTS_VALUE : av_pts * av_q2d(*tb);
|
|
||||||
// Should libavcodec set the PTS to AV_NOPTS_VALUE, it would end up as
|
|
||||||
// non-sense (usually negative zero) when unwrapped to double.
|
|
||||||
return av_pts == AV_NOPTS_VALUE ? MP_NOPTS_VALUE : (union pts){.i = av_pts}.d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set dst from mpkt. Note that dst is not refcountable.
|
// Set dst from mpkt. Note that dst is not refcountable.
|
||||||
|
Loading…
Reference in New Issue
Block a user