Skip to content
Open
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: 3 additions & 0 deletions packages/flutter_webrtc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
## NEXT

## 0.2.0

* Update minimum Flutter and Dart version to 3.13 and 3.1.
* Fix analyze issue.
* Update code format.
* Adds compatibility with `http` 1.0 in example.
* Update flutter_webrtc to 1.3.1.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a discrepancy between the version mentioned here (1.3.1) and the version mentioned in the PR title and example pubspecs (1.4.1). Please ensure the version is consistent across all files.

Suggested change
* Update flutter_webrtc to 1.3.1.
* Update flutter_webrtc to 1.4.1.


## 0.1.3

Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_webrtc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ For other Tizen devices :

```yaml
dependencies:
flutter_webrtc: ^0.9.46
flutter_webrtc_tizen: ^0.1.3
flutter_webrtc: ^1.3.1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The version mentioned here (1.3.1) should be updated to 1.4.1 to match the PR intent and other configuration files.

Suggested change
flutter_webrtc: ^1.3.1
flutter_webrtc: ^1.4.1

flutter_webrtc_tizen: ^0.2.0
```

## Functionality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
cupertino_icons: ^1.0.3
flutter:
sdk: flutter
flutter_webrtc: 0.9.46 # Use a fixed version due to build errors.
flutter_webrtc: ^1.4.1
flutter_webrtc_tizen:
path: ../../
http: ">=0.13.0 <2.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ description: Demonstrates how to use the webrtc plugin.
publish_to: "none"

environment:
sdk: ">=3.1.0 <4.0.0"
sdk: ">=3.3.0 <4.0.0"
flutter: ">=3.13.0"

dependencies:
cupertino_icons: ^1.0.2
flutter:
sdk: flutter
flutter_background: ^1.0.0
flutter_webrtc: 0.9.46 # Use a fixed version due to build errors.
flutter_webrtc: ^1.4.1
flutter_webrtc_tizen:
path: ../../
gallery_saver_plus: 3.2.4
path_provider: ^2.0.7
path_provider_tizen: ^2.0.2
permission_handler: ^10.4.3
permission_handler_tizen: ^1.3.0
web: ^0.3.0
sdp_transform: ^0.3.2
web: ^1.0.0

dev_dependencies:
flutter_test:
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_webrtc/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: flutter_webrtc_tizen
homepage: https://github.com/flutter-tizen/plugins
description: Flutter WebRTC plugin for Tizen, based on GoogleWebRTC.
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/flutter_webrtc
version: 0.1.3
version: 0.2.0

environment:
sdk: ">=3.1.0 <4.0.0"
sdk: ">=3.3.0 <4.0.0"
flutter: ">=3.13.0"

flutter:
Expand Down
16 changes: 15 additions & 1 deletion packages/flutter_webrtc/tizen/inc/flutter_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

#include <list>
#include <memory>
#include <mutex>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Please include <atomic> to support thread-safe flag management in EventChannelProxyImpl and other classes.

Suggested change
#include <mutex>
#include <atomic>
#include <mutex>

#include <optional>
#include <queue>
#include <string>

typedef flutter::EncodableValue EncodableValue;
Expand All @@ -26,6 +29,8 @@ typedef flutter::EventSink<EncodableValue> EventSink;
typedef flutter::MethodCall<EncodableValue> MethodCall;
typedef flutter::MethodResult<EncodableValue> MethodResult;

class TaskRunner;

// foo.StringValue() becomes std::get<std::string>(foo)
// foo.IsString() becomes std::holds_alternative<std::string>(foo)

Expand Down Expand Up @@ -88,6 +93,14 @@ inline double findDouble(const EncodableMap& map, const std::string& key) {
return 0.0;
}

inline std::optional<double> maybeFindDouble(const EncodableMap& map,
const std::string& key) {
auto it = map.find(EncodableValue(key));
if (it != map.end() && TypeIs<double>(it->second))
return GetValue<double>(it->second);
return std::nullopt;
}
Comment thread
xiaowei-guan marked this conversation as resolved.

