webrtc/audio/time_interval.h
Danil Chapovalov b9b146c9fe Replace rtc::Optional with absl::optional in audio, call and video
This is a no-op change because rtc::Optional is an alias to absl::optional

This CL generated by running script with parameters 'audio call video':
#!/bin/bash
find $@ -type f \( -name \*.h -o -name \*.cc \) \
-exec sed -i 's|rtc::Optional|absl::optional|g' {} \+ \
-exec sed -i 's|rtc::nullopt|absl::nullopt|g' {} \+ \
-exec sed -i 's|#include "api/optional.h"|#include "absl/types/optional.h"|' {} \+

find $@ -type f -name BUILD.gn \
-exec sed -r -i 's|"(../)*api:optional"|"//third_party/abseil-cpp/absl/types:optional"|' {} \+;

git cl format

Bug: webrtc:9078
Change-Id: I02c5db956846a88a268a300ba086703a02d62e36
Reviewed-on: https://webrtc-review.googlesource.com/83722
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23628}
2018-06-15 12:09:49 +00:00

65 lines
1.8 KiB
C++

/*
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef AUDIO_TIME_INTERVAL_H_
#define AUDIO_TIME_INTERVAL_H_
#include <stdint.h>
#include "absl/types/optional.h"
namespace webrtc {
// This class logs the first and last time its Extend() function is called.
//
// This class is not thread-safe; Extend() calls should only be made by a
// single thread at a time, such as within a lock or destructor.
//
// Example usage:
// // let x < y < z < u < v
// rtc::TimeInterval interval;
// ... // interval.Extend(); // at time x
// ...
// interval.Extend(); // at time y
// ...
// interval.Extend(); // at time u
// ...
// interval.Extend(z); // at time v
// ...
// if (!interval.Empty()) {
// int64_t active_time = interval.Length(); // returns (u - x)
// }
class TimeInterval {
public:
TimeInterval();
~TimeInterval();
// Extend the interval with the current time.
void Extend();
// Extend the interval with a given time.
void Extend(int64_t time);
// Take the convex hull with another interval.
void Extend(const TimeInterval& other_interval);
// True iff Extend has never been called.
bool Empty() const;
// Returns the time between the first and the last tick, in milliseconds.
int64_t Length() const;
private:
struct Interval {
Interval(int64_t first, int64_t last);
int64_t first, last;
};
absl::optional<Interval> interval_;
};
} // namespace webrtc
#endif // AUDIO_TIME_INTERVAL_H_