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