mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refine SrsHourGlass in time unit.
This commit is contained in:
parent
f5a1f9b774
commit
522cbf1df8
4 changed files with 29 additions and 25 deletions
|
@ -37,10 +37,10 @@ ISrsHourGlass::~ISrsHourGlass()
|
|||
{
|
||||
}
|
||||
|
||||
SrsHourGlass::SrsHourGlass(ISrsHourGlass* h, int resolution_ms)
|
||||
SrsHourGlass::SrsHourGlass(ISrsHourGlass* h, srs_utime_t resolution)
|
||||
{
|
||||
handler = h;
|
||||
resolution = resolution_ms;
|
||||
_resolution = resolution;
|
||||
total_elapse = 0;
|
||||
}
|
||||
|
||||
|
@ -48,12 +48,13 @@ SrsHourGlass::~SrsHourGlass()
|
|||
{
|
||||
}
|
||||
|
||||
srs_error_t SrsHourGlass::tick(int type, int interval)
|
||||
srs_error_t SrsHourGlass::tick(int type, srs_utime_t interval)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (resolution > 0 && (interval % resolution) != 0) {
|
||||
return srs_error_new(ERROR_SYSTEM_HOURGLASS_RESOLUTION, "hourglass interval=%d invalid, resolution=%d", interval, resolution);
|
||||
if (_resolution > 0 && (interval % _resolution) != 0) {
|
||||
return srs_error_new(ERROR_SYSTEM_HOURGLASS_RESOLUTION,
|
||||
"invalid interval=%dms, resolution=%dms", srsu2msi(interval), srsu2msi(_resolution));
|
||||
}
|
||||
|
||||
ticks[type] = interval;
|
||||
|
@ -65,10 +66,10 @@ srs_error_t SrsHourGlass::cycle()
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
map<int, int>::iterator it;
|
||||
map<int, srs_utime_t>::iterator it;
|
||||
for (it = ticks.begin(); it != ticks.end(); ++it) {
|
||||
int type = it->first;
|
||||
int interval = it->second;
|
||||
srs_utime_t interval = it->second;
|
||||
|
||||
if (interval == 0 || (total_elapse % interval) == 0) {
|
||||
if ((err = handler->notify(type, interval, total_elapse)) != srs_success) {
|
||||
|
@ -76,9 +77,10 @@ srs_error_t SrsHourGlass::cycle()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
total_elapse += resolution;
|
||||
srs_usleep(resolution * 1000);
|
||||
|
||||
// TODO: FIXME: Maybe we should use wallclock.
|
||||
total_elapse += _resolution;
|
||||
srs_usleep(_resolution);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue