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