blob: ce4abeb511364ba8c8172cbbc8fbc1ff5997f684 [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
Henrik Kjellander15583c12016-02-10 10:53:12 +010014#ifndef WEBRTC_API_RTPRECEIVERINTERFACE_H_
15#define WEBRTC_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
Henrik Kjellander15583c12016-02-10 10:53:12 +010020#include "webrtc/api/mediastreaminterface.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020021#include "webrtc/api/mediatypes.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010022#include "webrtc/api/proxy.h"
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070023#include "webrtc/api/rtpparameters.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020024#include "webrtc/rtc_base/refcount.h"
25#include "webrtc/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
42 int64_t timestamp_ms() const { return timestamp_ms_; }
43 void update_timestamp_ms(int64_t timestamp_ms) {
44 RTC_DCHECK_LE(timestamp_ms_, timestamp_ms);
45 timestamp_ms_ = timestamp_ms;
46 }
47
48 // The identifier of the source can be the CSRC or the SSRC.
49 uint32_t source_id() const { return source_id_; }
50
51 // The source can be either a contributing source or a synchronization source.
52 RtpSourceType source_type() const { return source_type_; }
53
54 // This isn't implemented yet and will always return an empty Optional.
55 // TODO(zhihuang): Implement this to return real audio level.
56 rtc::Optional<int8_t> audio_level() const { return rtc::Optional<int8_t>(); }
57
zhihuang04262222017-04-11 11:28:10 -070058 bool operator==(const RtpSource& o) const {
59 return timestamp_ms_ == o.timestamp_ms() && source_id_ == o.source_id() &&
60 source_type_ == o.source_type();
61 }
62
hbos8d609f62017-04-10 07:39:05 -070063 private:
64 int64_t timestamp_ms_;
65 uint32_t source_id_;
66 RtpSourceType source_type_;
67};
68
zhihuang184a3fd2016-06-14 11:47:14 -070069class RtpReceiverObserverInterface {
70 public:
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070071 // Note: Currently if there are multiple RtpReceivers of the same media type,
72 // they will all call OnFirstPacketReceived at once.
73 //
74 // In the future, it's likely that an RtpReceiver will only call
75 // OnFirstPacketReceived when a packet is received specifically for its
76 // SSRC/mid.
zhihuang184a3fd2016-06-14 11:47:14 -070077 virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0;
78
79 protected:
80 virtual ~RtpReceiverObserverInterface() {}
81};
82
deadbeef70ab1a12015-09-28 16:53:55 -070083class RtpReceiverInterface : public rtc::RefCountInterface {
84 public:
85 virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0;
86
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070087 // Audio or video receiver?
88 virtual cricket::MediaType media_type() const = 0;
89
deadbeef70ab1a12015-09-28 16:53:55 -070090 // Not to be confused with "mid", this is a field we can temporarily use
91 // to uniquely identify a receiver until we implement Unified Plan SDP.
92 virtual std::string id() const = 0;
93
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -070094 // The WebRTC specification only defines RTCRtpParameters in terms of senders,
95 // but this API also applies them to receivers, similar to ORTC:
96 // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*.
97 virtual RtpParameters GetParameters() const = 0;
deadbeefb10f32f2017-02-08 01:38:21 -080098 // Currently, doesn't support changing any parameters, but may in the future.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -070099 virtual bool SetParameters(const RtpParameters& parameters) = 0;
100
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700101 // Does not take ownership of observer.
102 // Must call SetObserver(nullptr) before the observer is destroyed.
zhihuang184a3fd2016-06-14 11:47:14 -0700103 virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0;
104
hbos8d609f62017-04-10 07:39:05 -0700105 // TODO(zhihuang): Remove the default implementation once the subclasses
106 // implement this. Currently, the only relevant subclass is the
107 // content::FakeRtpReceiver in Chromium.
108 virtual std::vector<RtpSource> GetSources() const {
109 return std::vector<RtpSource>();
110 }
111
deadbeef70ab1a12015-09-28 16:53:55 -0700112 protected:
113 virtual ~RtpReceiverInterface() {}
114};
115
116// Define proxy for RtpReceiverInterface.
deadbeefb10f32f2017-02-08 01:38:21 -0800117// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods
118// are called on is an implementation detail.
nisse72c8d2b2016-04-15 03:49:07 -0700119BEGIN_SIGNALING_PROXY_MAP(RtpReceiver)
deadbeefd99a2002017-01-18 08:55:23 -0800120 PROXY_SIGNALING_THREAD_DESTRUCTOR()
121 PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track)
122 PROXY_CONSTMETHOD0(cricket::MediaType, media_type)
123 PROXY_CONSTMETHOD0(std::string, id)
124 PROXY_CONSTMETHOD0(RtpParameters, GetParameters);
125 PROXY_METHOD1(bool, SetParameters, const RtpParameters&)
126 PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*);
hbos8d609f62017-04-10 07:39:05 -0700127 PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources);
128 END_PROXY_MAP()
deadbeef70ab1a12015-09-28 16:53:55 -0700129
130} // namespace webrtc
131
Henrik Kjellander15583c12016-02-10 10:53:12 +0100132#endif // WEBRTC_API_RTPRECEIVERINTERFACE_H_