blob: 682ce17f9cfd8e52e5c40815ce3eefe583670746 [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"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "rtc_base/critical_section.h"
philipelc707ab72016-04-01 02:01:54 -070021
22namespace webrtc {
23namespace video_coding {
philipel85d5c192019-09-25 17:15:37 +020024RtpFrameObject::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);
philipel85d5c192019-09-25 17:15:37 +020075 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
philipelc707ab72016-04-01 02:01:54 -070095RtpFrameObject::~RtpFrameObject() {
philipelc707ab72016-04-01 02:01:54 -070096}
97
philipelf4139332016-04-20 10:26:34 +020098uint16_t RtpFrameObject::first_seq_num() const {
philipel02447bc2016-05-13 06:01:03 -070099 return first_seq_num_;
philipelc707ab72016-04-01 02:01:54 -0700100}
101
philipelf4139332016-04-20 10:26:34 +0200102uint16_t RtpFrameObject::last_seq_num() const {
philipel02447bc2016-05-13 06:01:03 -0700103 return last_seq_num_;
104}
105
philipel5ceaaae2016-05-24 10:20:47 +0200106int RtpFrameObject::times_nacked() const {
107 return times_nacked_;
108}
109
Niels Möller87e2d782019-03-07 10:18:23 +0100110VideoFrameType RtpFrameObject::frame_type() const {
Johannes Krona3705562019-08-26 16:37:11 +0200111 return rtp_video_header_.frame_type;
philipel02447bc2016-05-13 06:01:03 -0700112}
113
114VideoCodecType RtpFrameObject::codec_type() const {
115 return codec_type_;
philipelc707ab72016-04-01 02:01:54 -0700116}
117
philipelb4d31082016-07-11 08:46:29 -0700118int64_t RtpFrameObject::ReceivedTime() const {
Ilya Nikolaevskiy4348ce22018-12-07 16:26:56 +0100119 return last_packet_received_time_;
philipelb4d31082016-07-11 08:46:29 -0700120}
121
122int64_t RtpFrameObject::RenderTime() const {
123 return _renderTimeMs;
124}
125
philipele0754302017-01-25 08:56:23 -0800126bool RtpFrameObject::delayed_by_retransmission() const {
127 return times_nacked() > 0;
128}
129
Johannes Krona3705562019-08-26 16:37:11 +0200130const RTPVideoHeader& RtpFrameObject::GetRtpVideoHeader() const {
131 return rtp_video_header_;
philipel02447bc2016-05-13 06:01:03 -0700132}
133
Johannes Krona3705562019-08-26 16:37:11 +0200134const absl::optional<RtpGenericFrameDescriptor>&
philipel2837edc2018-10-02 13:55:47 +0200135RtpFrameObject::GetGenericFrameDescriptor() const {
Johannes Krona3705562019-08-26 16:37:11 +0200136 return rtp_generic_frame_descriptor_;
philipel2837edc2018-10-02 13:55:47 +0200137}
138
Johannes Krona3705562019-08-26 16:37:11 +0200139const FrameMarking& RtpFrameObject::GetFrameMarking() const {
140 return rtp_video_header_.frame_marking;
Johnny Leee0c8b232018-09-11 16:50:49 -0400141}
142
philipelc707ab72016-04-01 02:01:54 -0700143} // namespace video_coding
144} // namespace webrtc