From a802afb206736279b0bf1c433f5d92b05a68b34f Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Tue, 20 Sep 2016 02:11:14 +0900 Subject: command: add audio-pts property to get the audio pts For audio files, this is identical to time-pos (except read-only). For audio-video files, this returns the audio position. Unlike time-pos, this is not quantized to a video frame. For video-only files, this property is unavailable. --- DOCS/man/input.rst | 6 ++++++ player/command.c | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 1f7862d1c1..92cdad77c0 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -984,6 +984,12 @@ Property list Remaining length of the file in seconds. Note that the file duration is not always exactly known, so this is an estimate. +``audio-pts`` (R) + Current audio playback position in current file in seconds. Unlike time-pos, + this updates more often than once per frame. For audio-only files, it is + mostly equivalent to time-pos, while for video-only files this property is + not available. + ``playtime-remaining`` ``time-remaining`` scaled by the current ``speed``. diff --git a/player/command.c b/player/command.c index 3e677bfd37..1807f269b9 100644 --- a/player/command.c +++ b/player/command.c @@ -796,6 +796,18 @@ static int mp_property_time_pos(void *ctx, struct m_property *prop, return property_time(action, arg, get_current_time(mpctx)); } +/// Current audio pts in seconds (R) +static int mp_property_audio_pts(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + if (!mpctx->playback_initialized || mpctx->audio_status < STATUS_PLAYING || + mpctx->audio_status >= STATUS_EOF) + return M_PROPERTY_UNAVAILABLE; + + return property_time(action, arg, playing_audio_pts(mpctx)); +} + static bool time_remaining(MPContext *mpctx, double *remaining) { double len = get_time_length(mpctx); @@ -3806,6 +3818,7 @@ static const struct m_property mp_properties_base[] = { {"time-start", mp_property_time_start}, {"time-pos", mp_property_time_pos}, {"time-remaining", mp_property_remaining}, + {"audio-pts", mp_property_audio_pts}, {"playtime-remaining", mp_property_playtime_remaining}, {"playback-time", mp_property_playback_time}, {"disc-title", mp_property_disc_title}, @@ -4034,7 +4047,7 @@ static const char *const *const mp_event_property_change[] = { E(MPV_EVENT_IDLE, "*"), E(MPV_EVENT_PAUSE, "pause", "paused-on-cache", "core-idle", "eof-reached"), E(MPV_EVENT_UNPAUSE, "pause", "paused-on-cache", "core-idle", "eof-reached"), - E(MPV_EVENT_TICK, "time-pos", "stream-pos", "stream-time-pos", "avsync", + E(MPV_EVENT_TICK, "time-pos", "audio-pts", "stream-pos", "avsync", "percent-pos", "time-remaining", "playtime-remaining", "playback-time", "estimated-vf-fps", "drop-frame-count", "vo-drop-frame-count", "total-avsync-change", "audio-speed-correction", "video-speed-correction", -- cgit v1.2.3