You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.9 KiB

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