stefan@webrtc.org | e0d6fa4 | 2012-03-20 22:10:56 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 11 | #ifndef MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_ |
| 12 | #define MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_ |
stefan@webrtc.org | e0d6fa4 | 2012-03-20 22:10:56 +0000 | [diff] [blame] | 13 | |
brandtr | 0aabdac | 2016-10-03 06:36:43 -0700 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 16 | #include "modules/include/module_common_types.h" |
| 17 | #include "modules/rtp_rtcp/source/forward_error_correction.h" |
| 18 | #include "rtc_base/basictypes.h" |
| 19 | #include "rtc_base/random.h" |
stefan@webrtc.org | e0d6fa4 | 2012-03-20 22:10:56 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
Danil Chapovalov | 1e80ce4 | 2016-02-19 16:02:15 +0100 | [diff] [blame] | 22 | namespace test { |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 23 | namespace fec { |
| 24 | |
brandtr | 0aabdac | 2016-10-03 06:36:43 -0700 | [diff] [blame] | 25 | struct AugmentedPacket : public ForwardErrorCorrection::Packet { |
Danil Chapovalov | 1e80ce4 | 2016-02-19 16:02:15 +0100 | [diff] [blame] | 26 | WebRtcRTPHeader header; |
| 27 | }; |
stefan@webrtc.org | e0d6fa4 | 2012-03-20 22:10:56 +0000 | [diff] [blame] | 28 | |
brandtr | 0aabdac | 2016-10-03 06:36:43 -0700 | [diff] [blame] | 29 | // TODO(brandtr): Consider merging MediaPacketGenerator and |
| 30 | // AugmentedPacketGenerator into a single class, since their functionality is |
| 31 | // similar. |
| 32 | |
brandtr | a4545ee | 2016-10-03 02:58:45 -0700 | [diff] [blame] | 33 | // This class generates media packets corresponding to a single frame. |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 34 | class MediaPacketGenerator { |
| 35 | public: |
| 36 | MediaPacketGenerator(uint32_t min_packet_size, |
| 37 | uint32_t max_packet_size, |
| 38 | uint32_t ssrc, |
| 39 | Random* random) |
| 40 | : min_packet_size_(min_packet_size), |
| 41 | max_packet_size_(max_packet_size), |
| 42 | ssrc_(ssrc), |
| 43 | random_(random) {} |
| 44 | |
| 45 | // Construct the media packets, up to |num_media_packets| packets. |
| 46 | ForwardErrorCorrection::PacketList ConstructMediaPackets( |
| 47 | int num_media_packets, |
| 48 | uint16_t start_seq_num); |
| 49 | ForwardErrorCorrection::PacketList ConstructMediaPackets( |
| 50 | int num_media_packets); |
| 51 | |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 52 | uint16_t GetNextSeqNum(); |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 53 | |
| 54 | private: |
| 55 | uint32_t min_packet_size_; |
| 56 | uint32_t max_packet_size_; |
| 57 | uint32_t ssrc_; |
| 58 | Random* random_; |
| 59 | |
| 60 | ForwardErrorCorrection::PacketList media_packets_; |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 61 | uint16_t next_seq_num_; |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
brandtr | 0aabdac | 2016-10-03 06:36:43 -0700 | [diff] [blame] | 64 | // This class generates media packets with a certain structure of the payload. |
| 65 | class AugmentedPacketGenerator { |
brandtr | a4545ee | 2016-10-03 02:58:45 -0700 | [diff] [blame] | 66 | public: |
brandtr | 0aabdac | 2016-10-03 06:36:43 -0700 | [diff] [blame] | 67 | explicit AugmentedPacketGenerator(uint32_t ssrc); |
brandtr | a4545ee | 2016-10-03 02:58:45 -0700 | [diff] [blame] | 68 | |
brandtr | 0aabdac | 2016-10-03 06:36:43 -0700 | [diff] [blame] | 69 | // Prepare for generating a new set of packets, corresponding to a frame. |
| 70 | void NewFrame(size_t num_packets); |
brandtr | a4545ee | 2016-10-03 02:58:45 -0700 | [diff] [blame] | 71 | |
brandtr | 0aabdac | 2016-10-03 06:36:43 -0700 | [diff] [blame] | 72 | // Increment and return the newly incremented sequence number. |
| 73 | uint16_t NextPacketSeqNum(); |
brandtr | a4545ee | 2016-10-03 02:58:45 -0700 | [diff] [blame] | 74 | |
brandtr | 0aabdac | 2016-10-03 06:36:43 -0700 | [diff] [blame] | 75 | // Return the next packet in the current frame. |
| 76 | std::unique_ptr<AugmentedPacket> NextPacket(size_t offset, size_t length); |
brandtr | a4545ee | 2016-10-03 02:58:45 -0700 | [diff] [blame] | 77 | |
brandtr | 0aabdac | 2016-10-03 06:36:43 -0700 | [diff] [blame] | 78 | protected: |
| 79 | // Given |header|, writes the appropriate RTP header fields in |data|. |
| 80 | static void WriteRtpHeader(const RTPHeader& header, uint8_t* data); |
brandtr | a4545ee | 2016-10-03 02:58:45 -0700 | [diff] [blame] | 81 | |
brandtr | 0aabdac | 2016-10-03 06:36:43 -0700 | [diff] [blame] | 82 | // Number of packets left to generate, in the current frame. |
| 83 | size_t num_packets_; |
brandtr | a4545ee | 2016-10-03 02:58:45 -0700 | [diff] [blame] | 84 | |
| 85 | private: |
brandtr | 0aabdac | 2016-10-03 06:36:43 -0700 | [diff] [blame] | 86 | uint32_t ssrc_; |
brandtr | a4545ee | 2016-10-03 02:58:45 -0700 | [diff] [blame] | 87 | uint16_t seq_num_; |
| 88 | uint32_t timestamp_; |
| 89 | }; |
| 90 | |
brandtr | 8d02ea7 | 2016-10-03 23:47:05 -0700 | [diff] [blame] | 91 | // This class generates media and FlexFEC packets for a single frame. |
| 92 | class FlexfecPacketGenerator : public AugmentedPacketGenerator { |
| 93 | public: |
| 94 | FlexfecPacketGenerator(uint32_t media_ssrc, uint32_t flexfec_ssrc); |
| 95 | |
| 96 | // Creates a new AugmentedPacket (with RTP headers) from a |
| 97 | // FlexFEC packet (without RTP headers). |
| 98 | std::unique_ptr<AugmentedPacket> BuildFlexfecPacket( |
| 99 | const ForwardErrorCorrection::Packet& packet); |
| 100 | |
| 101 | private: |
| 102 | uint32_t flexfec_ssrc_; |
| 103 | uint16_t flexfec_seq_num_; |
| 104 | uint32_t flexfec_timestamp_; |
| 105 | }; |
| 106 | |
brandtr | 0aabdac | 2016-10-03 06:36:43 -0700 | [diff] [blame] | 107 | // This class generates media and ULPFEC packets (both encapsulated in RED) |
| 108 | // for a single frame. |
| 109 | class UlpfecPacketGenerator : public AugmentedPacketGenerator { |
| 110 | public: |
| 111 | explicit UlpfecPacketGenerator(uint32_t ssrc); |
| 112 | |
| 113 | // Creates a new AugmentedPacket with the RED header added to the packet. |
| 114 | static std::unique_ptr<AugmentedPacket> BuildMediaRedPacket( |
| 115 | const AugmentedPacket& packet); |
| 116 | |
| 117 | // Creates a new AugmentedPacket with FEC payload and RED header. Does this by |
| 118 | // creating a new fake media AugmentedPacket, clears the marker bit and adds a |
| 119 | // RED header. Finally replaces the payload with the content of |
| 120 | // |packet->data|. |
| 121 | std::unique_ptr<AugmentedPacket> BuildUlpfecRedPacket( |
| 122 | const ForwardErrorCorrection::Packet& packet); |
| 123 | |
| 124 | private: |
| 125 | static void SetRedHeader(uint8_t payload_type, |
| 126 | size_t header_length, |
| 127 | AugmentedPacket* red_packet); |
| 128 | }; |
| 129 | |
brandtr | ece4aba | 2016-09-20 23:16:28 -0700 | [diff] [blame] | 130 | } // namespace fec |
| 131 | } // namespace test |
danilchap | 6a6f089 | 2015-12-10 12:39:08 -0800 | [diff] [blame] | 132 | } // namespace webrtc |
stefan@webrtc.org | e0d6fa4 | 2012-03-20 22:10:56 +0000 | [diff] [blame] | 133 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 134 | #endif // MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_ |