• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/video_coding/frame_object.h"
12 
13 #include <string.h>
14 
15 #include <utility>
16 
17 #include "api/video/encoded_image.h"
18 #include "api/video/video_timing.h"
19 #include "rtc_base/checks.h"
20 
21 namespace webrtc {
22 namespace video_coding {
RtpFrameObject(uint16_t first_seq_num,uint16_t last_seq_num,bool markerBit,int times_nacked,int64_t first_packet_received_time,int64_t last_packet_received_time,uint32_t rtp_timestamp,int64_t ntp_time_ms,const VideoSendTiming & timing,uint8_t payload_type,VideoCodecType codec,VideoRotation rotation,VideoContentType content_type,const RTPVideoHeader & video_header,const absl::optional<webrtc::ColorSpace> & color_space,RtpPacketInfos packet_infos,rtc::scoped_refptr<EncodedImageBuffer> image_buffer)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,
39     RtpPacketInfos packet_infos,
40     rtc::scoped_refptr<EncodedImageBuffer> image_buffer)
41     : first_seq_num_(first_seq_num),
42       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;
46 
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_);
53   _completeFrame = true;
54   _payloadType = payload_type;
55   SetTimestamp(rtp_timestamp);
56   ntp_time_ms_ = ntp_time_ms;
57   _frameType = rtp_video_header_.frame_type;
58 
59   // Setting frame's playout delays to the same values
60   // as of the first packet's.
61   SetPlayoutDelay(rtp_video_header_.playout_delay);
62 
63   SetEncodedData(std::move(image_buffer));
64   _encodedWidth = rtp_video_header_.width;
65   _encodedHeight = rtp_video_header_.height;
66 
67   // EncodedFrame members
68   SetPacketInfos(std::move(packet_infos));
69 
70   rotation_ = rotation;
71   SetColorSpace(color_space);
72   content_type_ = content_type;
73   if (timing.flags != VideoSendTiming::kInvalid) {
74     // ntp_time_ms_ may be -1 if not estimated yet. This is not a problem,
75     // as this will be dealt with at the time of reporting.
76     timing_.encode_start_ms = ntp_time_ms_ + timing.encode_start_delta_ms;
77     timing_.encode_finish_ms = ntp_time_ms_ + timing.encode_finish_delta_ms;
78     timing_.packetization_finish_ms =
79         ntp_time_ms_ + timing.packetization_finish_delta_ms;
80     timing_.pacer_exit_ms = ntp_time_ms_ + timing.pacer_exit_delta_ms;
81     timing_.network_timestamp_ms =
82         ntp_time_ms_ + timing.network_timestamp_delta_ms;
83     timing_.network2_timestamp_ms =
84         ntp_time_ms_ + timing.network2_timestamp_delta_ms;
85   }
86   timing_.receive_start_ms = first_packet_received_time;
87   timing_.receive_finish_ms = last_packet_received_time;
88   timing_.flags = timing.flags;
89   is_last_spatial_layer = markerBit;
90 }
91 
~RtpFrameObject()92 RtpFrameObject::~RtpFrameObject() {
93 }
94 
first_seq_num() const95 uint16_t RtpFrameObject::first_seq_num() const {
96   return first_seq_num_;
97 }
98 
last_seq_num() const99 uint16_t RtpFrameObject::last_seq_num() const {
100   return last_seq_num_;
101 }
102 
times_nacked() const103 int RtpFrameObject::times_nacked() const {
104   return times_nacked_;
105 }
106 
frame_type() const107 VideoFrameType RtpFrameObject::frame_type() const {
108   return rtp_video_header_.frame_type;
109 }
110 
codec_type() const111 VideoCodecType RtpFrameObject::codec_type() const {
112   return codec_type_;
113 }
114 
ReceivedTime() const115 int64_t RtpFrameObject::ReceivedTime() const {
116   return last_packet_received_time_;
117 }
118 
RenderTime() const119 int64_t RtpFrameObject::RenderTime() const {
120   return _renderTimeMs;
121 }
122 
delayed_by_retransmission() const123 bool RtpFrameObject::delayed_by_retransmission() const {
124   return times_nacked() > 0;
125 }
126 
GetRtpVideoHeader() const127 const RTPVideoHeader& RtpFrameObject::GetRtpVideoHeader() const {
128   return rtp_video_header_;
129 }
130 
131 }  // namespace video_coding
132 }  // namespace webrtc
133