-
-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathHandler.hpp
More file actions
154 lines (137 loc) · 5.22 KB
/
Handler.hpp
File metadata and controls
154 lines (137 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef MSC_HANDLER_HPP
#define MSC_HANDLER_HPP
#include "PeerConnection.hpp"
#include "sdp/RemoteSdp.hpp"
#include <json.hpp>
#include <api/media_stream_interface.h> // webrtc::MediaStreamTrackInterface
#include <api/peer_connection_interface.h> // webrtc::PeerConnectionInterface
#include <api/rtp_parameters.h> // webrtc::RtpEncodingParameters
#include <api/rtp_receiver_interface.h> // webrtc::RtpReceiverInterface
#include <api/rtp_sender_interface.h> // webrtc::RtpSenderInterface
#include <api/rtp_transceiver_interface.h> // webrtc::RtpTransceiverInterface
#include <string>
#include <unordered_map>
namespace mediasoupclient
{
class Handler : public PeerConnection::PrivateListener
{
public:
class PrivateListener
{
public:
virtual ~PrivateListener() = default;
virtual void OnConnect(nlohmann::json& dtlsParameters) = 0;
virtual void OnConnectionStateChange(
webrtc::PeerConnectionInterface::IceConnectionState connectionState) = 0;
};
public:
struct DataChannel
{
rtc::scoped_refptr<webrtc::DataChannelInterface> dataChannel;
nlohmann::json sctpStreamParameters;
};
public:
static nlohmann::json GetNativeRtpCapabilities(
const PeerConnection::Options* peerConnectionOptions = nullptr);
static nlohmann::json GetNativeSctpCapabilities();
public:
explicit Handler(
PrivateListener* privateListener,
const nlohmann::json& iceParameters,
const nlohmann::json& iceCandidates,
const nlohmann::json& dtlsParameters,
const nlohmann::json& sctpParameters,
const PeerConnection::Options* peerConnectionOptions);
public:
void Close();
nlohmann::json GetTransportStats();
void UpdateIceServers(const nlohmann::json& iceServerUris);
virtual void RestartIce(const nlohmann::json& iceParameters) = 0;
protected:
void SetupTransport(const std::string& localDtlsRole, nlohmann::json& localSdpObject);
/* Methods inherited from PeerConnectionListener. */
public:
void OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState newState) override;
protected:
// PrivateListener instance.
PrivateListener* privateListener{ nullptr };
// Remote SDP instance.
std::unique_ptr<Sdp::RemoteSdp> remoteSdp{ nullptr };
// Got transport local and remote parameters.
bool transportReady{ false };
// Map of RTCTransceivers indexed by MID.
std::unordered_map<std::string, webrtc::RtpTransceiverInterface*> mapMidTransceiver{};
// PeerConnection instance.
std::unique_ptr<PeerConnection> pc{ nullptr };
bool hasDataChannelMediaSection = false;
uint32_t nextSendSctpStreamId = 0;
// Initial server side DTLS role. If not 'auto', it will force the opposite
// value in client side.
std::string forcedLocalDtlsRole;
};
class SendHandler : public Handler
{
public:
struct SendResult
{
std::string localId;
webrtc::RtpSenderInterface* rtpSender{ nullptr };
nlohmann::json rtpParameters;
};
public:
SendHandler(
Handler::PrivateListener* privateListener,
const nlohmann::json& iceParameters,
const nlohmann::json& iceCandidates,
const nlohmann::json& dtlsParameters,
const nlohmann::json& sctpParameters,
const PeerConnection::Options* peerConnectionOptions,
const nlohmann::json& sendingRtpParametersByKind,
const nlohmann::json& sendingRemoteRtpParametersByKind = nlohmann::json());
public:
SendResult Send(
webrtc::MediaStreamTrackInterface* track,
std::vector<webrtc::RtpEncodingParameters>* encodings,
const nlohmann::json* codecOptions,
const nlohmann::json* codec);
void StopSending(const std::string& localId);
void ReplaceTrack(const std::string& localId, webrtc::MediaStreamTrackInterface* track);
void SetMaxSpatialLayer(const std::string& localId, uint8_t spatialLayer);
nlohmann::json GetSenderStats(const std::string& localId);
void RestartIce(const nlohmann::json& iceParameters) override;
DataChannel SendDataChannel(const std::string& label, webrtc::DataChannelInit dataChannelInit);
void PauseSending(const std::string& localId);
void ResumeSending(const std::string& localId);
private:
// Generic sending RTP parameters for audio and video.
nlohmann::json sendingRtpParametersByKind;
// Generic sending RTP parameters for audio and video suitable for the SDP
// remote answer.
nlohmann::json sendingRemoteRtpParametersByKind;
};
class RecvHandler : public Handler
{
public:
struct RecvResult
{
std::string localId;
webrtc::RtpReceiverInterface* rtpReceiver{ nullptr };
webrtc::MediaStreamTrackInterface* track{ nullptr };
};
public:
RecvHandler(
Handler::PrivateListener* privateListener,
const nlohmann::json& iceParameters,
const nlohmann::json& iceCandidates,
const nlohmann::json& dtlsParameters,
const nlohmann::json& sctpParameters,
const PeerConnection::Options* peerConnectionOptions);
RecvResult Receive(
const std::string& id, const std::string& kind, const nlohmann::json* rtpParameters);
void StopReceiving(const std::string& localId);
nlohmann::json GetReceiverStats(const std::string& localId);
void RestartIce(const nlohmann::json& iceParameters) override;
DataChannel ReceiveDataChannel(const std::string& label, webrtc::DataChannelInit dataChannelInit);
};
} // namespace mediasoupclient
#endif