blob: fd233abe317609d265ca187f54be4781a1a47b75 [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
ossu7bb87ee2017-01-23 04:56:25 -080020#include "webrtc/api/mediatypes.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010021#include "webrtc/api/mediastreaminterface.h"
22#include "webrtc/api/proxy.h"
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070023#include "webrtc/api/rtpparameters.h"
deadbeef70ab1a12015-09-28 16:53:55 -070024#include "webrtc/base/refcount.h"
25#include "webrtc/base/scoped_ref_ptr.h"
26
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
58 private:
59 int64_t timestamp_ms_;
60 uint32_t source_id_;
61 RtpSourceType source_type_;
62};
63
zhihuang184a3fd2016-06-14 11:47:14 -070064class RtpReceiverObserverInterface {
65 public:
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070066 // Note: Currently if there are multiple RtpReceivers of the same media type,
67 // they will all call OnFirstPacketReceived at once.
68 //
69 // In the future, it's likely that an RtpReceiver will only call
70 // OnFirstPacketReceived when a packet is received specifically for its
71 // SSRC/mid.
zhihuang184a3fd2016-06-14 11:47:14 -070072 virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0;
73
74 protected:
75 virtual ~RtpReceiverObserverInterface() {}
76};
77
deadbeef70ab1a12015-09-28 16:53:55 -070078class RtpReceiverInterface : public rtc::RefCountInterface {
79 public:
80 virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0;
81
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070082 // Audio or video receiver?
83 virtual cricket::MediaType media_type() const = 0;
84
deadbeef70ab1a12015-09-28 16:53:55 -070085 // Not to be confused with "mid", this is a field we can temporarily use
86 // to uniquely identify a receiver until we implement Unified Plan SDP.
87 virtual std::string id() const = 0;
88
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -070089 // The WebRTC specification only defines RTCRtpParameters in terms of senders,
90 // but this API also applies them to receivers, similar to ORTC:
91 // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*.
92 virtual RtpParameters GetParameters() const = 0;
deadbeefb10f32f2017-02-08 01:38:21 -080093 // Currently, doesn't support changing any parameters, but may in the future.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -070094 virtual bool SetParameters(const RtpParameters& parameters) = 0;
95
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070096 // Does not take ownership of observer.
97 // Must call SetObserver(nullptr) before the observer is destroyed.
zhihuang184a3fd2016-06-14 11:47:14 -070098 virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0;
99
hbos8d609f62017-04-10 07:39:05 -0700100 // TODO(zhihuang): Remove the default implementation once the subclasses
101 // implement this. Currently, the only relevant subclass is the
102 // content::FakeRtpReceiver in Chromium.
103 virtual std::vector<RtpSource> GetSources() const {
104 return std::vector<RtpSource>();
105 }
106
deadbeef70ab1a12015-09-28 16:53:55 -0700107 protected:
108 virtual ~RtpReceiverInterface() {}
109};
110
111// Define proxy for RtpReceiverInterface.
deadbeefb10f32f2017-02-08 01:38:21 -0800112// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods
113// are called on is an implementation detail.
nisse72c8d2b2016-04-15 03:49:07 -0700114BEGIN_SIGNALING_PROXY_MAP(RtpReceiver)
deadbeefd99a2002017-01-18 08:55:23 -0800115 PROXY_SIGNALING_THREAD_DESTRUCTOR()
116 PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track)
117 PROXY_CONSTMETHOD0(cricket::MediaType, media_type)
118 PROXY_CONSTMETHOD0(std::string, id)
119 PROXY_CONSTMETHOD0(RtpParameters, GetParameters);
120 PROXY_METHOD1(bool, SetParameters, const RtpParameters&)
121 PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*);
hbos8d609f62017-04-10 07:39:05 -0700122 PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources);
123 END_PROXY_MAP()
deadbeef70ab1a12015-09-28 16:53:55 -0700124
125} // namespace webrtc
126
Henrik Kjellander15583c12016-02-10 10:53:12 +0100127#endif // WEBRTC_API_RTPRECEIVERINTERFACE_H_