blob: 57f0c74a7edba36a8f80ae3009e61a0ca205cd1d [file] [log] [blame]
philipel1e9cf7f2018-05-17 13:34:53 +02001/*
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
17namespace webrtc {
18
19namespace {
20
21// When DataReader runs out of data provided in the constructor it will
22// just set/return 0 instead.
23struct 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
54class FuzzyFrameObject : public video_coding::EncodedFrame {
55 public:
56 FuzzyFrameObject() {}
57 ~FuzzyFrameObject() {}
58
59 bool GetBitstream(uint8_t* destination) const override { return false; }
60 uint32_t Timestamp() const override { return timestamp; }
61 int64_t ReceivedTime() const override { return 0; }
62 int64_t RenderTime() const override { return _renderTimeMs; }
63};
64} // namespace
65
66void FuzzOneInput(const uint8_t* data, size_t size) {
67 DataReader reader(data, size);
68 Clock* clock = Clock::GetRealTimeClock();
69 VCMJitterEstimator jitter_estimator(clock, 0, 0);
70 VCMTiming timing(clock);
71 video_coding::FrameBuffer frame_buffer(clock, &jitter_estimator, &timing,
72 nullptr);
73
74 while (reader.MoreToRead()) {
75 if (reader.GetNum<uint8_t>() & 1) {
76 std::unique_ptr<FuzzyFrameObject> frame(new FuzzyFrameObject());
77 frame->id.picture_id = reader.GetNum<int64_t>();
78 frame->id.spatial_layer = reader.GetNum<uint8_t>();
79 frame->timestamp = reader.GetNum<uint32_t>();
80 frame->num_references = reader.GetNum<uint8_t>() %
81 video_coding::EncodedFrame::kMaxFrameReferences;
82
83 for (size_t r = 0; r < frame->num_references; ++r)
84 frame->references[r] = reader.GetNum<int64_t>();
85
86 frame_buffer.InsertFrame(std::move(frame));
87 } else {
88 // Since we are not trying to trigger race conditions it does not make
89 // sense to have a wait time > 0.
90 const int kWaitTimeMs = 0;
91
92 std::unique_ptr<video_coding::EncodedFrame> frame(new FuzzyFrameObject());
93 bool keyframe_required = reader.GetNum<uint8_t>() % 2;
94 frame_buffer.NextFrame(kWaitTimeMs, &frame, keyframe_required);
95 }
96 }
97}
98
99} // namespace webrtc