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