philipel | 1e9cf7f | 2018-05-17 13:34:53 +0200 | [diff] [blame] | 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 "modules/video_coding/frame_buffer2.h" |
| 12 | |
| 13 | #include "modules/video_coding/jitter_estimator.h" |
| 14 | #include "modules/video_coding/timing.h" |
| 15 | #include "system_wrappers/include/clock.h" |
| 16 | |
| 17 | namespace webrtc { |
| 18 | |
| 19 | namespace { |
| 20 | |
| 21 | // When DataReader runs out of data provided in the constructor it will |
| 22 | // just set/return 0 instead. |
| 23 | struct DataReader { |
| 24 | DataReader(const uint8_t* data, size_t size) : data_(data), size_(size) {} |
| 25 | |
| 26 | void CopyTo(void* destination, size_t dest_size) { |
| 27 | memset(destination, 0, dest_size); |
| 28 | |
| 29 | size_t bytes_to_copy = std::min(size_ - offset_, dest_size); |
| 30 | memcpy(destination, data_ + offset_, bytes_to_copy); |
| 31 | offset_ += bytes_to_copy; |
| 32 | } |
| 33 | |
| 34 | template <typename T> |
| 35 | T GetNum() { |
| 36 | T res; |
| 37 | if (offset_ + sizeof(res) < size_) { |
| 38 | memcpy(&res, data_ + offset_, sizeof(res)); |
| 39 | offset_ += sizeof(res); |
| 40 | return res; |
| 41 | } |
| 42 | |
| 43 | offset_ = size_; |
| 44 | return T(0); |
| 45 | } |
| 46 | |
| 47 | bool MoreToRead() { return offset_ < size_; } |
| 48 | |
| 49 | const uint8_t* const data_; |
| 50 | size_t size_; |
| 51 | size_t offset_ = 0; |
| 52 | }; |
| 53 | |
| 54 | class FuzzyFrameObject : public video_coding::EncodedFrame { |
| 55 | public: |
| 56 | FuzzyFrameObject() {} |
| 57 | ~FuzzyFrameObject() {} |
| 58 | |
| 59 | bool GetBitstream(uint8_t* destination) const override { return false; } |
philipel | 1e9cf7f | 2018-05-17 13:34:53 +0200 | [diff] [blame] | 60 | int64_t ReceivedTime() const override { return 0; } |
| 61 | int64_t RenderTime() const override { return _renderTimeMs; } |
| 62 | }; |
| 63 | } // namespace |
| 64 | |
| 65 | void FuzzOneInput(const uint8_t* data, size_t size) { |
| 66 | DataReader reader(data, size); |
| 67 | Clock* clock = Clock::GetRealTimeClock(); |
| 68 | VCMJitterEstimator jitter_estimator(clock, 0, 0); |
| 69 | VCMTiming timing(clock); |
| 70 | video_coding::FrameBuffer frame_buffer(clock, &jitter_estimator, &timing, |
| 71 | nullptr); |
| 72 | |
| 73 | while (reader.MoreToRead()) { |
| 74 | if (reader.GetNum<uint8_t>() & 1) { |
| 75 | std::unique_ptr<FuzzyFrameObject> frame(new FuzzyFrameObject()); |
| 76 | frame->id.picture_id = reader.GetNum<int64_t>(); |
| 77 | frame->id.spatial_layer = reader.GetNum<uint8_t>(); |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 78 | frame->SetTimestamp(reader.GetNum<uint32_t>()); |
philipel | 1e9cf7f | 2018-05-17 13:34:53 +0200 | [diff] [blame] | 79 | frame->num_references = reader.GetNum<uint8_t>() % |
| 80 | video_coding::EncodedFrame::kMaxFrameReferences; |
| 81 | |
| 82 | for (size_t r = 0; r < frame->num_references; ++r) |
| 83 | frame->references[r] = reader.GetNum<int64_t>(); |
| 84 | |
| 85 | frame_buffer.InsertFrame(std::move(frame)); |
| 86 | } else { |
| 87 | // Since we are not trying to trigger race conditions it does not make |
| 88 | // sense to have a wait time > 0. |
| 89 | const int kWaitTimeMs = 0; |
| 90 | |
| 91 | std::unique_ptr<video_coding::EncodedFrame> frame(new FuzzyFrameObject()); |
| 92 | bool keyframe_required = reader.GetNum<uint8_t>() % 2; |
| 93 | frame_buffer.NextFrame(kWaitTimeMs, &frame, keyframe_required); |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | } // namespace webrtc |