blob: 311971d951da002d442068d85db86f33fc98bda0 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "api/mediastreaminterface.h"
21#include "api/mediatypes.h"
22#include "api/proxy.h"
23#include "api/rtpparameters.h"
24#include "rtc_base/refcount.h"
25#include "rtc_base/scoped_ref_ptr.h"
deadbeef70ab1a12015-09-28 16:53:55 -070026
27namespace webrtc {
28
hbos8d609f62017-04-10 07:39:05 -070029enum class RtpSourceType {
30 SSRC,
31 CSRC,
32};
33
34class RtpSource {
35 public:
36 RtpSource() = delete;
37 RtpSource(int64_t timestamp_ms, uint32_t source_id, RtpSourceType source_type)
38 : timestamp_ms_(timestamp_ms),
39 source_id_(source_id),
40 source_type_(source_type) {}
41
zstein2b706342017-08-24 14:52:17 -070042 RtpSource(int64_t timestamp_ms,
43 uint32_t source_id,
44 RtpSourceType source_type,
45 uint8_t audio_level)
46 : timestamp_ms_(timestamp_ms),
47 source_id_(source_id),
48 source_type_(source_type),
49 audio_level_(audio_level) {}
50
hbos8d609f62017-04-10 07:39:05 -070051 int64_t timestamp_ms() const { return timestamp_ms_; }
52 void update_timestamp_ms(int64_t timestamp_ms) {
53 RTC_DCHECK_LE(timestamp_ms_, timestamp_ms);
54 timestamp_ms_ = timestamp_ms;
55 }
56
57 // The identifier of the source can be the CSRC or the SSRC.
58 uint32_t source_id() const { return source_id_; }
59
60 // The source can be either a contributing source or a synchronization source.
61 RtpSourceType source_type() const { return source_type_; }
62
zstein2b706342017-08-24 14:52:17 -070063 rtc::Optional<uint8_t> audio_level() const { return audio_level_; }
64 void set_audio_level(const rtc::Optional<uint8_t>& level) {
65 audio_level_ = level;
66 }
hbos8d609f62017-04-10 07:39:05 -070067
zhihuang04262222017-04-11 11:28:10 -070068 bool operator==(const RtpSource& o) const {
69 return timestamp_ms_ == o.timestamp_ms() && source_id_ == o.source_id() &&
zstein2b706342017-08-24 14:52:17 -070070 source_type_ == o.source_type() && audio_level_ == o.audio_level_;
zhihuang04262222017-04-11 11:28:10 -070071 }
72
hbos8d609f62017-04-10 07:39:05 -070073 private:
74 int64_t timestamp_ms_;
75 uint32_t source_id_;
76 RtpSourceType source_type_;
zstein2b706342017-08-24 14:52:17 -070077 rtc::Optional<uint8_t> audio_level_;
hbos8d609f62017-04-10 07:39:05 -070078};
79
zhihuang184a3fd2016-06-14 11:47:14 -070080class RtpReceiverObserverInterface {
81 public:
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070082 // Note: Currently if there are multiple RtpReceivers of the same media type,
83 // they will all call OnFirstPacketReceived at once.
84 //
85 // In the future, it's likely that an RtpReceiver will only call
86 // OnFirstPacketReceived when a packet is received specifically for its
87 // SSRC/mid.
zhihuang184a3fd2016-06-14 11:47:14 -070088 virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0;
89
90 protected:
91 virtual ~RtpReceiverObserverInterface() {}
92};
93
deadbeef70ab1a12015-09-28 16:53:55 -070094class RtpReceiverInterface : public rtc::RefCountInterface {
95 public:
96 virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0;
Henrik Boström9e6fd2b2017-11-21 13:41:51 +010097 // The list of streams that |track| is associated with. This is the same as
98 // the [[AssociatedRemoteMediaStreams]] internal slot in the spec.
99 // https://w3c.github.io/webrtc-pc/#dfn-x%5B%5Bassociatedremotemediastreams%5D%5D
100 // TODO(hbos): Make pure virtual as soon as Chromium's mock implements this.
101 virtual std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams()
102 const {
103 return std::vector<rtc::scoped_refptr<MediaStreamInterface>>();
104 }
deadbeef70ab1a12015-09-28 16:53:55 -0700105
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700106 // Audio or video receiver?
107 virtual cricket::MediaType media_type() const = 0;
108
deadbeef70ab1a12015-09-28 16:53:55 -0700109 // Not to be confused with "mid", this is a field we can temporarily use
110 // to uniquely identify a receiver until we implement Unified Plan SDP.
111 virtual std::string id() const = 0;
112
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700113 // The WebRTC specification only defines RTCRtpParameters in terms of senders,
114 // but this API also applies them to receivers, similar to ORTC:
115 // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*.
116 virtual RtpParameters GetParameters() const = 0;
deadbeefb10f32f2017-02-08 01:38:21 -0800117 // Currently, doesn't support changing any parameters, but may in the future.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700118 virtual bool SetParameters(const RtpParameters& parameters) = 0;
119
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700120 // Does not take ownership of observer.
121 // Must call SetObserver(nullptr) before the observer is destroyed.
zhihuang184a3fd2016-06-14 11:47:14 -0700122 virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0;
123
hbos8d609f62017-04-10 07:39:05 -0700124 // TODO(zhihuang): Remove the default implementation once the subclasses
125 // implement this. Currently, the only relevant subclass is the
126 // content::FakeRtpReceiver in Chromium.
127 virtual std::vector<RtpSource> GetSources() const {
128 return std::vector<RtpSource>();
129 }
130
deadbeef70ab1a12015-09-28 16:53:55 -0700131 protected:
132 virtual ~RtpReceiverInterface() {}
133};
134
135// Define proxy for RtpReceiverInterface.
deadbeefb10f32f2017-02-08 01:38:21 -0800136// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods
137// are called on is an implementation detail.
nisse72c8d2b2016-04-15 03:49:07 -0700138BEGIN_SIGNALING_PROXY_MAP(RtpReceiver)
deadbeefd99a2002017-01-18 08:55:23 -0800139 PROXY_SIGNALING_THREAD_DESTRUCTOR()
140 PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track)
Henrik Boström9e6fd2b2017-11-21 13:41:51 +0100141 PROXY_CONSTMETHOD0(std::vector<rtc::scoped_refptr<MediaStreamInterface>>,
142 streams)
deadbeefd99a2002017-01-18 08:55:23 -0800143 PROXY_CONSTMETHOD0(cricket::MediaType, media_type)
144 PROXY_CONSTMETHOD0(std::string, id)
145 PROXY_CONSTMETHOD0(RtpParameters, GetParameters);
146 PROXY_METHOD1(bool, SetParameters, const RtpParameters&)
147 PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*);
hbos8d609f62017-04-10 07:39:05 -0700148 PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources);
149 END_PROXY_MAP()
deadbeef70ab1a12015-09-28 16:53:55 -0700150
151} // namespace webrtc
152
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200153#endif // API_RTPRECEIVERINTERFACE_H_