rtcp_demuxer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  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. #ifndef CALL_RTCP_DEMUXER_H_
  11. #define CALL_RTCP_DEMUXER_H_
  12. #include <map>
  13. #include <string>
  14. #include <vector>
  15. #include "api/array_view.h"
  16. #include "call/ssrc_binding_observer.h"
  17. namespace webrtc {
  18. class RtcpPacketSinkInterface;
  19. // This class represents the RTCP demuxing, for a single RTP session (i.e., one
  20. // SSRC space, see RFC 7656). It isn't thread aware, leaving responsibility of
  21. // multithreading issues to the user of this class.
  22. class RtcpDemuxer : public SsrcBindingObserver {
  23. public:
  24. RtcpDemuxer();
  25. ~RtcpDemuxer() override;
  26. // Registers a sink. The sink will be notified of incoming RTCP packets with
  27. // that sender-SSRC. The same sink can be registered for multiple SSRCs, and
  28. // the same SSRC can have multiple sinks. Null pointer is not allowed.
  29. // Sinks may be associated with both an SSRC and an RSID.
  30. // Sinks may be registered as SSRC/RSID-specific or broadcast, but not both.
  31. void AddSink(uint32_t sender_ssrc, RtcpPacketSinkInterface* sink);
  32. // Registers a sink. Once the RSID is resolved to an SSRC, the sink will be
  33. // notified of all RTCP packets with that sender-SSRC.
  34. // The same sink can be registered for multiple RSIDs, and
  35. // the same RSID 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(const std::string& rsid, RtcpPacketSinkInterface* sink);
  39. // Registers a sink. The sink will be notified of any incoming RTCP packet.
  40. // Null pointer is not allowed.
  41. // Sinks may be registered as SSRC/RSID-specific or broadcast, but not both.
  42. void AddBroadcastSink(RtcpPacketSinkInterface* sink);
  43. // Undo previous AddSink() calls with the given sink.
  44. void RemoveSink(const RtcpPacketSinkInterface* sink);
  45. // Undo AddBroadcastSink().
  46. void RemoveBroadcastSink(const RtcpPacketSinkInterface* sink);
  47. // Process a new RTCP packet and forward it to the appropriate sinks.
  48. void OnRtcpPacket(rtc::ArrayView<const uint8_t> packet);
  49. // Implement SsrcBindingObserver - become notified whenever RSIDs resolve to
  50. // an SSRC.
  51. void OnSsrcBoundToRsid(const std::string& rsid, uint32_t ssrc) override;
  52. // TODO(eladalon): Add the ability to resolve RSIDs and inform observers,
  53. // like in the RtpDemuxer case, once the relevant standard is finalized.
  54. private:
  55. // Records the association SSRCs to sinks.
  56. std::multimap<uint32_t, RtcpPacketSinkInterface*> ssrc_sinks_;
  57. // Records the association RSIDs to sinks.
  58. std::multimap<std::string, RtcpPacketSinkInterface*> rsid_sinks_;
  59. // Sinks which will receive notifications of all incoming RTCP packets.
  60. // Additional/removal of sinks is expected to be significantly less frequent
  61. // than RTCP message reception; container chosen for iteration performance.
  62. std::vector<RtcpPacketSinkInterface*> broadcast_sinks_;
  63. };
  64. } // namespace webrtc
  65. #endif // CALL_RTCP_DEMUXER_H_