Line data Source code
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 :
11 : #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_FORWARD_ERROR_CORRECTION_INTERNAL_H_
12 : #define WEBRTC_MODULES_RTP_RTCP_SOURCE_FORWARD_ERROR_CORRECTION_INTERNAL_H_
13 :
14 : #include "webrtc/modules/include/module_common_types.h"
15 : #include "webrtc/typedefs.h"
16 :
17 : namespace webrtc {
18 :
19 : // Maximum number of media packets that can be protected
20 : // by these packet masks.
21 : constexpr size_t kUlpfecMaxMediaPackets = 48;
22 :
23 : // Packet mask size in bytes (given L bit).
24 : constexpr size_t kUlpfecPacketMaskSizeLBitClear = 2;
25 : constexpr size_t kUlpfecPacketMaskSizeLBitSet = 6;
26 :
27 : // Convenience constants.
28 : constexpr size_t kUlpfecMinPacketMaskSize = kUlpfecPacketMaskSizeLBitClear;
29 : constexpr size_t kUlpfecMaxPacketMaskSize = kUlpfecPacketMaskSizeLBitSet;
30 :
31 : namespace internal {
32 :
33 : class PacketMaskTable {
34 : public:
35 : PacketMaskTable(FecMaskType fec_mask_type, int num_media_packets);
36 0 : ~PacketMaskTable() {}
37 : FecMaskType fec_mask_type() const { return fec_mask_type_; }
38 0 : const uint8_t*** fec_packet_mask_table() const {
39 0 : return fec_packet_mask_table_;
40 : }
41 :
42 : private:
43 : FecMaskType InitMaskType(FecMaskType fec_mask_type, int num_media_packets);
44 : const uint8_t*** InitMaskTable(FecMaskType fec_mask_type_);
45 : const FecMaskType fec_mask_type_;
46 : const uint8_t*** fec_packet_mask_table_;
47 : };
48 :
49 : // Returns an array of packet masks. The mask of a single FEC packet
50 : // corresponds to a number of mask bytes. The mask indicates which
51 : // media packets should be protected by the FEC packet.
52 :
53 : // \param[in] num_media_packets The number of media packets to protect.
54 : // [1, max_media_packets].
55 : // \param[in] num_fec_packets The number of FEC packets which will
56 : // be generated. [1, num_media_packets].
57 : // \param[in] num_imp_packets The number of important packets.
58 : // [0, num_media_packets].
59 : // num_imp_packets = 0 is the equal
60 : // protection scenario.
61 : // \param[in] use_unequal_protection Enables unequal protection: allocates
62 : // more protection to the num_imp_packets.
63 : // \param[in] mask_table An instance of the |PacketMaskTable|
64 : // class, which contains the type of FEC
65 : // packet mask used, and a pointer to the
66 : // corresponding packet masks.
67 : // \param[out] packet_mask A pointer to hold the packet mask array,
68 : // of size: num_fec_packets *
69 : // "number of mask bytes".
70 : void GeneratePacketMasks(int num_media_packets, int num_fec_packets,
71 : int num_imp_packets, bool use_unequal_protection,
72 : const PacketMaskTable& mask_table,
73 : uint8_t* packet_mask);
74 :
75 : // Returns the required packet mask size, given the number of sequence numbers
76 : // that will be covered.
77 : size_t PacketMaskSize(size_t num_sequence_numbers);
78 :
79 : // Inserts |num_zeros| zero columns into |new_mask| at position
80 : // |new_bit_index|. If the current byte of |new_mask| can't fit all zeros, the
81 : // byte will be filled with zeros from |new_bit_index|, but the next byte will
82 : // be untouched.
83 : void InsertZeroColumns(int num_zeros,
84 : uint8_t* new_mask,
85 : int new_mask_bytes,
86 : int num_fec_packets,
87 : int new_bit_index);
88 :
89 : // Copies the left most bit column from the byte pointed to by
90 : // |old_bit_index| in |old_mask| to the right most column of the byte pointed
91 : // to by |new_bit_index| in |new_mask|. |old_mask_bytes| and |new_mask_bytes|
92 : // represent the number of bytes used per row for each mask. |num_fec_packets|
93 : // represent the number of rows of the masks.
94 : // The copied bit is shifted out from |old_mask| and is shifted one step to
95 : // the left in |new_mask|. |new_mask| will contain "xxxx xxn0" after this
96 : // operation, where x are previously inserted bits and n is the new bit.
97 : void CopyColumn(uint8_t* new_mask,
98 : int new_mask_bytes,
99 : uint8_t* old_mask,
100 : int old_mask_bytes,
101 : int num_fec_packets,
102 : int new_bit_index,
103 : int old_bit_index);
104 :
105 : } // namespace internal
106 : } // namespace webrtc
107 :
108 : #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_FORWARD_ERROR_CORRECTION_INTERNAL_H_
|