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