inline std::vector<uint8_t> findVector(const EncodableMap& map,
const std::string& key) {
auto it = map.find(EncodableValue(key));
Expand Down Expand Up @@ -161,7 +174,8 @@ class MethodResultProxy {
class EventChannelProxy {
public:
static std::unique_ptr<EventChannelProxy> Create(
BinaryMessenger* messenger, const std::string& channelName);
BinaryMessenger* messenger, TaskRunner* task_runner,
const std::string& channelName);

virtual ~EventChannelProxy() = default;

Expand Down
4 changes: 4 additions & 0 deletions packages/flutter_webrtc/tizen/inc/flutter_data_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class FlutterRTCDataChannelObserver : public RTCDataChannelObserver {
public:
FlutterRTCDataChannelObserver(scoped_refptr<RTCDataChannel> data_channel,
BinaryMessenger* messenger,
TaskRunner* task_runner,
const std::string& channel_name);
virtual ~FlutterRTCDataChannelObserver();

Expand Down Expand Up @@ -38,6 +39,9 @@ class FlutterDataChannel {
const EncodableValue& data,
std::unique_ptr<MethodResultProxy>);

void DataChannelGetBufferedAmount(RTCDataChannel* data_channel,
std::unique_ptr<MethodResultProxy> result);

void DataChannelClose(RTCDataChannel* data_channel,
const std::string& data_channel_uuid,
std::unique_ptr<MethodResultProxy>);
Expand Down
39 changes: 39 additions & 0 deletions packages/flutter_webrtc/tizen/inc/flutter_data_packet_cryptor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef FLUTTER_WEBRTC_RTC_DATA_PACKET_CRYPTOR_HXX
#define FLUTTER_WEBRTC_RTC_DATA_PACKET_CRYPTOR_HXX

#include "flutter_common.h"
#include "flutter_webrtc_base.h"
#include "rtc_data_packet_cryptor.h"

namespace flutter_webrtc_plugin {

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

bool HandleDataPacketCryptorMethodCall(
const MethodCallProxy& method_call,
std::unique_ptr<MethodResultProxy> result,
std::unique_ptr<MethodResultProxy>* outResult);

void CreateDataPacketCryptor(const EncodableMap& constraints,
std::unique_ptr<MethodResultProxy> result);

void DataPacketCryptorDispose(const EncodableMap& constraints,
std::unique_ptr<MethodResultProxy> result);

void DataPacketCryptorEncrypt(const EncodableMap& constraints,
std::unique_ptr<MethodResultProxy> result);

void DataPacketCryptorDecrypt(const EncodableMap& constraints,
std::unique_ptr<MethodResultProxy> result);

private:
FlutterWebRTCBase* base_;
std::map<std::string, scoped_refptr<libwebrtc::RTCDataPacketCryptor>>
data_packet_cryptors_;
};

} // namespace flutter_webrtc_plugin

#endif // FLUTTER_WEBRTC_RTC_DATA_PACKET_CRYPTOR_HXX
36 changes: 36 additions & 0 deletions packages/flutter_webrtc/tizen/inc/flutter_frame_capturer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef FLUTTER_WEBRTC_RTC_FRAME_CAPTURER_HXX
#define FLUTTER_WEBRTC_RTC_FRAME_CAPTURER_HXX

#include <mutex>

#include "flutter_common.h"
#include "flutter_webrtc_base.h"
#include "rtc_video_frame.h"
#include "rtc_video_renderer.h"

namespace flutter_webrtc_plugin {

using namespace libwebrtc;

class FlutterFrameCapturer
: public RTCVideoRenderer<scoped_refptr<RTCVideoFrame>> {
public:
FlutterFrameCapturer(RTCVideoTrack* track, std::string path);

virtual void OnFrame(scoped_refptr<RTCVideoFrame> frame) override;

void CaptureFrame(std::unique_ptr<MethodResultProxy> result);

private:
RTCVideoTrack* track_;
std::string path_;
std::mutex mutex_;
scoped_refptr<RTCVideoFrame> frame_;
volatile bool catch_frame_;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In C++, volatile does not provide atomicity or memory ordering guarantees for thread synchronization. Use std::atomic<bool> instead, or use a condition variable for more efficient synchronization.

Suggested change
volatile bool catch_frame_;
std::atomic<bool> catch_frame_;


bool SaveFrame();
};

} // namespace flutter_webrtc_plugin

#endif // !FLUTTER_WEBRTC_RTC_FRAME_CAPTURER_HXX
14 changes: 10 additions & 4 deletions packages/flutter_webrtc/tizen/inc/flutter_frame_cryptor.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ namespace flutter_webrtc_plugin {
class FlutterFrameCryptorObserver : public libwebrtc::RTCFrameCryptorObserver {
public:
FlutterFrameCryptorObserver(BinaryMessenger* messenger,
TaskRunner* task_runner,
const std::string& channelName)
: event_channel_(EventChannelProxy::Create(messenger, channelName)) {}
: event_channel_(
EventChannelProxy::Create(messenger, task_runner, channelName)) {}
void OnFrameCryptionStateChanged(const string participant_id,
libwebrtc::RTCFrameCryptionState state);

Expand All @@ -23,8 +25,12 @@ class FlutterFrameCryptor {
public:
FlutterFrameCryptor(FlutterWebRTCBase* base) : base_(base) {}

bool HandleFrameCryptorMethodCall(const MethodCallProxy& method_call,
std::unique_ptr<MethodResultProxy> result);
// Since this takes ownership of result, ownership will be passed back to
// 'outResult' if this function fails
bool HandleFrameCryptorMethodCall(
const MethodCallProxy& method_call,
std::unique_ptr<MethodResultProxy> result,
std::unique_ptr<MethodResultProxy>* outResult);

void FrameCryptorFactoryCreateFrameCryptor(
const EncodableMap& constraints,
Expand Down Expand Up @@ -57,6 +63,7 @@ class FlutterFrameCryptor {

void KeyProviderExportSharedKey(const EncodableMap& constraints,
std::unique_ptr<MethodResultProxy> result);

void KeyProviderSetKey(const EncodableMap& constraints,
std::unique_ptr<MethodResultProxy> result);

Expand Down Expand Up @@ -91,7 +98,6 @@ class FlutterFrameCryptor {
frame_cryptors_;
std::map<std::string, scoped_refptr<FlutterFrameCryptorObserver>>
frame_cryptor_observers_;
std::map<std::string, scoped_refptr<libwebrtc::KeyProvider>> key_providers_;
};

} // namespace flutter_webrtc_plugin
Expand Down
1 change: 1 addition & 0 deletions packages/flutter_webrtc/tizen/inc/flutter_peerconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class FlutterPeerConnectionObserver : public RTCPeerConnectionObserver {
FlutterPeerConnectionObserver(FlutterWebRTCBase* base,
scoped_refptr<RTCPeerConnection> peerconnection,
BinaryMessenger* messenger,
TaskRunner* task_runner,
const std::string& channel_name,
std::string& peerConnectionId);

Expand Down
15 changes: 15 additions & 0 deletions packages/flutter_webrtc/tizen/inc/flutter_utf8_sanitize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef FLUTTER_WEBRTC_PLUGIN_FLUTTER_UTF8_SANITIZE_H_
#define FLUTTER_WEBRTC_PLUGIN_FLUTTER_UTF8_SANITIZE_H_

#include <string>

namespace flutter_webrtc_plugin {

// ADM/device buffers may not be valid UTF-8. Flutter StandardMessageCodec
// decodes as UTF-8; invalid bytes cause FormatException. Use before
// EncodableValue and when comparing ids from Dart.
std::string SanitizeUtf8ForFlutter(const std::string& input);

} // namespace flutter_webrtc_plugin

#endif // FLUTTER_WEBRTC_PLUGIN_FLUTTER_UTF8_SANITIZE_H_
1 change: 1 addition & 0 deletions packages/flutter_webrtc/tizen/inc/flutter_video_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class FlutterVideoRenderer
~FlutterVideoRenderer();

void initialize(TextureRegistrar* registrar, BinaryMessenger* messenger,
TaskRunner* task_runner,
std::unique_ptr<flutter::TextureVariant> texture,
int64_t texture_id);

Expand Down
11 changes: 10 additions & 1 deletion packages/flutter_webrtc/tizen/inc/flutter_webrtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

#include "flutter_common.h"
#include "flutter_data_channel.h"
#include "flutter_data_packet_cryptor.h"
#include "flutter_frame_cryptor.h"
#include "flutter_media_stream.h"
#include "flutter_peerconnection.h"
#include "flutter_video_renderer.h"
#include "libwebrtc.h"
#include "rtc_logging.h"

namespace flutter_webrtc_plugin {

Expand All @@ -18,20 +20,27 @@ class FlutterWebRTCPlugin : public flutter::Plugin {
virtual BinaryMessenger* messenger() = 0;

virtual TextureRegistrar* textures() = 0;

virtual TaskRunner* task_runner() = 0;
};

class FlutterWebRTC : public FlutterWebRTCBase,
public FlutterVideoRendererManager,
public FlutterMediaStream,
public FlutterPeerConnection,
public FlutterDataChannel,
public FlutterFrameCryptor {
public FlutterFrameCryptor,
public FlutterDataPacketCryptor {
public:
FlutterWebRTC(FlutterWebRTCPlugin* plugin);
virtual ~FlutterWebRTC();

void HandleMethodCall(const MethodCallProxy& method_call,
std::unique_ptr<MethodResultProxy> result);

private:
void initLoggerCallback(RTCLoggingSeverity severity);
RTCLoggingSeverity str2LogSeverity(std::string str);
};

} // namespace flutter_webrtc_plugin
Expand Down
Loading
Loading