blob: 0e32eae8cb7e32cc2ebbcd49bddb7931110ad847 [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;
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +010037 RtpSource(int64_t timestamp_ms,
38 uint32_t source_id,
39 RtpSourceType source_type);
zstein2b706342017-08-24 14:52:17 -070040 RtpSource(int64_t timestamp_ms,
41 uint32_t source_id,
42 RtpSourceType source_type,
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +010043 uint8_t audio_level);
44 RtpSource(const RtpSource&);
45 RtpSource& operator=(const RtpSource&);
46 ~RtpSource();
zstein2b706342017-08-24 14:52:17 -070047
hbos8d609f62017-04-10 07:39:05 -070048 int64_t timestamp_ms() const { return timestamp_ms_; }
49 void update_timestamp_ms(int64_t timestamp_ms) {
50 RTC_DCHECK_LE(timestamp_ms_, timestamp_ms);
51 timestamp_ms_ = timestamp_ms;
52 }
53
54 // The identifier of the source can be the CSRC or the SSRC.
55 uint32_t source_id() const { return source_id_; }
56
57 // The source can be either a contributing source or a synchronization source.
58 RtpSourceType source_type() const { return source_type_; }
59
zstein2b706342017-08-24 14:52:17 -070060 rtc::Optional<uint8_t> audio_level() const { return audio_level_; }
61 void set_audio_level(const rtc::Optional<uint8_t>& level) {
62 audio_level_ = level;
63 }
hbos8d609f62017-04-10 07:39:05 -070064
zhihuang04262222017-04-11 11:28:10 -070065 bool operator==(const RtpSource& o) const {
66 return timestamp_ms_ == o.timestamp_ms() && source_id_ == o.source_id() &&
zstein2b706342017-08-24 14:52:17 -070067 source_type_ == o.source_type() && audio_level_ == o.audio_level_;
zhihuang04262222017-04-11 11:28:10 -070068 }
69
hbos8d609f62017-04-10 07:39:05 -070070 private:
71 int64_t timestamp_ms_;
72 uint32_t source_id_;
73 RtpSourceType source_type_;
zstein2b706342017-08-24 14:52:17 -070074 rtc::Optional<uint8_t> audio_level_;
hbos8d609f62017-04-10 07:39:05 -070075};
76
zhihuang184a3fd2016-06-14 11:47:14 -070077class RtpReceiverObserverInterface {
78 public:
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070079 // Note: Currently if there are multiple RtpReceivers of the same media type,
80 // they will all call OnFirstPacketReceived at once.
81 //
82 // In the future, it's likely that an RtpReceiver will only call
83 // OnFirstPacketReceived when a packet is received specifically for its
84 // SSRC/mid.
zhihuang184a3fd2016-06-14 11:47:14 -070085 virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0;
86
87 protected:
88 virtual ~RtpReceiverObserverInterface() {}
89};
90
deadbeef70ab1a12015-09-28 16:53:55 -070091class RtpReceiverInterface : public rtc::RefCountInterface {
92 public:
93 virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0;
Henrik Boström9e6fd2b2017-11-21 13:41:51 +010094 // The list of streams that |track| is associated with. This is the same as
95 // the [[AssociatedRemoteMediaStreams]] internal slot in the spec.
96 // https://w3c.github.io/webrtc-pc/#dfn-x%5B%5Bassociatedremotemediastreams%5D%5D
97 // TODO(hbos): Make pure virtual as soon as Chromium's mock implements this.
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +010098 virtual std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams() const;
deadbeef70ab1a12015-09-28 16:53:55 -070099
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700100 // Audio or video receiver?
101 virtual cricket::MediaType media_type() const = 0;
102
deadbeef70ab1a12015-09-28 16:53:55 -0700103 // Not to be confused with "mid", this is a field we can temporarily use
104 // to uniquely identify a receiver until we implement Unified Plan SDP.
105 virtual std::string id() const = 0;
106
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700107 // The WebRTC specification only defines RTCRtpParameters in terms of senders,
108 // but this API also applies them to receivers, similar to ORTC:
109 // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*.
110 virtual RtpParameters GetParameters() const = 0;
deadbeefb10f32f2017-02-08 01:38:21 -0800111 // Currently, doesn't support changing any parameters, but may in the future.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700112 virtual bool SetParameters(const RtpParameters& parameters) = 0;
113
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700114 // Does not take ownership of observer.
115 // Must call SetObserver(nullptr) before the observer is destroyed.
zhihuang184a3fd2016-06-14 11:47:14 -0700116 virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0;
117
hbos8d609f62017-04-10 07:39:05 -0700118 // TODO(zhihuang): Remove the default implementation once the subclasses
119 // implement this. Currently, the only relevant subclass is the
120 // content::FakeRtpReceiver in Chromium.
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100121 virtual std::vector<RtpSource> GetSources() const;
122
deadbeef70ab1a12015-09-28 16:53:55 -0700123 protected:
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100124 ~RtpReceiverInterface() override = default;
deadbeef70ab1a12015-09-28 16:53:55 -0700125};
126
127// Define proxy for RtpReceiverInterface.
deadbeefb10f32f2017-02-08 01:38:21 -0800128// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods
129// are called on is an implementation detail.
nisse72c8d2b2016-04-15 03:49:07 -0700130BEGIN_SIGNALING_PROXY_MAP(RtpReceiver)
deadbeefd99a2002017-01-18 08:55:23 -0800131 PROXY_SIGNALING_THREAD_DESTRUCTOR()
132 PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track)
Henrik Boström9e6fd2b2017-11-21 13:41:51 +0100133 PROXY_CONSTMETHOD0(std::vector<rtc::scoped_refptr<MediaStreamInterface>>,
134 streams)
deadbeefd99a2002017-01-18 08:55:23 -0800135 PROXY_CONSTMETHOD0(cricket::MediaType, media_type)
136 PROXY_CONSTMETHOD0(std::string, id)
137 PROXY_CONSTMETHOD0(RtpParameters, GetParameters);
138 PROXY_METHOD1(bool, SetParameters, const RtpParameters&)
139 PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*);
hbos8d609f62017-04-10 07:39:05 -0700140 PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources);
141 END_PROXY_MAP()
deadbeef70ab1a12015-09-28 16:53:55 -0700142
143} // namespace webrtc
144
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200145#endif // API_RTPRECEIVERINTERFACE_H_