rtp_transport.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright 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 PC_RTP_TRANSPORT_H_
  11. #define PC_RTP_TRANSPORT_H_
  12. #include <string>
  13. #include "call/rtp_demuxer.h"
  14. #include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
  15. #include "pc/rtp_transport_internal.h"
  16. #include "rtc_base/third_party/sigslot/sigslot.h"
  17. namespace rtc {
  18. class CopyOnWriteBuffer;
  19. struct PacketOptions;
  20. class PacketTransportInternal;
  21. } // namespace rtc
  22. namespace webrtc {
  23. class RtpTransport : public RtpTransportInternal {
  24. public:
  25. RtpTransport(const RtpTransport&) = delete;
  26. RtpTransport& operator=(const RtpTransport&) = delete;
  27. explicit RtpTransport(bool rtcp_mux_enabled)
  28. : rtcp_mux_enabled_(rtcp_mux_enabled) {}
  29. bool rtcp_mux_enabled() const override { return rtcp_mux_enabled_; }
  30. void SetRtcpMuxEnabled(bool enable) override;
  31. const std::string& transport_name() const override;
  32. int SetRtpOption(rtc::Socket::Option opt, int value) override;
  33. int SetRtcpOption(rtc::Socket::Option opt, int value) override;
  34. rtc::PacketTransportInternal* rtp_packet_transport() const {
  35. return rtp_packet_transport_;
  36. }
  37. void SetRtpPacketTransport(rtc::PacketTransportInternal* rtp);
  38. rtc::PacketTransportInternal* rtcp_packet_transport() const {
  39. return rtcp_packet_transport_;
  40. }
  41. void SetRtcpPacketTransport(rtc::PacketTransportInternal* rtcp);
  42. bool IsReadyToSend() const override { return ready_to_send_; }
  43. bool IsWritable(bool rtcp) const override;
  44. bool SendRtpPacket(rtc::CopyOnWriteBuffer* packet,
  45. const rtc::PacketOptions& options,
  46. int flags) override;
  47. bool SendRtcpPacket(rtc::CopyOnWriteBuffer* packet,
  48. const rtc::PacketOptions& options,
  49. int flags) override;
  50. bool IsSrtpActive() const override { return false; }
  51. void UpdateRtpHeaderExtensionMap(
  52. const cricket::RtpHeaderExtensions& header_extensions) override;
  53. bool RegisterRtpDemuxerSink(const RtpDemuxerCriteria& criteria,
  54. RtpPacketSinkInterface* sink) override;
  55. bool UnregisterRtpDemuxerSink(RtpPacketSinkInterface* sink) override;
  56. protected:
  57. // These methods will be used in the subclasses.
  58. void DemuxPacket(rtc::CopyOnWriteBuffer packet, int64_t packet_time_us);
  59. bool SendPacket(bool rtcp,
  60. rtc::CopyOnWriteBuffer* packet,
  61. const rtc::PacketOptions& options,
  62. int flags);
  63. // Overridden by SrtpTransport.
  64. virtual void OnNetworkRouteChanged(
  65. absl::optional<rtc::NetworkRoute> network_route);
  66. virtual void OnRtpPacketReceived(rtc::CopyOnWriteBuffer packet,
  67. int64_t packet_time_us);
  68. virtual void OnRtcpPacketReceived(rtc::CopyOnWriteBuffer packet,
  69. int64_t packet_time_us);
  70. // Overridden by SrtpTransport and DtlsSrtpTransport.
  71. virtual void OnWritableState(rtc::PacketTransportInternal* packet_transport);
  72. private:
  73. void OnReadyToSend(rtc::PacketTransportInternal* transport);
  74. void OnSentPacket(rtc::PacketTransportInternal* packet_transport,
  75. const rtc::SentPacket& sent_packet);
  76. void OnReadPacket(rtc::PacketTransportInternal* transport,
  77. const char* data,
  78. size_t len,
  79. const int64_t& packet_time_us,
  80. int flags);
  81. // Updates "ready to send" for an individual channel and fires
  82. // SignalReadyToSend.
  83. void SetReadyToSend(bool rtcp, bool ready);
  84. void MaybeSignalReadyToSend();
  85. bool IsTransportWritable();
  86. bool rtcp_mux_enabled_;
  87. rtc::PacketTransportInternal* rtp_packet_transport_ = nullptr;
  88. rtc::PacketTransportInternal* rtcp_packet_transport_ = nullptr;
  89. bool ready_to_send_ = false;
  90. bool rtp_ready_to_send_ = false;
  91. bool rtcp_ready_to_send_ = false;
  92. RtpDemuxer rtp_demuxer_;
  93. // Used for identifying the MID for RtpDemuxer.
  94. RtpHeaderExtensionMap header_extension_map_;
  95. };
  96. } // namespace webrtc
  97. #endif // PC_RTP_TRANSPORT_H_