blob: afb737b71e1109a03718b811e4e869afada97638 [file] [log] [blame]
deadbeef6979b022015-09-24 23:47:531/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
deadbeef6979b022015-09-24 23:47:533 *
kjellanderb24317b2016-02-10 15:54:434 * 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 23:47:539 */
10
deadbeef70ab1a12015-09-28 23:53:5511// This file contains interfaces for RtpReceivers
12// http://w3c.github.io/webrtc-pc/#rtcrtpreceiver-interface
13
Mirko Bonadei92ea95e2017-09-15 04:47:3114#ifndef API_RTPRECEIVERINTERFACE_H_
15#define API_RTPRECEIVERINTERFACE_H_
deadbeef70ab1a12015-09-28 23:53:5516
17#include <string>
hbos8d609f62017-04-10 14:39:0518#include <vector>
deadbeef70ab1a12015-09-28 23:53:5519
Mirko Bonadei92ea95e2017-09-15 04:47:3120#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 23:53:5526
27namespace webrtc {
28
hbos8d609f62017-04-10 14:39:0529enum 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 21:52:1742 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 14:39:0551 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 21:52:1763 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 14:39:0567
zhihuang04262222017-04-11 18:28:1068 bool operator==(const RtpSource& o) const {
69 return timestamp_ms_ == o.timestamp_ms() && source_id_ == o.source_id() &&
zstein2b706342017-08-24 21:52:1770 source_type_ == o.source_type() && audio_level_ == o.audio_level_;
zhihuang04262222017-04-11 18:28:1071 }
72
hbos8d609f62017-04-10 14:39:0573 private:
74 int64_t timestamp_ms_;
75 uint32_t source_id_;
76 RtpSourceType source_type_;
zstein2b706342017-08-24 21:52:1777 rtc::Optional<uint8_t> audio_level_;
hbos8d609f62017-04-10 14:39:0578};
79
zhihuang184a3fd2016-06-14 18:47:1480class RtpReceiverObserverInterface {
81 public:
Taylor Brandstetterba29c6a2016-06-27 23:30:3582 // 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 18:47:1488 virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0;
89
90 protected:
91 virtual ~RtpReceiverObserverInterface() {}
92};
93
deadbeef70ab1a12015-09-28 23:53:5594class RtpReceiverInterface : public rtc::RefCountInterface {
95 public:
96 virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0;
97
Taylor Brandstetterba29c6a2016-06-27 23:30:3598 // Audio or video receiver?
99 virtual cricket::MediaType media_type() const = 0;
100
deadbeef70ab1a12015-09-28 23:53:55101 // Not to be confused with "mid", this is a field we can temporarily use
102 // to uniquely identify a receiver until we implement Unified Plan SDP.
103 virtual std::string id() const = 0;
104
Taylor Brandstetterdb0cd9e2016-05-16 18:40:30105 // The WebRTC specification only defines RTCRtpParameters in terms of senders,
106 // but this API also applies them to receivers, similar to ORTC:
107 // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*.
108 virtual RtpParameters GetParameters() const = 0;
deadbeefb10f32f2017-02-08 09:38:21109 // Currently, doesn't support changing any parameters, but may in the future.
Taylor Brandstetterdb0cd9e2016-05-16 18:40:30110 virtual bool SetParameters(const RtpParameters& parameters) = 0;
111
Taylor Brandstetterba29c6a2016-06-27 23:30:35112 // Does not take ownership of observer.
113 // Must call SetObserver(nullptr) before the observer is destroyed.
zhihuang184a3fd2016-06-14 18:47:14114 virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0;
115
hbos8d609f62017-04-10 14:39:05116 // TODO(zhihuang): Remove the default implementation once the subclasses
117 // implement this. Currently, the only relevant subclass is the
118 // content::FakeRtpReceiver in Chromium.
119 virtual std::vector<RtpSource> GetSources() const {
120 return std::vector<RtpSource>();
121 }
122
deadbeef70ab1a12015-09-28 23:53:55123 protected:
124 virtual ~RtpReceiverInterface() {}
125};
126
127// Define proxy for RtpReceiverInterface.
deadbeefb10f32f2017-02-08 09:38:21128// 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 10:49:07130BEGIN_SIGNALING_PROXY_MAP(RtpReceiver)
deadbeefd99a2002017-01-18 16:55:23131 PROXY_SIGNALING_THREAD_DESTRUCTOR()
132 PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track)
133 PROXY_CONSTMETHOD0(cricket::MediaType, media_type)
134 PROXY_CONSTMETHOD0(std::string, id)
135 PROXY_CONSTMETHOD0(RtpParameters, GetParameters);
136 PROXY_METHOD1(bool, SetParameters, const RtpParameters&)
137 PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*);
hbos8d609f62017-04-10 14:39:05138 PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources);
139 END_PROXY_MAP()
deadbeef70ab1a12015-09-28 23:53:55140
141} // namespace webrtc
142
Mirko Bonadei92ea95e2017-09-15 04:47:31143#endif // API_RTPRECEIVERINTERFACE_H_