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