2 DelayInterval延时间隔类——Live555源码阅读(一)基本组件类

时间:2022-03-13 18:14:56

这是Live555源码阅读的第一部分,包括了时间类,延时队列类,处理程序描述类,哈希表类这四个大类。

这里是时间相关类的第二个部分。

本文由乌合之众 lym瞎编,欢迎转载 http://www.cnblogs.com/oloroso/

DelayInterval延时间隔类

DelayInterval这个类只是为了在名字上方便使用。我们可以看上面的TimeVal类,其带参构造函数是protected权限的,这里的定义就是暴露了一个构造接口,方便使用。

class DelayInterval: public Timeval {
public:
DelayInterval(time_base_seconds seconds, time_base_seconds useconds)
: Timeval(seconds, useconds) {}
};

除此之外DelayInterval类还重载了全局的 “ * ”运算符。注意,这个不是在DelayInterval类内部重载的,这里的第一个参数是short类型。其使用的时候是类似于这样的 result = arg1 * arg2;其中result和arg2是DelayInterval对象。

DelayInterval operator*(short arg1, DelayInterval const& arg2);

其实现如下

DelayInterval operator*(short arg1, const DelayInterval& arg2) {
time_base_seconds result_seconds = arg1*arg2.seconds();
time_base_seconds result_useconds = arg1*arg2.useconds();
time_base_seconds carry = result_useconds/MILLION;
result_useconds -= carry*MILLION;
result_seconds += carry;
return DelayInterval(result_seconds, result_useconds);
}