From be63729ba5547fea0a557a44cb0d8b50be32d1fb Mon Sep 17 00:00:00 2001 From: albeu Date: Thu, 31 May 2007 12:42:02 +0000 Subject: [PATCH] Move the time printing code out of the length property. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@23434 b3059339-0415-0410-9bf9-f77b7e298cf2 --- command.c | 23 +---------------------- m_property.c | 25 +++++++++++++++++++++++++ m_property.h | 4 ++++ 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/command.c b/command.c index e6750f314b..4fbeb1921e 100644 --- a/command.c +++ b/command.c @@ -283,28 +283,7 @@ static int mp_property_length(m_option_t * prop, int action, void *arg, !(int) (len = demuxer_get_time_length(mpctx->demuxer))) return M_PROPERTY_UNAVAILABLE; - switch (action) { - case M_PROPERTY_PRINT: - if (!arg) - return M_PROPERTY_ERROR; - else { - int h, m, s = len; - h = s / 3600; - s -= h * 3600; - m = s / 60; - s -= m * 60; - *(char **) arg = malloc(20); - if (h > 0) - sprintf(*(char **) arg, "%d:%02d:%02d", h, m, s); - else if (m > 0) - sprintf(*(char **) arg, "%d:%02d", m, s); - else - sprintf(*(char **) arg, "%d", s); - return M_PROPERTY_OK; - } - break; - } - return m_property_double_ro(prop, action, arg, len); + return m_property_time_ro(prop, action, arg, len); } /// Demuxer meta data diff --git a/m_property.c b/m_property.c index 99beef9392..52a10ffe35 100644 --- a/m_property.c +++ b/m_property.c @@ -318,6 +318,31 @@ int m_property_double_ro(m_option_t* prop,int action, return M_PROPERTY_NOT_IMPLEMENTED; } +int m_property_time_ro(m_option_t* prop,int action, + void* arg,double var) { + switch(action) { + case M_PROPERTY_PRINT: + if (!arg) + return M_PROPERTY_ERROR; + else { + int h, m, s = var; + h = s / 3600; + s -= h * 3600; + m = s / 60; + s -= m * 60; + *(char **) arg = malloc(20); + if (h > 0) + sprintf(*(char **) arg, "%d:%02d:%02d", h, m, s); + else if (m > 0) + sprintf(*(char **) arg, "%d:%02d", m, s); + else + sprintf(*(char **) arg, "%d", s); + return M_PROPERTY_OK; + } + } + return m_property_double_ro(prop,action,arg,var); +} + int m_property_string_ro(m_option_t* prop,int action,void* arg,char* str) { switch(action) { case M_PROPERTY_GET: diff --git a/m_property.h b/m_property.h index f2ab0feb44..b28b9f3b8b 100644 --- a/m_property.h +++ b/m_property.h @@ -185,6 +185,10 @@ int m_property_delay(m_option_t* prop,int action, int m_property_double_ro(m_option_t* prop,int action, void* arg,double var); +/// Implement print +int m_property_time_ro(m_option_t* prop,int action, + void* arg,double var); + /// get/print the string int m_property_string_ro(m_option_t* prop,int action,void* arg, char* str);