| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 packet.dataPtr = data_buffer_; | 161 packet.dataPtr = data_buffer_; |
| 162 bool packet_available = stream_generator_->GetPacket(&packet, index); | 162 bool packet_available = stream_generator_->GetPacket(&packet, index); |
| 163 EXPECT_TRUE(packet_available); | 163 EXPECT_TRUE(packet_available); |
| 164 if (!packet_available) | 164 if (!packet_available) |
| 165 return kGeneralError; // Return here to avoid crashes below. | 165 return kGeneralError; // Return here to avoid crashes below. |
| 166 bool retransmitted = false; | 166 bool retransmitted = false; |
| 167 return jitter_buffer_->InsertPacket(packet, &retransmitted); | 167 return jitter_buffer_->InsertPacket(packet, &retransmitted); |
| 168 } | 168 } |
| 169 | 169 |
| 170 VCMFrameBufferEnum InsertFrame(FrameType frame_type) { | 170 VCMFrameBufferEnum InsertFrame(FrameType frame_type) { |
| 171 stream_generator_->GenerateFrame(frame_type, | 171 stream_generator_->GenerateFrame( |
| 172 (frame_type != kFrameEmpty) ? 1 : 0, | 172 frame_type, (frame_type != kEmptyFrame) ? 1 : 0, |
| 173 (frame_type == kFrameEmpty) ? 1 : 0, | 173 (frame_type == kEmptyFrame) ? 1 : 0, clock_->TimeInMilliseconds()); |
| 174 clock_->TimeInMilliseconds()); | |
| 175 VCMFrameBufferEnum ret = InsertPacketAndPop(0); | 174 VCMFrameBufferEnum ret = InsertPacketAndPop(0); |
| 176 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); | 175 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); |
| 177 return ret; | 176 return ret; |
| 178 } | 177 } |
| 179 | 178 |
| 180 VCMFrameBufferEnum InsertFrames(int num_frames, FrameType frame_type) { | 179 VCMFrameBufferEnum InsertFrames(int num_frames, FrameType frame_type) { |
| 181 VCMFrameBufferEnum ret_for_all = kNoError; | 180 VCMFrameBufferEnum ret_for_all = kNoError; |
| 182 for (int i = 0; i < num_frames; ++i) { | 181 for (int i = 0; i < num_frames; ++i) { |
| 183 VCMFrameBufferEnum ret = InsertFrame(frame_type); | 182 VCMFrameBufferEnum ret = InsertFrame(frame_type); |
| 184 if (ret < kNoError) { | 183 if (ret < kNoError) { |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 | 1042 |
| 1044 EXPECT_EQ(jitter_buffer_->InsertPacket(*packet_, &retransmitted), | 1043 EXPECT_EQ(jitter_buffer_->InsertPacket(*packet_, &retransmitted), |
| 1045 kDecodableSession); | 1044 kDecodableSession); |
| 1046 | 1045 |
| 1047 // Insert an empty (non-media) packet. | 1046 // Insert an empty (non-media) packet. |
| 1048 seq_num_++; | 1047 seq_num_++; |
| 1049 packet_->isFirstPacket = false; | 1048 packet_->isFirstPacket = false; |
| 1050 packet_->markerBit = false; | 1049 packet_->markerBit = false; |
| 1051 packet_->seqNum = seq_num_; | 1050 packet_->seqNum = seq_num_; |
| 1052 packet_->completeNALU = kNaluEnd; | 1051 packet_->completeNALU = kNaluEnd; |
| 1053 packet_->frameType = kFrameEmpty; | 1052 packet_->frameType = kEmptyFrame; |
| 1054 | 1053 |
| 1055 EXPECT_EQ(jitter_buffer_->InsertPacket(*packet_, &retransmitted), | 1054 EXPECT_EQ(jitter_buffer_->InsertPacket(*packet_, &retransmitted), |
| 1056 kDecodableSession); | 1055 kDecodableSession); |
| 1057 frame_out = DecodeIncompleteFrame(); | 1056 frame_out = DecodeIncompleteFrame(); |
| 1058 | 1057 |
| 1059 // One of the packets has been discarded by the jitter buffer. | 1058 // One of the packets has been discarded by the jitter buffer. |
| 1060 // Last frame can't be extracted yet. | 1059 // Last frame can't be extracted yet. |
| 1061 if (i < 10) { | 1060 if (i < 10) { |
| 1062 CheckOutFrame(frame_out, size_, false); | 1061 CheckOutFrame(frame_out, size_, false); |
| 1063 | 1062 |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1517 // inserted. Only return empty frames in the presence of subsequent frames. | 1516 // inserted. Only return empty frames in the presence of subsequent frames. |
| 1518 int maxSize = 1000; | 1517 int maxSize = 1000; |
| 1519 bool retransmitted = false; | 1518 bool retransmitted = false; |
| 1520 for (int i = 0; i < maxSize + 10; i++) { | 1519 for (int i = 0; i < maxSize + 10; i++) { |
| 1521 timestamp_ += 33 * 90; | 1520 timestamp_ += 33 * 90; |
| 1522 seq_num_++; | 1521 seq_num_++; |
| 1523 packet_->isFirstPacket = false; | 1522 packet_->isFirstPacket = false; |
| 1524 packet_->markerBit = false; | 1523 packet_->markerBit = false; |
| 1525 packet_->seqNum = seq_num_; | 1524 packet_->seqNum = seq_num_; |
| 1526 packet_->timestamp = timestamp_; | 1525 packet_->timestamp = timestamp_; |
| 1527 packet_->frameType = kFrameEmpty; | 1526 packet_->frameType = kEmptyFrame; |
| 1528 | 1527 |
| 1529 EXPECT_EQ(kNoError, jitter_buffer_->InsertPacket(*packet_, | 1528 EXPECT_EQ(kNoError, jitter_buffer_->InsertPacket(*packet_, |
| 1530 &retransmitted)); | 1529 &retransmitted)); |
| 1531 VCMEncodedFrame* testFrame = DecodeIncompleteFrame(); | 1530 VCMEncodedFrame* testFrame = DecodeIncompleteFrame(); |
| 1532 // Timestamp should never be the last TS inserted. | 1531 // Timestamp should never be the last TS inserted. |
| 1533 if (testFrame != NULL) { | 1532 if (testFrame != NULL) { |
| 1534 EXPECT_TRUE(testFrame->TimeStamp() < timestamp_); | 1533 EXPECT_TRUE(testFrame->TimeStamp() < timestamp_); |
| 1535 jitter_buffer_->ReleaseFrame(testFrame); | 1534 jitter_buffer_->ReleaseFrame(testFrame); |
| 1536 } | 1535 } |
| 1537 } | 1536 } |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1888 EXPECT_EQ(kCompleteSession, InsertPacketAndPop(1)); | 1887 EXPECT_EQ(kCompleteSession, InsertPacketAndPop(1)); |
| 1889 EXPECT_FALSE(DecodeCompleteFrame()); | 1888 EXPECT_FALSE(DecodeCompleteFrame()); |
| 1890 EXPECT_EQ(kCompleteSession, InsertPacketAndPop(0)); | 1889 EXPECT_EQ(kCompleteSession, InsertPacketAndPop(0)); |
| 1891 EXPECT_TRUE(DecodeCompleteFrame()); | 1890 EXPECT_TRUE(DecodeCompleteFrame()); |
| 1892 EXPECT_TRUE(DecodeCompleteFrame()); | 1891 EXPECT_TRUE(DecodeCompleteFrame()); |
| 1893 } | 1892 } |
| 1894 | 1893 |
| 1895 TEST_F(TestJitterBufferNack, EmptyPackets) { | 1894 TEST_F(TestJitterBufferNack, EmptyPackets) { |
| 1896 // Make sure empty packets doesn't clog the jitter buffer. | 1895 // Make sure empty packets doesn't clog the jitter buffer. |
| 1897 jitter_buffer_->SetNackMode(kNack, media_optimization::kLowRttNackMs, -1); | 1896 jitter_buffer_->SetNackMode(kNack, media_optimization::kLowRttNackMs, -1); |
| 1898 EXPECT_GE(InsertFrames(kMaxNumberOfFrames, kFrameEmpty), kNoError); | 1897 EXPECT_GE(InsertFrames(kMaxNumberOfFrames, kEmptyFrame), kNoError); |
| 1899 InsertFrame(kVideoFrameKey); | 1898 InsertFrame(kVideoFrameKey); |
| 1900 EXPECT_TRUE(DecodeCompleteFrame()); | 1899 EXPECT_TRUE(DecodeCompleteFrame()); |
| 1901 } | 1900 } |
| 1902 | 1901 |
| 1903 TEST_F(TestJitterBufferNack, NackTooOldPackets) { | 1902 TEST_F(TestJitterBufferNack, NackTooOldPackets) { |
| 1904 // Insert a key frame and decode it. | 1903 // Insert a key frame and decode it. |
| 1905 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError); | 1904 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError); |
| 1906 EXPECT_TRUE(DecodeCompleteFrame()); | 1905 EXPECT_TRUE(DecodeCompleteFrame()); |
| 1907 | 1906 |
| 1908 // Drop one frame and insert |kNackHistoryLength| to trigger NACKing a too | 1907 // Drop one frame and insert |kNackHistoryLength| to trigger NACKing a too |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2198 | 2197 |
| 2199 // Stream should be decodable from this point. | 2198 // Stream should be decodable from this point. |
| 2200 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); | 2199 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); |
| 2201 InsertFrame(kVideoFrameDelta); | 2200 InsertFrame(kVideoFrameDelta); |
| 2202 EXPECT_TRUE(DecodeCompleteFrame()); | 2201 EXPECT_TRUE(DecodeCompleteFrame()); |
| 2203 nack_list = jitter_buffer_->GetNackList(&extended); | 2202 nack_list = jitter_buffer_->GetNackList(&extended); |
| 2204 EXPECT_EQ(0u, nack_list.size()); | 2203 EXPECT_EQ(0u, nack_list.size()); |
| 2205 } | 2204 } |
| 2206 | 2205 |
| 2207 } // namespace webrtc | 2206 } // namespace webrtc |
| OLD | NEW |