blob: 2619735ebec26c1ae35653e68c24583ee07e6720 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#ifndef API_RTPRECEIVERINTERFACE_H_
15#define API_RTPRECEIVERINTERFACE_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
Benjamin Wrightd81ac952018-08-29 17:02:10 -070020#include "api/crypto/framedecryptorinterface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "api/mediastreaminterface.h"
22#include "api/mediatypes.h"
23#include "api/proxy.h"
24#include "api/rtpparameters.h"
25#include "rtc_base/refcount.h"
26#include "rtc_base/scoped_ref_ptr.h"
deadbeef70ab1a12015-09-28 16:53:55 -070027
28namespace webrtc {
29
hbos8d609f62017-04-10 07:39:05 -070030enum class RtpSourceType {
31 SSRC,
32 CSRC,
33};
34
35class RtpSource {
36 public:
37 RtpSource() = delete;
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +010038 RtpSource(int64_t timestamp_ms,
39 uint32_t source_id,
40 RtpSourceType source_type);
zstein2b706342017-08-24 14:52:17 -070041 RtpSource(int64_t timestamp_ms,
42 uint32_t source_id,
43 RtpSourceType source_type,
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +010044 uint8_t audio_level);
45 RtpSource(const RtpSource&);
46 RtpSource& operator=(const RtpSource&);
47 ~RtpSource();
zstein2b706342017-08-24 14:52:17 -070048
hbos8d609f62017-04-10 07:39:05 -070049 int64_t timestamp_ms() const { return timestamp_ms_; }
50 void update_timestamp_ms(int64_t timestamp_ms) {
51 RTC_DCHECK_LE(timestamp_ms_, timestamp_ms);
52 timestamp_ms_ = timestamp_ms;
53 }
54
55 // The identifier of the source can be the CSRC or the SSRC.
56 uint32_t source_id() const { return source_id_; }
57
58 // The source can be either a contributing source or a synchronization source.
59 RtpSourceType source_type() const { return source_type_; }
60
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020061 absl::optional<uint8_t> audio_level() const { return audio_level_; }
62 void set_audio_level(const absl::optional<uint8_t>& level) {
zstein2b706342017-08-24 14:52:17 -070063 audio_level_ = level;
64 }
hbos8d609f62017-04-10 07:39:05 -070065
zhihuang04262222017-04-11 11:28:10 -070066 bool operator==(const RtpSource& o) const {
67 return timestamp_ms_ == o.timestamp_ms() && source_id_ == o.source_id() &&
zstein2b706342017-08-24 14:52:17 -070068 source_type_ == o.source_type() && audio_level_ == o.audio_level_;
zhihuang04262222017-04-11 11:28:10 -070069 }
70
hbos8d609f62017-04-10 07:39:05 -070071 private:
72 int64_t timestamp_ms_;
73 uint32_t source_id_;
74 RtpSourceType source_type_;
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020075 absl::optional<uint8_t> audio_level_;
hbos8d609f62017-04-10 07:39:05 -070076};
77
zhihuang184a3fd2016-06-14 11:47:14 -070078class RtpReceiverObserverInterface {
79 public:
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070080 // Note: Currently if there are multiple RtpReceivers of the same media type,
81 // they will all call OnFirstPacketReceived at once.
82 //
83 // In the future, it's likely that an RtpReceiver will only call
84 // OnFirstPacketReceived when a packet is received specifically for its
85 // SSRC/mid.
zhihuang184a3fd2016-06-14 11:47:14 -070086 virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0;
87
88 protected:
89 virtual ~RtpReceiverObserverInterface() {}
90};
91
deadbeef70ab1a12015-09-28 16:53:55 -070092class RtpReceiverInterface : public rtc::RefCountInterface {
93 public:
94 virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0;
Henrik Boström9e6fd2b2017-11-21 13:41:51 +010095 // The list of streams that |track| is associated with. This is the same as
96 // the [[AssociatedRemoteMediaStreams]] internal slot in the spec.
Henrik Boström199e27b2018-07-04 20:51:53 +020097 // https://w3c.github.io/webrtc-pc/#dfn-associatedremotemediastreams
Henrik Boström9e6fd2b2017-11-21 13:41:51 +010098 // TODO(hbos): Make pure virtual as soon as Chromium's mock implements this.
Henrik Boström199e27b2018-07-04 20:51:53 +020099 // TODO(https://crbug.com/webrtc/9480): Remove streams() in favor of
100 // stream_ids() as soon as downstream projects are no longer dependent on
101 // stream objects.
102 virtual std::vector<std::string> stream_ids() const;
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100103 virtual std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams() const;
deadbeef70ab1a12015-09-28 16:53:55 -0700104
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700105 // Audio or video receiver?
106 virtual cricket::MediaType media_type() const = 0;
107
deadbeef70ab1a12015-09-28 16:53:55 -0700108 // Not to be confused with "mid", this is a field we can temporarily use
109 // to uniquely identify a receiver until we implement Unified Plan SDP.
110 virtual std::string id() const = 0;
111
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700112 // The WebRTC specification only defines RTCRtpParameters in terms of senders,
113 // but this API also applies them to receivers, similar to ORTC:
114 // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*.
115 virtual RtpParameters GetParameters() const = 0;
deadbeefb10f32f2017-02-08 01:38:21 -0800116 // Currently, doesn't support changing any parameters, but may in the future.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700117 virtual bool SetParameters(const RtpParameters& parameters) = 0;
118
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700119 // Does not take ownership of observer.
120 // Must call SetObserver(nullptr) before the observer is destroyed.
zhihuang184a3fd2016-06-14 11:47:14 -0700121 virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0;
122
hbos8d609f62017-04-10 07:39:05 -0700123 // TODO(zhihuang): Remove the default implementation once the subclasses
124 // implement this. Currently, the only relevant subclass is the
125 // content::FakeRtpReceiver in Chromium.
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100126 virtual std::vector<RtpSource> GetSources() const;
127
Benjamin Wrightd81ac952018-08-29 17:02:10 -0700128 // Sets a user defined frame decryptor that will decrypt the entire frame
129 // before it is sent across the network. This will decrypt the entire frame
130 // using the user provided decryption mechanism regardless of whether SRTP is
131 // enabled or not.
132 virtual void SetFrameDecryptor(
133 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor);
134
135 // Returns a pointer to the frame decryptor set previously by the
136 // user. This can be used to update the state of the object.
137 virtual rtc::scoped_refptr<FrameDecryptorInterface> GetFrameDecryptor() const;
138
deadbeef70ab1a12015-09-28 16:53:55 -0700139 protected:
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100140 ~RtpReceiverInterface() override = default;
deadbeef70ab1a12015-09-28 16:53:55 -0700141};
142
143// Define proxy for RtpReceiverInterface.
deadbeefb10f32f2017-02-08 01:38:21 -0800144// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods
145// are called on is an implementation detail.
nisse72c8d2b2016-04-15 03:49:07 -0700146BEGIN_SIGNALING_PROXY_MAP(RtpReceiver)
Yves Gerey665174f2018-06-19 15:03:05 +0200147PROXY_SIGNALING_THREAD_DESTRUCTOR()
148PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track)
Henrik Boström5b147782018-12-04 11:25:05 +0100149PROXY_CONSTMETHOD0(std::vector<std::string>, stream_ids)
Yves Gerey665174f2018-06-19 15:03:05 +0200150PROXY_CONSTMETHOD0(std::vector<rtc::scoped_refptr<MediaStreamInterface>>,
151 streams)
152PROXY_CONSTMETHOD0(cricket::MediaType, media_type)
153PROXY_CONSTMETHOD0(std::string, id)
154PROXY_CONSTMETHOD0(RtpParameters, GetParameters);
155PROXY_METHOD1(bool, SetParameters, const RtpParameters&)
156PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*);
157PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources);
Benjamin Wrightd81ac952018-08-29 17:02:10 -0700158PROXY_METHOD1(void,
159 SetFrameDecryptor,
160 rtc::scoped_refptr<FrameDecryptorInterface>);
161PROXY_CONSTMETHOD0(rtc::scoped_refptr<FrameDecryptorInterface>,
162 GetFrameDecryptor);
Yves Gerey665174f2018-06-19 15:03:05 +0200163END_PROXY_MAP()
deadbeef70ab1a12015-09-28 16:53:55 -0700164
165} // namespace webrtc
166
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200167#endif // API_RTPRECEIVERINTERFACE_H_