// static
//该函数的功能是从传入的参数s中解析出连个时间戳npt1,npt2,用浮点数表示
//数据的组织格式:形如123.45-125
//两个时间的分隔符是’-‘
// static
bool ASessionDescription::parseNTPRange(
const char *s, float *npt1, float *npt2) {
if (s[0] == '-') {
//如果传入参数s首字符就为分隔符'-'自然是错误的格式
//函数返回fasle表示失败
return false; // no start time available.
}
if (!strncmp("now", s, 3)) {
//如果第一个事件以"now"字符开头
//也返回错误,因暂时不支持绝对时间
return false; // no absolute start time available
}
//解析第一个时间npt1
char *end;
*npt1 = strtof(s, &end);
if (end == s || *end != '-') {
// Failed to parse float or trailing "dash".
//解析后如果end仍在开始的位置s
//或者end到达的位置的字符不为分隔符'-'
//解析发生了错误,返回false,表示失败
return false;
}
//跳过分割符s
s = end + 1; // skip the dash.
if (*s == '\0') {
//如果此时s已经到达了结尾字符'\0'
//说明没有指定第二个时间
//也即没有指定结束事件
//则将FLT_MAX的值赋值给*npt2
*npt2 = FLT_MAX; // open ended.
return true;
}
//代码执行到了这里说明指定了结束时间
if (!strncmp("now", s, 3)) {
//如果结束时间的字符表示以"now"
//也返回错误,因暂时不支持绝对时间
return false; // no absolute end time available
}
//解析结束时间
*npt2 = strtof(s, &end);
if (end == s || *end != '\0') {
//解析后,如果end仍然在开始的位置s,或者到达的位置不为结尾标志'\0'
//则函数返回false,表示失败
return false;
}
return *npt2 > *npt1;
}