Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Side by Side Diff: webrtc/test/fuzzers/transport_feedback_packet_loss_tracker_fuzzer.cc

Issue 2579613003: Add TransportFeedbackPacketLossTracker. (Closed)
Patch Set: on comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <algorithm>
12
13 #include "webrtc/base/array_view.h"
14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
15 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
16 #include "webrtc/voice_engine/transport_feedback_packet_loss_tracker.h"
17
18 namespace webrtc {
19
20 namespace {
21
22 using TransportFeedback = rtcp::TransportFeedback;
23
24 class FuzzTransportFeedback final : public rtcp::TransportFeedbackInterface {
25 public:
26 explicit FuzzTransportFeedback(rtc::ArrayView<const uint8_t> data)
27 : data_(data), ended_(false), data_idx_(0) {
28 ParseNextTransportFeedback();
29 }
30
31 uint16_t GetBaseSequence() const override { return base_seq_num_; }
32
33 std::vector<StatusSymbol> GetStatusVector() const override {
34 return statuses_;
35 }
36
37 void ParseNextTransportFeedback() {
38 statuses_.clear();
39
40 if (!ReadData<uint16_t>(&base_seq_num_)) {
41 return;
42 }
43
44 uint16_t num_statuses = 0;
45 if (!ReadData<uint16_t>(&num_statuses))
46 return;
47 num_statuses = std::max<uint16_t>(num_statuses, 1);
48
49 while (true) {
50 uint8_t status_byte = 0;
51 if (!ReadData<uint8_t>(&status_byte))
52 return;
53 // Each status byte contains 8 statuses.
54 for (size_t j = 0; j < 8; ++j) {
55 if (status_byte & 0x01) {
56 // |kReceivedSmallDelta| and |kReceivedLargeDelta| make no difference
57 // to TransportFeedbackPacketLossTracker. So we test only one case.
58 statuses_.push_back(
59 TransportFeedback::StatusSymbol::kReceivedSmallDelta);
60 } else {
61 statuses_.push_back(TransportFeedback::StatusSymbol::kNotReceived);
62 }
63 if (statuses_.size() >= num_statuses)
64 return;
65 status_byte >>= 1;
66 }
67 }
68 }
69
70 bool ended() const { return ended_; }
71
72 void SetBase(uint16_t base_sequence, int64_t ref_timestamp_us) override {
73 RTC_NOTREACHED();
74 }
75 void SetFeedbackSequenceNumber(uint8_t feedback_sequence) override {
76 RTC_NOTREACHED();
77 }
78 bool AddReceivedPacket(uint16_t sequence_number,
79 int64_t timestamp_us) override {
80 RTC_NOTREACHED();
81 return false;
82 }
83 std::vector<int16_t> GetReceiveDeltas() const override {
84 RTC_NOTREACHED();
85 return std::vector<int16_t>();
86 }
87 int64_t GetBaseTimeUs() const override {
88 RTC_NOTREACHED();
89 return 0;
90 }
91 std::vector<int64_t> GetReceiveDeltasUs() const override {
92 RTC_NOTREACHED();
93 return std::vector<int64_t>();
94 }
95
96 private:
97 template <typename T>
98 bool ReadData(T* value) {
99 RTC_DCHECK(!ended_);
100 if (data_idx_ + sizeof(T) > data_.size()) {
101 ended_ = true;
102 return false;
103 }
104 *value = ByteReader<T>::ReadBigEndian(&data_[data_idx_]);
105 data_idx_ += sizeof(T);
106 return true;
107 }
108
109 const rtc::ArrayView<const uint8_t> data_;
110 bool ended_;
111 size_t data_idx_;
112 uint16_t base_seq_num_;
113 std::vector<TransportFeedback::StatusSymbol> statuses_;
114 };
115
116 } // namespace
117
118 void FuzzOneInput(const uint8_t* data, size_t size) {
119 if (size < sizeof(uint32_t)) {
120 return;
121 }
122 constexpr size_t kSeqNumHalf = 0x8000u;
123 const size_t window_size_1 = std::min<size_t>(
124 kSeqNumHalf,
125 std::max<uint16_t>(1, ByteReader<uint16_t>::ReadBigEndian(data)));
126 data += sizeof(uint16_t);
127 const size_t window_size_2 = std::min<size_t>(
128 kSeqNumHalf,
129 std::max<uint16_t>(1, ByteReader<uint16_t>::ReadBigEndian(data)));
130 data += sizeof(uint16_t);
131 size -= 2 * sizeof(uint16_t);
132
133 TransportFeedbackPacketLossTracker tracker(
134 std::min(window_size_1, window_size_2),
135 std::max(window_size_1, window_size_2));
136 FuzzTransportFeedback feedback(rtc::ArrayView<const uint8_t>(data, size));
137 while (!feedback.ended()) {
138 tracker.OnReceivedTransportFeedback(feedback);
139 tracker.Validate();
140 feedback.ParseNextTransportFeedback();
141 }
142 }
143
144 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698