[FFmpeg-cvslog] r10533 - in trunk: ffmpeg.c ffplay.c ffserver.c libavformat/avformat.h libavformat/utils.c

benoit subversion
Wed Sep 19 14:38:07 CEST 2007


Author: benoit
Date: Wed Sep 19 14:38:07 2007
New Revision: 10533

Log:
Make parse_date return INT64_MIN in case of unparsable input.
Patch by Stefano Sabatini: [stefano sabatini-lala poste it]
Original thread:
[FFmpeg-devel] [PATCH] Enhace documentation forlibavformat/utils.c:parse_date
Date: 08/17/2007 09:40 PM


Modified:
   trunk/ffmpeg.c
   trunk/ffplay.c
   trunk/ffserver.c
   trunk/libavformat/avformat.h
   trunk/libavformat/utils.c

Modified: trunk/ffmpeg.c
==============================================================================
--- trunk/ffmpeg.c	(original)
+++ trunk/ffmpeg.c	Wed Sep 19 14:38:07 2007
@@ -2491,24 +2491,35 @@ static void opt_map_meta_data(const char
     m->in_file = strtol(p, (char **)&p, 0);
 }
 
+static int64_t parse_time_or_die(const char *timestr, int is_duration)
+{
+    int64_t us = parse_date(timestr, is_duration);
+    if (us == INT64_MIN) {
+        fprintf(stderr, "Invalid %s specification: %s\n",
+                is_duration ? "duration" : "date", timestr);
+        exit(1);
+    }
+    return us;
+}
+
 static void opt_recording_time(const char *arg)
 {
-    recording_time = parse_date(arg, 1);
+    recording_time = parse_time_or_die(arg, 1);
 }
 
 static void opt_start_time(const char *arg)
 {
-    start_time = parse_date(arg, 1);
+    start_time = parse_time_or_die(arg, 1);
 }
 
 static void opt_rec_timestamp(const char *arg)
 {
-    rec_timestamp = parse_date(arg, 0) / 1000000;
+    rec_timestamp = parse_time_or_die(arg, 0) / 1000000;
 }
 
 static void opt_input_ts_offset(const char *arg)
 {
-    input_ts_offset = parse_date(arg, 1);
+    input_ts_offset = parse_time_or_die(arg, 1);
 }
 
 static enum CodecID find_codec_or_die(const char *name, int type, int encoder)

Modified: trunk/ffplay.c
==============================================================================
--- trunk/ffplay.c	(original)
+++ trunk/ffplay.c	Wed Sep 19 14:38:07 2007
@@ -2406,6 +2406,10 @@ static void opt_sync(const char *arg)
 static void opt_seek(const char *arg)
 {
     start_time = parse_date(arg, 1);
+    if (start_time == INT64_MIN) {
+        fprintf(stderr, "Invalid duration specification: %s\n", arg);
+        exit(1);
+    }
 }
 
 static void opt_debug(const char *arg)

Modified: trunk/ffserver.c
==============================================================================
--- trunk/ffserver.c	(original)
+++ trunk/ffserver.c	Wed Sep 19 14:38:07 2007
@@ -1887,7 +1887,11 @@ static int open_input_stream(HTTPContext
         buf_size = FFM_PACKET_SIZE;
         /* compute position (absolute time) */
         if (find_info_tag(buf, sizeof(buf), "date", info))
+        {
             stream_pos = parse_date(buf, 0);
+            if (stream_pos == INT64_MIN)
+                return -1;
+        }
         else if (find_info_tag(buf, sizeof(buf), "buffer", info)) {
             int prebuffer = strtol(buf, 0, 10);
             stream_pos = av_gettime() - prebuffer * (int64_t)1000000;
@@ -1898,7 +1902,11 @@ static int open_input_stream(HTTPContext
         buf_size = 0;
         /* compute position (relative time) */
         if (find_info_tag(buf, sizeof(buf), "date", info))
+        {
             stream_pos = parse_date(buf, 1);
+            if (stream_pos == INT64_MIN)
+                return -1;
+        }
         else
             stream_pos = 0;
     }

Modified: trunk/libavformat/avformat.h
==============================================================================
--- trunk/libavformat/avformat.h	(original)
+++ trunk/libavformat/avformat.h	Wed Sep 19 14:38:07 2007
@@ -21,8 +21,8 @@
 #ifndef AVFORMAT_H
 #define AVFORMAT_H
 
-#define LIBAVFORMAT_VERSION_INT ((51<<16)+(13<<8)+3)
-#define LIBAVFORMAT_VERSION     51.13.3
+#define LIBAVFORMAT_VERSION_INT ((51<<16)+(13<<8)+4)
+#define LIBAVFORMAT_VERSION     51.13.4
 #define LIBAVFORMAT_BUILD       LIBAVFORMAT_VERSION_INT
 
 #define LIBAVFORMAT_IDENT       "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
@@ -794,19 +794,30 @@ attribute_deprecated int parse_image_siz
 attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
 
 /**
- * Converts date string to number of seconds since Jan 1st, 1970.
- *
+ * Parses \p datestr and returns a corresponding number of microseconds.
+ * @param datestr String representing a date or a duration.
+ * - If a date the syntax is:
  * @code
- * Syntax:
- * - If not a duration:
  *  [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
- * Time is localtime unless Z is suffixed to the end. In this case GMT
- * Return the date in micro seconds since 1970
- *
- * - If a duration:
- *  HH[:MM[:SS[.m...]]]
- *  S+[.m...]
  * @endcode
+ * Time is localtime unless Z is appended, in which case it is
+ * interpreted as UTC.
+ * If the year-month-day part isn't specified it takes the current
+ * year-month-day.
+ * Returns the number of microseconds since 1st of January, 1970 up to
+ * the time of the parsed date or INT64_MIN if \p datestr cannot be
+ * successfully parsed.
+ * - If a duration the syntax is:
+ * @code
+ *  [-]HH[:MM[:SS[.m...]]]
+ *  [-]S+[.m...]
+ * @endcode
+ * Returns the number of microseconds contained in a time interval
+ * with the specified duration or INT64_MIN if \p datestr cannot be
+ * succesfully parsed.
+ * @param duration Flag which tells how to interpret \p datestr, if
+ * not zero \p datestr is interpreted as a duration, otherwise as a
+ * date.
  */
 int64_t parse_date(const char *datestr, int duration);
 

Modified: trunk/libavformat/utils.c
==============================================================================
--- trunk/libavformat/utils.c	(original)
+++ trunk/libavformat/utils.c	Wed Sep 19 14:38:07 2007
@@ -2621,6 +2621,9 @@ int64_t parse_date(const char *datestr, 
         if (!q) {
             /* parse datestr as S+ */
             dt.tm_sec = strtol(p, (char **)&q, 10);
+            if (q == p)
+                /* the parsing didn't succeed */
+                return INT64_MIN;
             dt.tm_min = 0;
             dt.tm_hour = 0;
         }
@@ -2628,10 +2631,7 @@ int64_t parse_date(const char *datestr, 
 
     /* Now we have all the fields that we can get */
     if (!q) {
-        if (duration)
-            return 0;
-        else
-            return now * INT64_C(1000000);
+        return INT64_MIN;
     }
 
     if (duration) {




More information about the ffmpeg-cvslog mailing list