2012-03-20 22:10:56 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_
|
|
|
|
|
#define MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_
|
2012-03-20 22:10:56 +00:00
|
|
|
|
2016-10-03 06:36:43 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/source/forward_error_correction.h"
|
2020-03-11 12:59:07 +01:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/random.h"
|
2012-03-20 22:10:56 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2016-02-19 16:02:15 +01:00
|
|
|
namespace test {
|
2016-09-20 23:16:28 -07:00
|
|
|
namespace fec {
|
|
|
|
|
|
2016-10-03 06:36:43 -07:00
|
|
|
struct AugmentedPacket : public ForwardErrorCorrection::Packet {
|
2019-03-12 09:54:30 +01:00
|
|
|
RTPHeader header;
|
2016-02-19 16:02:15 +01:00
|
|
|
};
|
2012-03-20 22:10:56 +00:00
|
|
|
|
2016-10-03 06:36:43 -07:00
|
|
|
// TODO(brandtr): Consider merging MediaPacketGenerator and
|
|
|
|
|
// AugmentedPacketGenerator into a single class, since their functionality is
|
|
|
|
|
// similar.
|
|
|
|
|
|
2016-10-03 02:58:45 -07:00
|
|
|
// This class generates media packets corresponding to a single frame.
|
2016-09-20 23:16:28 -07:00
|
|
|
class MediaPacketGenerator {
|
|
|
|
|
public:
|
|
|
|
|
MediaPacketGenerator(uint32_t min_packet_size,
|
|
|
|
|
uint32_t max_packet_size,
|
|
|
|
|
uint32_t ssrc,
|
2018-03-09 15:37:03 +00:00
|
|
|
Random* random);
|
|
|
|
|
~MediaPacketGenerator();
|
2016-09-20 23:16:28 -07:00
|
|
|
|
2021-07-28 23:57:33 +02:00
|
|
|
// Construct the media packets, up to `num_media_packets` packets.
|
2016-09-20 23:16:28 -07:00
|
|
|
ForwardErrorCorrection::PacketList ConstructMediaPackets(
|
|
|
|
|
int num_media_packets,
|
|
|
|
|
uint16_t start_seq_num);
|
|
|
|
|
ForwardErrorCorrection::PacketList ConstructMediaPackets(
|
|
|
|
|
int num_media_packets);
|
|
|
|
|
|
2017-06-29 02:45:35 -07:00
|
|
|
uint16_t GetNextSeqNum();
|
2016-09-20 23:16:28 -07:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
uint32_t min_packet_size_;
|
|
|
|
|
uint32_t max_packet_size_;
|
|
|
|
|
uint32_t ssrc_;
|
|
|
|
|
Random* random_;
|
|
|
|
|
|
|
|
|
|
ForwardErrorCorrection::PacketList media_packets_;
|
2017-06-29 02:45:35 -07:00
|
|
|
uint16_t next_seq_num_;
|
2016-09-20 23:16:28 -07:00
|
|
|
};
|
|
|
|
|
|
2016-10-03 06:36:43 -07:00
|
|
|
// This class generates media packets with a certain structure of the payload.
|
|
|
|
|
class AugmentedPacketGenerator {
|
2016-10-03 02:58:45 -07:00
|
|
|
public:
|
2016-10-03 06:36:43 -07:00
|
|
|
explicit AugmentedPacketGenerator(uint32_t ssrc);
|
2016-10-03 02:58:45 -07:00
|
|
|
|
2016-10-03 06:36:43 -07:00
|
|
|
// Prepare for generating a new set of packets, corresponding to a frame.
|
|
|
|
|
void NewFrame(size_t num_packets);
|
2016-10-03 02:58:45 -07:00
|
|
|
|
2016-10-03 06:36:43 -07:00
|
|
|
// Increment and return the newly incremented sequence number.
|
|
|
|
|
uint16_t NextPacketSeqNum();
|
2016-10-03 02:58:45 -07:00
|
|
|
|
2016-10-03 06:36:43 -07:00
|
|
|
// Return the next packet in the current frame.
|
|
|
|
|
std::unique_ptr<AugmentedPacket> NextPacket(size_t offset, size_t length);
|
2016-10-03 02:58:45 -07:00
|
|
|
|
2016-10-03 06:36:43 -07:00
|
|
|
protected:
|
2021-07-28 23:57:33 +02:00
|
|
|
// Given `header`, writes the appropriate RTP header fields in `data`.
|
2016-10-03 06:36:43 -07:00
|
|
|
static void WriteRtpHeader(const RTPHeader& header, uint8_t* data);
|
2016-10-03 02:58:45 -07:00
|
|
|
|
2016-10-03 06:36:43 -07:00
|
|
|
// Number of packets left to generate, in the current frame.
|
|
|
|
|
size_t num_packets_;
|
2016-10-03 02:58:45 -07:00
|
|
|
|
|
|
|
|
private:
|
2016-10-03 06:36:43 -07:00
|
|
|
uint32_t ssrc_;
|
2016-10-03 02:58:45 -07:00
|
|
|
uint16_t seq_num_;
|
|
|
|
|
uint32_t timestamp_;
|
|
|
|
|
};
|
|
|
|
|
|
2016-10-03 23:47:05 -07:00
|
|
|
// This class generates media and FlexFEC packets for a single frame.
|
|
|
|
|
class FlexfecPacketGenerator : public AugmentedPacketGenerator {
|
|
|
|
|
public:
|
|
|
|
|
FlexfecPacketGenerator(uint32_t media_ssrc, uint32_t flexfec_ssrc);
|
|
|
|
|
|
|
|
|
|
// Creates a new AugmentedPacket (with RTP headers) from a
|
|
|
|
|
// FlexFEC packet (without RTP headers).
|
|
|
|
|
std::unique_ptr<AugmentedPacket> BuildFlexfecPacket(
|
|
|
|
|
const ForwardErrorCorrection::Packet& packet);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
uint32_t flexfec_ssrc_;
|
|
|
|
|
uint16_t flexfec_seq_num_;
|
|
|
|
|
uint32_t flexfec_timestamp_;
|
|
|
|
|
};
|
|
|
|
|
|
2016-10-03 06:36:43 -07:00
|
|
|
// This class generates media and ULPFEC packets (both encapsulated in RED)
|
|
|
|
|
// for a single frame.
|
|
|
|
|
class UlpfecPacketGenerator : public AugmentedPacketGenerator {
|
|
|
|
|
public:
|
|
|
|
|
explicit UlpfecPacketGenerator(uint32_t ssrc);
|
|
|
|
|
|
2019-09-20 11:40:12 +02:00
|
|
|
// Creates a new RtpPacket with the RED header added to the packet.
|
2020-03-11 12:59:07 +01:00
|
|
|
static RtpPacketReceived BuildMediaRedPacket(const AugmentedPacket& packet,
|
|
|
|
|
bool is_recovered);
|
2016-10-03 06:36:43 -07:00
|
|
|
|
2019-09-20 11:40:12 +02:00
|
|
|
// Creates a new RtpPacket with FEC payload and RED header. Does this by
|
2016-10-03 06:36:43 -07:00
|
|
|
// creating a new fake media AugmentedPacket, clears the marker bit and adds a
|
|
|
|
|
// RED header. Finally replaces the payload with the content of
|
2021-08-10 01:22:31 +02:00
|
|
|
// `packet->data`.
|
2020-03-11 12:59:07 +01:00
|
|
|
RtpPacketReceived BuildUlpfecRedPacket(
|
|
|
|
|
const ForwardErrorCorrection::Packet& packet);
|
2016-10-03 06:36:43 -07:00
|
|
|
};
|
|
|
|
|
|
2016-09-20 23:16:28 -07:00
|
|
|
} // namespace fec
|
|
|
|
|
} // namespace test
|
2015-12-10 12:39:08 -08:00
|
|
|
} // namespace webrtc
|
2012-03-20 22:10:56 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_
|