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