blob: 8d011b917a83ade6e271442946cd61aa675009df [file] [log] [blame]
philipelc707ab72016-04-01 02:01:54 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/video_coding/frame_object.h"
Rasmus Brandt58b72912017-10-25 11:09:23 +020012
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <string.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
Chen Xingf00bf422019-06-20 10:05:55 +020015#include <utility>
Yves Gerey3e707812018-11-28 16:47:49 +010016
17#include "api/video/encoded_image.h"
18#include "api/video/video_timing.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "rtc_base/checks.h"
philipelc707ab72016-04-01 02:01:54 -070020
21namespace webrtc {
philipel85d5c192019-09-25 17:15:37 +020022RtpFrameObject::RtpFrameObject(
23 uint16_t first_seq_num,
24 uint16_t last_seq_num,
25 bool markerBit,
26 int times_nacked,
27 int64_t first_packet_received_time,
28 int64_t last_packet_received_time,
29 uint32_t rtp_timestamp,
30 int64_t ntp_time_ms,
31 const VideoSendTiming& timing,
32 uint8_t payload_type,
33 VideoCodecType codec,
34 VideoRotation rotation,
35 VideoContentType content_type,
36 const RTPVideoHeader& video_header,
37 const absl::optional<webrtc::ColorSpace>& color_space,
philipel85d5c192019-09-25 17:15:37 +020038 RtpPacketInfos packet_infos,
39 rtc::scoped_refptr<EncodedImageBuffer> image_buffer)
Niels Möller08ae7ce2020-09-23 15:58:12 +020040 : image_buffer_(image_buffer),
41 first_seq_num_(first_seq_num),
philipel85d5c192019-09-25 17:15:37 +020042 last_seq_num_(last_seq_num),
43 last_packet_received_time_(last_packet_received_time),
44 times_nacked_(times_nacked) {
45 rtp_video_header_ = video_header;
philipel85d5c192019-09-25 17:15:37 +020046
47 // EncodedFrame members
48 codec_type_ = codec;
49
50 // TODO(philipel): Remove when encoded image is replaced by EncodedFrame.
51 // VCMEncodedFrame members
52 CopyCodecSpecific(&rtp_video_header_);
philipel85d5c192019-09-25 17:15:37 +020053 _payloadType = payload_type;
54 SetTimestamp(rtp_timestamp);
55 ntp_time_ms_ = ntp_time_ms;
56 _frameType = rtp_video_header_.frame_type;
57
58 // Setting frame's playout delays to the same values
59 // as of the first packet's.
60 SetPlayoutDelay(rtp_video_header_.playout_delay);
61
Niels Möller08ae7ce2020-09-23 15:58:12 +020062 SetEncodedData(image_buffer_);
philipel85d5c192019-09-25 17:15:37 +020063 _encodedWidth = rtp_video_header_.width;
64 _encodedHeight = rtp_video_header_.height;
65
66 // EncodedFrame members
67 SetPacketInfos(std::move(packet_infos));
68
69 rotation_ = rotation;
70 SetColorSpace(color_space);
philipel85d5c192019-09-25 17:15:37 +020071 content_type_ = content_type;
72 if (timing.flags != VideoSendTiming::kInvalid) {
73 // ntp_time_ms_ may be -1 if not estimated yet. This is not a problem,
74 // as this will be dealt with at the time of reporting.
75 timing_.encode_start_ms = ntp_time_ms_ + timing.encode_start_delta_ms;
76 timing_.encode_finish_ms = ntp_time_ms_ + timing.encode_finish_delta_ms;
77 timing_.packetization_finish_ms =
78 ntp_time_ms_ + timing.packetization_finish_delta_ms;
79 timing_.pacer_exit_ms = ntp_time_ms_ + timing.pacer_exit_delta_ms;
80 timing_.network_timestamp_ms =
81 ntp_time_ms_ + timing.network_timestamp_delta_ms;
82 timing_.network2_timestamp_ms =
83 ntp_time_ms_ + timing.network2_timestamp_delta_ms;
84 }
85 timing_.receive_start_ms = first_packet_received_time;
86 timing_.receive_finish_ms = last_packet_received_time;
87 timing_.flags = timing.flags;
88 is_last_spatial_layer = markerBit;
89}
90
philipelc707ab72016-04-01 02:01:54 -070091RtpFrameObject::~RtpFrameObject() {
philipelc707ab72016-04-01 02:01:54 -070092}
93
philipelf4139332016-04-20 10:26:34 +020094uint16_t RtpFrameObject::first_seq_num() const {
philipel02447bc2016-05-13 06:01:03 -070095 return first_seq_num_;
philipelc707ab72016-04-01 02:01:54 -070096}
97
philipelf4139332016-04-20 10:26:34 +020098uint16_t RtpFrameObject::last_seq_num() const {
philipel02447bc2016-05-13 06:01:03 -070099 return last_seq_num_;
100}
101
philipel5ceaaae2016-05-24 10:20:47 +0200102int RtpFrameObject::times_nacked() const {
103 return times_nacked_;
104}
105
Niels Möller87e2d782019-03-07 10:18:23 +0100106VideoFrameType RtpFrameObject::frame_type() const {
Johannes Krona3705562019-08-26 16:37:11 +0200107 return rtp_video_header_.frame_type;
philipel02447bc2016-05-13 06:01:03 -0700108}
109
110VideoCodecType RtpFrameObject::codec_type() const {
111 return codec_type_;
philipelc707ab72016-04-01 02:01:54 -0700112}
113
philipelb4d31082016-07-11 08:46:29 -0700114int64_t RtpFrameObject::ReceivedTime() const {
Ilya Nikolaevskiy4348ce22018-12-07 16:26:56 +0100115 return last_packet_received_time_;
philipelb4d31082016-07-11 08:46:29 -0700116}
117
118int64_t RtpFrameObject::RenderTime() const {
119 return _renderTimeMs;
120}
121
philipele0754302017-01-25 08:56:23 -0800122bool RtpFrameObject::delayed_by_retransmission() const {
123 return times_nacked() > 0;
124}
125
Johannes Krona3705562019-08-26 16:37:11 +0200126const RTPVideoHeader& RtpFrameObject::GetRtpVideoHeader() const {
127 return rtp_video_header_;
philipel02447bc2016-05-13 06:01:03 -0700128}
129
philipelc707ab72016-04-01 02:01:54 -0700130} // namespace webrtc