blob: e3e7cfa569c1bf3bc232216c83070f0719344072 [file] [log] [blame]
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +01001/*
2 * Copyright (c) 2017 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_RTCP_TRANSCEIVER_H_
12#define MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_H_
13
14#include <memory>
15#include <string>
16#include <vector>
17
18#include "modules/rtp_rtcp/source/rtcp_transceiver_config.h"
19#include "modules/rtp_rtcp/source/rtcp_transceiver_impl.h"
20#include "rtc_base/constructormagic.h"
21#include "rtc_base/copyonwritebuffer.h"
22#include "rtc_base/task_queue.h"
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010023
24namespace webrtc {
25//
26// Manage incoming and outgoing rtcp messages for multiple BUNDLED streams.
27//
28// This class is thread-safe wrapper of RtcpTransceiverImpl
Danil Chapovaloveb0edd82017-12-14 16:02:31 +010029class RtcpTransceiver : public RtcpFeedbackSenderInterface {
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010030 public:
31 explicit RtcpTransceiver(const RtcpTransceiverConfig& config);
Danil Chapovalovf0076d32018-09-05 16:46:40 +020032 // Blocks unless Stop was called.
33 // TODO(danilchap): Change destructor to never block by breaking assumption
34 // callbacks are not used after destruction.
Danil Chapovaloveb0edd82017-12-14 16:02:31 +010035 ~RtcpTransceiver() override;
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010036
Danil Chapovalovf0076d32018-09-05 16:46:40 +020037 // Start asynchronious destruction of the RtcpTransceiver.
38 // It is safe to call destructor right after Stop exits.
39 // No other methods can be called.
40 // Note that observers provided in constructor or registered with AddObserver
41 // still might be used by the transceiver until |on_destroyed| runs.
42 void Stop(std::unique_ptr<rtc::QueuedTask> on_destroyed);
43
Danil Chapovalova32d7102017-12-14 17:28:27 +010044 // Registers observer to be notified about incoming rtcp packets.
45 // Calls to observer will be done on the |config.task_queue|.
46 void AddMediaReceiverRtcpObserver(uint32_t remote_ssrc,
47 MediaReceiverRtcpObserver* observer);
48 // Deregisters the observer. Might return before observer is deregistered.
49 // Posts |on_removed| task when observer is deregistered.
50 void RemoveMediaReceiverRtcpObserver(
51 uint32_t remote_ssrc,
52 MediaReceiverRtcpObserver* observer,
53 std::unique_ptr<rtc::QueuedTask> on_removed);
54
Danil Chapovalove3927c52018-03-06 14:33:20 +010055 // Enables/disables sending rtcp packets eventually.
56 // Packets may be sent after the SetReadyToSend(false) returns, but no new
57 // packets will be scheduled.
58 void SetReadyToSend(bool ready);
59
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010060 // Handles incoming rtcp packets.
61 void ReceivePacket(rtc::CopyOnWriteBuffer packet);
62
63 // Sends RTCP packets starting with a sender or receiver report.
64 void SendCompoundPacket();
65
66 // (REMB) Receiver Estimated Max Bitrate.
67 // Includes REMB in following compound packets.
Danil Chapovaloveb0edd82017-12-14 16:02:31 +010068 void SetRemb(int64_t bitrate_bps, std::vector<uint32_t> ssrcs) override;
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010069 // Stops sending REMB in following compound packets.
Danil Chapovaloveb0edd82017-12-14 16:02:31 +010070 void UnsetRemb() override;
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010071
Danil Chapovalovd5cae4d2017-12-14 11:14:35 +010072 // TODO(bugs.webrtc.org/8239): Remove SendFeedbackPacket and SSRC functions
73 // and move generating of the TransportFeedback message inside
74 // RtcpTransceiverImpl when there is one RtcpTransceiver per rtp transport.
75
76 // Returns ssrc to put as sender ssrc into rtcp::TransportFeedback.
Danil Chapovaloveb0edd82017-12-14 16:02:31 +010077 uint32_t SSRC() const override;
78 bool SendFeedbackPacket(const rtcp::TransportFeedback& packet) override;
Danil Chapovalovd5cae4d2017-12-14 11:14:35 +010079
Danil Chapovalov327c43c2017-11-27 17:23:04 +010080 // Reports missing packets, https://tools.ietf.org/html/rfc4585#section-6.2.1
81 void SendNack(uint32_t ssrc, std::vector<uint16_t> sequence_numbers);
82
83 // Requests new key frame.
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +010084 // using PLI, https://tools.ietf.org/html/rfc4585#section-6.3.1.1
Danil Chapovalov8d19e032017-11-28 19:53:33 +010085 void SendPictureLossIndication(uint32_t ssrc);
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +010086 // using FIR, https://tools.ietf.org/html/rfc5104#section-4.3.1.2
87 void SendFullIntraRequest(std::vector<uint32_t> ssrcs);
Danil Chapovalova7e418c2017-11-21 11:08:53 +010088
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010089 private:
90 rtc::TaskQueue* const task_queue_;
91 std::unique_ptr<RtcpTransceiverImpl> rtcp_transceiver_;
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010092
93 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcpTransceiver);
94};
95
96} // namespace webrtc
97
98#endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_H_