Skip to content

Commit

Permalink
[video_player_videohole] Fix web build (flutter-tizen#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
MAUstaoglu authored Jul 28, 2023
1 parent 5736eeb commit b33b193
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 58 deletions.
3 changes: 2 additions & 1 deletion packages/video_player_videohole/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 0.1.2

* Increase the minimum Flutter version to 3.3.
* Fix web build

## 0.1.1

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright 2023 Samsung Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:ffi';
import 'dart:isolate';

import 'package:flutter/foundation.dart';

import 'drm_configs.dart';

typedef _InitDartApi = int Function(Pointer<Void>);
typedef _InitDartApiNative = IntPtr Function(Pointer<Void>);

typedef _RegisterSendPort = void Function(int, int);
typedef _RegisterSendPortNative = Void Function(Int64, Int64);

class _CppRequest {
_CppRequest.fromList(List<Object?> message)
: replyPort = message[0]! as SendPort,
pendingCall = message[1]! as int,
method = message[2]! as String,
data = message[3]! as Uint8List;

final SendPort replyPort;
final int pendingCall;
final String method;
final Uint8List data;
}

class _CppResponse {
_CppResponse(this.pendingCall, this.data);

final int pendingCall;
final Uint8List data;

List<Object?> toList() => <Object?>[pendingCall, data];
}

/// Registers the DRM callback and communication channel for handling license challenges.
///
/// This function is used to register the necessary callback and communication channel
/// to handle DRM-related operations and license challenges for the video playback.
/// It establishes communication with native code using DynamicLibrary, and handles
/// incoming requests for license challenges from the platform side.
///
/// The [drmConfigs] parameter contains configuration details for DRM operations,
/// including a [licenseCallback] function that is responsible for acquiring licenses
/// based on the provided challenges.
///
/// It is important to call this function within the [initialize] method of the video
/// player to enable DRM capabilities and communicate with the native side properly.
///
/// Example usage:
/// ```dart
/// registerDrmCallback(licenseCallback, _playerId);
/// ```
///
/// Note: This function should not be called directly outside the [initialize] method,
/// and it requires proper configuration and setup of the native C/C++ code to handle
/// DRM operations.
void registerDrmCallback(LicenseCallback licenseCallback, int playerId) {
final DynamicLibrary process = DynamicLibrary.process();
final _InitDartApi initDartApi =
process.lookupFunction<_InitDartApiNative, _InitDartApi>(
'VideoPlayerTizenPluginInitDartApi');
initDartApi(NativeApi.initializeApiDLData);

final ReceivePort receivePort = ReceivePort();
receivePort.listen((dynamic message) async {
final _CppRequest request = _CppRequest.fromList(message as List<Object?>);

if (request.method == 'onLicenseChallenge') {
final Uint8List challenge = request.data;
final Uint8List result = await licenseCallback(challenge);

final _CppResponse response = _CppResponse(request.pendingCall, result);
request.replyPort.send(response.toList());
}
});

final _RegisterSendPort registerSendPort =
process.lookupFunction<_RegisterSendPortNative, _RegisterSendPort>(
'VideoPlayerTizenPluginRegisterSendPort');
registerSendPort(playerId, receivePort.sendPort.nativePort);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2023 Samsung Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'drm_configs.dart';

/// Register DRM callback function (No-op implementation).
///
/// This function is a no-op (no-operation) implementation for registering the DRM callback
/// and communication channel to handle license challenges for video playback. It does not
/// perform any actual DRM operations but serves as a placeholder to maintain consistency
/// in the codebase when DRM functionality is not required.
///
/// This function does not perform any communication with the native side or any DRM-related
/// operations. It can be used when DRM functionality is not required, or when a specific DRM
/// plugin or platform support is not available.
///
/// Example usage:
/// ```dart
/// registerDrmCallback(drmConfigs, _playerId);
/// ```
///
/// Note: This function does not have any DRM functionality and should only be used in cases
/// where DRM support is not necessary or when using a DRM plugin that does not require native
/// communication for license handling.
void registerDrmCallback(LicenseCallback licenseCallback, int playerId) {}
59 changes: 3 additions & 56 deletions packages/video_player_videohole/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:ffi' hide Size;
import 'dart:io';
import 'dart:isolate';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand All @@ -15,6 +13,8 @@ import 'package:flutter/services.dart';
import 'src/closed_caption_file.dart';
import 'src/drm_configs.dart';
import 'src/hole.dart';
import 'src/register_drm_callback_stub.dart'
if (dart.library.ffi) 'src/register_drm_callback_real.dart';
import 'video_player_platform_interface.dart';

export 'src/closed_caption_file.dart';
Expand Down Expand Up @@ -193,34 +193,6 @@ class VideoPlayerValue {
}
}

typedef _InitDartApi = int Function(Pointer<Void>);
typedef _InitDartApiNative = IntPtr Function(Pointer<Void>);

typedef _RegisterSendPort = void Function(int, int);
typedef _RegisterSendPortNative = Void Function(Int64, Int64);

class _CppRequest {
_CppRequest.fromList(List<Object?> message)
: replyPort = message[0]! as SendPort,
pendingCall = message[1]! as int,
method = message[2]! as String,
data = message[3]! as Uint8List;

final SendPort replyPort;
final int pendingCall;
final String method;
final Uint8List data;
}

class _CppResponse {
_CppResponse(this.pendingCall, this.data);

final int pendingCall;
final Uint8List data;

List<Object?> toList() => <Object?>[pendingCall, data];
}

/// Controls a platform video player, and provides updates when the state is
/// changing.
///
Expand Down Expand Up @@ -452,32 +424,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
}

if (drmConfigs?.licenseCallback != null) {
final DynamicLibrary process = DynamicLibrary.process();
final _InitDartApi initDartApi =
process.lookupFunction<_InitDartApiNative, _InitDartApi>(
'VideoPlayerTizenPluginInitDartApi');
initDartApi(NativeApi.initializeApiDLData);

final ReceivePort receivePort = ReceivePort();
receivePort.listen((dynamic message) async {
final _CppRequest request =
_CppRequest.fromList(message as List<Object?>);

if (request.method == 'onLicenseChallenge') {
final Uint8List challenge = request.data;
final Uint8List result =
await drmConfigs!.licenseCallback!(challenge);

final _CppResponse response =
_CppResponse(request.pendingCall, result);
request.replyPort.send(response.toList());
}
});

final _RegisterSendPort registerSendPort =
process.lookupFunction<_RegisterSendPortNative, _RegisterSendPort>(
'VideoPlayerTizenPluginRegisterSendPort');
registerSendPort(_playerId, receivePort.sendPort.nativePort);
registerDrmCallback(drmConfigs!.licenseCallback!, _playerId);
}

void errorListener(Object obj) {
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player_videohole/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player_videohole
description: Flutter plugin for displaying inline video on Tizen TV devices.
homepage: https://github.com/flutter-tizen/plugins
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/video_player_videohole
version: 0.1.1
version: 0.1.2

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down

0 comments on commit b33b193

Please sign in to comment.