core: remove duplicated format_time() functions

This was an on-going transition to make mplayer format all times in the
same format.
This commit is contained in:
wm4 2012-09-01 21:59:13 +02:00
parent 5a13f5a5e8
commit 53bfaecd40
6 changed files with 32 additions and 53 deletions

View File

@ -2082,16 +2082,6 @@ static const char *property_error_string(int error_value)
return "UNKNOWN";
}
static char *format_time(double time)
{
int h, m, s = time;
h = s / 3600;
s -= h * 3600;
m = s / 60;
s -= m * 60;
return talloc_asprintf(NULL, "%02d:%02d:%02d", h, m, s);
}
static void show_chapters_on_osd(MPContext *mpctx)
{
int count = get_chapter_count(mpctx);
@ -2106,7 +2096,7 @@ static void show_chapters_on_osd(MPContext *mpctx)
for (n = 0; n < count; n++) {
char *name = chapter_display_name(mpctx, n);
double t = chapter_start_time(mpctx, n);
char* time = format_time(t);
char* time = mp_format_time(t, false);
res = talloc_asprintf_append(res, "%s", time);
talloc_free(time);
char *m1 = "> ", *m2 = " <";

View File

@ -380,16 +380,6 @@ int m_property_double_ro(const m_option_t *prop, int action,
return M_PROPERTY_NOT_IMPLEMENTED;
}
static char *format_time(double time)
{
int h, m, s = time;
h = s / 3600;
s -= h * 3600;
m = s / 60;
s -= m * 60;
return talloc_asprintf(NULL, "%02d:%02d:%02d", h, m, s);
}
int m_property_time_ro(const m_option_t *prop, int action,
void *arg, double var)
{
@ -398,7 +388,7 @@ int m_property_time_ro(const m_option_t *prop, int action,
if (!arg)
return M_PROPERTY_ERROR;
else {
*(char **)arg = format_time(var);
*(char **)arg = mp_format_time(var, false);
return M_PROPERTY_OK;
}
}

View File

@ -15,3 +15,22 @@
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "talloc.h"
#include "mpcommon.h"
char *mp_format_time(double time, bool fractions)
{
if (time < 0)
return talloc_strdup(NULL, "unknown");
int h, m, s = time;
h = s / 3600;
s -= h * 3600;
m = s / 60;
s -= m * 60;
char *res = talloc_asprintf(NULL, "%02d:%02d:%02d", h, m, s);
if (fractions)
res = talloc_asprintf_append(res, ".%03d",
(int)((time - (int)time) * 1000));
return res;
}

View File

@ -20,6 +20,7 @@
#define MPLAYER_MPCOMMON_H
#include <stdlib.h>
#include <stdbool.h>
// both int64_t and double should be able to represent this exactly
#define MP_NOPTS_VALUE (-1LL<<63)
@ -77,4 +78,6 @@
extern const char *mplayer_version;
char *mp_format_time(double time, bool fractions);
#endif /* MPLAYER_MPCOMMON_H */

View File

@ -1151,20 +1151,9 @@ static void saddf(char *buf, int len, const char *format, ...)
*/
static void sadd_hhmmssff(char *buf, int len, double time, bool fractions)
{
if (time < 0) {
saddf(buf, len, "unknown");
return;
}
int h, m, s = time;
h = s / 3600;
s -= h * 3600;
m = s / 60;
s -= m * 60;
saddf(buf, len, "%02d:", h);
saddf(buf, len, "%02d:", m);
saddf(buf, len, "%02d", s);
if (fractions)
saddf(buf, len, ".%02d", (int)((time - (int)time) * 100));
char *s = mp_format_time(time, fractions);
saddf(buf, len, "%s", s);
talloc_free(s);
}
static void sadd_percentage(char *buf, int len, int percent) {

View File

@ -67,20 +67,6 @@ static char *stripext(void *talloc_ctx, const char *s)
return talloc_asprintf(talloc_ctx, "%.*s", end - s, s);
}
static char *format_time(void *talloc_ctx, double time, bool sub_seconds)
{
int h, m, s = time;
h = s / 3600;
s -= h * 3600;
m = s / 60;
s -= m * 60;
char *res = talloc_asprintf(talloc_ctx, "%02d:%02d:%02d", h, m, s);
if (sub_seconds)
res = talloc_asprintf_append(res, ".%03d",
(int)((time - (int)time) * 1000));
return res;
}
static char *do_format_property(struct MPContext *mpctx, struct bstr s) {
struct bstr prop_name = s;
int fallbackpos = bstrchr(s, ':');
@ -179,10 +165,12 @@ static char *create_fname(struct MPContext *mpctx, char *template,
break;
}
case 'p':
case 'P':
append_filename(&res,
format_time(res, get_current_time(mpctx), fmt == 'P'));
case 'P': {
char *t = mp_format_time(get_current_time(mpctx), fmt == 'P');
append_filename(&res, t);
talloc_free(t);
break;
}
case 't': {
char fmt = *template;
if (!fmt)