deadbeef | 6979b02 | 2015-09-24 16:47:53 -0700 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
deadbeef | 6979b02 | 2015-09-24 16:47:53 -0700 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * 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. |
deadbeef | 6979b02 | 2015-09-24 16:47:53 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 11 | // This file contains classes that implement RtpReceiverInterface. |
| 12 | // An RtpReceiver associates a MediaStreamTrackInterface with an underlying |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 13 | // transport (provided by cricket::VoiceChannel/cricket::VideoChannel) |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 14 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 15 | #ifndef PC_RTP_RECEIVER_H_ |
| 16 | #define PC_RTP_RECEIVER_H_ |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 17 | |
pbos | c7c26a0 | 2017-01-02 08:42:32 -0800 | [diff] [blame] | 18 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 19 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 20 | #include <string> |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 21 | #include <vector> |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 22 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 23 | #include "absl/types/optional.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 24 | #include "api/crypto/frame_decryptor_interface.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 +0000 | [diff] [blame^] | 25 | #include "api/dtls_transport_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 26 | #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 Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 30 | #include "api/scoped_refptr.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 31 | #include "api/video/video_frame.h" |
| 32 | #include "api/video/video_sink_interface.h" |
| 33 | #include "api/video/video_source_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 34 | #include "media/base/media_channel.h" |
| 35 | #include "media/base/video_broadcaster.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 36 | #include "pc/video_track_source.h" |
| 37 | #include "rtc_base/ref_counted_object.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 38 | #include "rtc_base/thread.h" |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 39 | |
| 40 | namespace webrtc { |
| 41 | |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 42 | // Internal class used by PeerConnection. |
| 43 | class RtpReceiverInternal : public RtpReceiverInterface { |
| 44 | public: |
Harald Alvestrand | 1ee3325 | 2020-09-24 13:31:15 +0000 | [diff] [blame] | 45 | // Stops receiving. The track may be reactivated. |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 46 | virtual void Stop() = 0; |
Harald Alvestrand | 1ee3325 | 2020-09-24 13:31:15 +0000 | [diff] [blame] | 47 | // Stops the receiver permanently. |
| 48 | // Causes the associated track to enter kEnded state. Cannot be reversed. |
| 49 | virtual void StopAndEndTrack() = 0; |
Steve Anton | ef65ef1 | 2018-01-10 17:15:20 -0800 | [diff] [blame] | 50 | |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 51 | // Sets the underlying MediaEngine channel associated with this RtpSender. |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 52 | // A VoiceMediaChannel should be used for audio RtpSenders and |
| 53 | // a VideoMediaChannel should be used for video RtpSenders. |
| 54 | // Must call SetMediaChannel(nullptr) before the media channel is destroyed. |
| 55 | virtual void SetMediaChannel(cricket::MediaChannel* media_channel) = 0; |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 56 | |
Steve Anton | d367921 | 2018-01-17 17:41:02 -0800 | [diff] [blame] | 57 | // Configures the RtpReceiver with the underlying media channel, with the |
Saurav Das | 7262fc2 | 2019-09-11 16:23:05 -0700 | [diff] [blame] | 58 | // given SSRC as the stream identifier. |
Steve Anton | d367921 | 2018-01-17 17:41:02 -0800 | [diff] [blame] | 59 | virtual void SetupMediaChannel(uint32_t ssrc) = 0; |
| 60 | |
Saurav Das | 7262fc2 | 2019-09-11 16:23:05 -0700 | [diff] [blame] | 61 | // Configures the RtpReceiver with the underlying media channel to receive an |
| 62 | // unsignaled receive stream. |
| 63 | virtual void SetupUnsignaledMediaChannel() = 0; |
| 64 | |
Harald Alvestrand | 4a7b3ac | 2019-01-17 10:39:40 +0100 | [diff] [blame] | 65 | virtual void set_transport( |
| 66 | rtc::scoped_refptr<DtlsTransportInterface> dtls_transport) = 0; |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 67 | // This SSRC is used as an identifier for the receiver between the API layer |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 68 | // and the WebRtcVideoEngine, WebRtcVoiceEngine layer. |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 69 | virtual uint32_t ssrc() const = 0; |
Steve Anton | 6077675 | 2018-01-10 11:51:34 -0800 | [diff] [blame] | 70 | |
| 71 | // Call this to notify the RtpReceiver when the first packet has been received |
| 72 | // on the corresponding channel. |
| 73 | virtual void NotifyFirstPacketReceived() = 0; |
Steve Anton | ef65ef1 | 2018-01-10 17:15:20 -0800 | [diff] [blame] | 74 | |
| 75 | // Set the associated remote media streams for this receiver. The remote track |
| 76 | // will be removed from any streams that are no longer present and added to |
| 77 | // any new streams. |
Henrik Boström | 199e27b | 2018-07-04 20:51:53 +0200 | [diff] [blame] | 78 | virtual void set_stream_ids(std::vector<std::string> stream_ids) = 0; |
| 79 | // TODO(https://crbug.com/webrtc/9480): Remove SetStreams() in favor of |
| 80 | // set_stream_ids() as soon as downstream projects are no longer dependent on |
| 81 | // stream objects. |
Steve Anton | ef65ef1 | 2018-01-10 17:15:20 -0800 | [diff] [blame] | 82 | virtual void SetStreams( |
| 83 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) = 0; |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 84 | |
| 85 | // Returns an ID that changes if the attached track changes, but |
| 86 | // otherwise remains constant. Used to generate IDs for stats. |
| 87 | // The special value zero means that no track is attached. |
| 88 | virtual int AttachmentId() const = 0; |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 89 | |
Ruslan Burakov | 501bfba | 2019-02-11 10:29:19 +0100 | [diff] [blame] | 90 | protected: |
| 91 | static int GenerateUniqueId(); |
| 92 | |
| 93 | static std::vector<rtc::scoped_refptr<MediaStreamInterface>> |
| 94 | CreateStreamsFromIds(std::vector<std::string> stream_ids); |
| 95 | |
| 96 | static void MaybeAttachFrameDecryptorToMediaChannel( |
| 97 | const absl::optional<uint32_t>& ssrc, |
Steve Anton | 6077675 | 2018-01-10 11:51:34 -0800 | [diff] [blame] | 98 | rtc::Thread* worker_thread, |
Ruslan Burakov | 501bfba | 2019-02-11 10:29:19 +0100 | [diff] [blame] | 99 | rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor, |
| 100 | cricket::MediaChannel* media_channel, |
| 101 | bool stopped); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | } // namespace webrtc |
| 105 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 106 | #endif // PC_RTP_RECEIVER_H_ |