OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2017 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 class TransportFeedbackGenerator { |
| 23 public: |
| 24 explicit TransportFeedbackGenerator(rtc::ArrayView<const uint8_t> data) |
| 25 : data_(data), ended_(false), data_idx_(0) {} |
| 26 |
| 27 void GetNextTransportFeedback(rtcp::TransportFeedback* feedback) { |
| 28 uint16_t base_seq_num = 0; |
| 29 if (!ReadData<uint16_t>(&base_seq_num)) { |
| 30 return; |
| 31 } |
| 32 |
| 33 const int64_t kBaseTimeUs = 1234; // Irrelevant to this test. |
| 34 feedback->SetBase(base_seq_num, kBaseTimeUs); |
| 35 |
| 36 uint16_t num_statuses = 0; |
| 37 if (!ReadData<uint16_t>(&num_statuses)) |
| 38 return; |
| 39 num_statuses = std::max<uint16_t>(num_statuses, 1); |
| 40 |
| 41 uint16_t seq_num = base_seq_num; |
| 42 while (true) { |
| 43 uint8_t status_byte = 0; |
| 44 if (!ReadData<uint8_t>(&status_byte)) |
| 45 return; |
| 46 // Each status byte contains 8 statuses. |
| 47 for (size_t j = 0; j < 8; ++j) { |
| 48 if (status_byte & 0x01) { |
| 49 feedback->AddReceivedPacket(seq_num, kBaseTimeUs); |
| 50 } |
| 51 seq_num++; |
| 52 if (seq_num >= base_seq_num + num_statuses) { |
| 53 feedback->AddReceivedPacket(seq_num, kBaseTimeUs); |
| 54 return; |
| 55 } |
| 56 status_byte >>= 1; |
| 57 } |
| 58 } |
| 59 } |
| 60 |
| 61 bool ended() const { return ended_; } |
| 62 |
| 63 private: |
| 64 template <typename T> |
| 65 bool ReadData(T* value) { |
| 66 RTC_DCHECK(!ended_); |
| 67 if (data_idx_ + sizeof(T) > data_.size()) { |
| 68 ended_ = true; |
| 69 return false; |
| 70 } |
| 71 *value = ByteReader<T>::ReadBigEndian(&data_[data_idx_]); |
| 72 data_idx_ += sizeof(T); |
| 73 return true; |
| 74 } |
| 75 |
| 76 const rtc::ArrayView<const uint8_t> data_; |
| 77 bool ended_; |
| 78 size_t data_idx_; |
| 79 }; |
| 80 |
| 81 } // namespace |
| 82 |
| 83 void FuzzOneInput(const uint8_t* data, size_t size) { |
| 84 if (size < sizeof(uint32_t)) { |
| 85 return; |
| 86 } |
| 87 constexpr size_t kSeqNumHalf = 0x8000u; |
| 88 const size_t window_size_1 = std::min<size_t>( |
| 89 kSeqNumHalf, |
| 90 std::max<uint16_t>(1, ByteReader<uint16_t>::ReadBigEndian(data))); |
| 91 data += sizeof(uint16_t); |
| 92 const size_t window_size_2 = std::min<size_t>( |
| 93 kSeqNumHalf, |
| 94 std::max<uint16_t>(1, ByteReader<uint16_t>::ReadBigEndian(data))); |
| 95 data += sizeof(uint16_t); |
| 96 size -= 2 * sizeof(uint16_t); |
| 97 |
| 98 TransportFeedbackPacketLossTracker tracker( |
| 99 std::min(window_size_1, window_size_2), |
| 100 std::max(window_size_1, window_size_2)); |
| 101 TransportFeedbackGenerator feedback_generator( |
| 102 rtc::ArrayView<const uint8_t>(data, size)); |
| 103 while (!feedback_generator.ended()) { |
| 104 rtcp::TransportFeedback feedback; |
| 105 feedback_generator.GetNextTransportFeedback(&feedback); |
| 106 tracker.OnReceivedTransportFeedback(feedback); |
| 107 tracker.Validate(); |
| 108 } |
| 109 } |
| 110 |
| 111 } // namespace webrtc |
OLD | NEW |