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