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