Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/fec_test_helper.h

Issue 2271273004: Generalize UlpfecPacketGenerator into AugmentedPacketGenerator. (pt. 8) (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@style_fixes_fec_receiver_producer_fec
Patch Set: Rebase. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory>
15
14 #include "webrtc/base/basictypes.h" 16 #include "webrtc/base/basictypes.h"
15 #include "webrtc/base/random.h" 17 #include "webrtc/base/random.h"
16 #include "webrtc/modules/include/module_common_types.h" 18 #include "webrtc/modules/include/module_common_types.h"
17 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" 19 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h"
18 20
19 namespace webrtc { 21 namespace webrtc {
20 namespace test { 22 namespace test {
21 namespace fec { 23 namespace fec {
22 24
23 struct RawRtpPacket : public ForwardErrorCorrection::Packet { 25 struct AugmentedPacket : public ForwardErrorCorrection::Packet {
24 WebRtcRTPHeader header; 26 WebRtcRTPHeader header;
25 }; 27 };
26 28
29 // TODO(brandtr): Consider merging MediaPacketGenerator and
30 // AugmentedPacketGenerator into a single class, since their functionality is
31 // similar.
32
27 // This class generates media packets corresponding to a single frame. 33 // This class generates media packets corresponding to a single frame.
28 class MediaPacketGenerator { 34 class MediaPacketGenerator {
29 public: 35 public:
30 MediaPacketGenerator(uint32_t min_packet_size, 36 MediaPacketGenerator(uint32_t min_packet_size,
31 uint32_t max_packet_size, 37 uint32_t max_packet_size,
32 uint32_t ssrc, 38 uint32_t ssrc,
33 Random* random) 39 Random* random)
34 : min_packet_size_(min_packet_size), 40 : min_packet_size_(min_packet_size),
35 max_packet_size_(max_packet_size), 41 max_packet_size_(max_packet_size),
36 ssrc_(ssrc), 42 ssrc_(ssrc),
(...skipping 11 matching lines...) Expand all
48 private: 54 private:
49 uint32_t min_packet_size_; 55 uint32_t min_packet_size_;
50 uint32_t max_packet_size_; 56 uint32_t max_packet_size_;
51 uint32_t ssrc_; 57 uint32_t ssrc_;
52 Random* random_; 58 Random* random_;
53 59
54 ForwardErrorCorrection::PacketList media_packets_; 60 ForwardErrorCorrection::PacketList media_packets_;
55 uint16_t fec_seq_num_; 61 uint16_t fec_seq_num_;
56 }; 62 };
57 63
64 // This class generates media packets with a certain structure of the payload.
65 class AugmentedPacketGenerator {
66 public:
67 explicit AugmentedPacketGenerator(uint32_t ssrc);
68
69 // Prepare for generating a new set of packets, corresponding to a frame.
70 void NewFrame(size_t num_packets);
71
72 // Increment and return the sequence number.
philipel 2016/09/22 11:29:30 // Increment and returns the newly incremented seq
brandtr 2016/09/22 14:21:39 Done.
73 uint16_t NextSeqNum();
philipel 2016/09/22 11:29:30 I think NextPacketSeqNum might be a better name in
brandtr 2016/09/22 14:21:39 Yep, that works.
74
75 // Return the next packet in the current frame.
76 std::unique_ptr<AugmentedPacket> NextPacket(size_t offset, size_t length);
77
78 protected:
79 // Given |header|, writes the appropriate RTP header fields in |data|.
80 static void WriteRtpHeader(const RTPHeader& header, uint8_t* data);
81
82 size_t num_packets_; // Number of packets to generate.
philipel 2016/09/22 11:29:30 Move comment above |num_packets_|
brandtr 2016/09/22 14:21:39 Done.
83
84 private:
85 uint32_t ssrc_;
86 uint16_t seq_num_;
87 uint32_t timestamp_;
88 };
89
58 // This class generates media and ULPFEC packets (both encapsulated in RED) 90 // This class generates media and ULPFEC packets (both encapsulated in RED)
59 // for a single frame. 91 // for a single frame.
60 class UlpfecPacketGenerator { 92 class UlpfecPacketGenerator : public AugmentedPacketGenerator {
61 public: 93 public:
62 UlpfecPacketGenerator(); 94 explicit UlpfecPacketGenerator(uint32_t ssrc);
63 95
64 void NewFrame(int num_packets); 96 // Creates a new AugmentedPacket with the RED header added to the packet.
97 static std::unique_ptr<AugmentedPacket> BuildMediaRedPacket(
98 const AugmentedPacket& packet);
65 99
66 uint16_t NextSeqNum(); 100 // Creates a new AugmentedPacket with FEC payload and RED header. Does this by
67 101 // creating a new fake media AugmentedPacket, clears the marker bit and adds a
68 RawRtpPacket* NextPacket(int offset, size_t length); 102 // RED header. Finally replaces the payload with the content of
69 103 // |packet->data|.
70 // Creates a new RtpPacket with the RED header added to the packet. 104 std::unique_ptr<AugmentedPacket> BuildUlpfecRedPacket(
71 RawRtpPacket* BuildMediaRedPacket(const RawRtpPacket* packet); 105 const ForwardErrorCorrection::Packet& packet);
72
73 // Creates a new RtpPacket with FEC payload and red header. Does this by
74 // creating a new fake media RtpPacket, clears the marker bit and adds a RED
75 // header. Finally replaces the payload with the content of |packet->data|.
76 RawRtpPacket* BuildFecRedPacket(const ForwardErrorCorrection::Packet* packet);
77
78 void SetRedHeader(ForwardErrorCorrection::Packet* red_packet,
79 uint8_t payload_type,
80 size_t header_length) const;
81 106
82 private: 107 private:
83 static void BuildRtpHeader(uint8_t* data, const RTPHeader* header); 108 static void SetRedHeader(uint8_t payload_type,
84 109 size_t header_length,
85 int num_packets_; 110 AugmentedPacket* red_packet);
86 uint16_t seq_num_;
87 uint32_t timestamp_;
88 }; 111 };
89 112
90 } // namespace fec 113 } // namespace fec
91 } // namespace test 114 } // namespace test
92 } // namespace webrtc 115 } // namespace webrtc
93 116
94 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_ 117 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698