frame_object.cc (4776B)
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 11 #include "modules/rtp_rtcp/source/frame_object.h" 12 13 #include <cstdint> 14 #include <optional> 15 #include <utility> 16 17 #include "api/rtp_packet_infos.h" 18 #include "api/scoped_refptr.h" 19 #include "api/video/color_space.h" 20 #include "api/video/corruption_detection/frame_instrumentation_data.h" 21 #include "api/video/encoded_image.h" 22 #include "api/video/video_codec_type.h" 23 #include "api/video/video_content_type.h" 24 #include "api/video/video_frame_metadata.h" 25 #include "api/video/video_frame_type.h" 26 #include "api/video/video_rotation.h" 27 #include "api/video/video_timing.h" 28 #include "modules/rtp_rtcp/source/rtp_video_header.h" 29 30 namespace webrtc { 31 RtpFrameObject::RtpFrameObject( 32 uint16_t first_seq_num, 33 uint16_t last_seq_num, 34 bool markerBit, 35 int times_nacked, 36 int64_t first_packet_received_time, 37 int64_t last_packet_received_time, 38 uint32_t rtp_timestamp, 39 int64_t ntp_time_ms, 40 const VideoSendTiming& timing, 41 uint8_t payload_type, 42 VideoCodecType codec, 43 VideoRotation rotation, 44 VideoContentType content_type, 45 const RTPVideoHeader& video_header, 46 const std::optional<class ColorSpace>& color_space, 47 const std::optional<FrameInstrumentationData>& frame_instrumentation_data, 48 RtpPacketInfos packet_infos, 49 scoped_refptr<EncodedImageBuffer> image_buffer) 50 : image_buffer_(image_buffer), 51 first_seq_num_(first_seq_num), 52 last_seq_num_(last_seq_num), 53 last_packet_received_time_(last_packet_received_time), 54 times_nacked_(times_nacked) { 55 rtp_video_header_ = video_header; 56 57 // EncodedFrame members 58 codec_type_ = codec; 59 60 // TODO(philipel): Remove when encoded image is replaced by EncodedFrame. 61 // VCMEncodedFrame members 62 _codecSpecificInfo.frame_instrumentation_data = frame_instrumentation_data; 63 CopyCodecSpecific(&rtp_video_header_); 64 _payloadType = payload_type; 65 SetRtpTimestamp(rtp_timestamp); 66 ntp_time_ms_ = ntp_time_ms; 67 _frameType = rtp_video_header_.frame_type; 68 69 // Setting frame's playout delays to the same values 70 // as of the first packet's. 71 SetPlayoutDelay(rtp_video_header_.playout_delay); 72 73 SetEncodedData(image_buffer_); 74 _encodedWidth = rtp_video_header_.width; 75 _encodedHeight = rtp_video_header_.height; 76 77 if (packet_infos.begin() != packet_infos.end()) { 78 csrcs_ = packet_infos.begin()->csrcs(); 79 } 80 81 // EncodedFrame members 82 SetPacketInfos(std::move(packet_infos)); 83 84 rotation_ = rotation; 85 SetColorSpace(color_space); 86 SetVideoFrameTrackingId(rtp_video_header_.video_frame_tracking_id); 87 content_type_ = content_type; 88 if (timing.flags != VideoSendTiming::kInvalid) { 89 // ntp_time_ms_ may be -1 if not estimated yet. This is not a problem, 90 // as this will be dealt with at the time of reporting. 91 timing_.encode_start_ms = ntp_time_ms_ + timing.encode_start_delta_ms; 92 timing_.encode_finish_ms = ntp_time_ms_ + timing.encode_finish_delta_ms; 93 timing_.packetization_finish_ms = 94 ntp_time_ms_ + timing.packetization_finish_delta_ms; 95 timing_.pacer_exit_ms = ntp_time_ms_ + timing.pacer_exit_delta_ms; 96 timing_.network_timestamp_ms = 97 ntp_time_ms_ + timing.network_timestamp_delta_ms; 98 timing_.network2_timestamp_ms = 99 ntp_time_ms_ + timing.network2_timestamp_delta_ms; 100 } 101 timing_.receive_start_ms = first_packet_received_time; 102 timing_.receive_finish_ms = last_packet_received_time; 103 timing_.flags = timing.flags; 104 is_last_spatial_layer = markerBit; 105 } 106 107 RtpFrameObject::~RtpFrameObject() {} 108 109 uint16_t RtpFrameObject::first_seq_num() const { 110 return first_seq_num_; 111 } 112 113 uint16_t RtpFrameObject::last_seq_num() const { 114 return last_seq_num_; 115 } 116 117 int RtpFrameObject::times_nacked() const { 118 return times_nacked_; 119 } 120 121 VideoFrameType RtpFrameObject::frame_type() const { 122 return rtp_video_header_.frame_type; 123 } 124 125 VideoCodecType RtpFrameObject::codec_type() const { 126 return codec_type_; 127 } 128 129 int64_t RtpFrameObject::ReceivedTime() const { 130 return last_packet_received_time_; 131 } 132 133 int64_t RtpFrameObject::RenderTime() const { 134 return _renderTimeMs; 135 } 136 137 bool RtpFrameObject::delayed_by_retransmission() const { 138 return times_nacked() > 0; 139 } 140 141 const RTPVideoHeader& RtpFrameObject::GetRtpVideoHeader() const { 142 return rtp_video_header_; 143 } 144 145 void RtpFrameObject::SetHeaderFromMetadata(const VideoFrameMetadata& metadata) { 146 rtp_video_header_.SetFromMetadata(metadata); 147 } 148 } // namespace webrtc