rtp_transceiver_interface.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 stopping attribute indicates that the user has indicated that the
  80. // sender of this transceiver will stop sending, and that the receiver will
  81. // no longer receive. It is always true if stopped() is true.
  82. // If stopping() is true and stopped() is false, it means that the
  83. // transceiver's stop() method has been called, but the negotiation with
  84. // the other end for shutting down the transceiver is not yet done.
  85. // https://w3c.github.io/webrtc-pc/#dfn-stopping-0
  86. // TODO(hta): Remove default implementation.
  87. virtual bool stopping() const;
  88. // The direction attribute indicates the preferred direction of this
  89. // transceiver, which will be used in calls to CreateOffer and CreateAnswer.
  90. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
  91. virtual RtpTransceiverDirection direction() const = 0;
  92. // Sets the preferred direction of this transceiver. An update of
  93. // directionality does not take effect immediately. Instead, future calls to
  94. // CreateOffer and CreateAnswer mark the corresponding media descriptions as
  95. // sendrecv, sendonly, recvonly, or inactive.
  96. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
  97. // TODO(hta): Deprecate SetDirection without error and rename
  98. // SetDirectionWithError to SetDirection, remove default implementations.
  99. RTC_DEPRECATED virtual void SetDirection(
  100. RtpTransceiverDirection new_direction);
  101. virtual RTCError SetDirectionWithError(RtpTransceiverDirection new_direction);
  102. // The current_direction attribute indicates the current direction negotiated
  103. // for this transceiver. If this transceiver has never been represented in an
  104. // offer/answer exchange, or if the transceiver is stopped, the value is null.
  105. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-currentdirection
  106. virtual absl::optional<RtpTransceiverDirection> current_direction() const = 0;
  107. // An internal slot designating for which direction the relevant
  108. // PeerConnection events have been fired. This is to ensure that events like
  109. // OnAddTrack only get fired once even if the same session description is
  110. // applied again.
  111. // Exposed in the public interface for use by Chromium.
  112. virtual absl::optional<RtpTransceiverDirection> fired_direction() const;
  113. // Initiates a stop of the transceiver.
  114. // The stop is complete when stopped() returns true.
  115. // A stopped transceiver can be reused for a different track.
  116. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stop
  117. // TODO(hta): Rename to Stop() when users of the non-standard Stop() are
  118. // updated.
  119. virtual RTCError StopStandard();
  120. // Stops a transceiver immediately, without waiting for signalling.
  121. // This is an internal function, and is exposed for historical reasons.
  122. // https://w3c.github.io/webrtc-pc/#dfn-stop-the-rtcrtptransceiver
  123. virtual void StopInternal();
  124. RTC_DEPRECATED virtual void Stop();
  125. // The SetCodecPreferences method overrides the default codec preferences used
  126. // by WebRTC for this transceiver.
  127. // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-setcodecpreferences
  128. virtual RTCError SetCodecPreferences(
  129. rtc::ArrayView<RtpCodecCapability> codecs);
  130. virtual std::vector<RtpCodecCapability> codec_preferences() const;
  131. // Readonly attribute which contains the set of header extensions that was set
  132. // with SetOfferedRtpHeaderExtensions, or a default set if it has not been
  133. // called.
  134. // https://w3c.github.io/webrtc-extensions/#rtcrtptransceiver-interface
  135. virtual std::vector<RtpHeaderExtensionCapability> HeaderExtensionsToOffer()
  136. const;
  137. // The SetOfferedRtpHeaderExtensions method modifies the next SDP negotiation
  138. // so that it negotiates use of header extensions which are not kStopped.
  139. // https://w3c.github.io/webrtc-extensions/#rtcrtptransceiver-interface
  140. virtual webrtc::RTCError SetOfferedRtpHeaderExtensions(
  141. rtc::ArrayView<const RtpHeaderExtensionCapability>
  142. header_extensions_to_offer);
  143. protected:
  144. ~RtpTransceiverInterface() override = default;
  145. };
  146. } // namespace webrtc
  147. #endif // API_RTP_TRANSCEIVER_INTERFACE_H_