Skip to content

Commit

Permalink
Updated the dive_av package to display video frames on a Flutter text…
Browse files Browse the repository at this point in the history
…ure.
  • Loading branch information
larryaasen committed Feb 19, 2024
1 parent 13a0ba2 commit ccc8523
Show file tree
Hide file tree
Showing 13 changed files with 424 additions and 137 deletions.
19 changes: 16 additions & 3 deletions packages/dive_av/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class MyApp extends StatefulWidget {

class _MyAppState extends State<MyApp> {
final _diveAvPlugin = DiveAv();
int? _textureId;

@override
void initState() {
Expand All @@ -35,14 +36,24 @@ class _MyAppState extends State<MyApp> {
// Razer Kiyo Pro: 0x1421100015320e05
// FaceTime HD Camera (Built-in): 0x8020000005ac8514

final sourceId1 = await _diveAvPlugin.createVideoSource('0x1421100015320e05');
final textureId = await _diveAvPlugin.initializeTexture();

final sourceId1 = await _diveAvPlugin
.createVideoSource('0x1421100015320e05', textureId: textureId);
print('createVideoSource: $sourceId1');

setState(() {
_textureId = textureId;
});

// final sourceId2 = await _diveAvPlugin.createVideoSource('0x8020000005ac8514');
// print('createVideoSource: $sourceId2');

Future.delayed(const Duration(seconds: 10)).then((value) async {
if (sourceId1 != null) {
setState(() {
_textureId = null;
});
final rv1 = await _diveAvPlugin.removeSource(sourceId: sourceId1);
print('removeSource: $sourceId1, $rv1');
}
Expand All @@ -68,8 +79,10 @@ class _MyAppState extends State<MyApp> {
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: const Center(
child: Text('Running'),
body: Center(
child: _textureId == null
? const Text('Running')
: Texture(textureId: _textureId!),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Foundation

import dive_av

@available(macOS 13.0, *)
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DiveAVPlugin.register(with: registry.registrar(forPlugin: "DiveAVPlugin"))
}
2 changes: 1 addition & 1 deletion packages/dive_av/example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral

SPEC CHECKSUMS:
dive_av: 2c554534c6face82a66ab084f1b14bd4d576b26e
dive_av: e5d01276bf937eaab65f73b4786eb3a3062668ce
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down Expand Up @@ -631,7 +631,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -678,7 +678,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down
8 changes: 6 additions & 2 deletions packages/dive_av/lib/dive_av.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import 'dive_av_platform_interface.dart';

class DiveAv {
Future<String?> createVideoSource(String deviceUniqueID) async {
return DiveAvPlatform.instance.createVideoSource(deviceUniqueID);
Future<String?> createVideoSource(String deviceUniqueID, {int? textureId}) async {
return DiveAvPlatform.instance.createVideoSource(deviceUniqueID, textureId);
}

Future<bool> removeSource({required String sourceId}) async {
return DiveAvPlatform.instance.removeSource(sourceId: sourceId);
}

Future<int> initializeTexture() async {
return DiveAvPlatform.instance.initializeTexture();
}
}
14 changes: 11 additions & 3 deletions packages/dive_av/lib/dive_av_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ class MethodChannelDiveAv extends DiveAvPlatform {
final methodChannel = const MethodChannel('dive_av.io/plugin');

@override
Future<String?> createVideoSource(String deviceUniqueID) async {
final rv =
await methodChannel.invokeMethod<String?>('createVideoSource', {'device_uique_id': deviceUniqueID});
Future<String?> createVideoSource(String deviceUniqueID, int? textureId) async {
final rv = await methodChannel.invokeMethod<String?>('createVideoSource', {
'device_uique_id': deviceUniqueID,
'texture_id': textureId,
});
return rv;
}

Expand All @@ -21,4 +23,10 @@ class MethodChannelDiveAv extends DiveAvPlatform {
final rv = await methodChannel.invokeMethod<bool>('removeSource', {'source_id': sourceId}) ?? false;
return rv;
}

@override
Future<int> initializeTexture() async {
final rv = await methodChannel.invokeMethod<int>('initializeTexture') ?? 0;
return rv;
}
}
6 changes: 5 additions & 1 deletion packages/dive_av/lib/dive_av_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ abstract class DiveAvPlatform extends PlatformInterface {
_instance = instance;
}

Future<String?> createVideoSource(String deviceUniqueID) {
Future<String?> createVideoSource(String deviceUniqueID, int? textureId) {
throw UnimplementedError('createVideoSource has not been implemented.');
}

Future<bool> removeSource({required String sourceId}) {
throw UnimplementedError('removeSource has not been implemented.');
}

Future<int> initializeTexture() {
throw UnimplementedError('initializeTexture has not been implemented.');
}
}
Loading

0 comments on commit ccc8523

Please sign in to comment.