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