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

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

Issue 2579613003: Add TransportFeedbackPacketLossTracker. (Closed)
Patch Set: episode duration -> consecutive packet loss Created 4 years 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/remote_bitrate_estimator/transport_feedback_packet_loss _tracker.h"
15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
16 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
17
18 namespace webrtc {
19
20 namespace {
21
22 using TransportFeedback = rtcp::TransportFeedback;
23
24 class FuzzTransportFeedback : public TransportFeedback {
stefan-webrtc 2016/12/19 09:17:00 Shouldn't it be possible to write this without inh
minyue-webrtc 2016/12/19 10:21:55 It will somewhat complicated. TransportFeedback ha
stefan-webrtc 2016/12/20 12:13:41 I see. So basically what you want is a mock/fake v
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<TransportFeedback::StatusSymbol> GetStatusVector()
34 const override {
35 return statuses_;
36 }
37
38 void ParseNextTransportFeedback() {
39 statuses_.clear();
40
41 if (!ReadData<uint16_t>(&base_seq_num_)) {
42 return;
43 }
44
45 uint16_t num_statuses = 0;
46 if (!ReadData<uint16_t>(&num_statuses))
47 return;
48
49 while (statuses_.size() < num_statuses) {
50 uint8_t status_byte = 0;
51 if (!ReadData<uint8_t>(&status_byte))
52 break;
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 break;
65 status_byte >>= 1;
66 }
67 }
68 }
69
70 bool ended() const { return ended_; }
71
72 private:
73 template <typename T>
74 bool ReadData(T* value) {
75 RTC_DCHECK(!ended_);
76 if (data_idx_ + sizeof(T) > data_.size()) {
77 ended_ = true;
78 return false;
79 }
80 *value = ByteReader<T>::ReadBigEndian(&data_[data_idx_]);
81 data_idx_ += sizeof(T);
82 return true;
83 }
84
85 rtc::ArrayView<const uint8_t> data_;
86 bool ended_;
87 size_t data_idx_;
88 uint16_t base_seq_num_;
89 std::vector<TransportFeedback::StatusSymbol> statuses_;
90 };
91
92 } // namespace
93
94 void FuzzOneInput(const uint8_t* data, size_t size) {
95 if (size < sizeof(uint32_t)) {
96 return;
97 }
98 uint32_t dummy = ByteReader<uint32_t>::ReadBigEndian(data);
99 data += sizeof(uint32_t);
100 size -= sizeof(uint32_t);
101
102 size_t min_window_size = (dummy & 0x7FFF) + 1;
103 constexpr size_t kSeqNumHalf = 0x8000u;
104 size_t max_window_size =
105 std::min(kSeqNumHalf, min_window_size + ((dummy >> 16) & 0x7FFF));
106
107 TransportFeedbackPacketLossTracker tracker(min_window_size, max_window_size);
108 FuzzTransportFeedback feedback(rtc::ArrayView<const uint8_t>(data, size));
109 while (!feedback.ended()) {
110 tracker.OnReceivedTransportFeedback(feedback);
111 tracker.Validate();
112 feedback.ParseNextTransportFeedback();
113 }
114 }
115
116 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698