1 /*
2  *  Copyright (c) 2016 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_ULPFEC_HEADER_READER_WRITER_H_
12 #define MODULES_RTP_RTCP_SOURCE_ULPFEC_HEADER_READER_WRITER_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 #include "modules/rtp_rtcp/source/forward_error_correction.h"
18 
19 namespace webrtc {
20 
21 // FEC Level 0 Header, 10 bytes.
22 //    0                   1                   2                   3
23 //    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
24 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
25 //   |E|L|P|X|  CC   |M| PT recovery |            SN base            |
26 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
27 //   |                          TS recovery                          |
28 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29 //   |        length recovery        |
30 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31 //
32 // FEC Level 1 Header, 4 bytes (L = 0) or 8 bytes (L = 1).
33 //    0                   1                   2                   3
34 //    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 //   |       Protection Length       |             mask              |
37 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 //   |              mask cont. (present only when L = 1)             |
39 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 class UlpfecHeaderReader : public FecHeaderReader {
41  public:
42   UlpfecHeaderReader();
43   ~UlpfecHeaderReader() override;
44 
45   bool ReadFecHeader(
46       ForwardErrorCorrection::ReceivedFecPacket* fec_packet) const override;
47 };
48 
49 class UlpfecHeaderWriter : public FecHeaderWriter {
50  public:
51   UlpfecHeaderWriter();
52   ~UlpfecHeaderWriter() override;
53 
54   size_t MinPacketMaskSize(const uint8_t* packet_mask,
55                            size_t packet_mask_size) const override;
56 
57   size_t FecHeaderSize(size_t packet_mask_row_size) const override;
58 
59   void FinalizeFecHeader(
60       uint32_t media_ssrc,  // Unused by ULPFEC.
61       uint16_t seq_num_base,
62       const uint8_t* packet_mask,
63       size_t packet_mask_size,
64       ForwardErrorCorrection::Packet* fec_packet) const override;
65 };
66 
67 }  // namespace webrtc
68 
69 #endif  // MODULES_RTP_RTCP_SOURCE_ULPFEC_HEADER_READER_WRITER_H_
70