Browse Source

modify vid load method of shell

melon.yin 2 years ago
parent
commit
644e6bdf65
2 changed files with 12 additions and 49 deletions
  1. 11 48
      lib/data_host/web/shell.dart
  2. 1 1
      pubspec.yaml

+ 11 - 48
lib/data_host/web/shell.dart

@@ -5,32 +5,29 @@ class _VidDataHostShell implements VidDataHostInterface {
 
   static PlatformService get _platform => VidDataHostEnv.platformGetter!.call();
 
-  VidUsProbe? _probe;
-  int? _frameCount;
+  VidUsImageData? _data;
 
   @override
   final String url;
 
   @override
-  int get frameCount => _frameCount!;
+  int get frameCount => _data!.imageCount;
 
   @override
-  VidUsProbe get probe => _probe!;
+  VidUsProbe get probe => _data!.probe;
 
   @override
-  Future<VidUsImageData?> getData() async => null;
+  Future<VidUsImageData?> getData() async => _data;
 
   @override
   Future<VidDataHostLoadInfo?> load() async {
-    final rst = await _platform.loadVid(url);
-    if (!rst.isSuccess) return null;
+    final rst = await _platform.getVidFile(url);
+    if (rst == null || rst.isEmpty) return null;
 
-    final buffer = const Base64Decoder().convert(rst.probeBase64!);
-    final probe = VidUsProbe.fromBytes(buffer);
-    _probe = probe;
-    _frameCount = rst.frameCount;
+    final buffer = const Base64Decoder().convert(rst);
+    _data = VidUsImageData(buffer);
 
-    final info = VidDataHostLoadInfo(probe);
+    final info = VidDataHostLoadInfo(_data!.probe);
     return info;
   }
 
@@ -39,45 +36,11 @@ class _VidDataHostShell implements VidDataHostInterface {
     int index, {
     List<TProcessor>? processors,
   }) async {
-    final rpcProcessors = _convert2RpcProcessors(processors);
-    final rst = await _platform.getVidFrame(GetVidFrameRequest(
-      index: index,
-      processors: rpcProcessors,
-    ));
-    if (!rst.isSuccess) return null;
-
-    final buffer = const Base64Decoder().convert(rst.frameBase64!);
-    final frame = VidUsImage.fromBytes(buffer);
-    return frame;
+    return _data?.getImage(index);
   }
 
   @override
   Future<void> release() async {
-    _platform.releaseVid();
-  }
-
-  List<TOut>? _convert2RpcProcessors<TIn extends VidFrameProcessor,
-      TOut extends VidFrameProcessorBase>(List<TIn>? processors) {
-    if (processors == null || processors.isEmpty) return null;
-
-    final result = <TOut>[];
-    for (final processor in processors) {
-      final converted = _convert2RpcProcessor<TIn, TOut>(processor);
-      if (converted != null) {
-        result.add(converted);
-      }
-    }
-    return result;
-  }
-
-  TOut? _convert2RpcProcessor<TIn extends VidFrameProcessor,
-      TOut extends VidFrameProcessorBase>(TIn processor) {
-    if (processor is VidBrightnessProcessor) {
-      return VidFrameBrightnessProcessor(processor.brightness) as TOut;
-    }
-    if (processor is VidContrastProcessor) {
-      return VidFrameContrastProcessor(processor.contrast) as TOut;
-    }
-    return null;
+    _data = null;
   }
 }

+ 1 - 1
pubspec.yaml

@@ -21,7 +21,7 @@ dependencies:
   fis_jsonrpc:
     git:
       url: http://git.ius.plus:88/Project-Wing/fis_lib_jsonrpc.git
-      ref: ^1.1.1    
+      ref: ^1.1.2 
   image: 3.1.3     
 
 # dependency_overrides: