[MPlayer-cvslog] r37499 - in trunk/gui/util: misc.c misc.h
ib
subversion at mplayerhq.hu
Tue Sep 8 12:02:53 CEST 2015
Author: ib
Date: Tue Sep 8 12:02:53 2015
New Revision: 37499
Log:
Add auxiliary function msf2sec().
Convert minute:second:frame to seconds.
Modified:
trunk/gui/util/misc.c
trunk/gui/util/misc.h
Modified: trunk/gui/util/misc.c
==============================================================================
--- trunk/gui/util/misc.c Tue Sep 8 11:56:50 2015 (r37498)
+++ trunk/gui/util/misc.c Tue Sep 8 12:02:53 2015 (r37499)
@@ -21,6 +21,7 @@
* @brief Miscellaneous utilities
*/
+#include <ctype.h>
#include <string.h>
#include "misc.h"
@@ -64,3 +65,38 @@ float constrain(float value)
return value;
}
+
+/**
+ * @brief Convert MM:SS:FF (minute/second/frame) to seconds.
+ *
+ * @param msf string in MM:SS:FF format
+ *
+ * @return seconds equivalent to @a msf (0 in case of error)
+ */
+float msf2sec(const char *msf)
+{
+ int i;
+
+ for (i = 0; i < 8; i++)
+ switch (i) {
+ case 0:
+ case 1:
+ case 3:
+ case 4:
+ case 6:
+ case 7:
+ if (!isdigit(msf[i]))
+ return 0.0f;
+ break;
+
+ case 2:
+ case 5:
+ if (msf[i] != ':')
+ return 0.0f;
+ break;
+ }
+
+ return (msf[0] - '0') * 600 + (msf[1] - '0') * 60 +
+ (msf[3] - '0') * 10 + (msf[4] - '0') +
+ ((msf[6] - '0') * 10 + (msf[7] - '0')) / 75.0f;
+}
Modified: trunk/gui/util/misc.h
==============================================================================
--- trunk/gui/util/misc.h Tue Sep 8 11:56:50 2015 (r37498)
+++ trunk/gui/util/misc.h Tue Sep 8 12:02:53 2015 (r37499)
@@ -23,5 +23,6 @@
float constrain(float value);
char *fgetstr(char *str, int size, FILE *file);
+float msf2sec(const char *msf);
#endif /* MPLAYER_GUI_MISC_H */
More information about the MPlayer-cvslog
mailing list