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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 bool Insert(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 = |
| 62 keyframe == kKeyFrame ? kVideoFrameKey : kVideoFrameDelta; |
62 packet.is_first_packet_in_frame = first == kFirst; | 63 packet.is_first_packet_in_frame = first == kFirst; |
63 packet.markerBit = last == kLast; | 64 packet.markerBit = last == kLast; |
64 packet.sizeBytes = data_size; | 65 packet.sizeBytes = data_size; |
65 packet.dataPtr = data; | 66 packet.dataPtr = data; |
66 | 67 |
67 return packet_buffer_->InsertPacket(&packet); | 68 return packet_buffer_->InsertPacket(&packet); |
68 } | 69 } |
69 | 70 |
70 void CheckFrame(uint16_t first_seq_num) { | 71 void CheckFrame(uint16_t first_seq_num) { |
71 auto frame_it = frames_from_callback_.find(first_seq_num); | 72 auto frame_it = frames_from_callback_.find(first_seq_num); |
72 ASSERT_FALSE(frame_it == frames_from_callback_.end()) | 73 ASSERT_FALSE(frame_it == frames_from_callback_.end()) |
73 << "Could not find frame with first sequence number " << first_seq_num | 74 << "Could not find frame with first sequence number " << first_seq_num |
74 << "."; | 75 << "."; |
75 } | 76 } |
76 | 77 |
77 const int kStartSize = 16; | 78 const int kStartSize = 16; |
78 const int kMaxSize = 64; | 79 const int kMaxSize = 64; |
79 | 80 |
80 Random rand_; | 81 Random rand_; |
81 std::unique_ptr<Clock> clock_; | 82 std::unique_ptr<SimulatedClock> clock_; |
82 rtc::scoped_refptr<PacketBuffer> packet_buffer_; | 83 rtc::scoped_refptr<PacketBuffer> packet_buffer_; |
83 std::map<uint16_t, std::unique_ptr<RtpFrameObject>> frames_from_callback_; | 84 std::map<uint16_t, std::unique_ptr<RtpFrameObject>> frames_from_callback_; |
84 }; | 85 }; |
85 | 86 |
86 TEST_F(TestPacketBuffer, InsertOnePacket) { | 87 TEST_F(TestPacketBuffer, InsertOnePacket) { |
87 const uint16_t seq_num = Rand(); | 88 const uint16_t seq_num = Rand(); |
88 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); | 89 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); |
89 } | 90 } |
90 | 91 |
91 TEST_F(TestPacketBuffer, InsertMultiplePackets) { | 92 TEST_F(TestPacketBuffer, InsertMultiplePackets) { |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 | 471 |
471 TEST_F(TestPacketBuffer, ContinuousSeqNumDoubleMarkerBit) { | 472 TEST_F(TestPacketBuffer, ContinuousSeqNumDoubleMarkerBit) { |
472 Insert(2, kKeyFrame, kNotFirst, kNotLast); | 473 Insert(2, kKeyFrame, kNotFirst, kNotLast); |
473 Insert(1, kKeyFrame, kFirst, kLast); | 474 Insert(1, kKeyFrame, kFirst, kLast); |
474 frames_from_callback_.clear(); | 475 frames_from_callback_.clear(); |
475 Insert(3, kKeyFrame, kNotFirst, kLast); | 476 Insert(3, kKeyFrame, kNotFirst, kLast); |
476 | 477 |
477 EXPECT_EQ(0UL, frames_from_callback_.size()); | 478 EXPECT_EQ(0UL, frames_from_callback_.size()); |
478 } | 479 } |
479 | 480 |
| 481 TEST_F(TestPacketBuffer, PacketTimestamps) { |
| 482 rtc::Optional<int64_t> packet_ms; |
| 483 rtc::Optional<int64_t> packet_keyframe_ms; |
| 484 |
| 485 packet_ms = packet_buffer_->LastReceivedPacketMs(); |
| 486 packet_keyframe_ms = packet_buffer_->LastReceivedKeyframePacketMs(); |
| 487 EXPECT_FALSE(packet_ms); |
| 488 EXPECT_FALSE(packet_keyframe_ms); |
| 489 |
| 490 int64_t keyframe_ms = clock_->TimeInMilliseconds(); |
| 491 EXPECT_TRUE(Insert(100, kKeyFrame, kFirst, kLast)); |
| 492 packet_ms = packet_buffer_->LastReceivedPacketMs(); |
| 493 packet_keyframe_ms = packet_buffer_->LastReceivedKeyframePacketMs(); |
| 494 EXPECT_TRUE(packet_ms); |
| 495 EXPECT_TRUE(packet_keyframe_ms); |
| 496 EXPECT_EQ(keyframe_ms, *packet_ms); |
| 497 EXPECT_EQ(keyframe_ms, *packet_keyframe_ms); |
| 498 |
| 499 clock_->AdvanceTimeMilliseconds(100); |
| 500 int64_t delta_ms = clock_->TimeInMilliseconds(); |
| 501 EXPECT_TRUE(Insert(101, kDeltaFrame, kFirst, kLast)); |
| 502 packet_ms = packet_buffer_->LastReceivedPacketMs(); |
| 503 packet_keyframe_ms = packet_buffer_->LastReceivedKeyframePacketMs(); |
| 504 EXPECT_TRUE(packet_ms); |
| 505 EXPECT_TRUE(packet_keyframe_ms); |
| 506 EXPECT_EQ(delta_ms, *packet_ms); |
| 507 EXPECT_EQ(keyframe_ms, *packet_keyframe_ms); |
| 508 |
| 509 packet_buffer_->Clear(); |
| 510 packet_ms = packet_buffer_->LastReceivedPacketMs(); |
| 511 packet_keyframe_ms = packet_buffer_->LastReceivedKeyframePacketMs(); |
| 512 EXPECT_FALSE(packet_ms); |
| 513 EXPECT_FALSE(packet_keyframe_ms); |
| 514 } |
| 515 |
480 } // namespace video_coding | 516 } // namespace video_coding |
481 } // namespace webrtc | 517 } // namespace webrtc |
OLD | NEW |