Skip to content

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

Open
gin7773 wants to merge 29 commits into
flutter-tizen:masterfrom
gin7773:videohole/ffi_migration
Open

[video_player_videohole] Migrating from Platform Channels to Dart FFI#1073
gin7773 wants to merge 29 commits into
flutter-tizen:masterfrom
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.

@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
@gin7773
gin7773 requested a review from seungsoo47 August 5, 2026 08:20
",\"durationRange\":[" +
std::to_string(duration_pair.first) + "," +
std::to_string(duration_pair.second) + "]}";
return strdup(duration_json.c_str());

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.

Memory leak: ffi_get_duration returns strdup-allocated string, but ffi_get_track_info also returns strdup-allocated string — Dart side must call ffi_free_string

  • ffi_get_duration() returns strdup(duration_json.c_str()) — caller must free().
  • ffi_get_track_info() returns strdup(j.dump().c_str()) — caller must free().
  • Dart side: duration() and getTrackInfo() correctly call bindings._ffiFreeString(ptr) in finally blocks. ✅ Verified correct.
  • However: ffi_get_duration() returns strdup("-1") when player not found. The Dart side checks if (jsonString == '-1') and throws, but the finally block does free it. ✅ OK.

Comment thread packages/video_player_videohole/tizen/src/video_player.cc Outdated
Comment thread packages/video_player_videohole/tizen/src/media_player.cc
gin7773 added 3 commits August 5, 2026 18:45
- Move all FFI function implementations from video_player_tizen_plugin.cc to ffi_messages.cc
- Add ffi_prepare() function that was missing
- Use dependency injection pattern (ffi_set_plugin_registrar) for clean boundaries
- Keep video_player_tizen_plugin.cc minimal (plugin registration only)

Co-Authored-By: Cline SR
>
> 1. Fix potential deadlock in PostEventToDart
>    - Copy port number under lock, then release lock BEFORE calling Dart_PostCObject_DL
>    - Use explicit scope block to ensure lock is released immediately
>    - Prevents deadlock if Dart_PostCObject_DL blocks or callbacks into native code
>
> 2. Remove dead code (player_index variable)
>    - player_index in video_player.cc is no longer used
>    - ID generation moved to media_player.cc (player_id_counter)
>
> Co-Authored-By: Cline SR
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.

2 participants