Skip to content

[video_player_videohole] Migrating from Platform Channels to Dart FFI - #1073

Open
gin7773 wants to merge 41 commits into
flutter-tizen:mainfrom
gin7773:videohole/ffi_migration
Open

[video_player_videohole] Migrating from Platform Channels to Dart FFI#1073
gin7773 wants to merge 41 commits into
flutter-tizen:mainfrom
gin7773:videohole/ffi_migration

Conversation

@gin7773

@gin7773 gin7773 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Main changes:

  • Migrated from Platform Channels to Dart FFI.
  • Replaced EventChannel with FFI port for event callbacks.
  • Added JSON serialization for complex parameters.

Threading note

After migrating from Platform Channels to Dart FFI, some native calls are invoked synchronously from the Flutter UI thread rather than through the previous platform-channel handler path. The ecore_wl2 display path is marked with a TODO because those APIs are not thread-safe and will be revisited during the planned ecore-to-GLib migration.

Performance Comparison: FFI vs Platform Channel

Test Item / Iterations Method FFI avg (μs) Platform Channel avg (μs)
Simple Calls / 1000 each play 181 10,475
pause 3,081 1,904
setVolume 404 935
setLooping 170 360
setPlaybackSpeed 138 735
High Frequency Query / 1000 each getPosition 309 1,560
getDuration 462 478
getPosition+getDuration 719 887
String Transfer / 100 each getTrackInfo (video) 571 947
getTrackInfo (audio) 570 830
getTrackInfo (text) 299 426
SeekTo Call / 100 seekTo 51,414 148,544
Create+Dispose Cycle / 20 create+dispose 2,225,290 2,238,198
Memory (RSS) /proc/self/status VmRSS 1,232 KB 5,088 KB
Conclusion

FFI provides massive speedups for communication-heavy operations (3-58x) and uses 4.1x less memory. The only comparable areas are native-dominated operations (create+dispose) where communication overhead is negligible relative to player initialization.

@gin7773
gin7773 marked this pull request as draft July 28, 2026 10:38
gin7773 added 6 commits July 29, 2026 18:01
- Add nlohmann/json single-header library to tizen/third_party/
- Replace handwritten JSON parser with nlohmann/json in ParseJsonMap()
- Simplify ParseCreateMessage() to use json library directly
- Add EncodableValueFromJson() helper for JSON to EncodableValue conversion

This change improves JSON parsing reliability by supporting:
- Escape characters in strings
- Nested objects and arrays
- Unicode characters
- Proper error handling with parse_error exceptions

Co-Authored-By: Cline SR
- Add UnregisterAllPlayerEventPorts() function in video_player.cc
- Add ffi_unregister_all_player_event_ports() FFI wrapper
- Add Dart bindings in ffi_messages.g.dart
- Call unregisterAllPlayerEventPorts() in init() to clean up ports on hot restart

This fix prevents Dart port leaks when the Dart VM is restarted
(e.g., hot restart during development) while the native process continues.

Co-Authored-By: Cline SR
- Fix FFI event port symbol name mismatch (ffi_register_dart_port)
- Call Prepare() after RestorePlayer for two-phase initialization
- Return true from Play() when already playing (idempotent)
- Remove duplicate play() call in restored event handler

Co-Authored-By: Cline SR
@xiaowei-guan
xiaowei-guan self-requested a review July 30, 2026 09:24
@gin7773
gin7773 marked this pull request as ready for review August 5, 2026 08:19
@gin7773
gin7773 requested a review from JSUYA August 5, 2026 08:19
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.

3 participants