blob: 8ce2db524360a6092ac00c710411e52a69ef08a3 [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"
23#include "rtc_base/weak_ptr.h"
24
25namespace webrtc {
26//
27// Manage incoming and outgoing rtcp messages for multiple BUNDLED streams.
28//
29// This class is thread-safe wrapper of RtcpTransceiverImpl
30class RtcpTransceiver {
31 public:
32 explicit RtcpTransceiver(const RtcpTransceiverConfig& config);
33 ~RtcpTransceiver();
34
Danil Chapovalova32d7102017-12-14 17:28:27 +010035 // Registers observer to be notified about incoming rtcp packets.
36 // Calls to observer will be done on the |config.task_queue|.
37 void AddMediaReceiverRtcpObserver(uint32_t remote_ssrc,
38 MediaReceiverRtcpObserver* observer);
39 // Deregisters the observer. Might return before observer is deregistered.
40 // Posts |on_removed| task when observer is deregistered.
41 void RemoveMediaReceiverRtcpObserver(
42 uint32_t remote_ssrc,
43 MediaReceiverRtcpObserver* observer,
44 std::unique_ptr<rtc::QueuedTask> on_removed);
45
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010046 // Handles incoming rtcp packets.
47 void ReceivePacket(rtc::CopyOnWriteBuffer packet);
48
49 // Sends RTCP packets starting with a sender or receiver report.
50 void SendCompoundPacket();
51
52 // (REMB) Receiver Estimated Max Bitrate.
53 // Includes REMB in following compound packets.
Danil Chapovalov1de4b622017-12-13 13:35:10 +010054 void SetRemb(int64_t bitrate_bps, std::vector<uint32_t> ssrcs);
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010055 // Stops sending REMB in following compound packets.
56 void UnsetRemb();
57
Danil Chapovalovd5cae4d2017-12-14 11:14:35 +010058 // TODO(bugs.webrtc.org/8239): Remove SendFeedbackPacket and SSRC functions
59 // and move generating of the TransportFeedback message inside
60 // RtcpTransceiverImpl when there is one RtcpTransceiver per rtp transport.
61
62 // Returns ssrc to put as sender ssrc into rtcp::TransportFeedback.
63 uint32_t SSRC() const;
64 bool SendFeedbackPacket(const rtcp::TransportFeedback& packet);
65
Danil Chapovalov327c43c2017-11-27 17:23:04 +010066 // Reports missing packets, https://tools.ietf.org/html/rfc4585#section-6.2.1
67 void SendNack(uint32_t ssrc, std::vector<uint16_t> sequence_numbers);
68
69 // Requests new key frame.
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +010070 // using PLI, https://tools.ietf.org/html/rfc4585#section-6.3.1.1
Danil Chapovalov8d19e032017-11-28 19:53:33 +010071 void SendPictureLossIndication(uint32_t ssrc);
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +010072 // using FIR, https://tools.ietf.org/html/rfc5104#section-4.3.1.2
73 void SendFullIntraRequest(std::vector<uint32_t> ssrcs);
Danil Chapovalova7e418c2017-11-21 11:08:53 +010074
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010075 private:
76 rtc::TaskQueue* const task_queue_;
77 std::unique_ptr<RtcpTransceiverImpl> rtcp_transceiver_;
78 rtc::WeakPtrFactory<RtcpTransceiverImpl> ptr_factory_;
79 // TaskQueue, and thus tasks posted to it, may outlive this.
80 // Thus when Posting task class always pass copy of the weak_ptr to access
81 // the RtcpTransceiver and never guarantee it still will be alive when task
82 // runs.
83 rtc::WeakPtr<RtcpTransceiverImpl> ptr_;
84
85 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcpTransceiver);
86};
87
88} // namespace webrtc
89
90#endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_H_