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.

144 lines
4.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2016 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 "modules/video_coding/frame_object.h"
  11. #include <string.h>
  12. #include <utility>
  13. #include "api/video/encoded_image.h"
  14. #include "api/video/video_timing.h"
  15. #include "rtc_base/checks.h"
  16. #include "rtc_base/critical_section.h"
  17. namespace webrtc {
  18. namespace video_coding {
  19. RtpFrameObject::RtpFrameObject(
  20. uint16_t first_seq_num,
  21. uint16_t last_seq_num,
  22. bool markerBit,
  23. int times_nacked,
  24. int64_t first_packet_received_time,
  25. int64_t last_packet_received_time,
  26. uint32_t rtp_timestamp,
  27. int64_t ntp_time_ms,
  28. const VideoSendTiming& timing,
  29. uint8_t payload_type,
  30. VideoCodecType codec,
  31. VideoRotation rotation,
  32. VideoContentType content_type,
  33. const RTPVideoHeader& video_header,
  34. const absl::optional<webrtc::ColorSpace>& color_space,
  35. const absl::optional<RtpGenericFrameDescriptor>& generic_descriptor,
  36. RtpPacketInfos packet_infos,
  37. rtc::scoped_refptr<EncodedImageBuffer> image_buffer)
  38. : first_seq_num_(first_seq_num),
  39. last_seq_num_(last_seq_num),
  40. last_packet_received_time_(last_packet_received_time),
  41. times_nacked_(times_nacked) {
  42. rtp_video_header_ = video_header;
  43. rtp_generic_frame_descriptor_ = generic_descriptor;
  44. // EncodedFrame members
  45. codec_type_ = codec;
  46. // TODO(philipel): Remove when encoded image is replaced by EncodedFrame.
  47. // VCMEncodedFrame members
  48. CopyCodecSpecific(&rtp_video_header_);
  49. _completeFrame = true;
  50. _payloadType = payload_type;
  51. SetTimestamp(rtp_timestamp);
  52. ntp_time_ms_ = ntp_time_ms;
  53. _frameType = rtp_video_header_.frame_type;
  54. // Setting frame's playout delays to the same values
  55. // as of the first packet's.
  56. SetPlayoutDelay(rtp_video_header_.playout_delay);
  57. SetEncodedData(std::move(image_buffer));
  58. _encodedWidth = rtp_video_header_.width;
  59. _encodedHeight = rtp_video_header_.height;
  60. // EncodedFrame members
  61. SetPacketInfos(std::move(packet_infos));
  62. rotation_ = rotation;
  63. SetColorSpace(color_space);
  64. content_type_ = content_type;
  65. if (timing.flags != VideoSendTiming::kInvalid) {
  66. // ntp_time_ms_ may be -1 if not estimated yet. This is not a problem,
  67. // as this will be dealt with at the time of reporting.
  68. timing_.encode_start_ms = ntp_time_ms_ + timing.encode_start_delta_ms;
  69. timing_.encode_finish_ms = ntp_time_ms_ + timing.encode_finish_delta_ms;
  70. timing_.packetization_finish_ms =
  71. ntp_time_ms_ + timing.packetization_finish_delta_ms;
  72. timing_.pacer_exit_ms = ntp_time_ms_ + timing.pacer_exit_delta_ms;
  73. timing_.network_timestamp_ms =
  74. ntp_time_ms_ + timing.network_timestamp_delta_ms;
  75. timing_.network2_timestamp_ms =
  76. ntp_time_ms_ + timing.network2_timestamp_delta_ms;
  77. }
  78. timing_.receive_start_ms = first_packet_received_time;
  79. timing_.receive_finish_ms = last_packet_received_time;
  80. timing_.flags = timing.flags;
  81. is_last_spatial_layer = markerBit;
  82. }
  83. RtpFrameObject::~RtpFrameObject() {
  84. }
  85. uint16_t RtpFrameObject::first_seq_num() const {
  86. return first_seq_num_;
  87. }
  88. uint16_t RtpFrameObject::last_seq_num() const {
  89. return last_seq_num_;
  90. }
  91. int RtpFrameObject::times_nacked() const {
  92. return times_nacked_;
  93. }
  94. VideoFrameType RtpFrameObject::frame_type() const {
  95. return rtp_video_header_.frame_type;
  96. }
  97. VideoCodecType RtpFrameObject::codec_type() const {
  98. return codec_type_;
  99. }
  100. int64_t RtpFrameObject::ReceivedTime() const {
  101. return last_packet_received_time_;
  102. }
  103. int64_t RtpFrameObject::RenderTime() const {
  104. return _renderTimeMs;
  105. }
  106. bool RtpFrameObject::delayed_by_retransmission() const {
  107. return times_nacked() > 0;
  108. }
  109. const RTPVideoHeader& RtpFrameObject::GetRtpVideoHeader() const {
  110. return rtp_video_header_;
  111. }
  112. const absl::optional<RtpGenericFrameDescriptor>&
  113. RtpFrameObject::GetGenericFrameDescriptor() const {
  114. return rtp_generic_frame_descriptor_;
  115. }
  116. const FrameMarking& RtpFrameObject::GetFrameMarking() const {
  117. return rtp_video_header_.frame_marking;
  118. }
  119. } // namespace video_coding
  120. } // namespace webrtc