You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #include "api/video/video_timing.h"
  11. #include "api/array_view.h"
  12. #include "rtc_base/logging.h"
  13. #include "rtc_base/numerics/safe_conversions.h"
  14. #include "rtc_base/strings/string_builder.h"
  15. namespace webrtc {
  16. uint16_t VideoSendTiming::GetDeltaCappedMs(int64_t base_ms, int64_t time_ms) {
  17. if (time_ms < base_ms) {
  18. RTC_DLOG(LS_ERROR) << "Delta " << (time_ms - base_ms)
  19. << "ms expected to be positive";
  20. }
  21. return rtc::saturated_cast<uint16_t>(time_ms - base_ms);
  22. }
  23. TimingFrameInfo::TimingFrameInfo()
  24. : rtp_timestamp(0),
  25. capture_time_ms(-1),
  26. encode_start_ms(-1),
  27. encode_finish_ms(-1),
  28. packetization_finish_ms(-1),
  29. pacer_exit_ms(-1),
  30. network_timestamp_ms(-1),
  31. network2_timestamp_ms(-1),
  32. receive_start_ms(-1),
  33. receive_finish_ms(-1),
  34. decode_start_ms(-1),
  35. decode_finish_ms(-1),
  36. render_time_ms(-1),
  37. flags(VideoSendTiming::kNotTriggered) {}
  38. int64_t TimingFrameInfo::EndToEndDelay() const {
  39. return capture_time_ms >= 0 ? decode_finish_ms - capture_time_ms : -1;
  40. }
  41. bool TimingFrameInfo::IsLongerThan(const TimingFrameInfo& other) const {
  42. int64_t other_delay = other.EndToEndDelay();
  43. return other_delay == -1 || EndToEndDelay() > other_delay;
  44. }
  45. bool TimingFrameInfo::operator<(const TimingFrameInfo& other) const {
  46. return other.IsLongerThan(*this);
  47. }
  48. bool TimingFrameInfo::operator<=(const TimingFrameInfo& other) const {
  49. return !IsLongerThan(other);
  50. }
  51. bool TimingFrameInfo::IsOutlier() const {
  52. return !IsInvalid() && (flags & VideoSendTiming::kTriggeredBySize);
  53. }
  54. bool TimingFrameInfo::IsTimerTriggered() const {
  55. return !IsInvalid() && (flags & VideoSendTiming::kTriggeredByTimer);
  56. }
  57. bool TimingFrameInfo::IsInvalid() const {
  58. return flags == VideoSendTiming::kInvalid;
  59. }
  60. std::string TimingFrameInfo::ToString() const {
  61. if (IsInvalid()) {
  62. return "";
  63. }
  64. char buf[1024];
  65. rtc::SimpleStringBuilder sb(buf);
  66. sb << rtp_timestamp << ',' << capture_time_ms << ',' << encode_start_ms << ','
  67. << encode_finish_ms << ',' << packetization_finish_ms << ','
  68. << pacer_exit_ms << ',' << network_timestamp_ms << ','
  69. << network2_timestamp_ms << ',' << receive_start_ms << ','
  70. << receive_finish_ms << ',' << decode_start_ms << ',' << decode_finish_ms
  71. << ',' << render_time_ms << ',' << IsOutlier() << ','
  72. << IsTimerTriggered();
  73. return sb.str();
  74. }
  75. } // namespace webrtc