blob: a15864e34a2d5068a143de37e51773a6f6d72642 [file] [log] [blame]
deadbeef6979b022015-09-24 16:47:53 -07001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
deadbeef6979b022015-09-24 16:47:53 -07003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
deadbeef6979b022015-09-24 16:47:53 -07009 */
10
deadbeef70ab1a12015-09-28 16:53:55 -070011// This file contains interfaces for RtpReceivers
12// http://w3c.github.io/webrtc-pc/#rtcrtpreceiver-interface
13
Steve Anton10542f22019-01-11 09:11:00 -080014#ifndef API_RTP_RECEIVER_INTERFACE_H_
15#define API_RTP_RECEIVER_INTERFACE_H_
deadbeef70ab1a12015-09-28 16:53:55 -070016
17#include <string>
hbos8d609f62017-04-10 07:39:05 -070018#include <vector>
deadbeef70ab1a12015-09-28 16:53:55 -070019
Steve Anton10542f22019-01-11 09:11:00 -080020#include "api/crypto/frame_decryptor_interface.h"
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +010021#include "api/dtls_transport_interface.h"
Marina Ciocea412a31b2020-02-28 16:02:06 +010022#include "api/frame_transformer_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "api/media_stream_interface.h"
24#include "api/media_types.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "api/proxy.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "api/rtp_parameters.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010027#include "api/scoped_refptr.h"
Niels Möllera8370302019-09-02 15:16:49 +020028#include "api/transport/rtp/rtp_source.h"
Johannes Kronb5d91832019-05-21 13:19:22 +020029#include "rtc_base/deprecation.h"
Steve Anton10542f22019-01-11 09:11:00 -080030#include "rtc_base/ref_count.h"
Mirko Bonadei35214fc2019-09-23 14:54:28 +020031#include "rtc_base/system/rtc_export.h"
deadbeef70ab1a12015-09-28 16:53:55 -070032
33namespace webrtc {
34
zhihuang184a3fd2016-06-14 11:47:14 -070035class RtpReceiverObserverInterface {
36 public:
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070037 // Note: Currently if there are multiple RtpReceivers of the same media type,
38 // they will all call OnFirstPacketReceived at once.
39 //
40 // In the future, it's likely that an RtpReceiver will only call
41 // OnFirstPacketReceived when a packet is received specifically for its
42 // SSRC/mid.
zhihuang184a3fd2016-06-14 11:47:14 -070043 virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0;
44
45 protected:
46 virtual ~RtpReceiverObserverInterface() {}
47};
48
Mirko Bonadei35214fc2019-09-23 14:54:28 +020049class RTC_EXPORT RtpReceiverInterface : public rtc::RefCountInterface {
deadbeef70ab1a12015-09-28 16:53:55 -070050 public:
51 virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0;
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +010052
53 // The dtlsTransport attribute exposes the DTLS transport on which the
54 // media is received. It may be null.
55 // https://w3c.github.io/webrtc-pc/#dom-rtcrtpreceiver-transport
56 // TODO(https://bugs.webrtc.org/907849) remove default implementation
57 virtual rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const;
58
Henrik Boström9e6fd2b2017-11-21 13:41:51 +010059 // The list of streams that |track| is associated with. This is the same as
60 // the [[AssociatedRemoteMediaStreams]] internal slot in the spec.
Henrik Boström199e27b2018-07-04 20:51:53 +020061 // https://w3c.github.io/webrtc-pc/#dfn-associatedremotemediastreams
Henrik Boström9e6fd2b2017-11-21 13:41:51 +010062 // TODO(hbos): Make pure virtual as soon as Chromium's mock implements this.
Henrik Boström199e27b2018-07-04 20:51:53 +020063 // TODO(https://crbug.com/webrtc/9480): Remove streams() in favor of
64 // stream_ids() as soon as downstream projects are no longer dependent on
65 // stream objects.
66 virtual std::vector<std::string> stream_ids() const;
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +010067 virtual std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams() const;
deadbeef70ab1a12015-09-28 16:53:55 -070068
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070069 // Audio or video receiver?
70 virtual cricket::MediaType media_type() const = 0;
71
deadbeef70ab1a12015-09-28 16:53:55 -070072 // Not to be confused with "mid", this is a field we can temporarily use
73 // to uniquely identify a receiver until we implement Unified Plan SDP.
74 virtual std::string id() const = 0;
75
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -070076 // The WebRTC specification only defines RTCRtpParameters in terms of senders,
77 // but this API also applies them to receivers, similar to ORTC:
78 // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*.
79 virtual RtpParameters GetParameters() const = 0;
Saurav Das934afc62019-11-21 11:54:16 -080080 // TODO(dinosaurav): Delete SetParameters entirely after rolling to Chromium.
81 // Currently, doesn't support changing any parameters.
82 virtual bool SetParameters(const RtpParameters& parameters) { return false; }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -070083
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070084 // Does not take ownership of observer.
85 // Must call SetObserver(nullptr) before the observer is destroyed.
zhihuang184a3fd2016-06-14 11:47:14 -070086 virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0;
87
Ruslan Burakov4bac79e2019-04-03 19:55:33 +020088 // Sets the jitter buffer minimum delay until media playout. Actual observed
89 // delay may differ depending on the congestion control. |delay_seconds| is a
90 // positive value including 0.0 measured in seconds. |nullopt| means default
Ruslan Burakov428dcb22019-04-18 17:49:49 +020091 // value must be used.
Ruslan Burakov4bac79e2019-04-03 19:55:33 +020092 virtual void SetJitterBufferMinimumDelay(
Ruslan Burakov428dcb22019-04-18 17:49:49 +020093 absl::optional<double> delay_seconds) = 0;
Ruslan Burakov4bac79e2019-04-03 19:55:33 +020094
hbos8d609f62017-04-10 07:39:05 -070095 // TODO(zhihuang): Remove the default implementation once the subclasses
96 // implement this. Currently, the only relevant subclass is the
97 // content::FakeRtpReceiver in Chromium.
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +010098 virtual std::vector<RtpSource> GetSources() const;
99
Benjamin Wrightd81ac952018-08-29 17:02:10 -0700100 // Sets a user defined frame decryptor that will decrypt the entire frame
101 // before it is sent across the network. This will decrypt the entire frame
102 // using the user provided decryption mechanism regardless of whether SRTP is
103 // enabled or not.
104 virtual void SetFrameDecryptor(
105 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor);
106
107 // Returns a pointer to the frame decryptor set previously by the
108 // user. This can be used to update the state of the object.
109 virtual rtc::scoped_refptr<FrameDecryptorInterface> GetFrameDecryptor() const;
110
Marina Ciocea412a31b2020-02-28 16:02:06 +0100111 // Sets a frame transformer between the depacketizer and the decoder to enable
112 // client code to transform received frames according to their own processing
113 // logic.
114 virtual void SetDepacketizerToDecoderFrameTransformer(
115 rtc::scoped_refptr<FrameTransformerInterface> frame_transformer);
116
deadbeef70ab1a12015-09-28 16:53:55 -0700117 protected:
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100118 ~RtpReceiverInterface() override = default;
deadbeef70ab1a12015-09-28 16:53:55 -0700119};
120
121// Define proxy for RtpReceiverInterface.
deadbeefb10f32f2017-02-08 01:38:21 -0800122// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods
123// are called on is an implementation detail.
nisse72c8d2b2016-04-15 03:49:07 -0700124BEGIN_SIGNALING_PROXY_MAP(RtpReceiver)
Yves Gerey665174f2018-06-19 15:03:05 +0200125PROXY_SIGNALING_THREAD_DESTRUCTOR()
126PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track)
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100127PROXY_CONSTMETHOD0(rtc::scoped_refptr<DtlsTransportInterface>, dtls_transport)
Henrik Boström5b147782018-12-04 11:25:05 +0100128PROXY_CONSTMETHOD0(std::vector<std::string>, stream_ids)
Yves Gerey665174f2018-06-19 15:03:05 +0200129PROXY_CONSTMETHOD0(std::vector<rtc::scoped_refptr<MediaStreamInterface>>,
130 streams)
131PROXY_CONSTMETHOD0(cricket::MediaType, media_type)
132PROXY_CONSTMETHOD0(std::string, id)
Nico Weber22f99252019-02-20 10:13:16 -0500133PROXY_CONSTMETHOD0(RtpParameters, GetParameters)
Nico Weber22f99252019-02-20 10:13:16 -0500134PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*)
Ruslan Burakov4bac79e2019-04-03 19:55:33 +0200135PROXY_METHOD1(void, SetJitterBufferMinimumDelay, absl::optional<double>)
Nico Weber22f99252019-02-20 10:13:16 -0500136PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources)
Benjamin Wrightd81ac952018-08-29 17:02:10 -0700137PROXY_METHOD1(void,
138 SetFrameDecryptor,
Nico Weber22f99252019-02-20 10:13:16 -0500139 rtc::scoped_refptr<FrameDecryptorInterface>)
Benjamin Wrightd81ac952018-08-29 17:02:10 -0700140PROXY_CONSTMETHOD0(rtc::scoped_refptr<FrameDecryptorInterface>,
Nico Weber22f99252019-02-20 10:13:16 -0500141 GetFrameDecryptor)
Marina Ciocea412a31b2020-02-28 16:02:06 +0100142PROXY_METHOD1(void,
143 SetDepacketizerToDecoderFrameTransformer,
144 rtc::scoped_refptr<FrameTransformerInterface>)
Yves Gerey665174f2018-06-19 15:03:05 +0200145END_PROXY_MAP()
deadbeef70ab1a12015-09-28 16:53:55 -0700146
147} // namespace webrtc
148
Steve Anton10542f22019-01-11 09:11:00 -0800149#endif // API_RTP_RECEIVER_INTERFACE_H_