philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/video_coding/frame_object.h" |
Rasmus Brandt | 58b7291 | 2017-10-25 11:09:23 +0200 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <string.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 14 | |
Chen Xing | f00bf42 | 2019-06-20 10:05:55 +0200 | [diff] [blame] | 15 | #include <utility> |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 16 | |
| 17 | #include "api/video/encoded_image.h" |
| 18 | #include "api/video/video_timing.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #include "rtc_base/critical_section.h" |
philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | namespace video_coding { |
philipel | 85d5c19 | 2019-09-25 17:15:37 +0200 | [diff] [blame] | 24 | RtpFrameObject::RtpFrameObject( |
| 25 | uint16_t first_seq_num, |
| 26 | uint16_t last_seq_num, |
| 27 | bool markerBit, |
| 28 | int times_nacked, |
| 29 | int64_t first_packet_received_time, |
| 30 | int64_t last_packet_received_time, |
| 31 | uint32_t rtp_timestamp, |
| 32 | int64_t ntp_time_ms, |
| 33 | const VideoSendTiming& timing, |
| 34 | uint8_t payload_type, |
| 35 | VideoCodecType codec, |
| 36 | VideoRotation rotation, |
| 37 | VideoContentType content_type, |
| 38 | const RTPVideoHeader& video_header, |
| 39 | const absl::optional<webrtc::ColorSpace>& color_space, |
| 40 | const absl::optional<RtpGenericFrameDescriptor>& generic_descriptor, |
| 41 | RtpPacketInfos packet_infos, |
| 42 | rtc::scoped_refptr<EncodedImageBuffer> image_buffer) |
| 43 | : first_seq_num_(first_seq_num), |
| 44 | last_seq_num_(last_seq_num), |
| 45 | last_packet_received_time_(last_packet_received_time), |
| 46 | times_nacked_(times_nacked) { |
| 47 | rtp_video_header_ = video_header; |
| 48 | rtp_generic_frame_descriptor_ = generic_descriptor; |
| 49 | |
| 50 | // EncodedFrame members |
| 51 | codec_type_ = codec; |
| 52 | |
| 53 | // TODO(philipel): Remove when encoded image is replaced by EncodedFrame. |
| 54 | // VCMEncodedFrame members |
| 55 | CopyCodecSpecific(&rtp_video_header_); |
| 56 | _completeFrame = true; |
| 57 | _payloadType = payload_type; |
| 58 | SetTimestamp(rtp_timestamp); |
| 59 | ntp_time_ms_ = ntp_time_ms; |
| 60 | _frameType = rtp_video_header_.frame_type; |
| 61 | |
| 62 | // Setting frame's playout delays to the same values |
| 63 | // as of the first packet's. |
| 64 | SetPlayoutDelay(rtp_video_header_.playout_delay); |
| 65 | |
| 66 | SetEncodedData(std::move(image_buffer)); |
| 67 | _encodedWidth = rtp_video_header_.width; |
| 68 | _encodedHeight = rtp_video_header_.height; |
| 69 | |
| 70 | // EncodedFrame members |
| 71 | SetPacketInfos(std::move(packet_infos)); |
| 72 | |
| 73 | rotation_ = rotation; |
| 74 | SetColorSpace(color_space); |
philipel | 85d5c19 | 2019-09-25 17:15:37 +0200 | [diff] [blame] | 75 | content_type_ = content_type; |
| 76 | if (timing.flags != VideoSendTiming::kInvalid) { |
| 77 | // ntp_time_ms_ may be -1 if not estimated yet. This is not a problem, |
| 78 | // as this will be dealt with at the time of reporting. |
| 79 | timing_.encode_start_ms = ntp_time_ms_ + timing.encode_start_delta_ms; |
| 80 | timing_.encode_finish_ms = ntp_time_ms_ + timing.encode_finish_delta_ms; |
| 81 | timing_.packetization_finish_ms = |
| 82 | ntp_time_ms_ + timing.packetization_finish_delta_ms; |
| 83 | timing_.pacer_exit_ms = ntp_time_ms_ + timing.pacer_exit_delta_ms; |
| 84 | timing_.network_timestamp_ms = |
| 85 | ntp_time_ms_ + timing.network_timestamp_delta_ms; |
| 86 | timing_.network2_timestamp_ms = |
| 87 | ntp_time_ms_ + timing.network2_timestamp_delta_ms; |
| 88 | } |
| 89 | timing_.receive_start_ms = first_packet_received_time; |
| 90 | timing_.receive_finish_ms = last_packet_received_time; |
| 91 | timing_.flags = timing.flags; |
| 92 | is_last_spatial_layer = markerBit; |
| 93 | } |
| 94 | |
philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 95 | RtpFrameObject::~RtpFrameObject() { |
philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 96 | } |
| 97 | |
philipel | f413933 | 2016-04-20 10:26:34 +0200 | [diff] [blame] | 98 | uint16_t RtpFrameObject::first_seq_num() const { |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 99 | return first_seq_num_; |
philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 100 | } |
| 101 | |
philipel | f413933 | 2016-04-20 10:26:34 +0200 | [diff] [blame] | 102 | uint16_t RtpFrameObject::last_seq_num() const { |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 103 | return last_seq_num_; |
| 104 | } |
| 105 | |
philipel | 5ceaaae | 2016-05-24 10:20:47 +0200 | [diff] [blame] | 106 | int RtpFrameObject::times_nacked() const { |
| 107 | return times_nacked_; |
| 108 | } |
| 109 | |
Niels Möller | 87e2d78 | 2019-03-07 10:18:23 +0100 | [diff] [blame] | 110 | VideoFrameType RtpFrameObject::frame_type() const { |
Johannes Kron | a370556 | 2019-08-26 16:37:11 +0200 | [diff] [blame] | 111 | return rtp_video_header_.frame_type; |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | VideoCodecType RtpFrameObject::codec_type() const { |
| 115 | return codec_type_; |
philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 116 | } |
| 117 | |
philipel | b4d3108 | 2016-07-11 08:46:29 -0700 | [diff] [blame] | 118 | int64_t RtpFrameObject::ReceivedTime() const { |
Ilya Nikolaevskiy | 4348ce2 | 2018-12-07 16:26:56 +0100 | [diff] [blame] | 119 | return last_packet_received_time_; |
philipel | b4d3108 | 2016-07-11 08:46:29 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | int64_t RtpFrameObject::RenderTime() const { |
| 123 | return _renderTimeMs; |
| 124 | } |
| 125 | |
philipel | e075430 | 2017-01-25 08:56:23 -0800 | [diff] [blame] | 126 | bool RtpFrameObject::delayed_by_retransmission() const { |
| 127 | return times_nacked() > 0; |
| 128 | } |
| 129 | |
Johannes Kron | a370556 | 2019-08-26 16:37:11 +0200 | [diff] [blame] | 130 | const RTPVideoHeader& RtpFrameObject::GetRtpVideoHeader() const { |
| 131 | return rtp_video_header_; |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Johannes Kron | a370556 | 2019-08-26 16:37:11 +0200 | [diff] [blame] | 134 | const absl::optional<RtpGenericFrameDescriptor>& |
philipel | 2837edc | 2018-10-02 13:55:47 +0200 | [diff] [blame] | 135 | RtpFrameObject::GetGenericFrameDescriptor() const { |
Johannes Kron | a370556 | 2019-08-26 16:37:11 +0200 | [diff] [blame] | 136 | return rtp_generic_frame_descriptor_; |
philipel | 2837edc | 2018-10-02 13:55:47 +0200 | [diff] [blame] | 137 | } |
| 138 | |
Johannes Kron | a370556 | 2019-08-26 16:37:11 +0200 | [diff] [blame] | 139 | const FrameMarking& RtpFrameObject::GetFrameMarking() const { |
| 140 | return rtp_video_header_.frame_marking; |
Johnny Lee | e0c8b23 | 2018-09-11 16:50:49 -0400 | [diff] [blame] | 141 | } |
| 142 | |
philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 143 | } // namespace video_coding |
| 144 | } // namespace webrtc |