8000 feat: Add Unified-Plan support for windows. by cloudwebrtc · Pull Request #688 · flutter-webrtc/flutter-webrtc · GitHub
[go: up one dir, main page]

Skip to content

feat: Add Unified-Plan support for windows. #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions example/lib/src/loopback_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class _MyAppState extends State<LoopBackSample> {
bool _inCalling = false;
Timer? _timer;

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

@override
void initState() {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/native/mediadevices_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class MediaDeviceNative extends MediaDevices {

String streamId = response['streamId'];
var stream = MediaStreamNative(streamId, 'local');
stream.setMediaTracks(response['audioTracks'], response['videoTracks']);
stream.setMediaTracks(
response['audioTracks'] ?? [], response['videoTracks'] ?? []);
return stream;
} on PlatformException catch (e) {
throw 'Unable to getUserMedia: ${e.message}';
Expand Down
3 changes: 2 additions & 1 deletion windows/include/flutter_data_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class FlutterDataChannel {
public:
FlutterDataChannel(FlutterWebRTCBase *base) : base_(base) {}

void CreateDataChannel(const std::string &label,
void CreateDataChannel(const std::string& peerConnectionId,
const std::string& label,
const EncodableMap &dataChannelDict,
RTCPeerConnection *pc,
std::unique_ptr<MethodResult<EncodableValue>>);
Expand Down
171 changes: 143 additions & 28 deletions windows/include/flutter_peerconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ using namespace flutter;

class FlutterPeerConnectionObserver : public RTCPeerConnectionObserver {
public:
FlutterPeerConnectionObserver(FlutterWebRTCBase *base,
FlutterPeerConnectionObserver(FlutterWebRTCBase* base,
scoped_refptr<RTCPeerConnection> peerconnection,
BinaryMessenger *messenger,
const std::string &channel_name);
BinaryMessenger* messenger,
const std::string& channel_name,
std::string& peerConnectionId);

virtual void OnSignalingState(RTCSignalingState state) override;
virtual void OnIceGatheringState(RTCIceGatheringState state) override;
Expand All @@ -21,68 +22,182 @@ class FlutterPeerConnectionObserver : public RTCPeerConnectionObserver {
scoped_refptr<RTCIceCandidate> candidate) override;
virtual void OnAddStream(scoped_refptr<RTCMediaStream> stream) override;
virtual void OnRemoveStream(scoped_refptr<RTCMediaStream> stream) override;
virtual void OnAddTrack(scoped_refptr<RTCMediaStream> stream,
scoped_refptr<RTCMediaTrack> track) override;
virtual void OnRemoveTrack(scoped_refptr<RTCMediaStream> stream,
scoped_refptr<RTCMediaTrack> track) override;

virtual void OnTrack(scoped_refptr<RTCRtpTransceiver> transceiver) override;
virtual void OnAddTrack(vector<scoped_refptr<RTCMediaStream>> streams,
scoped_refptr<RTCRtpReceiver> receiver) override;
virtual void OnRemoveTrack(scoped_refptr<RTCRtpReceiver> receiver) override;
virtual void OnDataChannel(
scoped_refptr<RTCDataChannel> data_channel) override;
virtual void OnRenegotiationNeeded() override;

scoped_refptr<RTCMediaStream> MediaStreamForId(
const std::string &id) {
auto it = remote_streams_.find(id);
if (it != remote_streams_.end()) return (*it).second;
return nullptr;
}
scoped_refptr<RTCMediaStream> MediaStreamForId(const std::string& id);

void RemoveStreamForId(const std::string &id) {
auto it = remote_streams_.find(id);
if (it != remote_streams_.end()) remote_streams_.erase(it);
}
void RemoveStreamForId(const std::string& id);

private:
std::unique_ptr<EventChannel<EncodableValue>> event_channel_;
std::unique_ptr<EventSink<EncodableValue>> event_sink_;
scoped_refptr<RTCPeerConnection> peerconnection_;
std::map<std::string, scoped_refptr<RTCMediaStream>> remote_streams_;
FlutterWebRTCBase *base_;
FlutterWebRTCBase* base_;
std::string id_;
};

class FlutterPeerConnection {
public:
FlutterPeerConnection(FlutterWebRTCBase *base) : base_(base) {}
FlutterPeerConnection(FlutterWebRTCBase* base) : base_(base) {}

void CreateRTCPeerConnection(
const EncodableMap &configuration, const EncodableMap &constraints,
const EncodableMap& configuration,
const EncodableMap& constraints,
std::unique_ptr<MethodResult<EncodableValue>> result);

void RTCPeerConnectionClose(
RTCPeerConnection *pc, const std::string &uuid,
RTCPeerConnection* pc,
const std::string& uuid,
std::unique_ptr<MethodResult<EncodableValue>> result);

void RTCPeerConnectionDispose(
RTCPeerConnection* pc,
const std::string& uuid,
std::unique_ptr<MethodResult<EncodableValue>> result);

void CreateOffer(const EncodableMap &constraints, RTCPeerConnection *pc,
void CreateOffer(const EncodableMap& constraints,
RTCPeerConnection* pc,
std::unique_ptr<MethodResult<EncodableValue>> result);

void CreateAnswer(const EncodableMap &constraints, RTCPeerConnection *pc,
void CreateAnswer(const EncodableMap& constraints,
RTCPeerConnection* pc,
std::unique_ptr<MethodResult<EncodableValue>> result);

void SetLocalDescription(
RTCSessionDescription *sdp, RTCPeerConnection *pc,
RTCSessionDescription* sdp,
RTCPeerConnection* pc,
std::unique_ptr<MethodResult<EncodableValue>> result);

void SetRemoteDescription(
RTCSessionDescription *sdp, RTCPeerConnection *pc,
RTCSessionDescription* sdp,
RTCPeerConnection* pc,
std::unique_ptr<MethodResult<EncodableValue>> result);

void GetLocalDescription(
RTCPeerConnection* pc,
std::unique_ptr<MethodResult<EncodableValue>> result);

void AddIceCandidate(RTCIceCandidate *candidate, RTCPeerConnection *pc,
void GetRemoteDescription(
RTCPeerConnection* pc,
std::unique_ptr<MethodResult<EncodableValue>> resulte);

scoped_refptr<RTCRtpTransceiverInit> mapToRtpTransceiverInit(
const EncodableMap& transceiverInit);

RTCRtpTransceiverDirection stringToTransceiverDirection(
std::string direction);

libwebrtc::scoped_refptr<libwebrtc::RTCRtpEncodingParameters> mapToEncoding(
const EncodableMap& parameters);

void AddTransceiver(RTCPeerConnection* pc,
const std::string& trackId,
const std::string& mediaType,
const EncodableMap& transceiverInit,
std::unique_ptr<MethodResult<EncodableValue>> resulte);

void GetTransceivers(RTCPeerConnection* pc,
std::unique_ptr<MethodResult<EncodableValue>> resulte);

void GetReceivers(RTCPeerConnection* pc,
std::unique_ptr<MethodResult<EncodableValue>> resulte);

void RtpSenderDispose(RTCPeerConnection* pc,
std::string rtpSenderId,
std::unique_ptr<MethodResult<EncodableValue>> resulte);

void RtpSenderSetTrack(RTCPeerConnection* pc,
RTCMediaTrack* track,
std::string rtpSenderId,
std::unique_ptr<MethodResult<EncodableValue>> resulte);

void RtpSenderReplaceTrack(
RTCPeerConnection* pc,
RTCMediaTrack* track,
std::string rtpSenderId,
std::unique_ptr<MethodResult<EncodableValue>> resulte);

scoped_refptr<RTCRtpParameters> updateRtpParameters(
EncodableMap newParameters,
scoped_refptr<RTCRtpParameters> parameters);

void RtpSenderSetParameters(
RTCPeerConnection* pc,
std::string rtpSenderId,
const EncodableMap& parameters,
std::unique_ptr<MethodResult<EncodableValue>> resulte);

void RtpTransceiverStop(
RTCPeerConnection* pc,
std::string rtpTransceiverId,
std::unique_ptr<MethodResult<EncodableValue>> resulte);

void RtpTransceiverGetCurrentDirection(
RTCPeerConnection* pc,
std::string rtpTransceiverId,
std::unique_ptr<MethodResult<EncodableValue>> resulte);

void SetConfiguration(RTCPeerConnection* pc,
const EncodableMap& configuration,
std::unique_ptr<MethodResult<EncodableValue>> resulte);

void CaptureFrame(RTCVideoTrack* track,
std::string path,
std::unique_ptr<MethodResult<EncodableValue>> resulte);

scoped_refptr<RTCRtpTransceiver> getRtpTransceiverById(RTCPeerConnection* pc,
std::string id);

void RtpTransceiverSetDirection(
RTCPeerConnection* pc,
std::string rtpTransceiverId,
std::string direction,
std::unique_ptr<MethodResult<EncodableValue>> resulte);

void GetSenders(RTCPeerConnection* pc,
std::unique_ptr<MethodResult<EncodableValue>> resulte);

void AddIceCandidate(RTCIceCandidate* candidate,
RTCPeerConnection* pc,
std::unique_ptr<MethodResult<EncodableValue>> result);

void GetStats(const std::string &track_id, RTCPeerConnection *pc,
void GetStats(const std::string& track_id,
RTCPeerConnection* pc,
std::unique_ptr<MethodResult<EncodableValue>> result);

void MediaStreamAddTrack(
scoped_refptr<RTCMediaStream> stream,
scoped_refptr<RTCMediaTrack> track,
std::unique_ptr<MethodResult<EncodableValue>> result);

void MediaStreamRemoveTrack(
scoped_refptr<RTCMediaStream> stream,
scoped_refptr<RTCMediaTrack> track,
std::unique_ptr<MethodResult<EncodableValue>> result);

void AddTrack(RTCPeerConnection* pc,
scoped_refptr<RTCMediaTrack> track,
std::list<std::string> streamIds,
std::unique_ptr<MethodResult<EncodableValue>> result);

libwebrtc::scoped_refptr<libwebrtc::RTCRtpSender> GetRtpSenderById(
RTCPeerConnection* pc,
st 10787 d::string id);

void RemoveTrack(RTCPeerConnection* pc,
std::string senderId,
std::unique_ptr<MethodResult<EncodableValue>> result);

private:
FlutterWebRTCBase *base_;
FlutterWebRTCBase* base_;
};
} // namespace flutter_webrtc_plugin

Expand Down
12 changes: 10 additions & 2 deletions windows/include/flutter_video_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class FlutterVideoRenderer: public RTCVideoRenderer<scoped_refptr<RTCVideoFrame>

int64_t texture_id() { return texture_id_; }

bool CheckMediaStream(std::string mediaId);

bool CheckVideoTrack(std::string mediaId);

std::string media_stream_id;
private:
struct FrameSize {
size_t width;
Expand All @@ -44,6 +49,7 @@ class FlutterVideoRenderer: public RTCVideoRenderer<scoped_refptr<RTCVideoFrame>
mutable std::shared_ptr<uint8_t> rgb_buffer_;
mutable std::mutex mutex_;
RTCVideoFrame::VideoRotation rotation_ = RTCVideoFrame::kVideoRotation_0;

};

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

void SetMediaStream(int64_t texture_id, const std::string &stream_id);
void SetMediaStream(int64_t texture_id,
const std::string& stream_id);

void VideoRendererDispose(
int64_t texture_id, std::unique_ptr<MethodResult<EncodableValue>> result);
int64_t texture_id,
std::unique_ptr<MethodResult<EncodableValue>> result);

private:
FlutterWebRTCBase *base_;
Expand Down
Loading
0