Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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. |
| 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef PC_CHANNEL_INTERFACE_H_ |
| 12 | #define PC_CHANNEL_INTERFACE_H_ |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 13 | |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 14 | #include <memory> |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 15 | #include <string> |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 16 | #include <vector> |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 17 | |
Tomas Gunnarsson | 94f0194 | 2022-01-03 14:59:12 +0000 | [diff] [blame] | 18 | #include "absl/strings/string_view.h" |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 19 | #include "api/jsep.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #include "api/media_types.h" |
| 21 | #include "media/base/media_channel.h" |
| 22 | #include "pc/rtp_transport_internal.h" |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 23 | |
Tomas Gunnarsson | 5411b17 | 2022-01-24 08:45:26 +0100 | [diff] [blame] | 24 | namespace webrtc { |
| 25 | class Call; |
| 26 | class VideoBitrateAllocatorFactory; |
| 27 | } // namespace webrtc |
| 28 | |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 29 | namespace cricket { |
| 30 | |
| 31 | class MediaContentDescription; |
Tomas Gunnarsson | 5411b17 | 2022-01-24 08:45:26 +0100 | [diff] [blame] | 32 | class VideoChannel; |
| 33 | class VoiceChannel; |
| 34 | struct MediaConfig; |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 35 | |
Harald Alvestrand | d5f414c | 2022-01-24 09:11:23 +0000 | [diff] [blame] | 36 | // A Channel is a construct that groups media streams of the same type |
| 37 | // (audio or video), both outgoing and incoming. |
| 38 | // When the PeerConnection API is used, a Channel corresponds one to one |
| 39 | // to an RtpTransceiver. |
| 40 | // When Unified Plan is used, there can only be at most one outgoing and |
| 41 | // one incoming stream. With Plan B, there can be more than one. |
| 42 | |
| 43 | // ChannelInterface contains methods common to voice and video channels. |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 44 | // As more methods are added to BaseChannel, they should be included in the |
| 45 | // interface as well. |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 46 | // TODO(bugs.webrtc.org/13931): Merge this class into RtpTransceiver. |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 47 | class ChannelInterface { |
| 48 | public: |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 49 | virtual ~ChannelInterface() = default; |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 50 | virtual cricket::MediaType media_type() const = 0; |
| 51 | |
| 52 | virtual MediaChannel* media_channel() const = 0; |
| 53 | |
Tomas Gunnarsson | 94f0194 | 2022-01-03 14:59:12 +0000 | [diff] [blame] | 54 | // Returns a string view for the transport name. Fetching the transport name |
| 55 | // must be done on the network thread only and note that the lifetime of |
| 56 | // the returned object should be assumed to only be the calling scope. |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 57 | // TODO(deadbeef): This is redundant; remove this. |
Tomas Gunnarsson | 94f0194 | 2022-01-03 14:59:12 +0000 | [diff] [blame] | 58 | virtual absl::string_view transport_name() const = 0; |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 59 | |
Tomas Gunnarsson | 5411b17 | 2022-01-24 08:45:26 +0100 | [diff] [blame] | 60 | // TODO(tommi): Change return type to string_view. |
| 61 | virtual const std::string& mid() const = 0; |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 62 | |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 63 | // Enables or disables this channel |
Tommi | 1959f8f | 2021-04-26 10:20:19 +0200 | [diff] [blame] | 64 | virtual void Enable(bool enable) = 0; |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 65 | |
| 66 | // Used for latency measurements. |
Tommi | 99c8a80 | 2021-04-27 15:00:00 +0200 | [diff] [blame] | 67 | virtual void SetFirstPacketReceivedCallback( |
| 68 | std::function<void()> callback) = 0; |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 69 | |
| 70 | // Channel control |
| 71 | virtual bool SetLocalContent(const MediaContentDescription* content, |
| 72 | webrtc::SdpType type, |
Tomas Gunnarsson | d908d74 | 2022-01-05 10:44:26 +0000 | [diff] [blame] | 73 | std::string& error_desc) = 0; |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 74 | virtual bool SetRemoteContent(const MediaContentDescription* content, |
| 75 | webrtc::SdpType type, |
Tomas Gunnarsson | d908d74 | 2022-01-05 10:44:26 +0000 | [diff] [blame] | 76 | std::string& error_desc) = 0; |
Taylor Brandstetter | d0acbd8 | 2021-01-25 13:44:55 -0800 | [diff] [blame] | 77 | virtual bool SetPayloadTypeDemuxingEnabled(bool enabled) = 0; |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 78 | |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 79 | // Access to the local and remote streams that were set on the channel. |
| 80 | virtual const std::vector<StreamParams>& local_streams() const = 0; |
| 81 | virtual const std::vector<StreamParams>& remote_streams() const = 0; |
| 82 | |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 83 | // Set an RTP level transport. |
| 84 | // Some examples: |
| 85 | // * An RtpTransport without encryption. |
| 86 | // * An SrtpTransport for SDES. |
| 87 | // * A DtlsSrtpTransport for DTLS-SRTP. |
| 88 | virtual bool SetRtpTransport(webrtc::RtpTransportInternal* rtp_transport) = 0; |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
Tomas Gunnarsson | 5411b17 | 2022-01-24 08:45:26 +0100 | [diff] [blame] | 91 | class ChannelFactoryInterface { |
| 92 | public: |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 93 | virtual std::unique_ptr<VideoChannel> CreateVideoChannel( |
Tomas Gunnarsson | 5411b17 | 2022-01-24 08:45:26 +0100 | [diff] [blame] | 94 | webrtc::Call* call, |
| 95 | const MediaConfig& media_config, |
| 96 | const std::string& mid, |
| 97 | bool srtp_required, |
| 98 | const webrtc::CryptoOptions& crypto_options, |
| 99 | const VideoOptions& options, |
| 100 | webrtc::VideoBitrateAllocatorFactory* |
| 101 | video_bitrate_allocator_factory) = 0; |
| 102 | |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 103 | virtual std::unique_ptr<VoiceChannel> CreateVoiceChannel( |
Tomas Gunnarsson | 5411b17 | 2022-01-24 08:45:26 +0100 | [diff] [blame] | 104 | webrtc::Call* call, |
| 105 | const MediaConfig& media_config, |
| 106 | const std::string& mid, |
| 107 | bool srtp_required, |
| 108 | const webrtc::CryptoOptions& crypto_options, |
| 109 | const AudioOptions& options) = 0; |
| 110 | |
Tomas Gunnarsson | 5411b17 | 2022-01-24 08:45:26 +0100 | [diff] [blame] | 111 | protected: |
| 112 | virtual ~ChannelFactoryInterface() = default; |
| 113 | }; |
| 114 | |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 115 | } // namespace cricket |
| 116 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 117 | #endif // PC_CHANNEL_INTERFACE_H_ |