Skip to content

[flutter_webrtc_tizen]Upgrade flutter webrtc to 1.4.1#993

Open
xiaowei-guan wants to merge 14 commits intoflutter-tizen:masterfrom
xiaowei-guan:upgrade_webrtc
Open

[flutter_webrtc_tizen]Upgrade flutter webrtc to 1.4.1#993
xiaowei-guan wants to merge 14 commits intoflutter-tizen:masterfrom
xiaowei-guan:upgrade_webrtc

Conversation

@xiaowei-guan
Copy link
Copy Markdown
Contributor

@xiaowei-guan xiaowei-guan commented Apr 15, 2026

Fix #971

  • Upgrade flutter webrtc to 1.4.1

@xiaowei-guan xiaowei-guan marked this pull request as draft April 15, 2026 10:07
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the flutter_webrtc dependency to version 1.3.1 and introduces a TaskRunner interface to facilitate thread-safe event dispatching. New features include setVolume for audio tracks, dataChannelGetBufferedAmount, and configurable RTC logging severity. The refactor propagates the TaskRunner through various observers and managers and updates several WebRTC internal headers. Feedback identifies critical issues including a use-after-free vulnerability in setVolume, the lack of initialization for the task_runner_ member, and a dangling pointer risk with a static global logging proxy. Further improvements are requested regarding the robustness of the maybeFindDouble helper, adherence to C++ casting standards, and the restoration of a check for defined statistics members.

Comment thread packages/flutter_webrtc/tizen/src/flutter_webrtc.cc Outdated
Comment thread packages/flutter_webrtc/tizen/src/flutter_webrtc_tizen_plugin.cc
Comment thread packages/flutter_webrtc/tizen/src/flutter_webrtc.cc
Comment thread packages/flutter_webrtc/tizen/inc/flutter_common.h
Comment thread packages/flutter_webrtc/tizen/src/flutter_data_channel.cc Outdated
Comment thread packages/flutter_webrtc/tizen/src/flutter_peerconnection.cc
- 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
@xiaowei-guan xiaowei-guan changed the title Upgrade flutter webrtc to 1.3.1 Upgrade flutter webrtc to 1.4.1 Apr 24, 2026
@xiaowei-guan xiaowei-guan marked this pull request as ready for review April 24, 2026 11:30
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the flutter_webrtc_tizen plugin to version 0.2.0, increasing the minimum SDK requirements and updating the flutter_webrtc dependency. Key additions include a TaskRunner for thread-safe event dispatching, UTF-8 sanitization for device identifiers, and support for data packet encryption and frame capturing. The implementation also introduces audio volume control, buffered amount retrieval for data channels, and enhanced logging capabilities. Review feedback identifies critical issues in the frame capture logic, specifically a busy-wait loop that blocks the main thread and a memory leak in pixel buffer allocation. Additionally, concerns were raised regarding thread safety for shared flags, the use of volatile for synchronization, and potential crashes due to dangling pointers in the global logging callback.

Comment on lines +37 to +38
while (!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.

critical

This busy wait loop blocks the platform thread (main thread) until a frame is captured. This will cause the application UI to freeze and may trigger an ANR (Application Not Responding) if the frame capture takes too long or fails. Please use std::condition_variable with a timeout to wait for the frame asynchronously or at least non-blockingly.

int width = frame_.get()->width();
int height = frame_.get()->height();
int bytes_per_pixel = 4;
uint8_t* pixels = new uint8_t[width * height * bytes_per_pixel];
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.

high

The pixels buffer is allocated on the heap but never deleted, leading to a memory leak every time a frame is saved. Use std::vector<uint8_t> or std::unique_ptr<uint8_t[]> to manage the memory automatically.

Suggested change
uint8_t* pixels = new uint8_t[width * height * bytes_per_pixel];
std::vector<uint8_t> pixels(width * height * bytes_per_pixel);
frame_.get()->ConvertToARGB(RTCVideoFrame::Type::kABGR, pixels.data(),
/* unused */ -1, width, height);
FILE* file = fopen(path_.c_str(), "wb");
if (!file) {
return false;
}
svpng(file, width, height, pixels.data(), 1);


namespace flutter_webrtc_plugin {

static EventChannelProxy* eventChannelProxy = nullptr;
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.

high

The static global eventChannelProxy is a raw pointer to an object owned by a FlutterWebRTC instance. If the instance is destroyed, the pointer becomes dangling, and the logger callback (which is global to the process) will crash when it attempts to use it. Please ensure the log sink is removed and the pointer is cleared in the FlutterWebRTC destructor.

FlutterFrameCryptor::FlutterFrameCryptor(this),
FlutterDataPacketCryptor::FlutterDataPacketCryptor(this) {}

FlutterWebRTC::~FlutterWebRTC() {}
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.

high

The destructor should clean up the global logger sink to prevent crashes if log messages are received after the plugin instance is destroyed.

FlutterWebRTC::~FlutterWebRTC() {
  libwebrtc::LibWebRTCLogging::removeLogSink();
  eventChannelProxy = nullptr;
}

* 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.


#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>

std::unique_ptr<EventSink> sink_;
std::shared_ptr<flutter::EventSink<flutter::EncodableValue>> sink_;
std::list<EncodableValue> event_queue_;
bool on_listen_called_ = false;
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 on_listen_called_ flag is accessed from multiple threads (platform thread for callbacks and potentially other threads for Success). It should be atomic to avoid race conditions.

Suggested change
bool on_listen_called_ = false;
std::atomic<bool> on_listen_called_ = false;

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_;

return;
}

auto keyProvider = base_->key_providers_[keyProviderId];
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

Using operator[] on a std::map will insert a default-constructed entry if the key is not found. This pollutes the map with null entries for invalid IDs. It is better to use find() to check for existence.

  auto it = base_->key_providers_.find(keyProviderId);
  if (it == base_->key_providers_.end()) {
    result->Error("createDataPacketCryptor",
                  "createDataPacketCryptor() keyProvider is null");
    return;
  }
  auto keyProvider = it->second;

if (!member->IsDefined()) {
continue;
}
switch (member->GetType()) {
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 check if (!member->IsDefined()) was removed. Accessing values of undefined stats members can lead to unexpected behavior or garbage data. It is recommended to restore this check to ensure only defined stats are included in the report.

Suggested change
switch (member->GetType()) {
if (!member->IsDefined()) {
continue;
}
switch (member->GetType()) {

@xiaowei-guan xiaowei-guan changed the title Upgrade flutter webrtc to 1.4.1 [flutter webrtc tizen]Upgrade flutter webrtc to 1.4.1 Apr 24, 2026
@xiaowei-guan xiaowei-guan changed the title [flutter webrtc tizen]Upgrade flutter webrtc to 1.4.1 [flutter_webrtc_tizen]Upgrade flutter webrtc to 1.4.1 Apr 24, 2026
xiaowei-guan and others added 8 commits April 24, 2026 23:17
1.Fixed the use-after-free vulnerability caused by assigning `scoped_refptr<RTCMediaTrack>`
returned by `MediaTrackForId()` to raw pointers. The temporary `scoped_refptr` was being
destroyed at the end of the assignment statement, potentially deleting the track object
 before it could be used.
change so file Flags to soft
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flutter_webrtc_tizen] Upgrade to 1.41

1 participant