blob: 8c49f56b75644be4650fe41b2a4c30655cd0ce43 [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 classes that implement RtpReceiverInterface.
12// An RtpReceiver associates a MediaStreamTrackInterface with an underlying
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070013// transport (provided by cricket::VoiceChannel/cricket::VideoChannel)
deadbeef70ab1a12015-09-28 16:53:55 -070014
Steve Anton10542f22019-01-11 09:11:00 -080015#ifndef PC_RTP_RECEIVER_H_
16#define PC_RTP_RECEIVER_H_
deadbeef70ab1a12015-09-28 16:53:55 -070017
pbosc7c26a02017-01-02 08:42:32 -080018#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020019
deadbeef70ab1a12015-09-28 16:53:55 -070020#include <string>
Steve Anton36b29d12017-10-30 09:57:42 -070021#include <vector>
deadbeef70ab1a12015-09-28 16:53:55 -070022
Yves Gerey3e707812018-11-28 16:47:49 +010023#include "absl/types/optional.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "api/crypto/frame_decryptor_interface.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000025#include "api/dtls_transport_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "api/media_stream_interface.h"
27#include "api/media_types.h"
28#include "api/rtp_parameters.h"
29#include "api/rtp_receiver_interface.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010030#include "api/scoped_refptr.h"
Yves Gerey3e707812018-11-28 16:47:49 +010031#include "api/video/video_frame.h"
32#include "api/video/video_sink_interface.h"
33#include "api/video/video_source_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080034#include "media/base/media_channel.h"
35#include "media/base/video_broadcaster.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "pc/video_track_source.h"
Yves Gerey3e707812018-11-28 16:47:49 +010037#include "rtc_base/thread.h"
deadbeef70ab1a12015-09-28 16:53:55 -070038
39namespace webrtc {
40
deadbeefa601f5c2016-06-06 14:27:39 -070041// Internal class used by PeerConnection.
42class RtpReceiverInternal : public RtpReceiverInterface {
43 public:
Tommi6589def2022-02-17 23:36:47 +010044 // Call on the signaling thread, to let the receiver know that the the
45 // embedded source object should enter a stopped/ended state and the track's
46 // state set to `kEnded`, a final state that cannot be reversed.
deadbeefa601f5c2016-06-06 14:27:39 -070047 virtual void Stop() = 0;
Tommi6589def2022-02-17 23:36:47 +010048
Steve Anton57858b32018-02-15 15:19:50 -080049 // Sets the underlying MediaEngine channel associated with this RtpSender.
Amit Hilbuchdd9390c2018-11-13 16:26:05 -080050 // A VoiceMediaChannel should be used for audio RtpSenders and
51 // a VideoMediaChannel should be used for video RtpSenders.
Tommi6589def2022-02-17 23:36:47 +010052 // NOTE:
53 // * SetMediaChannel(nullptr) must be called before the media channel is
54 // destroyed.
55 // * This method must be invoked on the worker thread.
Amit Hilbuchdd9390c2018-11-13 16:26:05 -080056 virtual void SetMediaChannel(cricket::MediaChannel* media_channel) = 0;
Steve Anton57858b32018-02-15 15:19:50 -080057
Steve Antond3679212018-01-17 17:41:02 -080058 // Configures the RtpReceiver with the underlying media channel, with the
Saurav Das7262fc22019-09-11 16:23:05 -070059 // given SSRC as the stream identifier.
Steve Antond3679212018-01-17 17:41:02 -080060 virtual void SetupMediaChannel(uint32_t ssrc) = 0;
61
Saurav Das7262fc22019-09-11 16:23:05 -070062 // Configures the RtpReceiver with the underlying media channel to receive an
63 // unsignaled receive stream.
64 virtual void SetupUnsignaledMediaChannel() = 0;
65
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +010066 virtual void set_transport(
67 rtc::scoped_refptr<DtlsTransportInterface> dtls_transport) = 0;
deadbeefe814a0d2017-02-25 18:15:09 -080068 // This SSRC is used as an identifier for the receiver between the API layer
eladalonf1841382017-06-12 01:16:46 -070069 // and the WebRtcVideoEngine, WebRtcVoiceEngine layer.
deadbeefe814a0d2017-02-25 18:15:09 -080070 virtual uint32_t ssrc() const = 0;
Steve Anton60776752018-01-10 11:51:34 -080071
72 // Call this to notify the RtpReceiver when the first packet has been received
73 // on the corresponding channel.
74 virtual void NotifyFirstPacketReceived() = 0;
Steve Antonef65ef12018-01-10 17:15:20 -080075
76 // Set the associated remote media streams for this receiver. The remote track
77 // will be removed from any streams that are no longer present and added to
78 // any new streams.
Henrik Boström199e27b2018-07-04 20:51:53 +020079 virtual void set_stream_ids(std::vector<std::string> stream_ids) = 0;
80 // TODO(https://crbug.com/webrtc/9480): Remove SetStreams() in favor of
81 // set_stream_ids() as soon as downstream projects are no longer dependent on
82 // stream objects.
Steve Antonef65ef12018-01-10 17:15:20 -080083 virtual void SetStreams(
84 const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) = 0;
Steve Anton57858b32018-02-15 15:19:50 -080085
86 // Returns an ID that changes if the attached track changes, but
87 // otherwise remains constant. Used to generate IDs for stats.
88 // The special value zero means that no track is attached.
89 virtual int AttachmentId() const = 0;
deadbeefa601f5c2016-06-06 14:27:39 -070090
Ruslan Burakov501bfba2019-02-11 10:29:19 +010091 protected:
92 static int GenerateUniqueId();
93
94 static std::vector<rtc::scoped_refptr<MediaStreamInterface>>
95 CreateStreamsFromIds(std::vector<std::string> stream_ids);
deadbeef70ab1a12015-09-28 16:53:55 -070096};
97
98} // namespace webrtc
99
Steve Anton10542f22019-01-11 09:11:00 -0800100#endif // PC_RTP_RECEIVER_H_