blob: 2804c8ba45152adb7986cc0b7f02012749e5bf21 [file] [log] [blame]
ilnik2edc6842017-07-06 03:06:50 -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
11#include "webrtc/api/video/video_timing.h"
12
13#include <sstream>
14
15namespace webrtc {
16
17TimingFrameInfo::TimingFrameInfo()
18 : rtp_timestamp(0),
19 capture_time_ms(-1),
20 encode_start_ms(-1),
21 encode_finish_ms(-1),
22 packetization_finish_ms(-1),
23 pacer_exit_ms(-1),
24 network_timestamp_ms(-1),
25 network2_timestamp_ms(-1),
26 receive_start_ms(-1),
27 receive_finish_ms(-1),
28 decode_start_ms(-1),
29 decode_finish_ms(-1),
sprangba050a62017-08-18 02:51:12 -070030 render_time_ms(-1),
31 flags(TimingFrameFlags::kDefault) {}
ilnik2edc6842017-07-06 03:06:50 -070032
33int64_t TimingFrameInfo::EndToEndDelay() const {
34 return capture_time_ms >= 0 ? decode_finish_ms - capture_time_ms : -1;
35}
36
37bool TimingFrameInfo::IsLongerThan(const TimingFrameInfo& other) const {
38 int64_t other_delay = other.EndToEndDelay();
39 return other_delay == -1 || EndToEndDelay() > other_delay;
40}
41
ilnik75204c52017-09-04 03:35:40 -070042bool TimingFrameInfo::operator<(const TimingFrameInfo& other) const {
43 return other.IsLongerThan(*this);
44}
45
46bool TimingFrameInfo::operator<=(const TimingFrameInfo& other) const {
47 return !IsLongerThan(other);
48}
49
sprangba050a62017-08-18 02:51:12 -070050bool TimingFrameInfo::IsOutlier() const {
51 return !IsInvalid() && (flags & TimingFrameFlags::kTriggeredBySize);
52}
53
54bool TimingFrameInfo::IsTimerTriggered() const {
55 return !IsInvalid() && (flags & TimingFrameFlags::kTriggeredByTimer);
56}
57
58bool TimingFrameInfo::IsInvalid() const {
59 return flags == TimingFrameFlags::kInvalid;
60}
61
ilnik2edc6842017-07-06 03:06:50 -070062std::string TimingFrameInfo::ToString() const {
63 std::stringstream out;
sprangba050a62017-08-18 02:51:12 -070064 if (IsInvalid()) {
ilnik75204c52017-09-04 03:35:40 -070065 out << "";
sprangba050a62017-08-18 02:51:12 -070066 } else {
67 out << rtp_timestamp << ',' << capture_time_ms << ',' << encode_start_ms
68 << ',' << encode_finish_ms << ',' << packetization_finish_ms << ','
69 << pacer_exit_ms << ',' << network_timestamp_ms << ','
70 << network2_timestamp_ms << ',' << receive_start_ms << ','
71 << receive_finish_ms << ',' << decode_start_ms << ','
ilnik75204c52017-09-04 03:35:40 -070072 << decode_finish_ms << ',' << render_time_ms << ','
73 << IsOutlier() << ',' << IsTimerTriggered();
sprangba050a62017-08-18 02:51:12 -070074 }
ilnik2edc6842017-07-06 03:06:50 -070075 return out.str();
76}
77
78} // namespace webrtc