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