blob: cc103408a3a2467e5a0a02f88e390d74813c6c1d [file] [log] [blame]
sazac58f8c02017-07-19 00:39:19 -07001/*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "audio/time_interval.h"
12#include "rtc_base/checks.h"
13#include "rtc_base/timeutils.h"
sazac58f8c02017-07-19 00:39:19 -070014
15namespace webrtc {
16
17TimeInterval::TimeInterval() = default;
18TimeInterval::~TimeInterval() = default;
19
20void TimeInterval::Extend() {
21 Extend(rtc::TimeMillis());
22}
23
24void TimeInterval::Extend(int64_t time) {
25 if (!interval_) {
26 interval_.emplace(time, time);
27 } else {
28 if (time < interval_->first) {
29 interval_->first = time;
30 }
31 if (time > interval_->last) {
32 interval_->last = time;
33 }
34 }
35}
36
37void TimeInterval::Extend(const TimeInterval& other_interval) {
38 if (!other_interval.Empty()) {
39 Extend(other_interval.interval_->first);
40 Extend(other_interval.interval_->last);
41 }
42}
43
44bool TimeInterval::Empty() const {
45 return !interval_;
46}
47
48int64_t TimeInterval::Length() const {
49 RTC_DCHECK(interval_);
50 return interval_->last - interval_->first;
51}
52
53TimeInterval::Interval::Interval(int64_t first, int64_t last)
54 : first(first), last(last) {}
55
56} // namespace webrtc