• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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<VideoReceiveStream*> 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 VideoReceiveStream::Configs. Note
57   // the stream_state.transport must be set for each receiver stream.
58   static void Replay(
59       std::unique_ptr<StreamState> stream_state,
60       std::vector<VideoReceiveStream::Config> receive_stream_config,
61       const uint8_t* rtp_dump_data,
62       size_t rtp_dump_size);
63 
64  private:
65   // Reads the replay configuration from Json.
66   static std::vector<VideoReceiveStream::Config> ReadConfigFromFile(
67       const std::string& replay_config,
68       Transport* transport);
69 
70   // Configures the stream state based on the receiver configurations.
71   static void SetupVideoStreams(
72       std::vector<VideoReceiveStream::Config>* receive_stream_configs,
73       StreamState* stream_state,
74       Call* call);
75 
76   // Creates a new RtpReader which can read the RtpDump
77   static std::unique_ptr<test::RtpFileReader> CreateRtpReader(
78       const uint8_t* rtp_dump_data,
79       size_t rtp_dump_size);
80 
81   // Replays each packet to from the RtpDump.
82   static void ReplayPackets(rtc::FakeClock* clock,
83                             Call* call,
84                             test::RtpFileReader* rtp_reader);
85 };  // class RtpReplayer
86 
87 }  // namespace test
88 }  // namespace webrtc
89 
90 #endif  // TEST_FUZZERS_UTILS_RTP_REPLAYER_H_
91