Skip to content

[video_player_videohole]How to call a callback which allow app do drm license request? #506

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

Closed
hyue7 opened this issue Dec 28, 2022 · 7 comments

Comments

@hyue7
Copy link
Collaborator

hyue7 commented Dec 28, 2022

Hi,all!
About this requirement:
flutter-tizen/flutter-tizen#217 (comment)
We now need to call a callback in app, this callback can request drm license on its own and return license back to player, and then player use the return result to get license key.
For example:
The dart callback in app will like this:

Future<Uint8List> _getLicense(Uint8List challenge) async {
    ... requesting the license (making network requests to license server etc)

    return licensePayload;
}

player(in this file) will call this callback like this:

int DrmManager::OnChallengeData(void *session_id, int msg_type, void *msg, int msg_len, void *user_data){
...
response = _getLicense(challenge_data);
...
}

This process must be synchronized.

I have tried several ways to implement it but all have some problems.
1. Use methodchannel
channel->InvokeMethod("drm.getlicense", std::move(arguments),std::move(result_handler));
I tried used this asynchronous method to call the callback, and then lock the thread and wait for the return result(return result is necessary). But this will lead to the main thread locked, the result cannot be received. Because InvokeMethod and main function are on the same thread.The main function locked, InvokeMethod cannot go on.
2. Use FFI

--dart code--
FFI_calc calcFunc = nativeApi.lookupFunction<Native_calc, FFI_calc>("GetLicense");
--C code--
FLUTTER_PLUGIN_EXPORT void GetLicense(int (*callback)());

Use FFI to call the dart function, because of the dart isolate, doing a callback from another thread is not supported. According to this.
When I use the callback in another thread(plugin thread), it will occur an error: Cannot invoke native callback outside an isolate. There is no particularly good solution for this problem.

Do you have any good way to implement this requirement? :)

@xuelian-bai
Copy link

xuelian-bai commented Dec 28, 2022

More details about the requirement:
in function DrmLicenseHelper::DoTransactionTZ() https://github.sec.samsung.net/yue7-huang/video_player_videohole/blob/main/tizen/src/drm_licence.cc#L686, now we get license by making our own http request, but now app need to get license by itself, so here we will call app's callback(dart api) to get license, the possible function definition may be like this:
app_callback(int in_data, char *out_ppb_response, char *out_pcb_response)
so that we call this callback like this:

DRM_RESULT DrmLicenseHelper::DoTransactionTZ(
    const char* p_server_url, const void* pb_challenge,
    unsigned long cb_challenge, unsigned char** ppb_response,
    unsigned long* pcb_response, DrmLicenseHelper::EDrmType type,
    const char* p_cookie, SExtensionCtxTZ* p_ext_ctx) {
  *ppb_response = nullptr;
  *pcb_response = 0;
  app_callback(cb_challenge, ppb_response, pcb_response);  
  return result;
}

we must get response result before return.

@xuelian-bai
Copy link

@swift-kim @JSUYA

@JSUYA
Copy link
Member

JSUYA commented Dec 28, 2022

Hi, Have you checked this link? https://dart-review.googlesource.com/c/sdk/+/134704

https://dart-review.googlesource.com/c/sdk/+/134704/18/samples/ffi/async/sample_async_callback.dart
According to this code, it looks like calling the Function Pointer for callback1 using the Receive/Send Port.

  final interactiveCppRequests = ReceivePort()..listen(requestExecuteCallback);
  final int nativePort = interactiveCppRequests.sendPort.nativePort;

@hyue7
Copy link
Collaborator Author

hyue7 commented Dec 28, 2022

https://dart-review.googlesource.com/c/sdk/+/134704/18/samples/ffi/async/sample_async_callback.dart
According to this code, it looks like calling the Function Pointer for callback1 using the Receive/Send Port.

Hi, this way is asynchronous, what I need is a synchronous call. I must receive the return result and then can go on.

@JSUYA
Copy link
Member

JSUYA commented Dec 29, 2022

I found this synchronized package.
Could this be the solution we were looking for?
(I don't know if this can be used with FFI code)

For single process (single isolate) accessing some resources (database..), it can help to

Provide transaction on database system that don't have transaction mechanism (mongodb, file system)
In html application make sure some asynchronous UI operation are not conflicting (login, transition)

@swift-kim
Copy link
Member

swift-kim commented Jan 2, 2023

@xuelian-bai Sorry for the late response. What I suggested via messenger was to use FFI's port mechanism and a lock on the main thread just like this:

https://github.com/dart-lang/sdk/blob/9383820f15fd5a7910064eb1267bb733ab07f713/runtime/bin/ffi_test/ffi_test_functions_vmspecific.cc#L488-L490

I believe in this way you can block the main thread (platform thread) while the Dart callback is running on the UI thread. I just haven't tried so I'm not very sure if it's a feasible solution. Maybe @WonyoungChoi have tried it in his way to solve flutter-tizen/tizen_interop#10.

@hyue7
Copy link
Collaborator Author

hyue7 commented Jan 5, 2023

I believe in this way you can block the main thread (platform thread) while the Dart callback is running on the UI thread.

Thanks!! I have solved the problem according this.

@hyue7 hyue7 closed this as completed Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants