OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
11 #include <list> | 11 #include <list> |
12 | 12 |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "webrtc/base/random.h" |
14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
15 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" | 16 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |
16 | 17 |
17 using webrtc::ForwardErrorCorrection; | 18 using webrtc::ForwardErrorCorrection; |
18 | 19 |
19 // Minimum RTP header size in bytes. | 20 // Minimum RTP header size in bytes. |
20 const uint8_t kRtpHeaderSize = 12; | 21 const uint8_t kRtpHeaderSize = 12; |
21 | 22 |
22 // Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum. | 23 // Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum. |
23 const uint8_t kTransportOverhead = 28; | 24 const uint8_t kTransportOverhead = 28; |
(...skipping 10 matching lines...) Expand all Loading... |
34 while (!my_list->empty()) { | 35 while (!my_list->empty()) { |
35 packet = my_list->front(); | 36 packet = my_list->front(); |
36 delete packet; | 37 delete packet; |
37 my_list->pop_front(); | 38 my_list->pop_front(); |
38 } | 39 } |
39 } | 40 } |
40 | 41 |
41 class RtpFecTest : public ::testing::Test { | 42 class RtpFecTest : public ::testing::Test { |
42 protected: | 43 protected: |
43 RtpFecTest() | 44 RtpFecTest() |
44 : fec_(new ForwardErrorCorrection()), ssrc_(rand()), fec_seq_num_(0) {} | 45 : random_(0xfec133700742), |
| 46 fec_(new ForwardErrorCorrection()), |
| 47 ssrc_(random_.Rand<uint32_t>()), |
| 48 fec_seq_num_(0) {} |
45 | 49 |
| 50 webrtc::Random random_; |
46 ForwardErrorCorrection* fec_; | 51 ForwardErrorCorrection* fec_; |
47 int ssrc_; | 52 int ssrc_; |
48 uint16_t fec_seq_num_; | 53 uint16_t fec_seq_num_; |
49 | 54 |
50 PacketList media_packet_list_; | 55 PacketList media_packet_list_; |
51 PacketList fec_packet_list_; | 56 PacketList fec_packet_list_; |
52 ReceivedPacketList received_packet_list_; | 57 ReceivedPacketList received_packet_list_; |
53 RecoveredPacketList recovered_packet_list_; | 58 RecoveredPacketList recovered_packet_list_; |
54 | 59 |
55 // Media packet "i" is lost if media_loss_mask_[i] = 1, | 60 // Media packet "i" is lost if media_loss_mask_[i] = 1, |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 // last media packet in frame. | 889 // last media packet in frame. |
885 if (is_fec) seq_num++; | 890 if (is_fec) seq_num++; |
886 } | 891 } |
887 } | 892 } |
888 | 893 |
889 int RtpFecTest::ConstructMediaPacketsSeqNum(int num_media_packets, | 894 int RtpFecTest::ConstructMediaPacketsSeqNum(int num_media_packets, |
890 int start_seq_num) { | 895 int start_seq_num) { |
891 assert(num_media_packets > 0); | 896 assert(num_media_packets > 0); |
892 ForwardErrorCorrection::Packet* media_packet = NULL; | 897 ForwardErrorCorrection::Packet* media_packet = NULL; |
893 int sequence_number = start_seq_num; | 898 int sequence_number = start_seq_num; |
894 int time_stamp = rand(); | 899 int time_stamp = random_.Rand<int>(); |
895 | 900 |
896 for (int i = 0; i < num_media_packets; ++i) { | 901 for (int i = 0; i < num_media_packets; ++i) { |
897 media_packet = new ForwardErrorCorrection::Packet; | 902 media_packet = new ForwardErrorCorrection::Packet; |
898 media_packet_list_.push_back(media_packet); | 903 media_packet_list_.push_back(media_packet); |
899 media_packet->length = static_cast<size_t>( | 904 const uint32_t kMinPacketSize = kRtpHeaderSize; |
900 (static_cast<float>(rand()) / RAND_MAX) * | 905 const uint32_t kMaxPacketSize = IP_PACKET_SIZE - kRtpHeaderSize - |
901 (IP_PACKET_SIZE - kRtpHeaderSize - kTransportOverhead - | 906 kTransportOverhead - |
902 ForwardErrorCorrection::PacketOverhead())); | 907 ForwardErrorCorrection::PacketOverhead(); |
| 908 media_packet->length = random_.Rand(kMinPacketSize, kMaxPacketSize); |
903 | 909 |
904 if (media_packet->length < kRtpHeaderSize) { | |
905 media_packet->length = kRtpHeaderSize; | |
906 } | |
907 // Generate random values for the first 2 bytes | 910 // Generate random values for the first 2 bytes |
908 media_packet->data[0] = static_cast<uint8_t>(rand() % 256); | 911 media_packet->data[0] = random_.Rand<uint8_t>(); |
909 media_packet->data[1] = static_cast<uint8_t>(rand() % 256); | 912 media_packet->data[1] = random_.Rand<uint8_t>(); |
910 | 913 |
911 // The first two bits are assumed to be 10 by the FEC encoder. | 914 // The first two bits are assumed to be 10 by the FEC encoder. |
912 // In fact the FEC decoder will set the two first bits to 10 regardless of | 915 // In fact the FEC decoder will set the two first bits to 10 regardless of |
913 // what they actually were. Set the first two bits to 10 so that a memcmp | 916 // what they actually were. Set the first two bits to 10 so that a memcmp |
914 // can be performed for the whole restored packet. | 917 // can be performed for the whole restored packet. |
915 media_packet->data[0] |= 0x80; | 918 media_packet->data[0] |= 0x80; |
916 media_packet->data[0] &= 0xbf; | 919 media_packet->data[0] &= 0xbf; |
917 | 920 |
918 // FEC is applied to a whole frame. | 921 // FEC is applied to a whole frame. |
919 // A frame is signaled by multiple packets without the marker bit set | 922 // A frame is signaled by multiple packets without the marker bit set |
920 // followed by the last packet of the frame for which the marker bit is set. | 923 // followed by the last packet of the frame for which the marker bit is set. |
921 // Only push one (fake) frame to the FEC. | 924 // Only push one (fake) frame to the FEC. |
922 media_packet->data[1] &= 0x7f; | 925 media_packet->data[1] &= 0x7f; |
923 | 926 |
924 webrtc::ByteWriter<uint16_t>::WriteBigEndian(&media_packet->data[2], | 927 webrtc::ByteWriter<uint16_t>::WriteBigEndian(&media_packet->data[2], |
925 sequence_number); | 928 sequence_number); |
926 webrtc::ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[4], | 929 webrtc::ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[4], |
927 time_stamp); | 930 time_stamp); |
928 webrtc::ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[8], ssrc_); | 931 webrtc::ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[8], ssrc_); |
929 | 932 |
930 // Generate random values for payload. | 933 // Generate random values for payload. |
931 for (size_t j = 12; j < media_packet->length; ++j) { | 934 for (size_t j = 12; j < media_packet->length; ++j) { |
932 media_packet->data[j] = static_cast<uint8_t>(rand() % 256); | 935 media_packet->data[j] = random_.Rand<uint8_t>(); |
933 } | 936 } |
934 sequence_number++; | 937 sequence_number++; |
935 } | 938 } |
936 // Last packet, set marker bit. | 939 // Last packet, set marker bit. |
937 assert(media_packet != NULL); | 940 assert(media_packet != NULL); |
938 media_packet->data[1] |= 0x80; | 941 media_packet->data[1] |= 0x80; |
939 return sequence_number; | 942 return sequence_number; |
940 } | 943 } |
941 | 944 |
942 int RtpFecTest::ConstructMediaPackets(int num_media_packets) { | 945 int RtpFecTest::ConstructMediaPackets(int num_media_packets) { |
943 return ConstructMediaPacketsSeqNum(num_media_packets, rand()); | 946 return ConstructMediaPacketsSeqNum(num_media_packets, random_.Rand<int>()); |
944 } | 947 } |
OLD | NEW |