diff options
author | Andreas Huber <andih@google.com> | 2011-01-28 09:19:12 -0800 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2011-01-28 09:36:38 -0800 |
commit | 783e5cd85d4bd40b1a04dfdfed256c5dcb2525cc (patch) | |
tree | e546386b0c906212ec677e3c039671d1bcf1a0d1 /media/libstagefright/rtsp/ASessionDescription.cpp | |
parent | 8ce64ddc2828f74704a6473c4b934de16c0e3bd1 (diff) | |
download | frameworks_av-783e5cd85d4bd40b1a04dfdfed256c5dcb2525cc.zip frameworks_av-783e5cd85d4bd40b1a04dfdfed256c5dcb2525cc.tar.gz frameworks_av-783e5cd85d4bd40b1a04dfdfed256c5dcb2525cc.tar.bz2 |
More robust parsing of NPT time ranges in RTSP.
Change-Id: I3674501d2fd66aaface805c0a8678c74671a6dd3
related-to-bug: 3217210
Diffstat (limited to 'media/libstagefright/rtsp/ASessionDescription.cpp')
-rw-r--r-- | media/libstagefright/rtsp/ASessionDescription.cpp | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/media/libstagefright/rtsp/ASessionDescription.cpp b/media/libstagefright/rtsp/ASessionDescription.cpp index 77917b3..3e710dc 100644 --- a/media/libstagefright/rtsp/ASessionDescription.cpp +++ b/media/libstagefright/rtsp/ASessionDescription.cpp @@ -254,26 +254,12 @@ bool ASessionDescription::getDurationUs(int64_t *durationUs) const { return false; } - if (value == "npt=now-" || value == "npt=0-") { - return false; - } - if (strncmp(value.c_str(), "npt=", 4)) { return false; } - const char *s = value.c_str() + 4; - char *end; - double from = strtod(s, &end); - - if (end == s || *end != '-') { - return false; - } - - s = end + 1; - double to = strtod(s, &end); - - if (end == s || *end != '\0' || to < from) { + float from, to; + if (!parseNTPRange(value.c_str() + 4, &from, &to)) { return false; } @@ -307,5 +293,39 @@ void ASessionDescription::ParseFormatDesc( } } +// static +bool ASessionDescription::parseNTPRange( + const char *s, float *npt1, float *npt2) { + if (s[0] == '-') { + return false; // no start time available. + } + + if (!strncmp("now", s, 3)) { + return false; // no absolute start time available + } + + char *end; + *npt1 = strtof(s, &end); + + if (end == s || *end != '-') { + // Failed to parse float or trailing "dash". + return false; + } + + s = end + 1; // skip the dash. + + if (!strncmp("now", s, 3)) { + return false; // no absolute end time available + } + + *npt2 = strtof(s, &end); + + if (end == s || *end != '\0') { + return false; + } + + return *npt2 > *npt1; +} + } // namespace android |