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