niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
stefan@webrtc.org | 94355e0 | 2012-02-06 14:06:39 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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/session_info.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [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 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
| 17 | #include "absl/types/variant.h" |
| 18 | #include "modules/include/module_common_types.h" |
| 19 | #include "modules/include/module_common_types_public.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 20 | #include "modules/video_coding/codecs/interface/common_constants.h" |
| 21 | #include "modules/video_coding/codecs/vp8/include/vp8_globals.h" |
Ilya Nikolaevskiy | 8643b78 | 2018-06-07 16:15:40 +0200 | [diff] [blame] | 22 | #include "modules/video_coding/jitter_buffer_common.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "modules/video_coding/packet.h" |
| 24 | #include "rtc_base/logging.h" |
mikhal@webrtc.org | e185e9f | 2011-09-23 22:02:40 +0000 | [diff] [blame] | 25 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | namespace webrtc { |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 27 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 28 | namespace { |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 29 | |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 30 | uint16_t BufferToUWord16(const uint8_t* dataBuffer) { |
| 31 | return (dataBuffer[0] << 8) | dataBuffer[1]; |
| 32 | } |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 33 | |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 34 | } // namespace |
| 35 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 36 | VCMSessionInfo::VCMSessionInfo() |
Niels Möller | 425f713 | 2018-06-08 15:17:41 +0200 | [diff] [blame] | 37 | : complete_(false), |
Niels Möller | 8f7ce22 | 2019-03-21 15:43:58 +0100 | [diff] [blame] | 38 | frame_type_(VideoFrameType::kVideoFrameDelta), |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 39 | packets_(), |
| 40 | empty_seq_num_low_(-1), |
| 41 | empty_seq_num_high_(-1), |
mikhal@webrtc.org | f31a47a | 2013-08-26 17:10:11 +0000 | [diff] [blame] | 42 | first_packet_seq_num_(-1), |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 43 | last_packet_seq_num_(-1) {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame] | 45 | VCMSessionInfo::~VCMSessionInfo() {} |
| 46 | |
stefan@webrtc.org | b07aa40 | 2012-01-10 11:45:05 +0000 | [diff] [blame] | 47 | void VCMSessionInfo::UpdateDataPointers(const uint8_t* old_base_ptr, |
| 48 | const uint8_t* new_base_ptr) { |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 49 | for (PacketIterator it = packets_.begin(); it != packets_.end(); ++it) |
stefan@webrtc.org | b07aa40 | 2012-01-10 11:45:05 +0000 | [diff] [blame] | 50 | if ((*it).dataPtr != NULL) { |
Mirko Bonadei | 25ab322 | 2021-07-08 20:08:20 +0200 | [diff] [blame] | 51 | RTC_DCHECK(old_base_ptr != NULL && new_base_ptr != NULL); |
stefan@webrtc.org | b07aa40 | 2012-01-10 11:45:05 +0000 | [diff] [blame] | 52 | (*it).dataPtr = new_base_ptr + ((*it).dataPtr - old_base_ptr); |
| 53 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | } |
| 55 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 56 | int VCMSessionInfo::LowSequenceNumber() const { |
| 57 | if (packets_.empty()) |
| 58 | return empty_seq_num_low_; |
| 59 | return packets_.front().seqNum; |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 +0000 | [diff] [blame] | 60 | } |
| 61 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 62 | int VCMSessionInfo::HighSequenceNumber() const { |
| 63 | if (packets_.empty()) |
| 64 | return empty_seq_num_high_; |
stefan@webrtc.org | 7bc465b | 2013-04-11 17:48:02 +0000 | [diff] [blame] | 65 | if (empty_seq_num_high_ == -1) |
| 66 | return packets_.back().seqNum; |
| 67 | return LatestSequenceNumber(packets_.back().seqNum, empty_seq_num_high_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | } |
| 69 | |
stefan@webrtc.org | ffd28f9 | 2011-10-19 15:55:39 +0000 | [diff] [blame] | 70 | int VCMSessionInfo::PictureId() const { |
asapersson | a9455ab | 2015-07-31 06:10:09 -0700 | [diff] [blame] | 71 | if (packets_.empty()) |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 72 | return kNoPictureId; |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 73 | if (packets_.front().video_header.codec == kVideoCodecVP8) { |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 74 | return absl::get<RTPVideoHeaderVP8>( |
| 75 | packets_.front().video_header.video_type_header) |
| 76 | .pictureId; |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 77 | } else if (packets_.front().video_header.codec == kVideoCodecVP9) { |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 78 | return absl::get<RTPVideoHeaderVP9>( |
| 79 | packets_.front().video_header.video_type_header) |
| 80 | .picture_id; |
asapersson | a9455ab | 2015-07-31 06:10:09 -0700 | [diff] [blame] | 81 | } else { |
| 82 | return kNoPictureId; |
| 83 | } |
stefan@webrtc.org | ffd28f9 | 2011-10-19 15:55:39 +0000 | [diff] [blame] | 84 | } |
| 85 | |
mikhal@webrtc.org | f5ee1dc | 2011-12-08 19:04:47 +0000 | [diff] [blame] | 86 | int VCMSessionInfo::TemporalId() const { |
asapersson | a9455ab | 2015-07-31 06:10:09 -0700 | [diff] [blame] | 87 | if (packets_.empty()) |
mikhal@webrtc.org | f5ee1dc | 2011-12-08 19:04:47 +0000 | [diff] [blame] | 88 | return kNoTemporalIdx; |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 89 | if (packets_.front().video_header.codec == kVideoCodecVP8) { |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 90 | return absl::get<RTPVideoHeaderVP8>( |
| 91 | packets_.front().video_header.video_type_header) |
| 92 | .temporalIdx; |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 93 | } else if (packets_.front().video_header.codec == kVideoCodecVP9) { |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 94 | return absl::get<RTPVideoHeaderVP9>( |
| 95 | packets_.front().video_header.video_type_header) |
| 96 | .temporal_idx; |
asapersson | a9455ab | 2015-07-31 06:10:09 -0700 | [diff] [blame] | 97 | } else { |
| 98 | return kNoTemporalIdx; |
| 99 | } |
mikhal@webrtc.org | f5ee1dc | 2011-12-08 19:04:47 +0000 | [diff] [blame] | 100 | } |
| 101 | |
henrik.lundin@webrtc.org | eda86dc | 2011-12-13 14:11:06 +0000 | [diff] [blame] | 102 | bool VCMSessionInfo::LayerSync() const { |
asapersson | a9455ab | 2015-07-31 06:10:09 -0700 | [diff] [blame] | 103 | if (packets_.empty()) |
henrik.lundin@webrtc.org | eda86dc | 2011-12-13 14:11:06 +0000 | [diff] [blame] | 104 | return false; |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 105 | if (packets_.front().video_header.codec == kVideoCodecVP8) { |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 106 | return absl::get<RTPVideoHeaderVP8>( |
| 107 | packets_.front().video_header.video_type_header) |
| 108 | .layerSync; |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 109 | } else if (packets_.front().video_header.codec == kVideoCodecVP9) { |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 110 | return absl::get<RTPVideoHeaderVP9>( |
| 111 | packets_.front().video_header.video_type_header) |
| 112 | .temporal_up_switch; |
asapersson | a9455ab | 2015-07-31 06:10:09 -0700 | [diff] [blame] | 113 | } else { |
| 114 | return false; |
| 115 | } |
henrik.lundin@webrtc.org | eda86dc | 2011-12-13 14:11:06 +0000 | [diff] [blame] | 116 | } |
| 117 | |
mikhal@webrtc.org | f5ee1dc | 2011-12-08 19:04:47 +0000 | [diff] [blame] | 118 | int VCMSessionInfo::Tl0PicId() const { |
asapersson | a9455ab | 2015-07-31 06:10:09 -0700 | [diff] [blame] | 119 | if (packets_.empty()) |
mikhal@webrtc.org | f5ee1dc | 2011-12-08 19:04:47 +0000 | [diff] [blame] | 120 | return kNoTl0PicIdx; |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 121 | if (packets_.front().video_header.codec == kVideoCodecVP8) { |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 122 | return absl::get<RTPVideoHeaderVP8>( |
| 123 | packets_.front().video_header.video_type_header) |
| 124 | .tl0PicIdx; |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 125 | } else if (packets_.front().video_header.codec == kVideoCodecVP9) { |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 126 | return absl::get<RTPVideoHeaderVP9>( |
| 127 | packets_.front().video_header.video_type_header) |
| 128 | .tl0_pic_idx; |
asapersson | a9455ab | 2015-07-31 06:10:09 -0700 | [diff] [blame] | 129 | } else { |
| 130 | return kNoTl0PicIdx; |
| 131 | } |
mikhal@webrtc.org | f5ee1dc | 2011-12-08 19:04:47 +0000 | [diff] [blame] | 132 | } |
| 133 | |
stefan | a669a3a | 2016-10-06 05:04:52 -0700 | [diff] [blame] | 134 | std::vector<NaluInfo> VCMSessionInfo::GetNaluInfos() const { |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 135 | if (packets_.empty() || |
| 136 | packets_.front().video_header.codec != kVideoCodecH264) |
stefan | a669a3a | 2016-10-06 05:04:52 -0700 | [diff] [blame] | 137 | return std::vector<NaluInfo>(); |
| 138 | std::vector<NaluInfo> nalu_infos; |
| 139 | for (const VCMPacket& packet : packets_) { |
philipel | 7d745e5 | 2018-08-02 14:03:53 +0200 | [diff] [blame] | 140 | const auto& h264 = |
| 141 | absl::get<RTPVideoHeaderH264>(packet.video_header.video_type_header); |
| 142 | for (size_t i = 0; i < h264.nalus_length; ++i) { |
| 143 | nalu_infos.push_back(h264.nalus[i]); |
stefan | a669a3a | 2016-10-06 05:04:52 -0700 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | return nalu_infos; |
| 147 | } |
| 148 | |
asapersson | 9a4cd87 | 2015-10-23 00:27:14 -0700 | [diff] [blame] | 149 | void VCMSessionInfo::SetGofInfo(const GofInfoVP9& gof_info, size_t idx) { |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 150 | if (packets_.empty()) |
asapersson | 9a4cd87 | 2015-10-23 00:27:14 -0700 | [diff] [blame] | 151 | return; |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 152 | |
| 153 | auto* vp9_header = absl::get_if<RTPVideoHeaderVP9>( |
| 154 | &packets_.front().video_header.video_type_header); |
| 155 | if (!vp9_header || vp9_header->flexible_mode) |
| 156 | return; |
| 157 | |
| 158 | vp9_header->temporal_idx = gof_info.temporal_idx[idx]; |
| 159 | vp9_header->temporal_up_switch = gof_info.temporal_up_switch[idx]; |
| 160 | vp9_header->num_ref_pics = gof_info.num_ref_pics[idx]; |
asapersson | c253a1c | 2015-11-06 00:12:01 -0800 | [diff] [blame] | 161 | for (uint8_t i = 0; i < gof_info.num_ref_pics[idx]; ++i) { |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 162 | vp9_header->pid_diff[i] = gof_info.pid_diff[idx][i]; |
asapersson | 9a4cd87 | 2015-10-23 00:27:14 -0700 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 166 | void VCMSessionInfo::Reset() { |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 167 | complete_ = false; |
Niels Möller | 8f7ce22 | 2019-03-21 15:43:58 +0100 | [diff] [blame] | 168 | frame_type_ = VideoFrameType::kVideoFrameDelta; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 169 | packets_.clear(); |
| 170 | empty_seq_num_low_ = -1; |
| 171 | empty_seq_num_high_ = -1; |
mikhal@webrtc.org | f31a47a | 2013-08-26 17:10:11 +0000 | [diff] [blame] | 172 | first_packet_seq_num_ = -1; |
| 173 | last_packet_seq_num_ = -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 174 | } |
| 175 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 176 | size_t VCMSessionInfo::SessionLength() const { |
| 177 | size_t length = 0; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 178 | for (PacketIteratorConst it = packets_.begin(); it != packets_.end(); ++it) |
| 179 | length += (*it).sizeBytes; |
| 180 | return length; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 181 | } |
| 182 | |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 183 | int VCMSessionInfo::NumPackets() const { |
| 184 | return packets_.size(); |
| 185 | } |
| 186 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 187 | size_t VCMSessionInfo::InsertBuffer(uint8_t* frame_buffer, |
| 188 | PacketIterator packet_it) { |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 189 | VCMPacket& packet = *packet_it; |
| 190 | PacketIterator it; |
| 191 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 192 | // Calculate the offset into the frame buffer for this packet. |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 193 | size_t offset = 0; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 194 | for (it = packets_.begin(); it != packet_it; ++it) |
| 195 | offset += (*it).sizeBytes; |
| 196 | |
| 197 | // Set the data pointer to pointing to the start of this packet in the |
| 198 | // frame buffer. |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 199 | const uint8_t* packet_buffer = packet.dataPtr; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 200 | packet.dataPtr = frame_buffer + offset; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 201 | |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 202 | // We handle H.264 STAP-A packets in a special way as we need to remove the |
| 203 | // two length bytes between each NAL unit, and potentially add start codes. |
pbos | f1828e8 | 2015-07-28 08:20:59 -0700 | [diff] [blame] | 204 | // TODO(pbos): Remove H264 parsing from this step and use a fragmentation |
| 205 | // header supplied by the H264 depacketizer. |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 206 | const size_t kH264NALHeaderLengthInBytes = 1; |
| 207 | const size_t kLengthFieldLength = 2; |
philipel | 7d745e5 | 2018-08-02 14:03:53 +0200 | [diff] [blame] | 208 | const auto* h264 = |
| 209 | absl::get_if<RTPVideoHeaderH264>(&packet.video_header.video_type_header); |
| 210 | if (h264 && h264->packetization_type == kH264StapA) { |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 211 | size_t required_length = 0; |
| 212 | const uint8_t* nalu_ptr = packet_buffer + kH264NALHeaderLengthInBytes; |
| 213 | while (nalu_ptr < packet_buffer + packet.sizeBytes) { |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 214 | size_t length = BufferToUWord16(nalu_ptr); |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 215 | required_length += |
| 216 | length + (packet.insertStartCode ? kH264StartCodeLengthBytes : 0); |
| 217 | nalu_ptr += kLengthFieldLength + length; |
| 218 | } |
| 219 | ShiftSubsequentPackets(packet_it, required_length); |
| 220 | nalu_ptr = packet_buffer + kH264NALHeaderLengthInBytes; |
| 221 | uint8_t* frame_buffer_ptr = frame_buffer + offset; |
| 222 | while (nalu_ptr < packet_buffer + packet.sizeBytes) { |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 223 | size_t length = BufferToUWord16(nalu_ptr); |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 224 | nalu_ptr += kLengthFieldLength; |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 225 | frame_buffer_ptr += Insert(nalu_ptr, length, packet.insertStartCode, |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 226 | const_cast<uint8_t*>(frame_buffer_ptr)); |
| 227 | nalu_ptr += length; |
| 228 | } |
| 229 | packet.sizeBytes = required_length; |
| 230 | return packet.sizeBytes; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 231 | } |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 232 | ShiftSubsequentPackets( |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 233 | packet_it, packet.sizeBytes + |
| 234 | (packet.insertStartCode ? kH264StartCodeLengthBytes : 0)); |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 235 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 236 | packet.sizeBytes = |
| 237 | Insert(packet_buffer, packet.sizeBytes, packet.insertStartCode, |
| 238 | const_cast<uint8_t*>(packet.dataPtr)); |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 239 | return packet.sizeBytes; |
| 240 | } |
| 241 | |
| 242 | size_t VCMSessionInfo::Insert(const uint8_t* buffer, |
| 243 | size_t length, |
| 244 | bool insert_start_code, |
| 245 | uint8_t* frame_buffer) { |
| 246 | if (insert_start_code) { |
| 247 | const unsigned char startCode[] = {0, 0, 0, 1}; |
| 248 | memcpy(frame_buffer, startCode, kH264StartCodeLengthBytes); |
| 249 | } |
| 250 | memcpy(frame_buffer + (insert_start_code ? kH264StartCodeLengthBytes : 0), |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 251 | buffer, length); |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 252 | length += (insert_start_code ? kH264StartCodeLengthBytes : 0); |
| 253 | |
| 254 | return length; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 255 | } |
| 256 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 257 | void VCMSessionInfo::ShiftSubsequentPackets(PacketIterator it, |
| 258 | int steps_to_shift) { |
| 259 | ++it; |
| 260 | if (it == packets_.end()) |
| 261 | return; |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 262 | uint8_t* first_packet_ptr = const_cast<uint8_t*>((*it).dataPtr); |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 263 | int shift_length = 0; |
| 264 | // Calculate the total move length and move the data pointers in advance. |
| 265 | for (; it != packets_.end(); ++it) { |
| 266 | shift_length += (*it).sizeBytes; |
| 267 | if ((*it).dataPtr != NULL) |
| 268 | (*it).dataPtr += steps_to_shift; |
| 269 | } |
| 270 | memmove(first_packet_ptr + steps_to_shift, first_packet_ptr, shift_length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 271 | } |
| 272 | |
mikhal@webrtc.org | 6b9a7f8 | 2011-11-22 22:48:20 +0000 | [diff] [blame] | 273 | void VCMSessionInfo::UpdateCompleteSession() { |
mikhal@webrtc.org | f31a47a | 2013-08-26 17:10:11 +0000 | [diff] [blame] | 274 | if (HaveFirstPacket() && HaveLastPacket()) { |
mikhal@webrtc.org | 6b9a7f8 | 2011-11-22 22:48:20 +0000 | [diff] [blame] | 275 | // Do we have all the packets in this session? |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 276 | bool complete_session = true; |
| 277 | PacketIterator it = packets_.begin(); |
| 278 | PacketIterator prev_it = it; |
| 279 | ++it; |
| 280 | for (; it != packets_.end(); ++it) { |
| 281 | if (!InSequence(it, prev_it)) { |
| 282 | complete_session = false; |
mikhal@webrtc.org | 6b9a7f8 | 2011-11-22 22:48:20 +0000 | [diff] [blame] | 283 | break; |
| 284 | } |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 285 | prev_it = it; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 286 | } |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 287 | complete_ = complete_session; |
mikhal@webrtc.org | 6b9a7f8 | 2011-11-22 22:48:20 +0000 | [diff] [blame] | 288 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 289 | } |
| 290 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 291 | bool VCMSessionInfo::complete() const { |
| 292 | return complete_; |
mikhal@webrtc.org | 6b9a7f8 | 2011-11-22 22:48:20 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 295 | // Find the end of the NAL unit which the packet pointed to by `packet_it` |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 296 | // belongs to. Returns an iterator to the last packet of the frame if the end |
| 297 | // of the NAL unit wasn't found. |
| 298 | VCMSessionInfo::PacketIterator VCMSessionInfo::FindNaluEnd( |
| 299 | PacketIterator packet_it) const { |
| 300 | if ((*packet_it).completeNALU == kNaluEnd || |
| 301 | (*packet_it).completeNALU == kNaluComplete) { |
| 302 | return packet_it; |
| 303 | } |
| 304 | // Find the end of the NAL unit. |
| 305 | for (; packet_it != packets_.end(); ++packet_it) { |
| 306 | if (((*packet_it).completeNALU == kNaluComplete && |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 307 | (*packet_it).sizeBytes > 0) || |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 308 | // Found next NALU. |
| 309 | (*packet_it).completeNALU == kNaluStart) |
| 310 | return --packet_it; |
| 311 | if ((*packet_it).completeNALU == kNaluEnd) |
| 312 | return packet_it; |
| 313 | } |
| 314 | // The end wasn't found. |
| 315 | return --packet_it; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 316 | } |
| 317 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 318 | size_t VCMSessionInfo::DeletePacketData(PacketIterator start, |
| 319 | PacketIterator end) { |
| 320 | size_t bytes_to_delete = 0; // The number of bytes to delete. |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 321 | PacketIterator packet_after_end = end; |
| 322 | ++packet_after_end; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 323 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 324 | // Get the number of bytes to delete. |
| 325 | // Clear the size of these packets. |
| 326 | for (PacketIterator it = start; it != packet_after_end; ++it) { |
| 327 | bytes_to_delete += (*it).sizeBytes; |
| 328 | (*it).sizeBytes = 0; |
| 329 | (*it).dataPtr = NULL; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 330 | } |
| 331 | if (bytes_to_delete > 0) |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 332 | ShiftSubsequentPackets(end, -static_cast<int>(bytes_to_delete)); |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 333 | return bytes_to_delete; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 334 | } |
| 335 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 336 | VCMSessionInfo::PacketIterator VCMSessionInfo::FindNextPartitionBeginning( |
mikhal@webrtc.org | 2b810bf | 2013-09-03 19:09:49 +0000 | [diff] [blame] | 337 | PacketIterator it) const { |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 338 | while (it != packets_.end()) { |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 339 | if (absl::get<RTPVideoHeaderVP8>((*it).video_header.video_type_header) |
| 340 | .beginningOfPartition) { |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 341 | return it; |
stefan@webrtc.org | 4c059d8 | 2011-10-13 07:35:37 +0000 | [diff] [blame] | 342 | } |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 343 | ++it; |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 +0000 | [diff] [blame] | 344 | } |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 345 | return it; |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 +0000 | [diff] [blame] | 346 | } |
| 347 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 348 | VCMSessionInfo::PacketIterator VCMSessionInfo::FindPartitionEnd( |
| 349 | PacketIterator it) const { |
Mirko Bonadei | 25ab322 | 2021-07-08 20:08:20 +0200 | [diff] [blame] | 350 | RTC_DCHECK_EQ((*it).codec(), kVideoCodecVP8); |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 351 | PacketIterator prev_it = it; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 352 | const int partition_id = |
| 353 | absl::get<RTPVideoHeaderVP8>((*it).video_header.video_type_header) |
| 354 | .partitionId; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 355 | while (it != packets_.end()) { |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 356 | bool beginning = |
| 357 | absl::get<RTPVideoHeaderVP8>((*it).video_header.video_type_header) |
| 358 | .beginningOfPartition; |
| 359 | int current_partition_id = |
| 360 | absl::get<RTPVideoHeaderVP8>((*it).video_header.video_type_header) |
| 361 | .partitionId; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 362 | bool packet_loss_found = (!beginning && !InSequence(it, prev_it)); |
| 363 | if (packet_loss_found || |
| 364 | (beginning && current_partition_id != partition_id)) { |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 +0000 | [diff] [blame] | 365 | // Missing packet, the previous packet was the last in sequence. |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 366 | return prev_it; |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 +0000 | [diff] [blame] | 367 | } |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 368 | prev_it = it; |
| 369 | ++it; |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 +0000 | [diff] [blame] | 370 | } |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 371 | return prev_it; |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 +0000 | [diff] [blame] | 372 | } |
| 373 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 374 | bool VCMSessionInfo::InSequence(const PacketIterator& packet_it, |
| 375 | const PacketIterator& prev_packet_it) { |
| 376 | // If the two iterators are pointing to the same packet they are considered |
| 377 | // to be in sequence. |
| 378 | return (packet_it == prev_packet_it || |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 379 | (static_cast<uint16_t>((*prev_packet_it).seqNum + 1) == |
| 380 | (*packet_it).seqNum)); |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 +0000 | [diff] [blame] | 381 | } |
| 382 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 383 | size_t VCMSessionInfo::MakeDecodable() { |
| 384 | size_t return_length = 0; |
stefan@webrtc.org | 4ce0ba0 | 2012-02-28 12:09:09 +0000 | [diff] [blame] | 385 | if (packets_.empty()) { |
| 386 | return 0; |
| 387 | } |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 388 | PacketIterator it = packets_.begin(); |
| 389 | // Make sure we remove the first NAL unit if it's not decodable. |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 390 | if ((*it).completeNALU == kNaluIncomplete || (*it).completeNALU == kNaluEnd) { |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 391 | PacketIterator nalu_end = FindNaluEnd(it); |
| 392 | return_length += DeletePacketData(it, nalu_end); |
| 393 | it = nalu_end; |
| 394 | } |
| 395 | PacketIterator prev_it = it; |
| 396 | // Take care of the rest of the NAL units. |
| 397 | for (; it != packets_.end(); ++it) { |
| 398 | bool start_of_nalu = ((*it).completeNALU == kNaluStart || |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 399 | (*it).completeNALU == kNaluComplete); |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 400 | if (!start_of_nalu && !InSequence(it, prev_it)) { |
| 401 | // Found a sequence number gap due to packet loss. |
| 402 | PacketIterator nalu_end = FindNaluEnd(it); |
| 403 | return_length += DeletePacketData(it, nalu_end); |
| 404 | it = nalu_end; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 405 | } |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 406 | prev_it = it; |
| 407 | } |
| 408 | return return_length; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 409 | } |
| 410 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 411 | bool VCMSessionInfo::HaveFirstPacket() const { |
mikhal@webrtc.org | f31a47a | 2013-08-26 17:10:11 +0000 | [diff] [blame] | 412 | return !packets_.empty() && (first_packet_seq_num_ != -1); |
stefan@webrtc.org | 885cd13 | 2013-04-16 09:38:26 +0000 | [diff] [blame] | 413 | } |
| 414 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 415 | bool VCMSessionInfo::HaveLastPacket() const { |
mikhal@webrtc.org | f31a47a | 2013-08-26 17:10:11 +0000 | [diff] [blame] | 416 | return !packets_.empty() && (last_packet_seq_num_ != -1); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 417 | } |
| 418 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 419 | int VCMSessionInfo::InsertPacket(const VCMPacket& packet, |
| 420 | uint8_t* frame_buffer, |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 421 | const FrameData& frame_data) { |
Niels Möller | abbc50e | 2019-04-24 09:41:16 +0200 | [diff] [blame] | 422 | if (packet.video_header.frame_type == VideoFrameType::kEmptyFrame) { |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 423 | // Update sequence number of an empty packet. |
| 424 | // Only media packets are inserted into the packet list. |
| 425 | InformOfEmptyPacket(packet.seqNum); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 426 | return 0; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 427 | } |
| 428 | |
mikhal@webrtc.org | f31a47a | 2013-08-26 17:10:11 +0000 | [diff] [blame] | 429 | if (packets_.size() == kMaxPacketsInSession) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 430 | RTC_LOG(LS_ERROR) << "Max number of packets per frame has been reached."; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 431 | return -1; |
mikhal@webrtc.org | f31a47a | 2013-08-26 17:10:11 +0000 | [diff] [blame] | 432 | } |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 433 | |
| 434 | // Find the position of this packet in the packet list in sequence number |
| 435 | // order and insert it. Loop over the list in reverse order. |
| 436 | ReversePacketIterator rit = packets_.rbegin(); |
| 437 | for (; rit != packets_.rend(); ++rit) |
stefan@webrtc.org | 7bc465b | 2013-04-11 17:48:02 +0000 | [diff] [blame] | 438 | if (LatestSequenceNumber(packet.seqNum, (*rit).seqNum) == packet.seqNum) |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 439 | break; |
| 440 | |
| 441 | // Check for duplicate packets. |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 442 | if (rit != packets_.rend() && (*rit).seqNum == packet.seqNum && |
| 443 | (*rit).sizeBytes > 0) |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 444 | return -2; |
| 445 | |
Niels Möller | d5e02f0 | 2019-02-20 13:12:21 +0100 | [diff] [blame] | 446 | if (packet.codec() == kVideoCodecH264) { |
Niels Möller | abbc50e | 2019-04-24 09:41:16 +0200 | [diff] [blame] | 447 | frame_type_ = packet.video_header.frame_type; |
Niels Möller | d5e02f0 | 2019-02-20 13:12:21 +0100 | [diff] [blame] | 448 | if (packet.is_first_packet_in_frame() && |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 449 | (first_packet_seq_num_ == -1 || |
| 450 | IsNewerSequenceNumber(first_packet_seq_num_, packet.seqNum))) { |
| 451 | first_packet_seq_num_ = packet.seqNum; |
| 452 | } |
| 453 | if (packet.markerBit && |
| 454 | (last_packet_seq_num_ == -1 || |
| 455 | IsNewerSequenceNumber(packet.seqNum, last_packet_seq_num_))) { |
| 456 | last_packet_seq_num_ = packet.seqNum; |
| 457 | } |
| 458 | } else { |
| 459 | // Only insert media packets between first and last packets (when |
| 460 | // available). |
| 461 | // Placing check here, as to properly account for duplicate packets. |
| 462 | // Check if this is first packet (only valid for some codecs) |
| 463 | // Should only be set for one packet per session. |
Niels Möller | d5e02f0 | 2019-02-20 13:12:21 +0100 | [diff] [blame] | 464 | if (packet.is_first_packet_in_frame() && first_packet_seq_num_ == -1) { |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 465 | // The first packet in a frame signals the frame type. |
Niels Möller | abbc50e | 2019-04-24 09:41:16 +0200 | [diff] [blame] | 466 | frame_type_ = packet.video_header.frame_type; |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 467 | // Store the sequence number for the first packet. |
| 468 | first_packet_seq_num_ = static_cast<int>(packet.seqNum); |
| 469 | } else if (first_packet_seq_num_ != -1 && |
pbos@webrtc.org | 4f16c87 | 2014-11-24 09:06:48 +0000 | [diff] [blame] | 470 | IsNewerSequenceNumber(first_packet_seq_num_, packet.seqNum)) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 471 | RTC_LOG(LS_WARNING) |
| 472 | << "Received packet with a sequence number which is out " |
| 473 | "of frame boundaries"; |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 474 | return -3; |
Niels Möller | 8f7ce22 | 2019-03-21 15:43:58 +0100 | [diff] [blame] | 475 | } else if (frame_type_ == VideoFrameType::kEmptyFrame && |
Niels Möller | abbc50e | 2019-04-24 09:41:16 +0200 | [diff] [blame] | 476 | packet.video_header.frame_type != VideoFrameType::kEmptyFrame) { |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 477 | // Update the frame type with the type of the first media packet. |
| 478 | // TODO(mikhal): Can this trigger? |
Niels Möller | abbc50e | 2019-04-24 09:41:16 +0200 | [diff] [blame] | 479 | frame_type_ = packet.video_header.frame_type; |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 480 | } |
mikhal@webrtc.org | f31a47a | 2013-08-26 17:10:11 +0000 | [diff] [blame] | 481 | |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 482 | // Track the marker bit, should only be set for one packet per session. |
| 483 | if (packet.markerBit && last_packet_seq_num_ == -1) { |
| 484 | last_packet_seq_num_ = static_cast<int>(packet.seqNum); |
| 485 | } else if (last_packet_seq_num_ != -1 && |
| 486 | IsNewerSequenceNumber(packet.seqNum, last_packet_seq_num_)) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 487 | RTC_LOG(LS_WARNING) |
| 488 | << "Received packet with a sequence number which is out " |
| 489 | "of frame boundaries"; |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 490 | return -3; |
| 491 | } |
mikhal@webrtc.org | f31a47a | 2013-08-26 17:10:11 +0000 | [diff] [blame] | 492 | } |
| 493 | |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 494 | // The insert operation invalidates the iterator `rit`. |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 495 | PacketIterator packet_list_it = packets_.insert(rit.base(), packet); |
| 496 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 497 | size_t returnLength = InsertBuffer(frame_buffer, packet_list_it); |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 498 | UpdateCompleteSession(); |
Niels Möller | 375b346 | 2019-01-10 15:35:56 +0100 | [diff] [blame] | 499 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 500 | return static_cast<int>(returnLength); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 501 | } |
| 502 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 503 | void VCMSessionInfo::InformOfEmptyPacket(uint16_t seq_num) { |
| 504 | // Empty packets may be FEC or filler packets. They are sequential and |
| 505 | // follow the data packets, therefore, we should only keep track of the high |
| 506 | // and low sequence numbers and may assume that the packets in between are |
| 507 | // empty packets belonging to the same frame (timestamp). |
stefan@webrtc.org | 7bc465b | 2013-04-11 17:48:02 +0000 | [diff] [blame] | 508 | if (empty_seq_num_high_ == -1) |
| 509 | empty_seq_num_high_ = seq_num; |
| 510 | else |
| 511 | empty_seq_num_high_ = LatestSequenceNumber(seq_num, empty_seq_num_high_); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 512 | if (empty_seq_num_low_ == -1 || |
| 513 | IsNewerSequenceNumber(empty_seq_num_low_, seq_num)) |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 514 | empty_seq_num_low_ = seq_num; |
| 515 | } |
| 516 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 517 | } // namespace webrtc |