summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--command.c30
-rw-r--r--libmpdemux/demux_demuxers.c5
-rw-r--r--libmpdemux/demuxer.c63
-rw-r--r--libmpdemux/demuxer.h3
-rw-r--r--mp_core.h3
-rw-r--r--mplayer.c102
6 files changed, 91 insertions, 115 deletions
diff --git a/command.c b/command.c
index 1d1e9f016c..f669c19fff 100644
--- a/command.c
+++ b/command.c
@@ -389,7 +389,7 @@ static int mp_property_length(m_option_t *prop, int action, void *arg,
double len;
if (!mpctx->demuxer ||
- !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
+ !(int) (len = get_time_length(mpctx)))
return M_PROPERTY_UNAVAILABLE;
return m_property_time_ro(prop, action, arg, len);
@@ -411,14 +411,13 @@ static int mp_property_percent_pos(m_option_t *prop, int action,
break;
case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN:
- pos = demuxer_get_percent_pos(mpctx->demuxer);
+ pos = get_percent_pos(mpctx);
pos += (arg ? *(int*)arg : 10) *
(action == M_PROPERTY_STEP_UP ? 1 : -1);
M_PROPERTY_CLAMP(prop, pos);
break;
default:
- return m_property_int_ro(prop, action, arg,
- demuxer_get_percent_pos(mpctx->demuxer));
+ return m_property_int_ro(prop, action, arg, get_percent_pos(mpctx));
}
mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
@@ -445,9 +444,7 @@ static int mp_property_time_pos(m_option_t *prop, int action,
(action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
return M_PROPERTY_OK;
}
- return m_property_time_ro(prop, action, arg,
- mpctx->sh_video ? mpctx->sh_video->pts :
- playing_audio_pts(mpctx));
+ return m_property_time_ro(prop, action, arg, get_current_time(mpctx));
}
/// Current chapter (RW)
@@ -2795,8 +2792,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
case MP_CMD_EDL_MARK:
if (edl_fd) {
- float v = sh_video ? sh_video->pts :
- playing_audio_pts(mpctx);
+ float v = get_current_time(mpctx);
if (mpctx->begin_skip == MP_NOPTS_VALUE) {
mpctx->begin_skip = v;
mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
@@ -3021,9 +3017,9 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
break;
case MP_CMD_OSD_SHOW_PROGRESSION:{
- int len = demuxer_get_time_length(mpctx->demuxer);
- int pts = demuxer_get_current_time(mpctx->demuxer);
- set_osd_bar(mpctx, 0, "Position", 0, 100, demuxer_get_percent_pos(mpctx->demuxer));
+ int len = get_time_length(mpctx);
+ int pts = get_current_time(mpctx);
+ set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
"%c %02d:%02d:%02d / %02d:%02d:%02d",
mpctx->osd_function, pts/3600, (pts/60)%60, pts%60,
@@ -3280,7 +3276,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
case MP_CMD_GET_TIME_LENGTH:{
mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
- demuxer_get_time_length(mpctx->demuxer));
+ get_time_length(mpctx));
}
break;
@@ -3415,15 +3411,11 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
case MP_CMD_GET_PERCENT_POS:
mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
- demuxer_get_percent_pos(mpctx->demuxer));
+ get_percent_pos(mpctx));
break;
case MP_CMD_GET_TIME_POS:{
- float pos = 0;
- if (sh_video)
- pos = sh_video->pts;
- else if (sh_audio && mpctx->audio_out)
- pos = playing_audio_pts(mpctx);
+ float pos = get_current_time(mpctx);
mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
}
break;
diff --git a/libmpdemux/demux_demuxers.c b/libmpdemux/demux_demuxers.c
index 531f048508..906ea402c5 100644
--- a/libmpdemux/demux_demuxers.c
+++ b/libmpdemux/demux_demuxers.c
@@ -151,11 +151,8 @@ static int demux_demuxers_control(demuxer_t *demuxer,int cmd, void *arg){
dd_priv_t* priv = demuxer->priv;
switch (cmd) {
case DEMUXER_CTRL_GET_TIME_LENGTH:
- *((double *)arg) = demuxer_get_time_length(priv->vd);
- return DEMUXER_CTRL_OK;
case DEMUXER_CTRL_GET_PERCENT_POS:
- *((int *)arg) = demuxer_get_percent_pos(priv->vd);
- return DEMUXER_CTRL_OK;
+ return demux_control(priv->vd, cmd, arg);
}
return DEMUXER_CTRL_NOTIMPL;
}
diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c
index ae81ae3e33..99f1be9fe8 100644
--- a/libmpdemux/demuxer.c
+++ b/libmpdemux/demuxer.c
@@ -1379,69 +1379,6 @@ int demux_control(demuxer_t *demuxer, int cmd, void *arg)
return DEMUXER_CTRL_NOTIMPL;
}
-
-
-double demuxer_get_time_length(demuxer_t *demuxer)
-{
- double get_time_ans;
- sh_video_t *sh_video = demuxer->video->sh;
- sh_audio_t *sh_audio = demuxer->audio->sh;
- // <= 0 means DEMUXER_CTRL_NOTIMPL or DEMUXER_CTRL_DONTKNOW
- if (demux_control
- (demuxer, DEMUXER_CTRL_GET_TIME_LENGTH, (void *) &get_time_ans) <= 0) {
- if (sh_video && sh_video->i_bps && sh_audio && sh_audio->i_bps)
- get_time_ans = (double) (demuxer->movi_end -
- demuxer->movi_start) / (sh_video->i_bps +
- sh_audio->i_bps);
- else if (sh_video && sh_video->i_bps)
- get_time_ans = (double) (demuxer->movi_end -
- demuxer->movi_start) / sh_video->i_bps;
- else if (sh_audio && sh_audio->i_bps)
- get_time_ans = (double) (demuxer->movi_end -
- demuxer->movi_start) / sh_audio->i_bps;
- else
- get_time_ans = 0;
- }
- return get_time_ans;
-}
-
-/**
- * \brief demuxer_get_current_time() returns the time of the current play in three possible ways:
- * either when the stream reader satisfies STREAM_CTRL_GET_CURRENT_TIME (e.g. dvd)
- * or using sh_video->pts when the former method fails
- * 0 otherwise
- * \return the current play time
- */
-int demuxer_get_current_time(demuxer_t *demuxer)
-{
- double get_time_ans = 0;
- sh_video_t *sh_video = demuxer->video->sh;
- if (demuxer->stream_pts != MP_NOPTS_VALUE)
- get_time_ans = demuxer->stream_pts;
- else if (sh_video)
- get_time_ans = sh_video->pts;
- return (int) get_time_ans;
-}
-
-int demuxer_get_percent_pos(demuxer_t *demuxer)
-{
- int ans = 0;
- int res = demux_control(demuxer, DEMUXER_CTRL_GET_PERCENT_POS, &ans);
- int len = (demuxer->movi_end - demuxer->movi_start) / 100;
- if (res <= 0) {
- off_t pos = demuxer->filepos > 0 ? demuxer->filepos : stream_tell(demuxer->stream);
- if (len > 0)
- ans = (pos - demuxer->movi_start) / len;
- else
- ans = 0;
- }
- if (ans < 0)
- ans = 0;
- if (ans > 100)
- ans = 100;
- return ans;
-}
-
int demuxer_switch_audio(demuxer_t *demuxer, int index)
{
int res = demux_control(demuxer, DEMUXER_CTRL_SWITCH_AUDIO, &index);
diff --git a/libmpdemux/demuxer.h b/libmpdemux/demuxer.h
index 1a1f189b55..2c200ead1e 100644
--- a/libmpdemux/demuxer.h
+++ b/libmpdemux/demuxer.h
@@ -434,9 +434,6 @@ char* demux_info_get(demuxer_t *demuxer, const char *opt);
int demux_info_print(demuxer_t *demuxer);
int demux_control(demuxer_t *demuxer, int cmd, void *arg);
-int demuxer_get_current_time(demuxer_t *demuxer);
-double demuxer_get_time_length(demuxer_t *demuxer);
-int demuxer_get_percent_pos(demuxer_t *demuxer);
int demuxer_switch_audio(demuxer_t *demuxer, int index);
int demuxer_switch_video(demuxer_t *demuxer, int index);
diff --git a/mp_core.h b/mp_core.h
index 9ef9e6c972..b6e0007743 100644
--- a/mp_core.h
+++ b/mp_core.h
@@ -217,6 +217,9 @@ void unpause_player(struct MPContext *mpctx);
void add_step_frame(struct MPContext *mpctx);
int seek_chapter(struct MPContext *mpctx, int chapter, double *seek_pts,
char **chapter_name);
+double get_time_length(struct MPContext *mpctx);
+double get_current_time(struct MPContext *mpctx);
+int get_percent_pos(struct MPContext *mpctx);
int get_current_chapter(struct MPContext *mpctx);
char *chapter_display_name(struct MPContext *mpctx, int chapter);
diff --git a/mplayer.c b/mplayer.c
index 28439d05c7..d6007a58c4 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -596,7 +596,7 @@ char *get_metadata(struct MPContext *mpctx, metadata_t type)
return meta;
}
-static void print_file_properties(const MPContext *mpctx, const char *filename)
+static void print_file_properties(struct MPContext *mpctx, const char *filename)
{
double start_pts = MP_NOPTS_VALUE;
double video_start_pts = MP_NOPTS_VALUE;
@@ -636,9 +636,7 @@ static void print_file_properties(const MPContext *mpctx, const char *filename)
mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_START_TIME=%.2f\n", start_pts);
else
mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_START_TIME=unknown\n");
- mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_LENGTH=%.2f\n", mpctx->timeline ?
- mpctx->timeline[mpctx->num_timeline_parts].start :
- demuxer_get_time_length(mpctx->demuxer));
+ mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_LENGTH=%.2f\n", get_time_length(mpctx));
mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_SEEKABLE=%d\n",
mpctx->stream->seek && (!mpctx->demuxer || mpctx->demuxer->seekable));
if (mpctx->demuxer) {
@@ -1336,7 +1334,7 @@ static void print_status(struct MPContext *mpctx, double a_pos, bool at_frame)
if (mpctx->sh_audio) {
saddf(line, &pos, width, "A:%6.1f ", a_pos);
if (!sh_video) {
- float len = demuxer_get_time_length(mpctx->demuxer);
+ float len = get_time_length(mpctx);
saddf(line, &pos, width, "(");
sadd_hhmmssf(line, &pos, width, a_pos);
saddf(line, &pos, width, ") of %.1f (", len);
@@ -1674,12 +1672,7 @@ static void update_osd_msg(struct MPContext *mpctx)
char osd_text_timer[128];
if (mpctx->add_osd_seek_info) {
- double percentage;
- if (mpctx->timeline && mpctx->sh_video)
- percentage = mpctx->sh_video->pts * 100 /
- mpctx->timeline[mpctx->num_timeline_parts].start;
- else
- percentage = demuxer_get_percent_pos(mpctx->demuxer);
+ double percentage = get_percent_pos(mpctx);
set_osd_bar(mpctx, 0, "Position", 0, 100, percentage);
if (mpctx->sh_video)
mpctx->osd_show_percentage_until = (GetTimerMS() + 1000) | 1;
@@ -1699,22 +1692,13 @@ static void update_osd_msg(struct MPContext *mpctx)
if(mpctx->sh_video) {
// fallback on the timer
if (opts->osd_level >= 2) {
- int len;
- if (mpctx->timeline)
- len = mpctx->timeline[mpctx->num_timeline_parts].start;
- else
- len = demuxer_get_time_length(mpctx->demuxer);
+ int len = get_time_length(mpctx);
int percentage = -1;
char percentage_text[10];
- int pts = demuxer_get_current_time(mpctx->demuxer);
-
- if (mpctx->osd_show_percentage_until) {
- if (mpctx->timeline)
- percentage = mpctx->sh_video->pts * 100 /
- mpctx->timeline[mpctx->num_timeline_parts].start;
- else
- percentage = demuxer_get_percent_pos(mpctx->demuxer);
- }
+ int pts = get_current_time(mpctx);
+
+ if (mpctx->osd_show_percentage_until)
+ percentage = get_percent_pos(mpctx);
if (percentage >= 0)
snprintf(percentage_text, 9, " (%d%%)", percentage);
@@ -2081,7 +2065,7 @@ static mp_image_t *mp_dvdnav_restore_smpi(struct MPContext *mpctx,
decoded_frame = mpctx->nav_smpi;
/// increment video frame : continue playing after still frame
- len = demuxer_get_time_length(mpctx->demuxer);
+ len = get_time_length(mpctx);
if (mpctx->sh_video->pts >= len &&
mpctx->sh_video->pts > 0.0 && len > 0.0) {
mp_dvdnav_skip_still(mpctx->stream);
@@ -2867,6 +2851,72 @@ static int seek(MPContext *mpctx, double amount, int style)
return 0;
}
+
+double get_time_length(struct MPContext *mpctx)
+{
+ if (mpctx->timeline)
+ return mpctx->timeline[mpctx->num_timeline_parts].start;
+
+ struct demuxer *demuxer = mpctx->demuxer;
+ double get_time_ans;
+ // <= 0 means DEMUXER_CTRL_NOTIMPL or DEMUXER_CTRL_DONTKNOW
+ if (demux_control(demuxer, DEMUXER_CTRL_GET_TIME_LENGTH,
+ (void *) &get_time_ans) > 0)
+ return get_time_ans;
+
+ struct sh_video *sh_video = mpctx->d_video->sh;
+ struct sh_audio *sh_audio = mpctx->d_audio->sh;
+ if (sh_video && sh_video->i_bps && sh_audio && sh_audio->i_bps)
+ return (double) (demuxer->movi_end - demuxer->movi_start) /
+ (sh_video->i_bps + sh_audio->i_bps);
+ if (sh_video && sh_video->i_bps)
+ return (double) (demuxer->movi_end - demuxer->movi_start) /
+ sh_video->i_bps;
+ if (sh_audio && sh_audio->i_bps)
+ return (double) (demuxer->movi_end - demuxer->movi_start) /
+ sh_audio->i_bps;
+ return 0;
+}
+
+/* If there are timestamps from stream level then use those (for example
+ * DVDs can have consistent times there while the MPEG-level timestamps
+ * reset). */
+double get_current_time(struct MPContext *mpctx)
+{
+ struct demuxer *demuxer = mpctx->demuxer;
+ if (demuxer->stream_pts != MP_NOPTS_VALUE)
+ return demuxer->stream_pts;
+ struct sh_video *sh_video = demuxer->video->sh;
+ if (sh_video)
+ return sh_video->pts;
+ return playing_audio_pts(mpctx);
+}
+
+int get_percent_pos(struct MPContext *mpctx)
+{
+ struct demuxer *demuxer = mpctx->demuxer;
+ int ans = 0;
+ if (mpctx->timeline)
+ ans = get_current_time(mpctx) * 100 /
+ mpctx->timeline[mpctx->num_timeline_parts].start;
+ else if (demux_control(demuxer, DEMUXER_CTRL_GET_PERCENT_POS, &ans) > 0)
+ ;
+ else {
+ int len = (demuxer->movi_end - demuxer->movi_start) / 100;
+ off_t pos = demuxer->filepos > 0 ?
+ demuxer->filepos : stream_tell(demuxer->stream);
+ if (len > 0)
+ ans = (pos - demuxer->movi_start) / len;
+ else
+ ans = 0;
+ }
+ if (ans < 0)
+ ans = 0;
+ if (ans > 100)
+ ans = 100;
+ return ans;
+}
+
// -2 is no chapters, -1 is before first chapter
int get_current_chapter(struct MPContext *mpctx)
{