rtp_replayer.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2019 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. #ifndef TEST_FUZZERS_UTILS_RTP_REPLAYER_H_
  11. #define TEST_FUZZERS_UTILS_RTP_REPLAYER_H_
  12. #include <stdio.h>
  13. #include <map>
  14. #include <memory>
  15. #include <string>
  16. #include <vector>
  17. #include "api/rtc_event_log/rtc_event_log.h"
  18. #include "api/test/video/function_video_decoder_factory.h"
  19. #include "api/video_codecs/video_decoder.h"
  20. #include "call/call.h"
  21. #include "media/engine/internal_decoder_factory.h"
  22. #include "rtc_base/fake_clock.h"
  23. #include "rtc_base/time_utils.h"
  24. #include "test/null_transport.h"
  25. #include "test/rtp_file_reader.h"
  26. #include "test/test_video_capturer.h"
  27. #include "test/video_renderer.h"
  28. namespace webrtc {
  29. namespace test {
  30. // The RtpReplayer is a utility for fuzzing the RTP/RTCP receiver stack in
  31. // WebRTC. It achieves this by accepting a set of Receiver configurations and
  32. // an RtpDump (consisting of both RTP and RTCP packets). The |rtp_dump| is
  33. // passed in as a buffer to allow simple mutation fuzzing directly on the dump.
  34. class RtpReplayer final {
  35. public:
  36. // Holds all the important stream information required to emulate the WebRTC
  37. // rtp receival code path.
  38. struct StreamState {
  39. test::NullTransport transport;
  40. std::vector<std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>>> sinks;
  41. std::vector<VideoReceiveStream*> receive_streams;
  42. std::unique_ptr<VideoDecoderFactory> decoder_factory;
  43. };
  44. // Construct an RtpReplayer from a JSON replay configuration file.
  45. static void Replay(const std::string& replay_config_filepath,
  46. const uint8_t* rtp_dump_data,
  47. size_t rtp_dump_size);
  48. // Construct an RtpReplayer from a set of VideoReceiveStream::Configs. Note
  49. // the stream_state.transport must be set for each receiver stream.
  50. static void Replay(
  51. std::unique_ptr<StreamState> stream_state,
  52. std::vector<VideoReceiveStream::Config> receive_stream_config,
  53. const uint8_t* rtp_dump_data,
  54. size_t rtp_dump_size);
  55. private:
  56. // Reads the replay configuration from Json.
  57. static std::vector<VideoReceiveStream::Config> ReadConfigFromFile(
  58. const std::string& replay_config,
  59. Transport* transport);
  60. // Configures the stream state based on the receiver configurations.
  61. static void SetupVideoStreams(
  62. std::vector<VideoReceiveStream::Config>* receive_stream_configs,
  63. StreamState* stream_state,
  64. Call* call);
  65. // Creates a new RtpReader which can read the RtpDump
  66. static std::unique_ptr<test::RtpFileReader> CreateRtpReader(
  67. const uint8_t* rtp_dump_data,
  68. size_t rtp_dump_size);
  69. // Replays each packet to from the RtpDump.
  70. static void ReplayPackets(rtc::FakeClock* clock,
  71. Call* call,
  72. test::RtpFileReader* rtp_reader);
  73. }; // class RtpReplayer
  74. } // namespace test
  75. } // namespace webrtc
  76. #endif // TEST_FUZZERS_UTILS_RTP_REPLAYER_H_