diff options
author | Stefano Sabatini <stefano.sabatini-lala@poste.it> | 2011-02-16 08:52:36 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-02-18 19:52:30 +0100 |
commit | 40c3fe2c0873feed2a345032205560c4a816271f (patch) | |
tree | c4054eef6adff2f29cfb232fa2358c8be480ce27 /libavformat | |
parent | 0ebf475494837edd07fa6f58c540364795f9551c (diff) | |
download | ffmpeg-40c3fe2c0873feed2a345032205560c4a816271f.tar.gz |
Deprecate parse_date() in favor of av_parse_time().
The new av_parse_time() is created in libavutil/parseutils.h, all the
internal functions used by parse_date are moved to
libavutil/parseutils.c and made static.
Signed-off-by: Mans Rullgard <mans@mansr.com>
(cherry picked from commit f6c7375a175ac649558aefab14f3895b2cb469aa)
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/avformat.h | 29 | ||||
-rw-r--r-- | libavformat/cutils.c | 110 | ||||
-rw-r--r-- | libavformat/internal.h | 3 | ||||
-rw-r--r-- | libavformat/utils.c | 124 | ||||
-rw-r--r-- | libavformat/version.h | 3 |
5 files changed, 17 insertions, 252 deletions
diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 8752f07e07..7d69f510b0 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1478,34 +1478,17 @@ attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg); #endif +#if FF_API_PARSE_DATE /** * Parse datestr and return a corresponding number of microseconds. + * * @param datestr String representing a date or a duration. - * - If a date the syntax is: - * @code - * now|{[{YYYY-MM-DD|YYYYMMDD}[T|t| ]]{{HH[:MM[:SS[.m...]]]}|{HH[MM[SS[.m...]]]}}[Z|z]} - * @endcode - * If the value is "now" it takes the current time. - * Time is local time unless Z is appended, in which case it is - * interpreted as UTC. - * If the year-month-day part is not specified it takes the current - * year-month-day. - * @return the number of microseconds since 1st of January, 1970 up to - * the time of the parsed date or INT64_MIN if datestr cannot be - * successfully parsed. - * - If a duration the syntax is: - * @code - * [-]HH[:MM[:SS[.m...]]] - * [-]S+[.m...] - * @endcode - * @return the number of microseconds contained in a time interval - * with the specified duration or INT64_MIN if datestr cannot be - * successfully parsed. - * @param duration Flag which tells how to interpret datestr, if - * not zero datestr is interpreted as a duration, otherwise as a - * date. + * See av_parse_time() for the syntax of the provided string. + * @deprecated in favor of av_parse_time() */ +attribute_deprecated int64_t parse_date(const char *datestr, int duration); +#endif /** * Get the current time in microseconds. diff --git a/libavformat/cutils.c b/libavformat/cutils.c index c1b56139c0..e6578df2ce 100644 --- a/libavformat/cutils.c +++ b/libavformat/cutils.c @@ -42,25 +42,6 @@ void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem) *nb_ptr = nb; } -time_t mktimegm(struct tm *tm) -{ - time_t t; - - int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday; - - if (m < 3) { - m += 12; - y--; - } - - t = 86400 * - (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469); - - t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec; - - return t; -} - #define ISLEAP(y) (((y) % 4 == 0) && (((y) % 100) != 0 || ((y) % 400) == 0)) #define LEAPS_COUNT(y) ((y)/4 - (y)/100 + (y)/400) @@ -95,94 +76,3 @@ struct tm *brktimegm(time_t secs, struct tm *tm) return tm; } - -/* get a positive number between n_min and n_max, for a maximum length - of len_max. Return -1 if error. */ -static int date_get_num(const char **pp, - int n_min, int n_max, int len_max) -{ - int i, val, c; - const char *p; - - p = *pp; - val = 0; - for(i = 0; i < len_max; i++) { - c = *p; - if (!isdigit(c)) - break; - val = (val * 10) + c - '0'; - p++; - } - /* no number read ? */ - if (p == *pp) - return -1; - if (val < n_min || val > n_max) - return -1; - *pp = p; - return val; -} - -/* small strptime for ffmpeg */ -const char *small_strptime(const char *p, const char *fmt, - struct tm *dt) -{ - int c, val; - - for(;;) { - c = *fmt++; - if (c == '\0') { - return p; - } else if (c == '%') { - c = *fmt++; - switch(c) { - case 'H': - val = date_get_num(&p, 0, 23, 2); - if (val == -1) - return NULL; - dt->tm_hour = val; - break; - case 'M': - val = date_get_num(&p, 0, 59, 2); - if (val == -1) - return NULL; - dt->tm_min = val; - break; - case 'S': - val = date_get_num(&p, 0, 59, 2); - if (val == -1) - return NULL; - dt->tm_sec = val; - break; - case 'Y': - val = date_get_num(&p, 0, 9999, 4); - if (val == -1) - return NULL; - dt->tm_year = val - 1900; - break; - case 'm': - val = date_get_num(&p, 1, 12, 2); - if (val == -1) - return NULL; - dt->tm_mon = val - 1; - break; - case 'd': - val = date_get_num(&p, 1, 31, 2); - if (val == -1) - return NULL; - dt->tm_mday = val; - break; - case '%': - goto match; - default: - return NULL; - } - } else { - match: - if (c != *p) - return NULL; - p++; - } - } - return p; -} - diff --git a/libavformat/internal.h b/libavformat/internal.h index 2fdf61f938..16aa0af189 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -48,10 +48,7 @@ do {\ } while(0) #endif -time_t mktimegm(struct tm *tm); struct tm *brktimegm(time_t secs, struct tm *tm); -const char *small_strptime(const char *p, const char *fmt, - struct tm *dt); char *ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase); diff --git a/libavformat/utils.c b/libavformat/utils.c index 1d746cb50e..b9ec7fd0af 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3380,124 +3380,16 @@ uint64_t ff_ntp_time(void) return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US; } -int64_t parse_date(const char *datestr, int duration) -{ - const char *p; - int64_t t; - struct tm dt; - int i; - static const char * const date_fmt[] = { - "%Y-%m-%d", - "%Y%m%d", - }; - static const char * const time_fmt[] = { - "%H:%M:%S", - "%H%M%S", - }; - const char *q; - int is_utc, len; - char lastch; - int negative = 0; - -#undef time - time_t now = time(0); - - len = strlen(datestr); - if (len > 0) - lastch = datestr[len - 1]; - else - lastch = '\0'; - is_utc = (lastch == 'z' || lastch == 'Z'); - - memset(&dt, 0, sizeof(dt)); - - p = datestr; - q = NULL; - if (!duration) { - if (!strncasecmp(datestr, "now", len)) - return (int64_t) now * 1000000; - - /* parse the year-month-day part */ - for (i = 0; i < FF_ARRAY_ELEMS(date_fmt); i++) { - q = small_strptime(p, date_fmt[i], &dt); - if (q) { - break; - } - } - - /* if the year-month-day part is missing, then take the - * current year-month-day time */ - if (!q) { - if (is_utc) { - dt = *gmtime(&now); - } else { - dt = *localtime(&now); - } - dt.tm_hour = dt.tm_min = dt.tm_sec = 0; - } else { - p = q; - } - - if (*p == 'T' || *p == 't' || *p == ' ') - p++; - - /* parse the hour-minute-second part */ - for (i = 0; i < FF_ARRAY_ELEMS(time_fmt); i++) { - q = small_strptime(p, time_fmt[i], &dt); - if (q) { - break; - } - } - } else { - /* parse datestr as a duration */ - if (p[0] == '-') { - negative = 1; - ++p; - } - /* parse datestr as HH:MM:SS */ - q = small_strptime(p, time_fmt[0], &dt); - 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) { - return INT64_MIN; - } - - if (duration) { - t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec; - } else { - dt.tm_isdst = -1; /* unknown */ - if (is_utc) { - t = mktimegm(&dt); - } else { - t = mktime(&dt); - } - } - - t *= 1000000; +#if FF_API_PARSE_DATE +#include "libavutil/parseutils.h" - /* parse the .m... part */ - if (*q == '.') { - int val, n; - q++; - for (val = 0, n = 100000; n >= 1; n /= 10, q++) { - if (!isdigit(*q)) - break; - val += n * (*q - '0'); - } - t += val; - } - return negative ? -t : t; +int64_t parse_date(const char *timestr, int duration) +{ + int64_t timeval; + av_parse_time(&timeval, timestr, duration); + return timeval; } +#endif int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info) { diff --git a/libavformat/version.h b/libavformat/version.h index 922dd89f1c..3663ec55b9 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -95,5 +95,8 @@ #ifndef FF_API_DUMP_FORMAT #define FF_API_DUMP_FORMAT (LIBAVFORMAT_VERSION_MAJOR < 54) #endif +#ifndef FF_API_PARSE_DATE +#define FF_API_PARSE_DATE (LIBAVFORMAT_VERSION_MAJOR < 54) +#endif #endif //AVFORMAT_VERSION_H |