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)
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)
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;
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;
}
#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)
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);
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;
}
/* 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) {