blob: b4106daa5849ec8fa60275cb5bcc176125339517 [file] [log] [blame]
Amit Hilbuchdd9390c2018-11-14 00:26:051/*
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 Anton10542f22019-01-11 17:11:0011#ifndef PC_CHANNEL_INTERFACE_H_
12#define PC_CHANNEL_INTERFACE_H_
Amit Hilbuchdd9390c2018-11-14 00:26:0513
Jakob Ivarsson68f4e272024-10-25 14:58:2914#include <functional>
Harald Alvestrand3af79d12022-04-29 15:04:5815#include <memory>
Amit Hilbuchdd9390c2018-11-14 00:26:0516#include <string>
Amit Hilbuchbcd39d42019-01-26 01:13:5617#include <vector>
Amit Hilbuchdd9390c2018-11-14 00:26:0518
Tomas Gunnarsson94f01942022-01-03 14:59:1219#include "absl/strings/string_view.h"
Amit Hilbuchdd9390c2018-11-14 00:26:0520#include "api/jsep.h"
Steve Anton10542f22019-01-11 17:11:0021#include "api/media_types.h"
22#include "media/base/media_channel.h"
23#include "pc/rtp_transport_internal.h"
Amit Hilbuchdd9390c2018-11-14 00:26:0524
Tomas Gunnarsson5411b172022-01-24 07:45:2625namespace webrtc {
26class Call;
27class VideoBitrateAllocatorFactory;
28} // namespace webrtc
29
Amit Hilbuchdd9390c2018-11-14 00:26:0530namespace cricket {
31
Harald Alvestrand1251c642023-01-04 12:42:5632class VoiceChannel;
33class VideoChannel;
Amit Hilbuchdd9390c2018-11-14 00:26:0534class MediaContentDescription;
Tomas Gunnarsson5411b172022-01-24 07:45:2635struct MediaConfig;
Amit Hilbuchdd9390c2018-11-14 00:26:0536
Harald Alvestrandd5f414c2022-01-24 09:11:2337// 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 Hilbuchdd9390c2018-11-14 00:26:0545// As more methods are added to BaseChannel, they should be included in the
46// interface as well.
Harald Alvestrand3af79d12022-04-29 15:04:5847// TODO(bugs.webrtc.org/13931): Merge this class into RtpTransceiver.
Amit Hilbuchdd9390c2018-11-14 00:26:0548class ChannelInterface {
49 public:
Harald Alvestrand3af79d12022-04-29 15:04:5850 virtual ~ChannelInterface() = default;
Amit Hilbuchdd9390c2018-11-14 00:26:0551 virtual cricket::MediaType media_type() const = 0;
52
Harald Alvestrand1251c642023-01-04 12:42:5653 virtual VideoChannel* AsVideoChannel() = 0;
54 virtual VoiceChannel* AsVoiceChannel() = 0;
55
Harald Alvestrand50454ef2022-12-15 16:49:1356 virtual MediaSendChannelInterface* media_send_channel() = 0;
Harald Alvestrand25adc8e2022-05-03 13:44:3457 // Typecasts of media_channel(). Will cause an exception if the
58 // channel is of the wrong type.
Harald Alvestrand50454ef2022-12-15 16:49:1359 virtual VideoMediaSendChannelInterface* video_media_send_channel() = 0;
60 virtual VoiceMediaSendChannelInterface* voice_media_send_channel() = 0;
61 virtual MediaReceiveChannelInterface* media_receive_channel() = 0;
Harald Alvestrand36fafc82022-12-08 08:47:4262 // Typecasts of media_channel(). Will cause an exception if the
63 // channel is of the wrong type.
Harald Alvestrand50454ef2022-12-15 16:49:1364 virtual VideoMediaReceiveChannelInterface* video_media_receive_channel() = 0;
65 virtual VoiceMediaReceiveChannelInterface* voice_media_receive_channel() = 0;
Amit Hilbuchdd9390c2018-11-14 00:26:0566
Tomas Gunnarsson94f01942022-01-03 14:59:1267 // 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 Hilbuchdd9390c2018-11-14 00:26:0570 // TODO(deadbeef): This is redundant; remove this.
Tomas Gunnarsson94f01942022-01-03 14:59:1271 virtual absl::string_view transport_name() const = 0;
Amit Hilbuchdd9390c2018-11-14 00:26:0572
Tomas Gunnarsson5411b172022-01-24 07:45:2673 // TODO(tommi): Change return type to string_view.
74 virtual const std::string& mid() const = 0;
Amit Hilbuchdd9390c2018-11-14 00:26:0575
Amit Hilbuchdd9390c2018-11-14 00:26:0576 // Enables or disables this channel
Tommi1959f8f2021-04-26 08:20:1977 virtual void Enable(bool enable) = 0;
Amit Hilbuchdd9390c2018-11-14 00:26:0578
79 // Used for latency measurements.
Tommi99c8a802021-04-27 13:00:0080 virtual void SetFirstPacketReceivedCallback(
81 std::function<void()> callback) = 0;
Jakob Ivarsson68f4e272024-10-25 14:58:2982 virtual void SetFirstPacketSentCallback(std::function<void()> callback) = 0;
Amit Hilbuchdd9390c2018-11-14 00:26:0583
84 // Channel control
85 virtual bool SetLocalContent(const MediaContentDescription* content,
86 webrtc::SdpType type,
Tomas Gunnarssond908d742022-01-05 10:44:2687 std::string& error_desc) = 0;
Amit Hilbuchdd9390c2018-11-14 00:26:0588 virtual bool SetRemoteContent(const MediaContentDescription* content,
89 webrtc::SdpType type,
Tomas Gunnarssond908d742022-01-05 10:44:2690 std::string& error_desc) = 0;
Taylor Brandstetterd0acbd82021-01-25 21:44:5591 virtual bool SetPayloadTypeDemuxingEnabled(bool enabled) = 0;
Amit Hilbuchdd9390c2018-11-14 00:26:0592
Amit Hilbuchbcd39d42019-01-26 01:13:5693 // 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 Hilbuchdd9390c2018-11-14 00:26:0597 // 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 Hilbuchdd9390c2018-11-14 00:26:05103};
104
105} // namespace cricket
106
Steve Anton10542f22019-01-11 17:11:00107#endif // PC_CHANNEL_INTERFACE_H_