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

Skip to content

Add support for windows. #290

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 10 commits into from
Jan 20, 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
8000
Diff view
Diff view
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Defines the Chromium style for automatic reformatting.
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
BasedOnStyle: Chromium
# This defaults to 'Auto'. Explicitly set it for a while, so that
# 'vector<vector<int> >' in existing files gets formatted to
# 'vector<vector<int>>'. ('Auto' means that clang-format will only use
# 'int>>' if the file already contains at least one such instance.)
Standard: Cpp11
SortIncludes: true
---
Language: ObjC
ColumnLimit: 100
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ WebRTC plugin for Flutter Mobile/Desktop/Web

| Feature | Android | iOS | [Web](https://flutter.dev/web) | macOS | Windows | Linux | [Fuchsia](https://fuchsia.googlesource.com/) |
| :-------------: | :-------------:| :-----: | :-----: | :-----: | :-----: | :-----: | :-----: |
| Audio/Video | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | [WIP] | |
| Data Channel | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | [WIP] | |
| Audio/Video | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | |
| Data Channel | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | |
| Screen Capture | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | | | |
| Unified-Plan | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | | |
| Simulcast | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | | |
Expand Down
11 changes: 6 additions & 5 deletions example/lib/src/loopback_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class _MyAppState extends State<LoopBackSample> {

void _onAddStream(MediaStream stream) {
print('New stream: ' + stream.id);
//_remoteRenderer.srcObject = stream;
_remoteRenderer.srcObject = stream;
}

void _onRemoveStream(MediaStream stream) {
Expand Down Expand Up @@ -175,7 +175,7 @@ class _MyAppState extends State<LoopBackSample> {
_localStream =
await navigator.mediaDevices.getUserMedia(mediaConstraints);
_localRenderer.srcObject = _localStream;

await _peerConnection.addStream(_localStream);
/* old API
await _peerConnection.addStream(_localStream);
// Unified-Plan
Expand All @@ -184,13 +184,13 @@ class _MyAppState extends State<LoopBackSample> {
});
*/
// or

/*
await _peerConnection.addTransceiver(
track: _localStream.getAudioTracks()[0],
init: RTCRtpTransceiverInit(
direction: TransceiverDirection.SendRecv, streams: [_localStream]),
);

*/
/*
// ignore: unused_local_variable
var transceiver = await _peerConnection.addTransceiver(
Expand All @@ -200,6 +200,7 @@ class _MyAppState extends State<LoopBackSample> {
);
*/

/*
// Unified-Plan Simulcast
await _peerConnection.addTransceiver(
track: _localStream.getVideoTracks()[0],
Expand Down Expand Up @@ -227,7 +228,7 @@ class _MyAppState extends State<LoopBackSample> {
),
],
));
/*

await _peerConnection.addTransceiver(
kind: RTCRtpMediaType.RTCRtpMediaTypeVideo);
await _peerConnection.addTransceiver(
Expand Down
4 changes: 2 additions & 2 deletions lib/src/native/media_stream_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class MediaStreamNative extends MediaStream {

void setMediaTracks(List<dynamic> audioTracks, List<dynamic> videoTracks) {
_audioTracks.clear();
audioTracks.forEach((track) {
audioTracks?.forEach((track) {
_audioTracks.add(MediaStreamTrackNative(
track['id'], track['label'], track['kind'], track['enabled']));
});

_videoTracks.clear();
videoTracks.forEach((track) {
videoTracks?.forEach((track) {
_videoTracks.add(MediaStreamTrackNative(
track['id'], track['label'], track['kind'], track['enabled']));
});
Expand Down
5 changes: 3 additions & 2 deletions lib/src/native/rtc_video_view_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ class RTCVideoView extends StatelessWidget {
return SizedBox(
width: constraints.maxHeight * value.aspectRatio,
height: constraints.maxHeight,
child: value.renderVideo ? child : Container(),
child: child,
);
},
child: Transform(
transform: Matrix4.identity()..rotateY(mirror ? -pi : 0.0),
alignment: FractionalOffset.center,
child: videoRenderer.textureId != null
child: videoRenderer.textureId != null &&
videoRenderer.srcObject != null
? Texture(
textureId: videoRenderer.textureId,
filterQuality: filterQuality,
Expand Down
1 change: 0 additions & 1 deletion macos/WebRTC.framework/Headers

This file was deleted.

1 change: 1 addition & 0 deletions macos/WebRTC.framework/Headers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Versions/Current/Headers
1 change: 0 additions & 1 deletion macos/WebRTC.framework/Modules

This file was deleted.

1 change: 1 addition & 0 deletions macos/WebRTC.framework/Modules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Versions/Current/Modules
1 change: 0 additions & 1 deletion macos/WebRTC.framework/Resources

This file was deleted.

1 change: 1 addition & 0 deletions macos/WebRTC.framework/Resources
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Versions/Current/Resources
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ flutter:
pluginClass: FlutterWebRTCPlugin
macos:
pluginClass: FlutterWebRTCPlugin
windows:
pluginClass: FlutterWebRTCPlugin
4 changes: 4 additions & 0 deletions windows/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
flutter/

# Visual Studio files
*.user
46 changes: 46 additions & 0 deletions windows/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.15)
set(PROJECT_NAME "flutter_webrtc")
project(${PROJECT_NAME} LANGUAGES CXX)

# This value is used when generating builds using this plugin, so it must
# not be changed
set(PLUGIN_NAME "flutter_webrtc_plugin")

add_definitions(-DLIB_WEBRTC_API_DLL)

add_library(${PLUGIN_NAME} SHARED
"flutter_webrtc_plugin.cc"
"src/flutter_data_channel.cc"
"src/flutter_media_stream.cc"
"src/flutter_peerconnection.cc"
"src/flutter_video_renderer.cc"
"src/flutter_webrtc.cc"
"src/flutter_webrtc_base.cc"
"third_party/uuidxx/uuidxx.cc"
)

include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/uuidxx"
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/uuidxx"
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/libwebrtc/include"
)

apply_standard_settings(${PLUGIN_NAME})
set_target_properties(${PLUGIN_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden)
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
target_include_directories(${PLUGIN_NAME} INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)
target_link_libraries(${PLUGIN_NAME} PRIVATE
flutter
flutter_wrapper_plugin
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/libwebrtc/lib/libwebrtc.dll.lib"
)

# List of absolute paths to libraries that should be bundled with the plugin
set(flutter_webrtc_bundled_libraries
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/libwebrtc/lib/libwebrtc.dll"
PARENT_SCOPE
)
72 changes: 72 additions & 0 deletions windows/flutter_webrtc_plugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "flutter_webrtc/flutter_web_r_t_c_plugin.h"

#include <flutter/standard_message_codec.h>

#include "flutter_webrtc.h"

const char *kChannelName = "FlutterWebRTC.Method";

namespace flutter_webrtc_plugin {

// A webrtc plugin for windows/linux.
class FlutterWebRTCPluginImpl : public FlutterWebRTCPlugin {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrar *registrar) {
auto channel = std::make_unique<flutter::MethodChannel<EncodableValue>>(
registrar->messenger(), kChannelName,
&flutter::StandardMethodCodec::GetInstance());

auto *channel_pointer = channel.get();

// Uses new instead of make_unique due to private constructor.
std::unique_ptr<FlutterWebRTCPluginImpl> plugin(
new FlutterWebRTCPluginImpl(registrar, std::move(channel)));

channel_pointer->SetMethodCallHandler(
[plugin_pointer = plugin.get()](const auto &call, auto result) {
plugin_pointer->HandleMethodCall(call, std::move(result));
});

registrar->AddPlugin(std::move(plugin));
}

virtual ~FlutterWebRTCPluginImpl() {}

flutter::BinaryMessenger *messenger() { return messenger_; }

flutter::TextureRegistrar *textures() { return textures_; }

private:
// Creates a plugin that communicates on the given channel.
FlutterWebRTCPluginImpl(
flutter::PluginRegistrar *registrar,
std::unique_ptr<flutter::MethodChannel<EncodableValue>> channel)
: channel_(std::move(channel)),
messenger_(registrar->messenger()),
textures_(registrar->texture_registrar()) {
webrtc_ = std::make_unique<FlutterWebRTC>(this);
}

// Called when a method is called on |channel_|;
void HandleMethodCall(
const flutter::MethodCall<EncodableValue> &method_call,
std::unique_ptr<flutter::MethodResult<EncodableValue>> result) {
// handle method call and forward to webrtc native sdk.
webrtc_->HandleMethodCall(method_call, std::move(result));
}

private:
std::unique_ptr<flutter::MethodChannel<EncodableValue>> channel_;
std::unique_ptr<FlutterWebRTC> webrtc_;
flutter::BinaryMessenger *messenger_;
flutter::TextureRegistrar *textures_;
};

} // namespace flutter_webrtc_plugin

void FlutterWebRTCPluginRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar) {
static auto *plugin_registrar = new flutter::PluginRegistrar(registrar);
flutter_webrtc_plugin::FlutterWebRTCPluginImpl::RegisterWithRegistrar(
plugin_registrar);
}
51 changes: 51 additions & 0 deletions windows/include/flutter_data_channel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef FLUTTER_WEBRTC_RTC_DATA_CHANNEL_HXX
#define FLUTTER_WEBRTC_RTC_DATA_CHANNEL_HXX

#include "flutter_webrtc_base.h"

namespace flutter_webrtc_plugin {

class FlutterRTCDataChannelObserver : public RTCDataChannelObserver {
public:
FlutterRTCDataChannelObserver(scoped_refptr<RTCDataChannel> data_channel,
BinaryMessenger *messenger,
const std::string &channel_name);
virtual ~FlutterRTCDataChannelObserver();

virtual void OnStateChange(RTCDataChannelState state) override;

virtual void OnMessage(const char *buffer, int length, bool binary) override;

scoped_refptr<RTCDataChannel> data_channel() { return data_channel_; }

private:
std::unique_ptr<EventChannel<EncodableValue>> event_channel_;
std::unique_ptr<EventSink<EncodableValue>> event_sink_;
scoped_refptr<RTCDataChannel> data_channel_;
};

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

void CreateDataChannel(const std::string &label,
const EncodableMap &dataChannelDict,
RTCPeerConnection *pc,
std::unique_ptr<MethodResult<EncodableValue>>);

void DataChannelSend(RTCDataChannel *data_channel, const std::string &type,
const EncodableValue &data,
std::unique_ptr<MethodResult<EncodableValue>>);

void DataChannelClose(RTCDataChannel *data_channel,
std::unique_ptr<MethodResult<EncodableValue>>);

RTCDataChannel *DataChannelFormId(int id);

private:
FlutterWebRTCBase *base_;
};

} // namespace flutter_webrtc_plugin

#endif // !FLUTTER_WEBRTC_RTC_DATA_CHANNEL_HXX
50 changes: 50 additions & 0 deletions windows/include/flutter_media_stream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef FLUTTER_WEBRTC_RTC_GET_USERMEDIA_HXX
#define FLUTTER_WEBRTC_RTC_GET_USERMEDIA_HXX

#include "flutter_webrtc_base.h"

namespace flutter_webrtc_plugin {

using namespace flutter;

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

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

void GetUserAudio(const EncodableMap &constraints,
scoped_refptr<RTCMediaStream> stream, EncodableMap &params);

void GetUserVideo(const EncodableMap &constraints,
scoped_refptr<RTCMediaStream> stream, EncodableMap &params);

void GetSources(std::unique_ptr<MethodResult<EncodableValue>> result);

void MediaStreamGetTracks(
const std::string &stream_id,
std::unique_ptr<MethodResult<EncodableValue>> result);

void MediaStreamDispose(const std::string &stream_id,
std::unique_ptr<MethodResult<EncodableValue>> result);

void MediaStreamTrackSetEnable(
const std::string &track_id,
std::unique_ptr<MethodResult<EncodableValue>> result);

void MediaStreamTrackSwitchCamera(
const std::string &track_id,
std::unique_ptr<MethodResult<EncodableValue>> result);

void MediaStreamTrackDispose(
const std::string &track_id,
std::unique_ptr<MethodResult<EncodableValue>> result);

private:
FlutterWebRTCBase *base_;
};

} // namespace flutter_webrtc_plugin

#endif // !FLUTTER_WEBRTC_RTC_GET_USERMEDIA_HXX
Loading
0