blob: 06294b479708cf2b7a4f0664adda697ab9d6fa8f [file] [log] [blame]
brandtra8b38552016-10-10 16:44:57 -07001/*
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 WEBRTC_MODULES_RTP_RTCP_INCLUDE_FLEXFEC_RECEIVER_H_
12#define WEBRTC_MODULES_RTP_RTCP_INCLUDE_FLEXFEC_RECEIVER_H_
13
14#include <memory>
15
16#include "webrtc/base/basictypes.h"
brandtr0a4c1612016-11-03 08:18:27 -070017#include "webrtc/base/sequenced_task_checker.h"
18#include "webrtc/call.h"
19#include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h"
brandtrd55c3f62016-10-31 04:51:33 -070020#include "webrtc/modules/rtp_rtcp/include/ulpfec_receiver.h"
brandtr0a4c1612016-11-03 08:18:27 -070021#include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h"
22#include "webrtc/system_wrappers/include/clock.h"
brandtra8b38552016-10-10 16:44:57 -070023
24namespace webrtc {
25
brandtr4e523862016-10-18 23:50:45 -070026// Callback interface for packets recovered by FlexFEC. The implementation
27// should be able to demultiplex the recovered RTP packets based on SSRC.
brandtra8b38552016-10-10 16:44:57 -070028class RecoveredPacketReceiver {
29 public:
30 virtual bool OnRecoveredPacket(const uint8_t* packet, size_t length) = 0;
31
32 protected:
33 virtual ~RecoveredPacketReceiver() = default;
34};
35
36class FlexfecReceiver {
37 public:
brandtr0a4c1612016-11-03 08:18:27 -070038 FlexfecReceiver(uint32_t ssrc,
39 uint32_t protected_media_ssrc,
40 RecoveredPacketReceiver* callback);
41 ~FlexfecReceiver();
brandtra8b38552016-10-10 16:44:57 -070042
43 // Inserts a received packet (can be either media or FlexFEC) into the
44 // internal buffer, and sends the received packets to the erasure code.
45 // All newly recovered packets are sent back through the callback.
brandtr0a4c1612016-11-03 08:18:27 -070046 bool AddAndProcessReceivedPacket(const uint8_t* packet, size_t packet_length);
brandtra8b38552016-10-10 16:44:57 -070047
48 // Returns a counter describing the added and recovered packets.
brandtr0a4c1612016-11-03 08:18:27 -070049 FecPacketCounter GetPacketCounter() const;
50
51 private:
52 bool AddReceivedPacket(const uint8_t* packet, size_t packet_length);
53 bool ProcessReceivedPackets();
54
55 // Config.
56 const uint32_t ssrc_;
57 const uint32_t protected_media_ssrc_;
58
59 // Erasure code interfacing and callback.
60 std::unique_ptr<ForwardErrorCorrection> erasure_code_;
61 ForwardErrorCorrection::ReceivedPacketList received_packets_;
62 ForwardErrorCorrection::RecoveredPacketList recovered_packets_;
63 RecoveredPacketReceiver* const callback_;
64
65 // Logging and stats.
66 Clock* const clock_;
67 int64_t last_recovered_packet_ms_;
68 FecPacketCounter packet_counter_;
69
70 rtc::SequencedTaskChecker sequence_checker_;
brandtra8b38552016-10-10 16:44:57 -070071};
72
73} // namespace webrtc
74
75#endif // WEBRTC_MODULES_RTP_RTCP_INCLUDE_FLEXFEC_RECEIVER_H_