blob: 494e0cea4b579a0940ad67bba4517266dbfe87a6 [file] [log] [blame]
eladalona52722f2017-06-26 11:23:54 -07001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef CALL_RTCP_DEMUXER_H_
12#define CALL_RTCP_DEMUXER_H_
eladalona52722f2017-06-26 11:23:54 -070013
14#include <map>
15#include <string>
16#include <vector>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/array_view.h"
19#include "call/ssrc_binding_observer.h"
eladalona52722f2017-06-26 11:23:54 -070020
21namespace webrtc {
22
23class RtcpPacketSinkInterface;
24
25// This class represents the RTCP demuxing, for a single RTP session (i.e., one
26// SSRC space, see RFC 7656). It isn't thread aware, leaving responsibility of
27// multithreading issues to the user of this class.
Steve Antonb3329172017-08-17 15:23:51 -070028class RtcpDemuxer : public SsrcBindingObserver {
eladalona52722f2017-06-26 11:23:54 -070029 public:
30 RtcpDemuxer();
31 ~RtcpDemuxer() override;
32
33 // Registers a sink. The sink will be notified of incoming RTCP packets with
34 // that sender-SSRC. The same sink can be registered for multiple SSRCs, and
35 // the same SSRC can have multiple sinks. Null pointer is not allowed.
36 // Sinks may be associated with both an SSRC and an RSID.
37 // Sinks may be registered as SSRC/RSID-specific or broadcast, but not both.
38 void AddSink(uint32_t sender_ssrc, RtcpPacketSinkInterface* sink);
39
40 // Registers a sink. Once the RSID is resolved to an SSRC, the sink will be
41 // notified of all RTCP packets with that sender-SSRC.
42 // The same sink can be registered for multiple RSIDs, and
43 // the same RSID can have multiple sinks. Null pointer is not allowed.
44 // Sinks may be associated with both an SSRC and an RSID.
45 // Sinks may be registered as SSRC/RSID-specific or broadcast, but not both.
46 void AddSink(const std::string& rsid, RtcpPacketSinkInterface* sink);
47
48 // Registers a sink. The sink will be notified of any incoming RTCP packet.
49 // Null pointer is not allowed.
50 // Sinks may be registered as SSRC/RSID-specific or broadcast, but not both.
51 void AddBroadcastSink(RtcpPacketSinkInterface* sink);
52
53 // Undo previous AddSink() calls with the given sink.
54 void RemoveSink(const RtcpPacketSinkInterface* sink);
55
56 // Undo AddBroadcastSink().
57 void RemoveBroadcastSink(const RtcpPacketSinkInterface* sink);
58
59 // Process a new RTCP packet and forward it to the appropriate sinks.
60 void OnRtcpPacket(rtc::ArrayView<const uint8_t> packet);
61
Steve Antonb3329172017-08-17 15:23:51 -070062 // Implement SsrcBindingObserver - become notified whenever RSIDs resolve to
63 // an SSRC.
64 void OnSsrcBoundToRsid(const std::string& rsid, uint32_t ssrc) override;
eladalona52722f2017-06-26 11:23:54 -070065
66 // TODO(eladalon): Add the ability to resolve RSIDs and inform observers,
67 // like in the RtpDemuxer case, once the relevant standard is finalized.
68
69 private:
70 // Records the association SSRCs to sinks.
71 std::multimap<uint32_t, RtcpPacketSinkInterface*> ssrc_sinks_;
72
73 // Records the association RSIDs to sinks.
74 std::multimap<std::string, RtcpPacketSinkInterface*> rsid_sinks_;
75
76 // Sinks which will receive notifications of all incoming RTCP packets.
77 // Additional/removal of sinks is expected to be significantly less frequent
78 // than RTCP message reception; container chosen for iteration performance.
79 std::vector<RtcpPacketSinkInterface*> broadcast_sinks_;
80};
81
82} // namespace webrtc
83
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020084#endif // CALL_RTCP_DEMUXER_H_