[vlc-commits] snapshot: add true subsecond timestamp and pad with zeroes (fix #9012)

Rémi Denis-Courmont git at videolan.org
Sun Jul 21 19:04:06 CEST 2013


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jul 21 20:03:03 2013 +0300| [181ea34b9e93819d96ff88d421186c63c5a3e7dc] | committer: Rémi Denis-Courmont

snapshot: add true subsecond timestamp and pad with zeroes (fix #9012)

The previous value was quite bogus.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=181ea34b9e93819d96ff88d421186c63c5a3e7dc
---

 src/video_output/snapshot.c |   40 ++++++++++++++++------------------------
 1 file changed, 16 insertions(+), 24 deletions(-)

diff --git a/src/video_output/snapshot.c b/src/video_output/snapshot.c
index 5accd89..0519101 100644
--- a/src/video_output/snapshot.c
+++ b/src/video_output/snapshot.c
@@ -28,6 +28,7 @@
 
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/time.h>
 #include <dirent.h>
 #include <time.h>
 
@@ -174,30 +175,21 @@ int vout_snapshot_SaveImage(char **name, int *sequential,
                 free(filename);
             }
         } else {
-            struct tm    curtime;
-            time_t       lcurtime = time(NULL) ;
-
-            if (!localtime_r(&lcurtime, &curtime)) {
-                const unsigned int id = (image->i_pts / 100000) & 0xFFFFFF;
-
-                msg_Warn(object, "failed to get current time. Falling back to legacy snapshot naming");
-
-                if (asprintf(&filename, "%s" DIR_SEP "%s%u.%s",
-                             cfg->path, prefix, id, cfg->format) < 0)
-                    filename = NULL;
-            } else {
-                /* suffix with the last decimal digit in 10s of seconds resolution
-                 * FIXME gni ? */
-                const int id = (image->i_pts / (100*1000)) & 0xFF;
-                char buffer[128];
-
-                if (!strftime(buffer, sizeof(buffer), "%Y-%m-%d-%Hh%Mm%Ss", &curtime))
-                    strcpy(buffer, "error");
-
-                if (asprintf(&filename, "%s" DIR_SEP "%s%s%1u.%s",
-                             cfg->path, prefix, buffer, id, cfg->format) < 0)
-                    filename = NULL;
-            }
+            struct timeval tv;
+            struct tm curtime;
+            char buffer[128];
+
+            gettimeofday(&tv, NULL);
+            if (localtime_r(&tv.tv_sec, &curtime) == NULL)
+                gmtime_r(&tv.tv_sec, &curtime);
+            if (strftime(buffer, sizeof(buffer), "%Y-%m-%d-%Hh%Mm%Ss",
+                         &curtime) == 0)
+                strcpy(buffer, "error");
+
+            if (asprintf(&filename, "%s" DIR_SEP "%s%s%03lu.%s",
+                         cfg->path, prefix, buffer, tv.tv_usec / 1000,
+                         cfg->format) < 0)
+                filename = NULL;
         }
         free(prefix);
     } else {



More information about the vlc-commits mailing list