8000 feat: Add Unified-Plan support for windows. (#688) · flutter-robert/flutter-webrtc@2f8b8f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f8b8f7

Browse files
authored
feat: Add Unified-Plan support for windows. (flutter-webrtc#688)
* feat: Add unified-plan support for windows. * fix: fix data-channel. * fix: fix bug for AddTransceiver. * fix: fixed bug.
1 parent 7fb1316 commit 2f8b8f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3335
-471
lines changed

example/lib/src/loopback_sample.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ class _MyAppState extends State<LoopBackSample> {
1919
bool _inCalling = false;
2020
Timer? _timer;
2121

22-
String get sdpSemantics =>
23-
WebRTC.platformIsWindows ? 'plan-b' : 'unified-plan';
22+
String get sdpSemantics => 'unified-plan';
2423

2524
@override
2625
void initState() {

lib/src/native/mediadevices_impl.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class MediaDeviceNative extends MediaDevices {
2323

2424
String streamId = response['streamId'];
2525
var stream = MediaStreamNative(streamId, 'local');
26-
stream.setMediaTracks(response['audioTracks'], response['videoTracks']);
26+
stream.setMediaTracks(
27+
response['audioTracks'] ?? [], response['videoTracks'] ?? []);
2728
return stream;
2829
} on PlatformException catch (e) {
2930
throw 'Unable to getUserMedia: ${e.message}';

windows/include/flutter_data_channel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class FlutterDataChannel {
2828
public:
2929
FlutterDataChannel(FlutterWebRTCBase *base) : base_(base) {}
3030

31-
void CreateDataChannel(const std::string &label,
31+
void CreateDataChannel(const std::string& peerConnectionId,
32+
const std::string& label,
3233
const EncodableMap &dataChannelDict,
3334
RTCPeerConnection *pc,
3435
std::unique_ptr<MethodResult<EncodableValue>>);

windows/include/flutter_peerconnection.h

Lines changed: 143 additions & 28 deletions
< F438 /tr>
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ using namespace flutter;
99

1010
class FlutterPeerConnectionObserver : public RTCPeerConnectionObserver {
1111
public:
12-
FlutterPeerConnectionObserver(FlutterWebRTCBase *base,
12+
FlutterPeerConnectionObserver(FlutterWebRTCBase* base,
1313
scoped_refptr<RTCPeerConnection> peerconnection,
14-
BinaryMessenger *messenger,
15-
const std::string &channel_name);
14+
BinaryMessenger* messenger,
15+
const std::string& channel_name,
16+
std::string& peerConnectionId);
1617

1718
virtual void OnSignalingState(RTCSignalingState state) override;
1819
virtual void OnIceGatheringState(RTCIceGatheringState state) override;
@@ -21,68 +22,182 @@ class FlutterPeerConnectionObserver : public RTCPeerConnectionObserver {
2122
scoped_refptr<RTCIceCandidate> candidate) override;
2223
virtual void OnAddStream(scoped_refptr<RTCMediaStream> stream) override;
2324
virtual void OnRemoveStream(scoped_refptr<RTCMediaStream> stream) override;
24-
virtual void OnAddTrack(scoped_refptr<RTCMediaStream> stream,
25-
scoped_refptr<RTCMediaTrack> track) override;
26-
virtual void OnRemoveTrack(scoped_refptr<RTCMediaStream> stream,
27-
scoped_refptr<RTCMediaTrack> track) override;
25+
26+
virtual void OnTrack(scoped_refptr<RTCRtpTransceiver> transceiver) override;
27+
virtual void OnAddTrack(vector<scoped_refptr<RTCMediaStream>> streams,
28+
scoped_refptr<RTCRtpReceiver> receiver) override;
29+
virtual void OnRemoveTrack(scoped_refptr<RTCRtpReceiver> receiver) override;
2830
virtual void OnDataChannel(
2931
scoped_refptr<RTCDataChannel> data_channel) override;
3032
virtual void OnRenegotiationNeeded() override;
3133

32-
scoped_refptr<RTCMediaStream> MediaStreamForId(
33-
const std::string &id) {
34-
auto it = remote_streams_.find(id);
35-
if (it != remote_streams_.end()) return (*it).second;
36-
return nullptr;
37-
}
34+
scoped_refptr<RTCMediaStream> MediaStreamForId(const std::string& id);
3835

39-
void RemoveStreamForId(const std::string &id) {
40-
auto it = remote_streams_.find(id);
41-
if (it != remote_streams_.end()) remote_streams_.erase(it);
42-
}
36+
void RemoveStreamForId(const std::string& id);
4337

4438
private:
4539
std::unique_ptr<EventChannel<EncodableValue>> event_channel_;
4640
std::unique_ptr<EventSink<EncodableValue>> event_sink_;
4741
scoped_refptr<RTCPeerConnection> peerconnection_;
4842
std::map<std::string, scoped_refptr<RTCMediaStream>> remote_streams_;
49-
FlutterWebRTCBase *base_;
43+
FlutterWebRTCBase* base_;
44+
std::string id_;
5045
};
5146

5247
class FlutterPeerConnection {
5348
public:
54-
FlutterPeerConnection(FlutterWebRTCBase *base) : base_(base) {}
49+
FlutterPeerConnection(FlutterWebRTCBase* base) : base_(base) {}
5550

5651
void CreateRTCPeerConnection(
57-
const EncodableMap &configuration, const EncodableMap &constraints,
52+
const EncodableMap& configuration,
53+
const EncodableMap& constraints,
5854
std::unique_ptr<MethodResult<EncodableValue>> result);
5955

6056
void RTCPeerConnectionClose(
61-
RTCPeerConnection *pc, const std::string &uuid,
57+
RTCPeerConnection* pc,
58+
const std::string& uuid,
59+
std::unique_ptr<MethodResult<EncodableValue>> result);
60+
61+
void RTCPeerConnectionDispose(
62+
RTCPeerConnection* pc,
63+
const std::string& uuid,
6264
std::unique_ptr<MethodResult<EncodableValue>> result);
6365

64-
void CreateOffer(const EncodableMap &constraints, RTCPeerConnection *pc,
66+
void CreateOffer(const EncodableMap& constraints,
67+
RTCPeerConnection* pc,
6568
std::unique_ptr<MethodResult<EncodableValue>> result);
6669

67-
void CreateAnswer(const EncodableMap &constraints, RTCPeerConnection *pc,
70+
void CreateAnswer(const EncodableMap& constraints,
71+
RTCPeerConnection* pc,
6872
std::unique_ptr<MethodResult<EncodableValue>> result);
6973

7074
void SetLocalDescription(
71-
RTCSessionDescription *sdp, RTCPeerConnection *pc,
75+
RTCSessionDescription* sdp,
76+
RTCPeerConnection* pc,
7277
std::unique_ptr<MethodResult<EncodableValue>> result);
7378

7479
void SetRemoteDescription(
75-
RTCSessionDescription *sdp, RTCPeerConnection *pc,
80+
RTCSessionDescription* sdp,
81+
RTCPeerConnection* pc,
82+
std::unique_ptr<MethodResult<EncodableValue>> result);
83+
84+
void GetLocalDescription(
85+
RTCPeerConnection* pc,
7686
std::unique_ptr<MethodResult<EncodableValue>> result);
7787

78-
void AddIceCandidate(RTCIceCandidate *candidate, RTCPeerConnection *pc,
88+
void GetRemoteDescription(
89+
RTCPeerConnection* pc,
90+
std::unique_ptr<MethodResult<EncodableValue>> resulte);
91+
92+
scoped_refptr<RTCRtpTransceiverInit> mapToRtpTransceiverInit(
93+
const EncodableMap& transceiverInit);
94+
95+
RTCRtpTransceiverDirection stringToTransceiverDirection(
96+
std::string direction);
97+
98+
libwebrtc::scoped_refptr<libwebrtc::RTCRtpEncodingParameters> mapToEncoding(
99+
const EncodableMap& parameters);
100+
101+
void AddTransceiver(RTCPeerConnection* pc,
102+
const std::string& trackId,
103+
const std::string& mediaType,
104+
const EncodableMap& transceiverInit,
105+
std::unique_ptr<MethodResult<EncodableValue>> resulte);
106+
107+
void GetTransceivers(RTCPeerConnection* pc,
108+
std::unique_ptr<MethodResult<EncodableValue>> resulte);
109+
110+
void GetReceivers(RTCPeerConnection* pc,
111+
std::unique_ptr<MethodResult<EncodableValue>> resulte);
112+
113+
void RtpSenderDispose(RTCPeerConnection* pc,
114+
std::string rtpSenderId,
115+
std::unique_ptr<MethodResult<EncodableValue>> resulte);
116+
117+
void RtpSenderSetTrack(RTCPeerConnection* pc,
118+
RTCMediaTrack* track,
119+
std::string rtpSenderId,
120+
std::unique_ptr<MethodResult<EncodableValue>> resulte);
121+
122+
void 1CF5 RtpSenderReplaceTrack(
123+
RTCPeerConnection* pc,
124+
RTCMediaTrack* track,
125+
std::string rtpSenderId,
126+
std::unique_ptr<MethodResult<EncodableValue>> resulte);
127+
128+
scoped_refptr<RTCRtpParameters> updateRtpParameters(
129+
EncodableMap newParameters,
130+
scoped_refptr<RTCRtpParameters> parameters);
131+
132+
void RtpSenderSetParameters(
133+
RTCPeerConnection* pc,
134+
std::string rtpSenderId,
135+
const EncodableMap& parameters,
136+
std::unique_ptr<MethodResult<EncodableValue>> resulte);
137+
138+
void RtpTransceiverStop(
139+
RTCPeerConnection* pc,
140+
std::string rtpTransceiverId,
141+
std::unique_ptr<MethodResult<EncodableValue>> resulte);
142+
143+
void RtpTransceiverGetCurrentDirection(
144+
RTCPeerConnection* pc,
145+
std::string rtpTransceiverId,
146+
std::unique_ptr<MethodResult<EncodableValue>> resulte);
147+
148+
void SetConfiguration(RTCPeerConnection* pc,
149+
const EncodableMap& configuration,
150+
std::unique_ptr<MethodResult<EncodableValue>> resulte);
151+
152+
void CaptureFrame(RTCVideoTrack* track,
153+
std::string path,
154+
std::unique_ptr<MethodResult<EncodableValue>> resulte);
155+
156+
scoped_refptr<RTCRtpTransceiver> getRtpTransceiverById(RTCPeerConnection* pc,
157+
std::string id);
158+
159+
void RtpTransceiverSetDirection(
160+
RTCPeerConnection* pc,
161+
std::string rtpTransceiverId,
162+
std::string direction,
163+
std::unique_ptr<MethodResult<EncodableValue>> resulte);
164+
165+
void GetSenders(RTCPeerConnection* pc,
166+
std::unique_ptr<MethodResult<EncodableValue>> resulte);
167+
168+
void AddIceCandidate(RTCIceCandidate* candidate,
169+
RTCPeerConnection* pc,
79170
std::unique_ptr<MethodResult<EncodableValue>> result);
80171

81-
void GetStats(const std::string &track_id, RTCPeerConnection *pc,
172+
void GetStats(const std::string& track_id,
173+
RTCPeerConnection* pc,
174+
std::unique_ptr<MethodResult<EncodableValue>> result);
175+
176+
void MediaStreamAddTrack(
177+
scoped_refptr<RTCMediaStream> stream,
178+
scoped_refptr<RTCMediaTrack> track,
179+
std::unique_ptr<MethodResult<EncodableValue>> result);
180+
181+
void MediaStreamRemoveTrack(
182+
scoped_refptr<RTCMediaStream> stream,
183+
scoped_refptr<RTCMediaTrack> track,
184+
std::unique_ptr<MethodResult<EncodableValue>> result);
185+
186+
void AddTrack(RTCPeerConnection* pc,
187+
scoped_refptr<RTCMediaTrack> track,
188+
std::list<std::string> streamIds,
82189
std::unique_ptr<MethodResult<EncodableValue>> result);
83190

191+
libwebrtc::scoped_refptr<libwebrtc::RTCRtpSender> GetRtpSenderById(
192+
RTCPeerConnection* pc,
193+
std::string id);
194+
195+
void RemoveTrack(RTCPeerConnection* pc,
196+
std::string senderId,
197+
std::unique_ptr<MethodResult<EncodableValue>> result);
198+
84199
private:
85-
FlutterWebRTCBase *base_;
200+
FlutterWebRTCBase* base_;
86201
};
87202
} // namespace flutter_webrtc_plugin
88203

windows/include/flutter_video_renderer.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class FlutterVideoRenderer: public RTCVideoRenderer<scoped_refptr<RTCVideoFrame>
2626

2727
int64_t texture_id() { return texture_id_; }
2828

29+
bool CheckMediaStream(std::string mediaId);
30+
31+
bool CheckVideoTrack(std::string mediaId);
32+
33+
std::string media_stream_id;
2934
private:
3035
struct FrameSize {
3136
size_t width;
@@ -44,6 +49,7 @@ class FlutterVideoRenderer: public RTCVideoRenderer<scoped_refptr<RTCVideoFrame>
4449
mutable std::shared_ptr<uint8_t> rgb_buffer_;
4550
mutable std::mutex mutex_;
4651
RTCVideoFrame::VideoRotation rotation_ = RTCVideoFrame::kVideoRotation_0;
52+
4753
};
4854

4955
class FlutterVideoRendererManager {
@@ -53,10 +59,12 @@ class FlutterVideoRendererManager {
5359
void CreateVideoRendererTexture(
5460
std::unique_ptr<MethodResult<EncodableValue>> result);
5561

56-
void SetMediaStream(int64_t texture_id, const std::string &stream_id);
62+
void SetMediaStream(int64_t texture_id,
63+
const std::string& stream_id);
5764

5865
void VideoRendererDispose(
59-
int64_t texture_id, std::unique_ptr<MethodResult<EncodableValue>> result);
66+
int64_t texture_id,
67+
std::unique_ptr<MethodResult<EncodableValue>> result);
6068

6169
private:
6270
FlutterWebRTCBase *base_;

0 commit comments

Comments
 (0)
0