video_timing.h (5703B)
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 11 #ifndef API_VIDEO_VIDEO_TIMING_H_ 12 #define API_VIDEO_VIDEO_TIMING_H_ 13 14 #include <stdint.h> 15 16 #include <limits> 17 #include <string> 18 19 #include "api/units/time_delta.h" 20 #include "rtc_base/system/rtc_export.h" 21 22 namespace webrtc { 23 24 // Video timing timestamps in ms counted from capture_time_ms of a frame. 25 // This structure represents data sent in video-timing RTP header extension. 26 struct RTC_EXPORT VideoSendTiming { 27 enum TimingFrameFlags : uint8_t { 28 kNotTriggered = 0, // Timing info valid, but not to be transmitted. 29 // Used on send-side only. 30 kTriggeredByTimer = 1 << 0, // Frame marked for tracing by periodic timer. 31 kTriggeredBySize = 1 << 1, // Frame marked for tracing due to size. 32 kInvalid = std::numeric_limits<uint8_t>::max() // Invalid, ignore! 33 }; 34 35 // Returns |time_ms - base_ms| capped at max 16-bit value. 36 // Used to fill this data structure as per 37 // https://webrtc.org/experiments/rtp-hdrext/video-timing/ extension stores 38 // 16-bit deltas of timestamps from packet capture time. 39 static uint16_t GetDeltaCappedMs(int64_t base_ms, int64_t time_ms); 40 static uint16_t GetDeltaCappedMs(TimeDelta delta); 41 42 uint16_t encode_start_delta_ms; 43 uint16_t encode_finish_delta_ms; 44 uint16_t packetization_finish_delta_ms; 45 uint16_t pacer_exit_delta_ms; 46 uint16_t network_timestamp_delta_ms; 47 uint16_t network2_timestamp_delta_ms; 48 uint8_t flags = TimingFrameFlags::kInvalid; 49 }; 50 51 // Used to report precise timings of a 'timing frames'. Contains all important 52 // timestamps for a lifetime of that specific frame. Reported as a string via 53 // GetStats(). Only frame which took the longest between two GetStats calls is 54 // reported. 55 struct RTC_EXPORT TimingFrameInfo { 56 TimingFrameInfo(); 57 58 // Returns end-to-end delay of a frame, if sender and receiver timestamps are 59 // synchronized, -1 otherwise. 60 int64_t EndToEndDelay() const; 61 62 // Returns true if current frame took longer to process than `other` frame. 63 // If other frame's clocks are not synchronized, current frame is always 64 // preferred. 65 bool IsLongerThan(const TimingFrameInfo& other) const; 66 67 // Returns true if flags are set to indicate this frame was marked for tracing 68 // due to the size being outside some limit. 69 bool IsOutlier() const; 70 71 // Returns true if flags are set to indicate this frame was marked fro tracing 72 // due to cyclic timer. 73 bool IsTimerTriggered() const; 74 75 // Returns true if the timing data is marked as invalid, in which case it 76 // should be ignored. 77 bool IsInvalid() const; 78 79 std::string ToString() const; 80 81 bool operator<(const TimingFrameInfo& other) const; 82 83 bool operator<=(const TimingFrameInfo& other) const; 84 85 uint32_t rtp_timestamp; // Identifier of a frame. 86 // All timestamps below are in local monotonous clock of a receiver. 87 // If sender clock is not yet estimated, sender timestamps 88 // (capture_time_ms ... pacer_exit_ms) are negative values, still 89 // relatively correct. 90 int64_t capture_time_ms; // Captrue time of a frame. 91 int64_t encode_start_ms; // Encode start time. 92 int64_t encode_finish_ms; // Encode completion time. 93 int64_t packetization_finish_ms; // Time when frame was passed to pacer. 94 int64_t pacer_exit_ms; // Time when last packet was pushed out of pacer. 95 // Two in-network RTP processor timestamps: meaning is application specific. 96 int64_t network_timestamp_ms; 97 int64_t network2_timestamp_ms; 98 int64_t receive_start_ms; // First received packet time. 99 int64_t receive_finish_ms; // Last received packet time. 100 int64_t decode_start_ms; // Decode start time. 101 int64_t decode_finish_ms; // Decode completion time. 102 int64_t render_time_ms; // Proposed render time to insure smooth playback. 103 104 uint8_t flags; // Flags indicating validity and/or why tracing was triggered. 105 }; 106 107 // Minimum and maximum playout delay values from capture to render. 108 // These are best effort values. 109 // 110 // min = max = 0 indicates that the receiver should try and render 111 // frame as soon as possible. 112 // 113 // min = x, max = y indicates that the receiver is free to adapt 114 // in the range (x, y) based on network jitter. 115 // This class ensures invariant 0 <= min <= max <= kMax. 116 class RTC_EXPORT VideoPlayoutDelay { 117 public: 118 // Maximum supported value for the delay limit. 119 static constexpr TimeDelta kMax = TimeDelta::Millis(10) * 0xFFF; 120 121 // Creates delay limits that indicates receiver should try to render frame 122 // as soon as possible. 123 static VideoPlayoutDelay Minimal() { 124 return VideoPlayoutDelay(TimeDelta::Zero(), TimeDelta::Zero()); 125 } 126 127 // Creates valid, but unspecified limits. 128 VideoPlayoutDelay() = default; 129 VideoPlayoutDelay(const VideoPlayoutDelay&) = default; 130 VideoPlayoutDelay& operator=(const VideoPlayoutDelay&) = default; 131 VideoPlayoutDelay(TimeDelta min, TimeDelta max); 132 133 bool Set(TimeDelta min, TimeDelta max); 134 135 TimeDelta min() const { return min_; } 136 TimeDelta max() const { return max_; } 137 138 friend bool operator==(const VideoPlayoutDelay& lhs, 139 const VideoPlayoutDelay& rhs) { 140 return lhs.min_ == rhs.min_ && lhs.max_ == rhs.max_; 141 } 142 143 private: 144 TimeDelta min_ = TimeDelta::Zero(); 145 TimeDelta max_ = kMax; 146 }; 147 148 } // namespace webrtc 149 150 #endif // API_VIDEO_VIDEO_TIMING_H_