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

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

Issue 2579613003: Add TransportFeedbackPacketLossTracker. (Closed)
Patch Set: moving to voice engine 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/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 : public TransportFeedback {
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 num_statuses = (num_statuses & 0xFFFE) + 1; // To make num_statuses > 1.
stefan-webrtc 2016/12/20 17:03:19 I'd write this like this instead: num_statuses = s
minyue-webrtc 2016/12/28 14:48:32 sure.better to read although requires some casting
49
50 while (statuses_.size() < num_statuses) {
kwiberg-webrtc 2016/12/22 02:31:41 For simplicity, make the outer loop infinite, and
minyue-webrtc 2016/12/28 14:48:32 yes, nice!
51 uint8_t status_byte = 0;
52 if (!ReadData<uint8_t>(&status_byte))
53 break;
54 // Each status byte contains 8 statuses.
55 for (size_t j = 0; j < 8; ++j) {
56 if (status_byte & 0x01) {
57 // |kReceivedSmallDelta| and |kReceivedLargeDelta| make no difference
58 // to TransportFeedbackPacketLossTracker. So we test only one case.
59 statuses_.push_back(
60 TransportFeedback::StatusSymbol::kReceivedSmallDelta);
61 } else {
62 statuses_.push_back(TransportFeedback::StatusSymbol::kNotReceived);
63 }
64 if (statuses_.size() >= num_statuses)
65 break;
66 status_byte >>= 1;
67 }
68 }
69 }
70
71 bool ended() const { return ended_; }
72
73 private:
74 template <typename T>
75 bool ReadData(T* value) {
76 RTC_DCHECK(!ended_);
77 if (data_idx_ + sizeof(T) > data_.size()) {
78 ended_ = true;
79 return false;
80 }
81 *value = ByteReader<T>::ReadBigEndian(&data_[data_idx_]);
82 data_idx_ += sizeof(T);
83 return true;
84 }
85
86 rtc::ArrayView<const uint8_t> data_;
kwiberg-webrtc 2016/12/22 02:31:41 const?
minyue-webrtc 2016/12/28 14:48:32 Done.
87 bool ended_;
88 size_t data_idx_;
89 uint16_t base_seq_num_;
90 std::vector<TransportFeedback::StatusSymbol> statuses_;
91 };
92
93 } // namespace
94
95 void FuzzOneInput(const uint8_t* data, size_t size) {
96 if (size < sizeof(uint32_t)) {
97 return;
98 }
99 uint32_t dummy = ByteReader<uint32_t>::ReadBigEndian(data);
kwiberg-webrtc 2016/12/22 02:31:41 You're using this value below, so is it really a d
minyue-webrtc 2016/12/28 14:48:32 not needed any longer.
100 data += sizeof(uint32_t);
101 size -= sizeof(uint32_t);
102
103 size_t min_window_size = (dummy & 0x7FFF) + 1;
104 constexpr size_t kSeqNumHalf = 0x8000u;
105 size_t max_window_size =
106 std::min(kSeqNumHalf, min_window_size + ((dummy >> 16) & 0x7FFF));
kwiberg-webrtc 2016/12/22 02:31:41 OK, so min_window_size and max_window_size are two
minyue-webrtc 2016/12/28 14:48:32 Yes, I did your suggestion but with some changes.
kwiberg-webrtc 2017/01/05 02:51:11 Acknowledged.
107
108 TransportFeedbackPacketLossTracker tracker(min_window_size, max_window_size);
109 FuzzTransportFeedback feedback(rtc::ArrayView<const uint8_t>(data, size));
110 while (!feedback.ended()) {
111 tracker.OnReceivedTransportFeedback(feedback);
112 tracker.Validate();
113 feedback.ParseNextTransportFeedback();
114 }
115 }
116
117 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698