saza | c58f8c0 | 2017-07-19 00:39:19 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "audio/time_interval.h" |
| 12 | #include "rtc_base/checks.h" |
| 13 | #include "rtc_base/timeutils.h" |
saza | c58f8c0 | 2017-07-19 00:39:19 -0700 | [diff] [blame] | 14 | |
| 15 | namespace webrtc { |
| 16 | |
| 17 | TimeInterval::TimeInterval() = default; |
| 18 | TimeInterval::~TimeInterval() = default; |
| 19 | |
| 20 | void TimeInterval::Extend() { |
| 21 | Extend(rtc::TimeMillis()); |
| 22 | } |
| 23 | |
| 24 | void 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 | |
| 37 | void 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 | |
| 44 | bool TimeInterval::Empty() const { |
| 45 | return !interval_; |
| 46 | } |
| 47 | |
| 48 | int64_t TimeInterval::Length() const { |
| 49 | RTC_DCHECK(interval_); |
| 50 | return interval_->last - interval_->first; |
| 51 | } |
| 52 | |
| 53 | TimeInterval::Interval::Interval(int64_t first, int64_t last) |
| 54 | : first(first), last(last) {} |
| 55 | |
| 56 | } // namespace webrtc |