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