rtp_receiver_interface.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright 2015 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. // This file contains interfaces for RtpReceivers
  11. // http://w3c.github.io/webrtc-pc/#rtcrtpreceiver-interface
  12. #ifndef API_RTP_RECEIVER_INTERFACE_H_
  13. #define API_RTP_RECEIVER_INTERFACE_H_
  14. #include <string>
  15. #include <vector>
  16. #include "api/crypto/frame_decryptor_interface.h"
  17. #include "api/dtls_transport_interface.h"
  18. #include "api/frame_transformer_interface.h"
  19. #include "api/media_stream_interface.h"
  20. #include "api/media_types.h"
  21. #include "api/proxy.h"
  22. #include "api/rtp_parameters.h"
  23. #include "api/scoped_refptr.h"
  24. #include "api/transport/rtp/rtp_source.h"
  25. #include "rtc_base/deprecation.h"
  26. #include "rtc_base/ref_count.h"
  27. #include "rtc_base/system/rtc_export.h"
  28. namespace webrtc {
  29. class RtpReceiverObserverInterface {
  30. public:
  31. // Note: Currently if there are multiple RtpReceivers of the same media type,
  32. // they will all call OnFirstPacketReceived at once.
  33. //
  34. // In the future, it's likely that an RtpReceiver will only call
  35. // OnFirstPacketReceived when a packet is received specifically for its
  36. // SSRC/mid.
  37. virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0;
  38. protected:
  39. virtual ~RtpReceiverObserverInterface() {}
  40. };
  41. class RTC_EXPORT RtpReceiverInterface : public rtc::RefCountInterface {
  42. public:
  43. virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0;
  44. // The dtlsTransport attribute exposes the DTLS transport on which the
  45. // media is received. It may be null.
  46. // https://w3c.github.io/webrtc-pc/#dom-rtcrtpreceiver-transport
  47. // TODO(https://bugs.webrtc.org/907849) remove default implementation
  48. virtual rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const;
  49. // The list of streams that |track| is associated with. This is the same as
  50. // the [[AssociatedRemoteMediaStreams]] internal slot in the spec.
  51. // https://w3c.github.io/webrtc-pc/#dfn-associatedremotemediastreams
  52. // TODO(hbos): Make pure virtual as soon as Chromium's mock implements this.
  53. // TODO(https://crbug.com/webrtc/9480): Remove streams() in favor of
  54. // stream_ids() as soon as downstream projects are no longer dependent on
  55. // stream objects.
  56. virtual std::vector<std::string> stream_ids() const;
  57. virtual std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams() const;
  58. // Audio or video receiver?
  59. virtual cricket::MediaType media_type() const = 0;
  60. // Not to be confused with "mid", this is a field we can temporarily use
  61. // to uniquely identify a receiver until we implement Unified Plan SDP.
  62. virtual std::string id() const = 0;
  63. // The WebRTC specification only defines RTCRtpParameters in terms of senders,
  64. // but this API also applies them to receivers, similar to ORTC:
  65. // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*.
  66. virtual RtpParameters GetParameters() const = 0;
  67. // TODO(dinosaurav): Delete SetParameters entirely after rolling to Chromium.
  68. // Currently, doesn't support changing any parameters.
  69. virtual bool SetParameters(const RtpParameters& parameters) { return false; }
  70. // Does not take ownership of observer.
  71. // Must call SetObserver(nullptr) before the observer is destroyed.
  72. virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0;
  73. // Sets the jitter buffer minimum delay until media playout. Actual observed
  74. // delay may differ depending on the congestion control. |delay_seconds| is a
  75. // positive value including 0.0 measured in seconds. |nullopt| means default
  76. // value must be used.
  77. virtual void SetJitterBufferMinimumDelay(
  78. absl::optional<double> delay_seconds) = 0;
  79. // TODO(zhihuang): Remove the default implementation once the subclasses
  80. // implement this. Currently, the only relevant subclass is the
  81. // content::FakeRtpReceiver in Chromium.
  82. virtual std::vector<RtpSource> GetSources() const;
  83. // Sets a user defined frame decryptor that will decrypt the entire frame
  84. // before it is sent across the network. This will decrypt the entire frame
  85. // using the user provided decryption mechanism regardless of whether SRTP is
  86. // enabled or not.
  87. virtual void SetFrameDecryptor(
  88. rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor);
  89. // Returns a pointer to the frame decryptor set previously by the
  90. // user. This can be used to update the state of the object.
  91. virtual rtc::scoped_refptr<FrameDecryptorInterface> GetFrameDecryptor() const;
  92. // Sets a frame transformer between the depacketizer and the decoder to enable
  93. // client code to transform received frames according to their own processing
  94. // logic.
  95. virtual void SetDepacketizerToDecoderFrameTransformer(
  96. rtc::scoped_refptr<FrameTransformerInterface> frame_transformer);
  97. protected:
  98. ~RtpReceiverInterface() override = default;
  99. };
  100. // Define proxy for RtpReceiverInterface.
  101. // TODO(deadbeef): Move this to .cc file and out of api/. What threads methods
  102. // are called on is an implementation detail.
  103. BEGIN_SIGNALING_PROXY_MAP(RtpReceiver)
  104. PROXY_SIGNALING_THREAD_DESTRUCTOR()
  105. PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track)
  106. PROXY_CONSTMETHOD0(rtc::scoped_refptr<DtlsTransportInterface>, dtls_transport)
  107. PROXY_CONSTMETHOD0(std::vector<std::string>, stream_ids)
  108. PROXY_CONSTMETHOD0(std::vector<rtc::scoped_refptr<MediaStreamInterface>>,
  109. streams)
  110. BYPASS_PROXY_CONSTMETHOD0(cricket::MediaType, media_type)
  111. BYPASS_PROXY_CONSTMETHOD0(std::string, id)
  112. PROXY_CONSTMETHOD0(RtpParameters, GetParameters)
  113. PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*)
  114. PROXY_METHOD1(void, SetJitterBufferMinimumDelay, absl::optional<double>)
  115. PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources)
  116. PROXY_METHOD1(void,
  117. SetFrameDecryptor,
  118. rtc::scoped_refptr<FrameDecryptorInterface>)
  119. PROXY_CONSTMETHOD0(rtc::scoped_refptr<FrameDecryptorInterface>,
  120. GetFrameDecryptor)
  121. PROXY_METHOD1(void,
  122. SetDepacketizerToDecoderFrameTransformer,
  123. rtc::scoped_refptr<FrameTransformerInterface>)
  124. END_PROXY_MAP()
  125. } // namespace webrtc
  126. #endif // API_RTP_RECEIVER_INTERFACE_H_