video_timing.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #ifndef API_VIDEO_VIDEO_TIMING_H_
  11. #define API_VIDEO_VIDEO_TIMING_H_
  12. #include <stdint.h>
  13. #include <limits>
  14. #include <string>
  15. namespace webrtc {
  16. // Video timing timestamps in ms counted from capture_time_ms of a frame.
  17. // This structure represents data sent in video-timing RTP header extension.
  18. struct VideoSendTiming {
  19. enum TimingFrameFlags : uint8_t {
  20. kNotTriggered = 0, // Timing info valid, but not to be transmitted.
  21. // Used on send-side only.
  22. kTriggeredByTimer = 1 << 0, // Frame marked for tracing by periodic timer.
  23. kTriggeredBySize = 1 << 1, // Frame marked for tracing due to size.
  24. kInvalid = std::numeric_limits<uint8_t>::max() // Invalid, ignore!
  25. };
  26. // Returns |time_ms - base_ms| capped at max 16-bit value.
  27. // Used to fill this data structure as per
  28. // https://webrtc.org/experiments/rtp-hdrext/video-timing/ extension stores
  29. // 16-bit deltas of timestamps from packet capture time.
  30. static uint16_t GetDeltaCappedMs(int64_t base_ms, int64_t time_ms);
  31. uint16_t encode_start_delta_ms;
  32. uint16_t encode_finish_delta_ms;
  33. uint16_t packetization_finish_delta_ms;
  34. uint16_t pacer_exit_delta_ms;
  35. uint16_t network_timestamp_delta_ms;
  36. uint16_t network2_timestamp_delta_ms;
  37. uint8_t flags;
  38. };
  39. // Used to report precise timings of a 'timing frames'. Contains all important
  40. // timestamps for a lifetime of that specific frame. Reported as a string via
  41. // GetStats(). Only frame which took the longest between two GetStats calls is
  42. // reported.
  43. struct TimingFrameInfo {
  44. TimingFrameInfo();
  45. // Returns end-to-end delay of a frame, if sender and receiver timestamps are
  46. // synchronized, -1 otherwise.
  47. int64_t EndToEndDelay() const;
  48. // Returns true if current frame took longer to process than |other| frame.
  49. // If other frame's clocks are not synchronized, current frame is always
  50. // preferred.
  51. bool IsLongerThan(const TimingFrameInfo& other) const;
  52. // Returns true if flags are set to indicate this frame was marked for tracing
  53. // due to the size being outside some limit.
  54. bool IsOutlier() const;
  55. // Returns true if flags are set to indicate this frame was marked fro tracing
  56. // due to cyclic timer.
  57. bool IsTimerTriggered() const;
  58. // Returns true if the timing data is marked as invalid, in which case it
  59. // should be ignored.
  60. bool IsInvalid() const;
  61. std::string ToString() const;
  62. bool operator<(const TimingFrameInfo& other) const;
  63. bool operator<=(const TimingFrameInfo& other) const;
  64. uint32_t rtp_timestamp; // Identifier of a frame.
  65. // All timestamps below are in local monotonous clock of a receiver.
  66. // If sender clock is not yet estimated, sender timestamps
  67. // (capture_time_ms ... pacer_exit_ms) are negative values, still
  68. // relatively correct.
  69. int64_t capture_time_ms; // Captrue time of a frame.
  70. int64_t encode_start_ms; // Encode start time.
  71. int64_t encode_finish_ms; // Encode completion time.
  72. int64_t packetization_finish_ms; // Time when frame was passed to pacer.
  73. int64_t pacer_exit_ms; // Time when last packet was pushed out of pacer.
  74. // Two in-network RTP processor timestamps: meaning is application specific.
  75. int64_t network_timestamp_ms;
  76. int64_t network2_timestamp_ms;
  77. int64_t receive_start_ms; // First received packet time.
  78. int64_t receive_finish_ms; // Last received packet time.
  79. int64_t decode_start_ms; // Decode start time.
  80. int64_t decode_finish_ms; // Decode completion time.
  81. int64_t render_time_ms; // Proposed render time to insure smooth playback.
  82. uint8_t flags; // Flags indicating validity and/or why tracing was triggered.
  83. };
  84. // Minimum and maximum playout delay values from capture to render.
  85. // These are best effort values.
  86. //
  87. // A value < 0 indicates no change from previous valid value.
  88. //
  89. // min = max = 0 indicates that the receiver should try and render
  90. // frame as soon as possible.
  91. //
  92. // min = x, max = y indicates that the receiver is free to adapt
  93. // in the range (x, y) based on network jitter.
  94. struct VideoPlayoutDelay {
  95. VideoPlayoutDelay() = default;
  96. VideoPlayoutDelay(int min_ms, int max_ms) : min_ms(min_ms), max_ms(max_ms) {}
  97. int min_ms = -1;
  98. int max_ms = -1;
  99. bool operator==(const VideoPlayoutDelay& rhs) const {
  100. return min_ms == rhs.min_ms && max_ms == rhs.max_ms;
  101. }
  102. };
  103. // TODO(bugs.webrtc.org/7660): Old name, delete after downstream use is updated.
  104. using PlayoutDelay = VideoPlayoutDelay;
  105. } // namespace webrtc
  106. #endif // API_VIDEO_VIDEO_TIMING_H_