Line data Source code
1 : /*
2 : * Copyright (c) 2015 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_RTCP_PACKET_TRANSPORT_FEEDBACK_H_
12 : #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_TRANSPORT_FEEDBACK_H_
13 :
14 : #include <memory>
15 : #include <vector>
16 :
17 : #include "webrtc/base/constructormagic.h"
18 : #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rtpfb.h"
19 :
20 : namespace webrtc {
21 : namespace rtcp {
22 : class CommonHeader;
23 :
24 : class TransportFeedback : public Rtpfb {
25 : public:
26 : // TODO(sprang): IANA reg?
27 : static constexpr uint8_t kFeedbackMessageType = 15;
28 : // Convert to multiples of 0.25ms.
29 : static constexpr int kDeltaScaleFactor = 250;
30 : // Maximum number of packets (including missing) TransportFeedback can report.
31 : static constexpr size_t kMaxReportedPackets = 0xffff;
32 :
33 : TransportFeedback();
34 : ~TransportFeedback() override;
35 :
36 : void SetBase(uint16_t base_sequence, // Seq# of first packet in this msg.
37 : int64_t ref_timestamp_us); // Reference timestamp for this msg.
38 : void SetFeedbackSequenceNumber(uint8_t feedback_sequence);
39 : // NOTE: This method requires increasing sequence numbers (excepting wraps).
40 : bool AddReceivedPacket(uint16_t sequence_number, int64_t timestamp_us);
41 :
42 : enum class StatusSymbol {
43 : kNotReceived,
44 : kReceivedSmallDelta,
45 : kReceivedLargeDelta,
46 : };
47 :
48 : uint16_t GetBaseSequence() const;
49 : std::vector<TransportFeedback::StatusSymbol> GetStatusVector() const;
50 : std::vector<int16_t> GetReceiveDeltas() const;
51 :
52 : // Get the reference time in microseconds, including any precision loss.
53 : int64_t GetBaseTimeUs() const;
54 : // Convenience method for getting all deltas as microseconds. The first delta
55 : // is relative the base time.
56 : std::vector<int64_t> GetReceiveDeltasUs() const;
57 :
58 : bool Parse(const CommonHeader& packet);
59 : static std::unique_ptr<TransportFeedback> ParseFrom(const uint8_t* buffer,
60 : size_t length);
61 : // Pre and postcondition for all public methods. Should always return true.
62 : // This function is for tests.
63 : bool IsConsistent() const;
64 :
65 : protected:
66 : bool Create(uint8_t* packet,
67 : size_t* position,
68 : size_t max_length,
69 : PacketReadyCallback* callback) const override;
70 :
71 : size_t BlockLength() const override;
72 :
73 : private:
74 : // Size in bytes of a delta time in rtcp packet.
75 : // Valid values are 0 (packet wasn't received), 1 or 2.
76 : using DeltaSize = uint8_t;
77 : // Keeps DeltaSizes that can be encoded into single chunk if it is last chunk.
78 : class LastChunk;
79 : struct ReceivedPacket {
80 0 : ReceivedPacket(uint16_t sequence_number, int16_t delta_ticks)
81 0 : : sequence_number(sequence_number), delta_ticks(delta_ticks) {}
82 : uint16_t sequence_number;
83 : int16_t delta_ticks;
84 : };
85 :
86 : // Reset packet to consistent empty state.
87 : void Clear();
88 :
89 : bool AddDeltaSize(DeltaSize delta_size);
90 :
91 : uint16_t base_seq_no_;
92 : uint16_t num_seq_no_;
93 : int32_t base_time_ticks_;
94 : uint8_t feedback_seq_;
95 :
96 : int64_t last_timestamp_us_;
97 : std::vector<ReceivedPacket> packets_;
98 : // All but last encoded packet chunks.
99 : std::vector<uint16_t> encoded_chunks_;
100 : const std::unique_ptr<LastChunk> last_chunk_;
101 : size_t size_bytes_;
102 :
103 : RTC_DISALLOW_COPY_AND_ASSIGN(TransportFeedback);
104 : };
105 :
106 : } // namespace rtcp
107 : } // namespace webrtc
108 : #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_TRANSPORT_FEEDBACK_H_
|