| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_ | 11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_ |
| 12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_ | 12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_ |
| 13 | 13 |
| 14 #include "webrtc/base/basictypes.h" | 14 #include "webrtc/base/basictypes.h" |
| 15 #include "webrtc/base/random.h" | 15 #include "webrtc/base/random.h" |
| 16 #include "webrtc/modules/include/module_common_types.h" | 16 #include "webrtc/modules/include/module_common_types.h" |
| 17 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" | 17 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |
| 18 | 18 |
| 19 namespace webrtc { | 19 namespace webrtc { |
| 20 namespace test { | 20 namespace test { |
| 21 | |
| 22 // needed to not clash with another webrtc::FrameGenerator. | |
| 23 namespace fec { | 21 namespace fec { |
| 24 | 22 |
| 25 struct RawRtpPacket : public ForwardErrorCorrection::Packet { | 23 struct RawRtpPacket : public ForwardErrorCorrection::Packet { |
| 26 WebRtcRTPHeader header; | 24 WebRtcRTPHeader header; |
| 27 }; | 25 }; |
| 28 | 26 |
| 29 class FrameGenerator { | 27 // This class generates media packets corresponding to a single frame. |
| 30 public: | |
| 31 FrameGenerator(); | |
| 32 | |
| 33 void NewFrame(int num_packets); | |
| 34 | |
| 35 uint16_t NextSeqNum(); | |
| 36 | |
| 37 RawRtpPacket* NextPacket(int offset, size_t length); | |
| 38 | |
| 39 // Creates a new RtpPacket with the RED header added to the packet. | |
| 40 RawRtpPacket* BuildMediaRedPacket(const RawRtpPacket* packet); | |
| 41 | |
| 42 // Creates a new RtpPacket with FEC payload and red header. Does this by | |
| 43 // creating a new fake media RtpPacket, clears the marker bit and adds a RED | |
| 44 // header. Finally replaces the payload with the content of |packet->data|. | |
| 45 RawRtpPacket* BuildFecRedPacket(const ForwardErrorCorrection::Packet* packet); | |
| 46 | |
| 47 void SetRedHeader(ForwardErrorCorrection::Packet* red_packet, | |
| 48 uint8_t payload_type, | |
| 49 size_t header_length) const; | |
| 50 | |
| 51 private: | |
| 52 static void BuildRtpHeader(uint8_t* data, const RTPHeader* header); | |
| 53 | |
| 54 int num_packets_; | |
| 55 uint16_t seq_num_; | |
| 56 uint32_t timestamp_; | |
| 57 }; | |
| 58 | |
| 59 class MediaPacketGenerator { | 28 class MediaPacketGenerator { |
| 60 public: | 29 public: |
| 61 MediaPacketGenerator(uint32_t min_packet_size, | 30 MediaPacketGenerator(uint32_t min_packet_size, |
| 62 uint32_t max_packet_size, | 31 uint32_t max_packet_size, |
| 63 Random* random) | 32 Random* random) |
| 64 : min_packet_size_(min_packet_size), | 33 : min_packet_size_(min_packet_size), |
| 65 max_packet_size_(max_packet_size), | 34 max_packet_size_(max_packet_size), |
| 66 random_(random) {} | 35 random_(random) {} |
| 67 | 36 |
| 68 // Construct the media packets, up to |num_media_packets| packets. | 37 // Construct the media packets, up to |num_media_packets| packets. |
| 69 void ConstructMediaPacketsSeqNum(int num_media_packets, | 38 void ConstructMediaPacketsSeqNum(int num_media_packets, |
| 70 uint16_t start_seq_num); | 39 uint16_t start_seq_num); |
| 71 void ConstructMediaPackets(int num_media_packets); | 40 void ConstructMediaPackets(int num_media_packets); |
| 72 | 41 |
| 73 ForwardErrorCorrection::PacketList* GetMediaPackets(); | 42 ForwardErrorCorrection::PacketList* GetMediaPackets(); |
| 74 uint32_t GetSsrc(); | 43 uint32_t GetSsrc(); |
| 75 uint16_t GetFecSeqNum(); | 44 uint16_t GetFecSeqNum(); |
| 76 | 45 |
| 77 private: | 46 private: |
| 78 uint32_t min_packet_size_; | 47 uint32_t min_packet_size_; |
| 79 uint32_t max_packet_size_; | 48 uint32_t max_packet_size_; |
| 80 Random* random_; | 49 Random* random_; |
| 81 | 50 |
| 82 ForwardErrorCorrection::PacketList media_packets_; | 51 ForwardErrorCorrection::PacketList media_packets_; |
| 83 uint32_t ssrc_; | 52 uint32_t ssrc_; |
| 84 uint16_t fec_seq_num_; | 53 uint16_t fec_seq_num_; |
| 85 }; | 54 }; |
| 86 | 55 |
| 56 // This class generates media and ULPFEC packets (both encapsulated in RED) |
| 57 // for a single frame. |
| 58 class UlpfecPacketGenerator { |
| 59 public: |
| 60 UlpfecPacketGenerator(); |
| 61 |
| 62 void NewFrame(int num_packets); |
| 63 |
| 64 uint16_t NextSeqNum(); |
| 65 |
| 66 RawRtpPacket* NextPacket(int offset, size_t length); |
| 67 |
| 68 // Creates a new RtpPacket with the RED header added to the packet. |
| 69 RawRtpPacket* BuildMediaRedPacket(const RawRtpPacket* packet); |
| 70 |
| 71 // Creates a new RtpPacket with FEC payload and RED header. Does this by |
| 72 // creating a new fake media RtpPacket, clears the marker bit and adds a RED |
| 73 // header. Finally replaces the payload with the content of |packet->data|. |
| 74 RawRtpPacket* BuildFecRedPacket(const ForwardErrorCorrection::Packet* packet); |
| 75 |
| 76 void SetRedHeader(ForwardErrorCorrection::Packet* red_packet, |
| 77 uint8_t payload_type, |
| 78 size_t header_length) const; |
| 79 |
| 80 private: |
| 81 static void BuildRtpHeader(uint8_t* data, const RTPHeader* header); |
| 82 |
| 83 int num_packets_; |
| 84 uint16_t seq_num_; |
| 85 uint32_t timestamp_; |
| 86 }; |
| 87 |
| 87 } // namespace fec | 88 } // namespace fec |
| 88 } // namespace test | 89 } // namespace test |
| 89 } // namespace webrtc | 90 } // namespace webrtc |
| 90 | 91 |
| 91 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_ | 92 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_ |
| OLD | NEW |