Merge "More robust parsing of NPT time ranges in RTSP." into honeycomb
This commit is contained in:
committed by
Android (Google) Code Review
commit
b0eb8bb76c
@@ -254,26 +254,12 @@ bool ASessionDescription::getDurationUs(int64_t *durationUs) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value == "npt=now-" || value == "npt=0-") {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strncmp(value.c_str(), "npt=", 4)) {
|
if (strncmp(value.c_str(), "npt=", 4)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *s = value.c_str() + 4;
|
float from, to;
|
||||||
char *end;
|
if (!parseNTPRange(value.c_str() + 4, &from, &to)) {
|
||||||
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) {
|
|
||||||
return false;
|
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
|
} // namespace android
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,14 @@ struct ASessionDescription : public RefBase {
|
|||||||
|
|
||||||
bool findAttribute(size_t index, const char *key, AString *value) const;
|
bool findAttribute(size_t index, const char *key, AString *value) const;
|
||||||
|
|
||||||
|
// parses strings of the form
|
||||||
|
// npt := npt-time "-" npt-time? | "-" npt-time
|
||||||
|
// npt-time := "now" | [0-9]+("." [0-9]*)?
|
||||||
|
//
|
||||||
|
// Returns true iff both "npt1" and "npt2" times were available,
|
||||||
|
// i.e. we have a fixed duration, otherwise this is live streaming.
|
||||||
|
static bool parseNTPRange(const char *s, float *npt1, float *npt2);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~ASessionDescription();
|
virtual ~ASessionDescription();
|
||||||
|
|
||||||
|
|||||||
@@ -938,13 +938,11 @@ struct MyHandler : public AHandler {
|
|||||||
|
|
||||||
AString val;
|
AString val;
|
||||||
CHECK(GetAttribute(range.c_str(), "npt", &val));
|
CHECK(GetAttribute(range.c_str(), "npt", &val));
|
||||||
float npt1, npt2;
|
|
||||||
|
|
||||||
if (val == "now-" || val == "0-") {
|
float npt1, npt2;
|
||||||
|
if (!ASessionDescription::parseNTPRange(val.c_str(), &npt1, &npt2)) {
|
||||||
// This is a live stream and therefore not seekable.
|
// This is a live stream and therefore not seekable.
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
CHECK_EQ(sscanf(val.c_str(), "%f-%f", &npt1, &npt2), 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i = response->mHeaders.indexOfKey("rtp-info");
|
i = response->mHeaders.indexOfKey("rtp-info");
|
||||||
|
|||||||
Reference in New Issue
Block a user