OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 <algorithm> | 11 #include <algorithm> |
12 | 12 |
13 #include "webrtc/base/array_view.h" | 13 #include "webrtc/base/array_view.h" |
14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
15 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 15 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
16 #include "webrtc/voice_engine/transport_feedback_packet_loss_tracker.h" | 16 #include "webrtc/voice_engine/transport_feedback_packet_loss_tracker.h" |
17 | 17 |
18 namespace webrtc { | 18 namespace webrtc { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 template <typename T> | |
23 T FuzzInput(const uint8_t** data, size_t* size) { | |
24 RTC_CHECK(*size >= sizeof(T)); | |
25 T rc = ByteReader<T>::ReadBigEndian(*data); | |
26 *data += sizeof(T); | |
27 *size -= sizeof(T); | |
28 return rc; | |
29 } | |
30 | |
31 size_t FuzzInRange(const uint8_t** data, | |
minyue-webrtc
2017/01/31 08:28:11
I see that you want a uniformly distributed value
elad.alon_webrtc.org
2017/01/31 12:42:23
Good suggestion, thanks. I'll just modify to 0x100
| |
32 size_t* size, | |
33 size_t lower, | |
34 size_t upper) { | |
35 RTC_CHECK_LE(lower, upper); | |
36 RTC_CHECK_LT(upper - lower, 1 << (8 * sizeof(uint16_t))); | |
37 // Decrease the bias created by min-max by making sure we only use the | |
38 // minimum number of randomized bits necessary. | |
39 const size_t range = upper - lower; | |
40 size_t mask = 1; | |
41 while (mask < range) | |
42 mask = (mask << 1) | 1; | |
43 return lower + std::min(FuzzInput<uint16_t>(data, size) & mask, range); | |
44 } | |
45 | |
22 class TransportFeedbackGenerator { | 46 class TransportFeedbackGenerator { |
23 public: | 47 public: |
24 explicit TransportFeedbackGenerator(rtc::ArrayView<const uint8_t> data) | 48 explicit TransportFeedbackGenerator(rtc::ArrayView<const uint8_t> data) |
25 : data_(data), ended_(false), data_idx_(0) {} | 49 : data_(data), ended_(false), data_idx_(0) {} |
26 | 50 |
27 void GetNextTransportFeedback(rtcp::TransportFeedback* feedback) { | 51 void GetNextTransportFeedback(rtcp::TransportFeedback* feedback) { |
28 uint16_t base_seq_num = 0; | 52 uint16_t base_seq_num = 0; |
29 if (!ReadData<uint16_t>(&base_seq_num)) { | 53 if (!ReadData<uint16_t>(&base_seq_num)) { |
30 return; | 54 return; |
31 } | 55 } |
(...skipping 24 matching lines...) Expand all Loading... | |
56 status_byte >>= 1; | 80 status_byte >>= 1; |
57 } | 81 } |
58 } | 82 } |
59 } | 83 } |
60 | 84 |
61 bool ended() const { return ended_; } | 85 bool ended() const { return ended_; } |
62 | 86 |
63 private: | 87 private: |
64 template <typename T> | 88 template <typename T> |
65 bool ReadData(T* value) { | 89 bool ReadData(T* value) { |
66 RTC_DCHECK(!ended_); | 90 RTC_CHECK(!ended_); |
67 if (data_idx_ + sizeof(T) > data_.size()) { | 91 if (data_idx_ + sizeof(T) > data_.size()) { |
68 ended_ = true; | 92 ended_ = true; |
69 return false; | 93 return false; |
70 } | 94 } |
71 *value = ByteReader<T>::ReadBigEndian(&data_[data_idx_]); | 95 *value = ByteReader<T>::ReadBigEndian(&data_[data_idx_]); |
72 data_idx_ += sizeof(T); | 96 data_idx_ += sizeof(T); |
73 return true; | 97 return true; |
74 } | 98 } |
75 | 99 |
76 const rtc::ArrayView<const uint8_t> data_; | 100 const rtc::ArrayView<const uint8_t> data_; |
77 bool ended_; | 101 bool ended_; |
78 size_t data_idx_; | 102 size_t data_idx_; |
79 }; | 103 }; |
80 | 104 |
81 } // namespace | 105 } // namespace |
82 | 106 |
83 void FuzzOneInput(const uint8_t* data, size_t size) { | 107 void FuzzOneInput(const uint8_t* data, size_t size) { |
84 if (size < sizeof(uint32_t)) { | 108 if (size < 3 * sizeof(uint16_t)) { |
85 return; | 109 return; |
86 } | 110 } |
87 constexpr size_t kSeqNumHalf = 0x8000u; | 111 constexpr size_t kSeqNumHalf = 0x8000u; |
88 const size_t window_size_1 = std::min<size_t>( | 112 |
89 kSeqNumHalf, | 113 // 0x8000 >= max_window_size >= plr_min_num_packets > rplr_min_num_pairs >= 1 |
90 std::max<uint16_t>(1, ByteReader<uint16_t>::ReadBigEndian(data))); | 114 // (The distribution isn't uniform, but it's enough; more would be overkill.) |
91 data += sizeof(uint16_t); | 115 const size_t max_window_size = FuzzInRange(&data, &size, 2, kSeqNumHalf); |
92 const size_t window_size_2 = std::min<size_t>( | 116 const size_t plr_min_num_packets = |
93 kSeqNumHalf, | 117 FuzzInRange(&data, &size, 2, max_window_size); |
94 std::max<uint16_t>(1, ByteReader<uint16_t>::ReadBigEndian(data))); | 118 const size_t rplr_min_num_pairs = |
95 data += sizeof(uint16_t); | 119 FuzzInRange(&data, &size, 1, plr_min_num_packets - 1); |
96 size -= 2 * sizeof(uint16_t); | |
97 | 120 |
98 TransportFeedbackPacketLossTracker tracker( | 121 TransportFeedbackPacketLossTracker tracker( |
99 std::min(window_size_1, window_size_2), | 122 max_window_size, plr_min_num_packets, rplr_min_num_pairs); |
100 std::max(window_size_1, window_size_2)); | 123 |
101 TransportFeedbackGenerator feedback_generator( | 124 TransportFeedbackGenerator feedback_generator( |
102 rtc::ArrayView<const uint8_t>(data, size)); | 125 rtc::ArrayView<const uint8_t>(data, size)); |
126 | |
103 while (!feedback_generator.ended()) { | 127 while (!feedback_generator.ended()) { |
104 rtcp::TransportFeedback feedback; | 128 rtcp::TransportFeedback feedback; |
105 feedback_generator.GetNextTransportFeedback(&feedback); | 129 feedback_generator.GetNextTransportFeedback(&feedback); |
106 tracker.OnReceivedTransportFeedback(feedback); | 130 tracker.OnReceivedTransportFeedback(feedback); |
107 tracker.Validate(); | 131 tracker.Validate(); |
108 } | 132 } |
109 } | 133 } |
110 | 134 |
111 } // namespace webrtc | 135 } // namespace webrtc |
OLD | NEW |