rtp_transceiver_interface.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 API_RTP_TRANSCEIVER_INTERFACE_H_
  11. #define API_RTP_TRANSCEIVER_INTERFACE_H_
  12. #include <string>
  13. #include <vector>
  14. #include "absl/types/optional.h"
  15. #include "api/array_view.h"
  16. #include "api/media_types.h"
  17. #include "api/rtp_parameters.h"
  18. #include "api/rtp_receiver_interface.h"
  19. #include "api/rtp_sender_interface.h"
  20. #include "api/rtp_transceiver_direction.h"
  21. #include "api/scoped_refptr.h"
  22. #include "rtc_base/ref_count.h"
  23. #include "rtc_base/system/rtc_export.h"
  24. namespace webrtc {
  25. // Structure for initializing an RtpTransceiver in a call to
  26. // PeerConnectionInterface::AddTransceiver.
  27. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverinit
  28. struct RTC_EXPORT RtpTransceiverInit final {
  29. RtpTransceiverInit();
  30. RtpTransceiverInit(const RtpTransceiverInit&);
  31. ~RtpTransceiverInit();
  32. // Direction of the RtpTransceiver. See RtpTransceiverInterface::direction().
  33. RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv;
  34. // The added RtpTransceiver will be added to these streams.
  35. std::vector<std::string> stream_ids;
  36. // TODO(bugs.webrtc.org/7600): Not implemented.
  37. std::vector<RtpEncodingParameters> send_encodings;
  38. };
  39. // The RtpTransceiverInterface maps to the RTCRtpTransceiver defined by the
  40. // WebRTC specification. A transceiver represents a combination of an RtpSender
  41. // and an RtpReceiver than share a common mid. As defined in JSEP, an
  42. // RtpTransceiver is said to be associated with a media description if its mid
  43. // property is non-null; otherwise, it is said to be disassociated.
  44. // JSEP: https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-24
  45. //
  46. // Note that RtpTransceivers are only supported when using PeerConnection with
  47. // Unified Plan SDP.
  48. //
  49. // This class is thread-safe.
  50. //
  51. // WebRTC specification for RTCRtpTransceiver, the JavaScript analog:
  52. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver
  53. class RTC_EXPORT RtpTransceiverInterface : public rtc::RefCountInterface {
  54. public:
  55. // Media type of the transceiver. Any sender(s)/receiver(s) will have this
  56. // type as well.
  57. virtual cricket::MediaType media_type() const = 0;
  58. // The mid attribute is the mid negotiated and present in the local and
  59. // remote descriptions. Before negotiation is complete, the mid value may be
  60. // null. After rollbacks, the value may change from a non-null value to null.
  61. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-mid
  62. virtual absl::optional<std::string> mid() const = 0;
  63. // The sender attribute exposes the RtpSender corresponding to the RTP media
  64. // that may be sent with the transceiver's mid. The sender is always present,
  65. // regardless of the direction of media.
  66. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-sender
  67. virtual rtc::scoped_refptr<RtpSenderInterface> sender() const = 0;
  68. // The receiver attribute exposes the RtpReceiver corresponding to the RTP
  69. // media that may be received with the transceiver's mid. The receiver is
  70. // always present, regardless of the direction of media.
  71. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-receiver
  72. virtual rtc::scoped_refptr<RtpReceiverInterface> receiver() const = 0;
  73. // The stopped attribute indicates that the sender of this transceiver will no
  74. // longer send, and that the receiver will no longer receive. It is true if
  75. // either stop has been called or if setting the local or remote description
  76. // has caused the RtpTransceiver to be stopped.
  77. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stopped
  78. virtual bool stopped() const = 0;
  79. // The direction attribute indicates the preferred direction of this
  80. // transceiver, which will be used in calls to CreateOffer and CreateAnswer.
  81. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
  82. virtual RtpTransceiverDirection direction() const = 0;
  83. // Sets the preferred direction of this transceiver. An update of
  84. // directionality does not take effect immediately. Instead, future calls to
  85. // CreateOffer and CreateAnswer mark the corresponding media descriptions as
  86. // sendrecv, sendonly, recvonly, or inactive.
  87. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
  88. virtual void SetDirection(RtpTransceiverDirection new_direction) = 0;
  89. // The current_direction attribute indicates the current direction negotiated
  90. // for this transceiver. If this transceiver has never been represented in an
  91. // offer/answer exchange, or if the transceiver is stopped, the value is null.
  92. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-currentdirection
  93. virtual absl::optional<RtpTransceiverDirection> current_direction() const = 0;
  94. // An internal slot designating for which direction the relevant
  95. // PeerConnection events have been fired. This is to ensure that events like
  96. // OnAddTrack only get fired once even if the same session description is
  97. // applied again.
  98. // Exposed in the public interface for use by Chromium.
  99. virtual absl::optional<RtpTransceiverDirection> fired_direction() const;
  100. // The Stop method irreversibly stops the RtpTransceiver. The sender of this
  101. // transceiver will no longer send, the receiver will no longer receive.
  102. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stop
  103. virtual void Stop() = 0;
  104. // The SetCodecPreferences method overrides the default codec preferences used
  105. // by WebRTC for this transceiver.
  106. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-setcodecpreferences
  107. virtual RTCError SetCodecPreferences(
  108. rtc::ArrayView<RtpCodecCapability> codecs);
  109. virtual std::vector<RtpCodecCapability> codec_preferences() const;
  110. // Readonly attribute which contains the set of header extensions that was set
  111. // with SetOfferedRtpHeaderExtensions, or a default set if it has not been
  112. // called.
  113. // https://w3c.github.io/webrtc-extensions/#rtcrtptransceiver-interface
  114. virtual std::vector<RtpHeaderExtensionCapability> HeaderExtensionsToOffer()
  115. const;
  116. protected:
  117. ~RtpTransceiverInterface() override = default;
  118. };
  119. } // namespace webrtc
  120. #endif // API_RTP_TRANSCEIVER_INTERFACE_H_