blob: 7d9870b8f1b9086e01b6096faac65de8b1d1a74e [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"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "api/media_stream_interface.h"
23#include "api/media_types.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "api/proxy.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "api/rtp_parameters.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010026#include "api/scoped_refptr.h"
Steve Anton10542f22019-01-11 09:11:00 -080027#include "rtc_base/ref_count.h"
deadbeef70ab1a12015-09-28 16:53:55 -070028
29namespace webrtc {
30
hbos8d609f62017-04-10 07:39:05 -070031enum class RtpSourceType {
32 SSRC,
33 CSRC,
34};
35
36class RtpSource {
37 public:
38 RtpSource() = delete;
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +010039 RtpSource(int64_t timestamp_ms,
40 uint32_t source_id,
41 RtpSourceType source_type);
zstein2b706342017-08-24 14:52:17 -070042 RtpSource(int64_t timestamp_ms,
43 uint32_t source_id,
44 RtpSourceType source_type,
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +010045 uint8_t audio_level);
46 RtpSource(const RtpSource&);
47 RtpSource& operator=(const RtpSource&);
48 ~RtpSource();
zstein2b706342017-08-24 14:52:17 -070049
hbos8d609f62017-04-10 07:39:05 -070050 int64_t timestamp_ms() const { return timestamp_ms_; }
51 void update_timestamp_ms(int64_t timestamp_ms) {
52 RTC_DCHECK_LE(timestamp_ms_, timestamp_ms);
53 timestamp_ms_ = timestamp_ms;
54 }
55
56 // The identifier of the source can be the CSRC or the SSRC.
57 uint32_t source_id() const { return source_id_; }
58
59 // The source can be either a contributing source or a synchronization source.
60 RtpSourceType source_type() const { return source_type_; }
61
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020062 absl::optional<uint8_t> audio_level() const { return audio_level_; }
63 void set_audio_level(const absl::optional<uint8_t>& level) {
zstein2b706342017-08-24 14:52:17 -070064 audio_level_ = level;
65 }
hbos8d609f62017-04-10 07:39:05 -070066
zhihuang04262222017-04-11 11:28:10 -070067 bool operator==(const RtpSource& o) const {
68 return timestamp_ms_ == o.timestamp_ms() && source_id_ == o.source_id() &&
zstein2b706342017-08-24 14:52:17 -070069 source_type_ == o.source_type() && audio_level_ == o.audio_level_;
zhihuang04262222017-04-11 11:28:10 -070070 }
71
hbos8d609f62017-04-10 07:39:05 -070072 private:
73 int64_t timestamp_ms_;
74 uint32_t source_id_;
75 RtpSourceType source_type_;
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020076 absl::optional<uint8_t> audio_level_;
hbos8d609f62017-04-10 07:39:05 -070077};
78
zhihuang184a3fd2016-06-14 11:47:14 -070079class RtpReceiverObserverInterface {
80 public:
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070081 // Note: Currently if there are multiple RtpReceivers of the same media type,
82 // they will all call OnFirstPacketReceived at once.
83 //
84 // In the future, it's likely that an RtpReceiver will only call
85 // OnFirstPacketReceived when a packet is received specifically for its
86 // SSRC/mid.
zhihuang184a3fd2016-06-14 11:47:14 -070087 virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0;
88
89 protected:
90 virtual ~RtpReceiverObserverInterface() {}
91};
92
deadbeef70ab1a12015-09-28 16:53:55 -070093class RtpReceiverInterface : public rtc::RefCountInterface {
94 public:
95 virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0;
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +010096
97 // The dtlsTransport attribute exposes the DTLS transport on which the
98 // media is received. It may be null.
99 // https://w3c.github.io/webrtc-pc/#dom-rtcrtpreceiver-transport
100 // TODO(https://bugs.webrtc.org/907849) remove default implementation
101 virtual rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const;
102
Henrik Boström9e6fd2b2017-11-21 13:41:51 +0100103 // The list of streams that |track| is associated with. This is the same as
104 // the [[AssociatedRemoteMediaStreams]] internal slot in the spec.
Henrik Boström199e27b2018-07-04 20:51:53 +0200105 // https://w3c.github.io/webrtc-pc/#dfn-associatedremotemediastreams
Henrik Boström9e6fd2b2017-11-21 13:41:51 +0100106 // TODO(hbos): Make pure virtual as soon as Chromium's mock implements this.
Henrik Boström199e27b2018-07-04 20:51:53 +0200107 // TODO(https://crbug.com/webrtc/9480): Remove streams() in favor of
108 // stream_ids() as soon as downstream projects are no longer dependent on
109 // stream objects.
110 virtual std::vector<std::string> stream_ids() const;
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100111 virtual std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams() const;
deadbeef70ab1a12015-09-28 16:53:55 -0700112
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700113 // Audio or video receiver?
114 virtual cricket::MediaType media_type() const = 0;
115
deadbeef70ab1a12015-09-28 16:53:55 -0700116 // Not to be confused with "mid", this is a field we can temporarily use
117 // to uniquely identify a receiver until we implement Unified Plan SDP.
118 virtual std::string id() const = 0;
119
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700120 // The WebRTC specification only defines RTCRtpParameters in terms of senders,
121 // but this API also applies them to receivers, similar to ORTC:
122 // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*.
123 virtual RtpParameters GetParameters() const = 0;
deadbeefb10f32f2017-02-08 01:38:21 -0800124 // Currently, doesn't support changing any parameters, but may in the future.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700125 virtual bool SetParameters(const RtpParameters& parameters) = 0;
126
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700127 // Does not take ownership of observer.
128 // Must call SetObserver(nullptr) before the observer is destroyed.
zhihuang184a3fd2016-06-14 11:47:14 -0700129 virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0;
130
hbos8d609f62017-04-10 07:39:05 -0700131 // TODO(zhihuang): Remove the default implementation once the subclasses
132 // implement this. Currently, the only relevant subclass is the
133 // content::FakeRtpReceiver in Chromium.
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100134 virtual std::vector<RtpSource> GetSources() const;
135
Benjamin Wrightd81ac952018-08-29 17:02:10 -0700136 // Sets a user defined frame decryptor that will decrypt the entire frame
137 // before it is sent across the network. This will decrypt the entire frame
138 // using the user provided decryption mechanism regardless of whether SRTP is
139 // enabled or not.
140 virtual void SetFrameDecryptor(
141 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor);
142
143 // Returns a pointer to the frame decryptor set previously by the
144 // user. This can be used to update the state of the object.
145 virtual rtc::scoped_refptr<FrameDecryptorInterface> GetFrameDecryptor() const;
146
deadbeef70ab1a12015-09-28 16:53:55 -0700147 protected:
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100148 ~RtpReceiverInterface() override = default;
deadbeef70ab1a12015-09-28 16:53:55 -0700149};
150
151// Define proxy for RtpReceiverInterface.
deadbeefb10f32f2017-02-08 01:38:21 -0800152// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods
153// are called on is an implementation detail.
nisse72c8d2b2016-04-15 03:49:07 -0700154BEGIN_SIGNALING_PROXY_MAP(RtpReceiver)
Yves Gerey665174f2018-06-19 15:03:05 +0200155PROXY_SIGNALING_THREAD_DESTRUCTOR()
156PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track)
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100157PROXY_CONSTMETHOD0(rtc::scoped_refptr<DtlsTransportInterface>, dtls_transport)
Henrik Boström5b147782018-12-04 11:25:05 +0100158PROXY_CONSTMETHOD0(std::vector<std::string>, stream_ids)
Yves Gerey665174f2018-06-19 15:03:05 +0200159PROXY_CONSTMETHOD0(std::vector<rtc::scoped_refptr<MediaStreamInterface>>,
160 streams)
161PROXY_CONSTMETHOD0(cricket::MediaType, media_type)
162PROXY_CONSTMETHOD0(std::string, id)
Nico Weber22f99252019-02-20 10:13:16 -0500163PROXY_CONSTMETHOD0(RtpParameters, GetParameters)
Yves Gerey665174f2018-06-19 15:03:05 +0200164PROXY_METHOD1(bool, SetParameters, const RtpParameters&)
Nico Weber22f99252019-02-20 10:13:16 -0500165PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*)
166PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources)
Benjamin Wrightd81ac952018-08-29 17:02:10 -0700167PROXY_METHOD1(void,
168 SetFrameDecryptor,
Nico Weber22f99252019-02-20 10:13:16 -0500169 rtc::scoped_refptr<FrameDecryptorInterface>)
Benjamin Wrightd81ac952018-08-29 17:02:10 -0700170PROXY_CONSTMETHOD0(rtc::scoped_refptr<FrameDecryptorInterface>,
Nico Weber22f99252019-02-20 10:13:16 -0500171 GetFrameDecryptor)
Yves Gerey665174f2018-06-19 15:03:05 +0200172END_PROXY_MAP()
deadbeef70ab1a12015-09-28 16:53:55 -0700173
174} // namespace webrtc
175
Steve Anton10542f22019-01-11 09:11:00 -0800176#endif // API_RTP_RECEIVER_INTERFACE_H_