double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t) { double length = get_time_length(mpctx); double start = get_start_time(mpctx); switch (t.type) { case REL_TIME_ABSOLUTE: return t.pos; case REL_TIME_RELATIVE: if (t.pos >= 0) { return start + t.pos; } else { if (length != 0) return MPMAX(start + length + t.pos, 0.0); } break; case REL_TIME_PERCENT: if (length != 0) return start + length * (t.pos / 100.0); break; case REL_TIME_CHAPTER: if (chapter_start_time(mpctx, t.pos) != MP_NOPTS_VALUE) return chapter_start_time(mpctx, t.pos); break; } return MP_NOPTS_VALUE; }
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t) { double length = get_time_length(mpctx); // declaration up here because of C grammar quirk double chapter_start_pts; switch (t.type) { case REL_TIME_ABSOLUTE: return t.pos; case REL_TIME_RELATIVE: if (t.pos >= 0) { return t.pos; } else { if (length >= 0) return MPMAX(length + t.pos, 0.0); } break; case REL_TIME_PERCENT: if (length >= 0) return length * (t.pos / 100.0); break; case REL_TIME_CHAPTER: chapter_start_pts = chapter_start_time(mpctx, t.pos); if (chapter_start_pts != MP_NOPTS_VALUE){ /* * rel_time_to_abs always returns rebased timetamps, * even with --rebase-start-time=no. (See the above two * cases.) chapter_start_time values are not rebased without * --rebase-start-time=yes, so we need to rebase them * here to be consistent with the rest of rel_time_to_abs. */ if (mpctx->demuxer && !mpctx->opts->rebase_start_time){ chapter_start_pts -= mpctx->demuxer->start_time; } return chapter_start_pts; } break; } return MP_NOPTS_VALUE; }
static void print_status(struct MPContext *mpctx) { struct MPOpts *opts = mpctx->opts; update_window_title(mpctx, false); update_vo_playback_state(mpctx); if (!opts->use_terminal) return; if (opts->quiet || !mpctx->playback_initialized || !mpctx->playing_msg_shown) { term_osd_set_status(mpctx, ""); return; } if (opts->status_msg) { char *r = mp_property_expand_escaped_string(mpctx, opts->status_msg); term_osd_set_status(mpctx, r); talloc_free(r); return; } char *line = NULL; // Playback status if (is_busy(mpctx)) { saddf(&line, "(...) "); } else if (mpctx->paused_for_cache && !opts->pause) { saddf(&line, "(Buffering) "); } else if (mpctx->paused) { saddf(&line, "(Paused) "); } if (mpctx->d_audio) saddf(&line, "A"); if (mpctx->d_video) saddf(&line, "V"); saddf(&line, ": "); // Playback position sadd_hhmmssff_u(&line, get_playback_time(mpctx), mpctx->opts->osd_fractions); double len = get_time_length(mpctx); if (len >= 0) { saddf(&line, " / "); sadd_hhmmssff(&line, len, mpctx->opts->osd_fractions); } sadd_percentage(&line, get_percent_pos(mpctx)); // other if (opts->playback_speed != 1) saddf(&line, " x%4.2f", opts->playback_speed); // A-V sync if (mpctx->d_audio && mpctx->d_video && mpctx->sync_audio_to_video) { saddf(&line, " A-V:%7.3f", mpctx->last_av_difference); if (fabs(mpctx->total_avsync_change) > 0.05) saddf(&line, " ct:%7.3f", mpctx->total_avsync_change); } #if HAVE_ENCODING double position = get_current_pos_ratio(mpctx, true); char lavcbuf[80]; if (encode_lavc_getstatus(mpctx->encode_lavc_ctx, lavcbuf, sizeof(lavcbuf), position) >= 0) { // encoding stats saddf(&line, " %s", lavcbuf); } else #endif { // VO stats if (mpctx->d_video) { if (mpctx->display_sync_active) { saddf(&line, " DS: %d/%"PRId64, mpctx->mistimed_frames_total, vo_get_delayed_count(mpctx->video_out)); } int64_t c = vo_get_drop_count(mpctx->video_out); if (c > 0 || mpctx->dropped_frames_total > 0) { saddf(&line, " Dropped: %"PRId64, c); if (mpctx->dropped_frames_total) saddf(&line, "/%d", mpctx->dropped_frames_total); } } } if (mpctx->demuxer) { int64_t fill = -1; demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_FILL, &fill); if (fill >= 0) { saddf(&line, " Cache: "); struct demux_ctrl_reader_state s = {.ts_duration = -1}; demux_control(mpctx->demuxer, DEMUXER_CTRL_GET_READER_STATE, &s); if (s.ts_duration < 0) { saddf(&line, "???"); } else { saddf(&line, "%2ds", (int)s.ts_duration); } if (fill >= 1024 * 1024) { saddf(&line, "+%lldMB", (long long)(fill / 1024 / 1024)); } else { saddf(&line, "+%lldKB", (long long)(fill / 1024)); } } }
void print_status(struct MPContext *mpctx) { struct MPOpts *opts = mpctx->opts; update_window_title(mpctx, false); if (!opts->use_terminal) return; if (opts->quiet || !(mpctx->initialized_flags & INITIALIZED_PLAYBACK)) { term_osd_set_status(mpctx, ""); return; } if (opts->status_msg) { char *r = mp_property_expand_escaped_string(mpctx, opts->status_msg); term_osd_set_status(mpctx, r); talloc_free(r); return; } char *line = NULL; // Playback status if (mpctx->paused_for_cache && !opts->pause) { saddf(&line, "(Buffering) "); } else if (mpctx->paused) { saddf(&line, "(Paused) "); } if (mpctx->d_audio) saddf(&line, "A"); if (mpctx->d_video) saddf(&line, "V"); saddf(&line, ": "); // Playback position double cur = get_current_time(mpctx); sadd_hhmmssff(&line, cur, mpctx->opts->osd_fractions); double len = get_time_length(mpctx); if (len >= 0) { saddf(&line, " / "); sadd_hhmmssff(&line, len, mpctx->opts->osd_fractions); } sadd_percentage(&line, get_percent_pos(mpctx)); // other if (opts->playback_speed != 1) saddf(&line, " x%4.2f", opts->playback_speed); // A-V sync if (mpctx->d_audio && mpctx->d_video && mpctx->sync_audio_to_video) { if (mpctx->last_av_difference != MP_NOPTS_VALUE) saddf(&line, " A-V:%7.3f", mpctx->last_av_difference); else saddf(&line, " A-V: ???"); if (fabs(mpctx->total_avsync_change) > 0.05) saddf(&line, " ct:%7.3f", mpctx->total_avsync_change); } #if HAVE_ENCODING double position = get_current_pos_ratio(mpctx, true); char lavcbuf[80]; if (encode_lavc_getstatus(mpctx->encode_lavc_ctx, lavcbuf, sizeof(lavcbuf), position) >= 0) { // encoding stats saddf(&line, " %s", lavcbuf); } else #endif { // VO stats if (mpctx->d_video && mpctx->drop_frame_cnt) saddf(&line, " Late: %d", mpctx->drop_frame_cnt); } int cache = mp_get_cache_percent(mpctx); if (cache >= 0) saddf(&line, " Cache: %d%%", cache); if (opts->term_osd_bar) { saddf(&line, "\n"); get_screen_size(); add_term_osd_bar(mpctx, &line, screen_width); } // end term_osd_set_status(mpctx, line); talloc_free(line); }