| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 return; | 42 return; |
| 43 } | 43 } |
| 44 frames_from_callback_.insert( | 44 frames_from_callback_.insert( |
| 45 std::make_pair(frame->first_seq_num(), std::move(frame))); | 45 std::make_pair(frame->first_seq_num(), std::move(frame))); |
| 46 } | 46 } |
| 47 | 47 |
| 48 enum IsKeyFrame { kKeyFrame, kDeltaFrame }; | 48 enum IsKeyFrame { kKeyFrame, kDeltaFrame }; |
| 49 enum IsFirst { kFirst, kNotFirst }; | 49 enum IsFirst { kFirst, kNotFirst }; |
| 50 enum IsLast { kLast, kNotLast }; | 50 enum IsLast { kLast, kNotLast }; |
| 51 | 51 |
| 52 void InsertPacket(uint16_t seq_num, // packet sequence number | 52 bool Insert(uint16_t seq_num, // packet sequence number |
| 53 IsKeyFrame keyframe, // is keyframe | 53 IsKeyFrame keyframe, // is keyframe |
| 54 IsFirst first, // is first packet of frame | 54 IsFirst first, // is first packet of frame |
| 55 IsLast last, // is last packet of frame | 55 IsLast last, // is last packet of frame |
| 56 int data_size = 0, // size of data | 56 int data_size = 0, // size of data |
| 57 uint8_t* data = nullptr) { // data pointer | 57 uint8_t* data = nullptr) { // data pointer |
| 58 VCMPacket packet; | 58 VCMPacket packet; |
| 59 packet.codec = kVideoCodecGeneric; | 59 packet.codec = kVideoCodecGeneric; |
| 60 packet.seqNum = seq_num; | 60 packet.seqNum = seq_num; |
| 61 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta; | 61 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta; |
| 62 packet.isFirstPacket = first == kFirst; | 62 packet.isFirstPacket = first == kFirst; |
| 63 packet.markerBit = last == kLast; | 63 packet.markerBit = last == kLast; |
| 64 packet.sizeBytes = data_size; | 64 packet.sizeBytes = data_size; |
| 65 packet.dataPtr = data; | 65 packet.dataPtr = data; |
| 66 | 66 |
| 67 EXPECT_TRUE(packet_buffer_->InsertPacket(packet)); | 67 return packet_buffer_->InsertPacket(packet); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void CheckFrame(uint16_t first_seq_num) { | 70 void CheckFrame(uint16_t first_seq_num) { |
| 71 auto frame_it = frames_from_callback_.find(first_seq_num); | 71 auto frame_it = frames_from_callback_.find(first_seq_num); |
| 72 ASSERT_FALSE(frame_it == frames_from_callback_.end()) | 72 ASSERT_FALSE(frame_it == frames_from_callback_.end()) |
| 73 << "Could not find frame with first sequence number " << first_seq_num | 73 << "Could not find frame with first sequence number " << first_seq_num |
| 74 << "."; | 74 << "."; |
| 75 } | 75 } |
| 76 | 76 |
| 77 const int kStartSize = 16; | 77 const int kStartSize = 16; |
| 78 const int kMaxSize = 64; | 78 const int kMaxSize = 64; |
| 79 | 79 |
| 80 Random rand_; | 80 Random rand_; |
| 81 std::unique_ptr<Clock> clock_; | 81 std::unique_ptr<Clock> clock_; |
| 82 rtc::scoped_refptr<PacketBuffer> packet_buffer_; | 82 rtc::scoped_refptr<PacketBuffer> packet_buffer_; |
| 83 std::map<uint16_t, std::unique_ptr<RtpFrameObject>> frames_from_callback_; | 83 std::map<uint16_t, std::unique_ptr<RtpFrameObject>> frames_from_callback_; |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 TEST_F(TestPacketBuffer, InsertOnePacket) { | 86 TEST_F(TestPacketBuffer, InsertOnePacket) { |
| 87 uint16_t seq_num = Rand(); | 87 const uint16_t seq_num = Rand(); |
| 88 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); | 88 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 TEST_F(TestPacketBuffer, InsertMultiplePackets) { | 91 TEST_F(TestPacketBuffer, InsertMultiplePackets) { |
| 92 uint16_t seq_num = Rand(); | 92 const uint16_t seq_num = Rand(); |
| 93 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); | 93 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); |
| 94 InsertPacket(seq_num + 1, kKeyFrame, kFirst, kLast); | 94 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kFirst, kLast)); |
| 95 InsertPacket(seq_num + 2, kKeyFrame, kFirst, kLast); | 95 EXPECT_TRUE(Insert(seq_num + 2, kKeyFrame, kFirst, kLast)); |
| 96 InsertPacket(seq_num + 3, kKeyFrame, kFirst, kLast); | 96 EXPECT_TRUE(Insert(seq_num + 3, kKeyFrame, kFirst, kLast)); |
| 97 } | 97 } |
| 98 | 98 |
| 99 TEST_F(TestPacketBuffer, InsertDuplicatePacket) { | 99 TEST_F(TestPacketBuffer, InsertDuplicatePacket) { |
| 100 uint16_t seq_num = Rand(); | 100 const uint16_t seq_num = Rand(); |
| 101 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); | 101 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); |
| 102 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); | 102 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); |
| 103 } |
| 104 |
| 105 TEST_F(TestPacketBuffer, SeqNumWrap) { |
| 106 uint16_t seq_num = 0xFFFF; |
| 107 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); |
| 108 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kFirst, kLast)); |
| 109 |
| 110 CheckFrame(seq_num); |
| 111 } |
| 112 |
| 113 TEST_F(TestPacketBuffer, InsertOldPackets) { |
| 114 const uint16_t seq_num = Rand(); |
| 115 |
| 116 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast)); |
| 117 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast)); |
| 118 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kNotFirst, kLast)); |
| 119 ASSERT_EQ(2UL, frames_from_callback_.size()); |
| 120 |
| 121 frames_from_callback_.erase(seq_num + 2); |
| 122 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast)); |
| 123 ASSERT_EQ(1UL, frames_from_callback_.size()); |
| 124 |
| 125 frames_from_callback_.erase(frames_from_callback_.find(seq_num)); |
| 126 ASSERT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast)); |
| 127 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast)); |
| 128 |
| 129 packet_buffer_->ClearTo(seq_num + 2); |
| 130 EXPECT_FALSE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast)); |
| 131 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kFirst, kLast)); |
| 132 ASSERT_EQ(2UL, frames_from_callback_.size()); |
| 103 } | 133 } |
| 104 | 134 |
| 105 TEST_F(TestPacketBuffer, NackCount) { | 135 TEST_F(TestPacketBuffer, NackCount) { |
| 106 uint16_t seq_num = Rand(); | 136 const uint16_t seq_num = Rand(); |
| 107 | 137 |
| 108 VCMPacket packet; | 138 VCMPacket packet; |
| 109 packet.codec = kVideoCodecGeneric; | 139 packet.codec = kVideoCodecGeneric; |
| 110 packet.seqNum = seq_num; | 140 packet.seqNum = seq_num; |
| 111 packet.frameType = kVideoFrameKey; | 141 packet.frameType = kVideoFrameKey; |
| 112 packet.isFirstPacket = true; | 142 packet.isFirstPacket = true; |
| 113 packet.markerBit = false; | 143 packet.markerBit = false; |
| 114 packet.timesNacked = 0; | 144 packet.timesNacked = 0; |
| 115 | 145 |
| 116 packet_buffer_->InsertPacket(packet); | 146 packet_buffer_->InsertPacket(packet); |
| 117 | 147 |
| 118 packet.seqNum++; | 148 packet.seqNum++; |
| 119 packet.isFirstPacket = false; | 149 packet.isFirstPacket = false; |
| 120 packet.timesNacked = 1; | 150 packet.timesNacked = 1; |
| 121 packet_buffer_->InsertPacket(packet); | 151 packet_buffer_->InsertPacket(packet); |
| 122 | 152 |
| 123 packet.seqNum++; | 153 packet.seqNum++; |
| 124 packet.timesNacked = 3; | 154 packet.timesNacked = 3; |
| 125 packet_buffer_->InsertPacket(packet); | 155 packet_buffer_->InsertPacket(packet); |
| 126 | 156 |
| 127 packet.seqNum++; | 157 packet.seqNum++; |
| 128 packet.markerBit = true; | 158 packet.markerBit = true; |
| 129 packet.timesNacked = 1; | 159 packet.timesNacked = 1; |
| 130 packet_buffer_->InsertPacket(packet); | 160 packet_buffer_->InsertPacket(packet); |
| 131 | 161 |
| 132 | |
| 133 ASSERT_EQ(1UL, frames_from_callback_.size()); | 162 ASSERT_EQ(1UL, frames_from_callback_.size()); |
| 134 RtpFrameObject* frame = frames_from_callback_.begin()->second.get(); | 163 RtpFrameObject* frame = frames_from_callback_.begin()->second.get(); |
| 135 EXPECT_EQ(3, frame->times_nacked()); | 164 EXPECT_EQ(3, frame->times_nacked()); |
| 136 } | 165 } |
| 137 | 166 |
| 138 TEST_F(TestPacketBuffer, FrameSize) { | 167 TEST_F(TestPacketBuffer, FrameSize) { |
| 139 uint16_t seq_num = Rand(); | 168 const uint16_t seq_num = Rand(); |
| 140 uint8_t data[] = {1, 2, 3, 4, 5}; | 169 uint8_t data[] = {1, 2, 3, 4, 5}; |
| 141 | 170 |
| 142 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast, 5, data); | 171 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast, 5, data)); |
| 143 InsertPacket(seq_num + 1, kKeyFrame, kNotFirst, kNotLast, 5, data); | 172 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kNotFirst, kNotLast, 5, data)); |
| 144 InsertPacket(seq_num + 2, kKeyFrame, kNotFirst, kNotLast, 5, data); | 173 EXPECT_TRUE(Insert(seq_num + 2, kKeyFrame, kNotFirst, kNotLast, 5, data)); |
| 145 InsertPacket(seq_num + 3, kKeyFrame, kNotFirst, kLast, 5, data); | 174 EXPECT_TRUE(Insert(seq_num + 3, kKeyFrame, kNotFirst, kLast, 5, data)); |
| 146 | 175 |
| 147 ASSERT_EQ(1UL, frames_from_callback_.size()); | 176 ASSERT_EQ(1UL, frames_from_callback_.size()); |
| 148 EXPECT_EQ(20UL, frames_from_callback_.begin()->second->size); | 177 EXPECT_EQ(20UL, frames_from_callback_.begin()->second->size); |
| 149 } | 178 } |
| 150 | 179 |
| 151 TEST_F(TestPacketBuffer, ExpandBuffer) { | 180 TEST_F(TestPacketBuffer, ExpandBuffer) { |
| 152 uint16_t seq_num = Rand(); | 181 const uint16_t seq_num = Rand(); |
| 153 | 182 |
| 154 for (int i = 0; i < kStartSize + 1; ++i) { | 183 for (int i = 0; i < kStartSize + 1; ++i) { |
| 155 InsertPacket(seq_num + i, kKeyFrame, kFirst, kLast); | 184 EXPECT_TRUE(Insert(seq_num + i, kKeyFrame, kFirst, kLast)); |
| 156 } | 185 } |
| 157 } | 186 } |
| 158 | 187 |
| 188 TEST_F(TestPacketBuffer, SingleFrameExpandsBuffer) { |
| 189 const uint16_t seq_num = Rand(); |
| 190 |
| 191 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast)); |
| 192 for (int i = 1; i < kStartSize; ++i) |
| 193 EXPECT_TRUE(Insert(seq_num + i, kKeyFrame, kNotFirst, kNotLast)); |
| 194 EXPECT_TRUE(Insert(seq_num + kStartSize, kKeyFrame, kNotFirst, kLast)); |
| 195 |
| 196 ASSERT_EQ(1UL, frames_from_callback_.size()); |
| 197 CheckFrame(seq_num); |
| 198 } |
| 199 |
| 159 TEST_F(TestPacketBuffer, ExpandBufferOverflow) { | 200 TEST_F(TestPacketBuffer, ExpandBufferOverflow) { |
| 160 uint16_t seq_num = Rand(); | 201 const uint16_t seq_num = Rand(); |
| 161 | 202 |
| 162 for (int i = 0; i < kMaxSize; ++i) { | 203 for (int i = 0; i < kMaxSize; ++i) |
| 163 InsertPacket(seq_num + i, kKeyFrame, kFirst, kLast); | 204 EXPECT_TRUE(Insert(seq_num + i, kKeyFrame, kFirst, kLast)); |
| 164 } | 205 EXPECT_FALSE(Insert(seq_num + kMaxSize + 1, kKeyFrame, kFirst, kLast)); |
| 165 | |
| 166 VCMPacket packet; | |
| 167 packet.seqNum = seq_num + kMaxSize + 1; | |
| 168 EXPECT_FALSE(packet_buffer_->InsertPacket(packet)); | |
| 169 } | 206 } |
| 170 | 207 |
| 171 TEST_F(TestPacketBuffer, OnePacketOneFrame) { | 208 TEST_F(TestPacketBuffer, OnePacketOneFrame) { |
| 172 uint16_t seq_num = Rand(); | 209 const uint16_t seq_num = Rand(); |
| 173 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); | 210 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); |
| 174 ASSERT_EQ(1UL, frames_from_callback_.size()); | 211 ASSERT_EQ(1UL, frames_from_callback_.size()); |
| 175 CheckFrame(seq_num); | 212 CheckFrame(seq_num); |
| 176 } | 213 } |
| 177 | 214 |
| 178 TEST_F(TestPacketBuffer, TwoPacketsTwoFrames) { | 215 TEST_F(TestPacketBuffer, TwoPacketsTwoFrames) { |
| 179 uint16_t seq_num = Rand(); | 216 const uint16_t seq_num = Rand(); |
| 180 | 217 |
| 181 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); | 218 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); |
| 182 InsertPacket(seq_num + 1, kKeyFrame, kFirst, kLast); | 219 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kFirst, kLast)); |
| 183 | 220 |
| 184 EXPECT_EQ(2UL, frames_from_callback_.size()); | 221 EXPECT_EQ(2UL, frames_from_callback_.size()); |
| 185 CheckFrame(seq_num); | 222 CheckFrame(seq_num); |
| 186 CheckFrame(seq_num + 1); | 223 CheckFrame(seq_num + 1); |
| 187 } | 224 } |
| 188 | 225 |
| 189 TEST_F(TestPacketBuffer, TwoPacketsOneFrames) { | 226 TEST_F(TestPacketBuffer, TwoPacketsOneFrames) { |
| 190 uint16_t seq_num = Rand(); | 227 const uint16_t seq_num = Rand(); |
| 191 | 228 |
| 192 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast); | 229 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast)); |
| 193 InsertPacket(seq_num + 1, kKeyFrame, kNotFirst, kLast); | 230 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kNotFirst, kLast)); |
| 194 | 231 |
| 195 EXPECT_EQ(1UL, frames_from_callback_.size()); | 232 EXPECT_EQ(1UL, frames_from_callback_.size()); |
| 196 CheckFrame(seq_num); | 233 CheckFrame(seq_num); |
| 197 } | 234 } |
| 198 | 235 |
| 199 TEST_F(TestPacketBuffer, ThreePacketReorderingOneFrame) { | 236 TEST_F(TestPacketBuffer, ThreePacketReorderingOneFrame) { |
| 200 uint16_t seq_num = Rand(); | 237 const uint16_t seq_num = Rand(); |
| 201 | 238 |
| 202 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast); | 239 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast)); |
| 203 InsertPacket(seq_num + 2, kKeyFrame, kNotFirst, kLast); | 240 EXPECT_TRUE(Insert(seq_num + 2, kKeyFrame, kNotFirst, kLast)); |
| 204 InsertPacket(seq_num + 1, kKeyFrame, kNotFirst, kNotLast); | 241 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kNotFirst, kNotLast)); |
| 205 | 242 |
| 206 EXPECT_EQ(1UL, frames_from_callback_.size()); | 243 EXPECT_EQ(1UL, frames_from_callback_.size()); |
| 207 CheckFrame(seq_num); | 244 CheckFrame(seq_num); |
| 208 } | 245 } |
| 209 | 246 |
| 210 TEST_F(TestPacketBuffer, DiscardOldPacket) { | 247 TEST_F(TestPacketBuffer, Frames) { |
| 211 VCMPacket packet; | 248 const uint16_t seq_num = Rand(); |
| 212 packet.seqNum = Rand(); | |
| 213 EXPECT_TRUE(packet_buffer_->InsertPacket(packet)); | |
| 214 packet.seqNum += 2; | |
| 215 EXPECT_TRUE(packet_buffer_->InsertPacket(packet)); | |
| 216 | 249 |
| 217 for (int i = 3; i < kMaxSize; ++i) { | 250 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); |
| 218 ++packet.seqNum; | 251 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kFirst, kLast)); |
| 219 EXPECT_TRUE(packet_buffer_->InsertPacket(packet)); | 252 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast)); |
| 220 } | 253 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kFirst, kLast)); |
| 221 | |
| 222 ++packet.seqNum; | |
| 223 EXPECT_FALSE(packet_buffer_->InsertPacket(packet)); | |
| 224 packet_buffer_->ClearTo(packet.seqNum + 1); | |
| 225 EXPECT_TRUE(packet_buffer_->InsertPacket(packet)); | |
| 226 } | |
| 227 | |
| 228 TEST_F(TestPacketBuffer, DiscardMultipleOldPackets) { | |
| 229 uint16_t seq_num = Rand(); | |
| 230 VCMPacket packet; | |
| 231 packet.seqNum = seq_num; | |
| 232 EXPECT_TRUE(packet_buffer_->InsertPacket(packet)); | |
| 233 packet.seqNum += 2; | |
| 234 EXPECT_TRUE(packet_buffer_->InsertPacket(packet)); | |
| 235 | |
| 236 for (int i = 3; i < kMaxSize; ++i) { | |
| 237 ++packet.seqNum; | |
| 238 EXPECT_TRUE(packet_buffer_->InsertPacket(packet)); | |
| 239 } | |
| 240 | |
| 241 packet_buffer_->ClearTo(seq_num + 15); | |
| 242 for (int i = 0; i < 15; ++i) { | |
| 243 ++packet.seqNum; | |
| 244 EXPECT_TRUE(packet_buffer_->InsertPacket(packet)); | |
| 245 } | |
| 246 for (int i = 15; i < kMaxSize; ++i) { | |
| 247 ++packet.seqNum; | |
| 248 EXPECT_FALSE(packet_buffer_->InsertPacket(packet)); | |
| 249 } | |
| 250 } | |
| 251 | |
| 252 TEST_F(TestPacketBuffer, Frames) { | |
| 253 uint16_t seq_num = Rand(); | |
| 254 | |
| 255 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); | |
| 256 InsertPacket(seq_num + 1, kDeltaFrame, kFirst, kLast); | |
| 257 InsertPacket(seq_num + 2, kDeltaFrame, kFirst, kLast); | |
| 258 InsertPacket(seq_num + 3, kDeltaFrame, kFirst, kLast); | |
| 259 | 254 |
| 260 ASSERT_EQ(4UL, frames_from_callback_.size()); | 255 ASSERT_EQ(4UL, frames_from_callback_.size()); |
| 261 CheckFrame(seq_num); | 256 CheckFrame(seq_num); |
| 262 CheckFrame(seq_num + 1); | 257 CheckFrame(seq_num + 1); |
| 263 CheckFrame(seq_num + 2); | 258 CheckFrame(seq_num + 2); |
| 264 CheckFrame(seq_num + 3); | 259 CheckFrame(seq_num + 3); |
| 265 } | 260 } |
| 266 | 261 |
| 262 TEST_F(TestPacketBuffer, ClearSinglePacket) { |
| 263 const uint16_t seq_num = Rand(); |
| 264 |
| 265 for (int i = 0; i < kMaxSize; ++i) |
| 266 EXPECT_TRUE(Insert(seq_num + i, kDeltaFrame, kFirst, kLast)); |
| 267 |
| 268 packet_buffer_->ClearTo(seq_num); |
| 269 EXPECT_TRUE(Insert(seq_num + kMaxSize, kDeltaFrame, kFirst, kLast)); |
| 270 } |
| 271 |
| 272 TEST_F(TestPacketBuffer, OneIncompleteFrame) { |
| 273 const uint16_t seq_num = Rand(); |
| 274 |
| 275 EXPECT_TRUE(Insert(seq_num, kDeltaFrame, kFirst, kNotLast)); |
| 276 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kLast)); |
| 277 EXPECT_TRUE(Insert(seq_num - 1, kDeltaFrame, kNotFirst, kLast)); |
| 278 |
| 279 ASSERT_EQ(1UL, frames_from_callback_.size()); |
| 280 CheckFrame(seq_num); |
| 281 } |
| 282 |
| 283 TEST_F(TestPacketBuffer, TwoIncompleteFramesFullBuffer) { |
| 284 const uint16_t seq_num = Rand(); |
| 285 |
| 286 for (int i = 1; i < kMaxSize - 1; ++i) |
| 287 EXPECT_TRUE(Insert(seq_num + i, kDeltaFrame, kNotFirst, kNotLast)); |
| 288 EXPECT_TRUE(Insert(seq_num, kDeltaFrame, kFirst, kNotLast)); |
| 289 EXPECT_TRUE(Insert(seq_num - 1, kDeltaFrame, kNotFirst, kLast)); |
| 290 |
| 291 ASSERT_EQ(0UL, frames_from_callback_.size()); |
| 292 } |
| 293 |
| 267 TEST_F(TestPacketBuffer, FramesReordered) { | 294 TEST_F(TestPacketBuffer, FramesReordered) { |
| 268 uint16_t seq_num = Rand(); | 295 const uint16_t seq_num = Rand(); |
| 269 | 296 |
| 270 InsertPacket(seq_num + 1, kDeltaFrame, kFirst, kLast); | 297 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kFirst, kLast)); |
| 271 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); | 298 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); |
| 272 InsertPacket(seq_num + 3, kDeltaFrame, kFirst, kLast); | 299 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kFirst, kLast)); |
| 273 InsertPacket(seq_num + 2, kDeltaFrame, kFirst, kLast); | 300 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast)); |
| 274 | 301 |
| 275 ASSERT_EQ(4UL, frames_from_callback_.size()); | 302 ASSERT_EQ(4UL, frames_from_callback_.size()); |
| 276 CheckFrame(seq_num); | 303 CheckFrame(seq_num); |
| 277 CheckFrame(seq_num + 1); | 304 CheckFrame(seq_num + 1); |
| 278 CheckFrame(seq_num + 2); | 305 CheckFrame(seq_num + 2); |
| 279 CheckFrame(seq_num + 3); | 306 CheckFrame(seq_num + 3); |
| 280 } | 307 } |
| 281 | 308 |
| 282 TEST_F(TestPacketBuffer, GetBitstreamFromFrame) { | 309 TEST_F(TestPacketBuffer, GetBitstreamFromFrame) { |
| 283 // "many bitstream, such data" with null termination. | 310 // "many bitstream, such data" with null termination. |
| 284 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20}; | 311 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20}; |
| 285 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72, | 312 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72, |
| 286 0x65, 0x61, 0x6d, 0x2c, 0x20}; | 313 0x65, 0x61, 0x6d, 0x2c, 0x20}; |
| 287 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20}; | 314 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20}; |
| 288 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0}; | 315 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0}; |
| 289 uint8_t | 316 uint8_t |
| 290 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)]; | 317 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)]; |
| 291 | 318 |
| 292 uint16_t seq_num = Rand(); | 319 const uint16_t seq_num = Rand(); |
| 293 | 320 |
| 294 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast, sizeof(many), many); | 321 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast, sizeof(many), many)); |
| 295 InsertPacket(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast, sizeof(bitstream), | 322 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast, |
| 296 bitstream); | 323 sizeof(bitstream), bitstream)); |
| 297 InsertPacket(seq_num + 2, kDeltaFrame, kNotFirst, kNotLast, sizeof(such), | 324 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kNotLast, |
| 298 such); | 325 sizeof(such), such)); |
| 299 InsertPacket(seq_num + 3, kDeltaFrame, kNotFirst, kLast, sizeof(data), data); | 326 EXPECT_TRUE( |
| 327 Insert(seq_num + 3, kDeltaFrame, kNotFirst, kLast, sizeof(data), data)); |
| 300 | 328 |
| 301 ASSERT_EQ(1UL, frames_from_callback_.size()); | 329 ASSERT_EQ(1UL, frames_from_callback_.size()); |
| 302 CheckFrame(seq_num); | 330 CheckFrame(seq_num); |
| 303 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result)); | 331 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result)); |
| 304 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0); | 332 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0); |
| 305 } | 333 } |
| 306 | 334 |
| 307 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) { | 335 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) { |
| 308 uint16_t seq_num = Rand(); | 336 const uint16_t seq_num = Rand(); |
| 309 | 337 |
| 310 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast); | 338 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast)); |
| 311 InsertPacket(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast); | 339 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast)); |
| 312 InsertPacket(seq_num + 2, kDeltaFrame, kNotFirst, kLast); | 340 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kLast)); |
| 313 EXPECT_EQ(1UL, frames_from_callback_.size()); | 341 EXPECT_EQ(1UL, frames_from_callback_.size()); |
| 314 CheckFrame(seq_num); | 342 CheckFrame(seq_num); |
| 315 | 343 |
| 316 frames_from_callback_.clear(); | 344 frames_from_callback_.clear(); |
| 317 | 345 |
| 318 // Insert frame that fills the whole buffer. | 346 // Insert frame that fills the whole buffer. |
| 319 InsertPacket(seq_num + 3, kKeyFrame, kFirst, kNotLast); | 347 EXPECT_TRUE(Insert(seq_num + 3, kKeyFrame, kFirst, kNotLast)); |
| 320 for (int i = 0; i < kMaxSize - 2; ++i) | 348 for (int i = 0; i < kMaxSize - 2; ++i) |
| 321 InsertPacket(seq_num + i + 4, kDeltaFrame, kNotFirst, kNotLast); | 349 EXPECT_TRUE(Insert(seq_num + i + 4, kDeltaFrame, kNotFirst, kNotLast)); |
| 322 InsertPacket(seq_num + kMaxSize + 2, kKeyFrame, kNotFirst, kLast); | 350 EXPECT_TRUE(Insert(seq_num + kMaxSize + 2, kKeyFrame, kNotFirst, kLast)); |
| 323 EXPECT_EQ(1UL, frames_from_callback_.size()); | 351 EXPECT_EQ(1UL, frames_from_callback_.size()); |
| 324 CheckFrame(seq_num + 3); | 352 CheckFrame(seq_num + 3); |
| 325 } | 353 } |
| 326 | 354 |
| 327 TEST_F(TestPacketBuffer, Clear) { | 355 TEST_F(TestPacketBuffer, Clear) { |
| 328 uint16_t seq_num = Rand(); | 356 const uint16_t seq_num = Rand(); |
| 329 | 357 |
| 330 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast); | 358 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast)); |
| 331 InsertPacket(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast); | 359 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast)); |
| 332 InsertPacket(seq_num + 2, kDeltaFrame, kNotFirst, kLast); | 360 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kLast)); |
| 333 EXPECT_EQ(1UL, frames_from_callback_.size()); | 361 EXPECT_EQ(1UL, frames_from_callback_.size()); |
| 334 CheckFrame(seq_num); | 362 CheckFrame(seq_num); |
| 335 | 363 |
| 336 packet_buffer_->Clear(); | 364 packet_buffer_->Clear(); |
| 337 | 365 |
| 338 InsertPacket(seq_num + kStartSize, kKeyFrame, kFirst, kNotLast); | 366 EXPECT_TRUE(Insert(seq_num + kStartSize, kKeyFrame, kFirst, kNotLast)); |
| 339 InsertPacket(seq_num + kStartSize + 1, kDeltaFrame, kNotFirst, kNotLast); | 367 EXPECT_TRUE( |
| 340 InsertPacket(seq_num + kStartSize + 2, kDeltaFrame, kNotFirst, kLast); | 368 Insert(seq_num + kStartSize + 1, kDeltaFrame, kNotFirst, kNotLast)); |
| 369 EXPECT_TRUE(Insert(seq_num + kStartSize + 2, kDeltaFrame, kNotFirst, kLast)); |
| 341 EXPECT_EQ(2UL, frames_from_callback_.size()); | 370 EXPECT_EQ(2UL, frames_from_callback_.size()); |
| 342 CheckFrame(seq_num + kStartSize); | 371 CheckFrame(seq_num + kStartSize); |
| 343 } | 372 } |
| 344 | 373 |
| 345 TEST_F(TestPacketBuffer, InvalidateFrameByClearing) { | 374 TEST_F(TestPacketBuffer, InvalidateFrameByClearing) { |
| 346 VCMPacket packet; | 375 const uint16_t seq_num = Rand(); |
| 347 packet.frameType = kVideoFrameKey; | 376 |
| 348 packet.isFirstPacket = true; | 377 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); |
| 349 packet.markerBit = true; | |
| 350 packet.seqNum = Rand(); | |
| 351 EXPECT_TRUE(packet_buffer_->InsertPacket(packet)); | |
| 352 ASSERT_EQ(1UL, frames_from_callback_.size()); | 378 ASSERT_EQ(1UL, frames_from_callback_.size()); |
| 353 | 379 |
| 354 packet_buffer_->Clear(); | 380 packet_buffer_->Clear(); |
| 355 EXPECT_FALSE(frames_from_callback_.begin()->second->GetBitstream(nullptr)); | 381 EXPECT_FALSE(frames_from_callback_.begin()->second->GetBitstream(nullptr)); |
| 356 } | 382 } |
| 357 | 383 |
| 358 } // namespace video_coding | 384 } // namespace video_coding |
| 359 } // namespace webrtc | 385 } // namespace webrtc |
| OLD | NEW |