瀏覽代碼

Merge branch 'master' of http://git.ius.plus/melon.yin/fis_lib_vid

melon.yin 2 年之前
父節點
當前提交
c71ca8880b

+ 3 - 0
lib/async_vid/shell/reader.dart

@@ -47,6 +47,9 @@ class AsyncShellVidDataReader extends AsyncVidDataReaderBase {
         'MinChunkSize': minChunkSize,
       },
     );
+    if (result != null) {
+      initChunk(result!);
+    }
     return result;
   }
 }

+ 1 - 1
lib/async_vid/vid_data.dart

@@ -78,7 +78,7 @@ abstract class AsyncVidImageDataBase {
     if (!_initialized) {
       var header = await _readHeader();
       if (header != vid_header) {
-        // throw Exception("The input data is not a VID data.");
+        throw Exception("The input data is not a VID data.");
       }
       _version = await _readVersion();
       //Get probe info

+ 7 - 23
lib/data_channel/channel.dart

@@ -26,6 +26,10 @@ abstract class VidDataChannel {
     return VidDataChannelImpl(url);
   }
 
+  static void receiveChunk(String id, Uint8List chunk) {
+    VidDataChannelImpl.receiveChunk(id, chunk);
+  }
+
   /// 下载进度变更事件
   final downloadProgressChanged = FEventHandler<VidDownloadProgressInfo>();
 
@@ -41,29 +45,9 @@ abstract class VidDataChannel {
     if (_initialized) return true;
 
     try {
-      final completer = Completer<bool>();
-      final timer = Timer(
-        Duration(milliseconds: timeout),
-        () {
-          if (!completer.isCompleted) {
-            completer.complete(_initialized);
-          }
-          if (!_initialized) {
-            source?.close();
-          }
-        },
-      );
-      _innerLoad(timeout).then((value) {
-        _initialized = true;
-        if (timer.isActive) {
-          timer.cancel();
-        }
-        completer.complete(true);
-      });
-      return completer.future;
-    } catch (e) {
-      return false;
-    }
+      _initialized = await _innerLoad(timeout);
+    } catch (e) {}
+    return _initialized;
   }
 
   /// 分发下载进度回调

+ 4 - 0
lib/data_channel/channel_io.dart

@@ -1,3 +1,5 @@
+import 'dart:typed_data';
+
 import 'package:fis_vid/async_vid/cached/vid_data.dart';
 import 'package:fis_vid/async_vid/http/vid_data.dart';
 import 'package:fis_vid/async_vid/vid_data.dart';
@@ -9,6 +11,8 @@ import 'channel.dart';
 class VidDataChannelImpl extends VidDataChannel {
   VidDataChannelImpl(String url) : super(url);
 
+  static void receiveChunk(String id, Uint8List chunk) {}
+
   @override
   Future<AsyncVidImageDataBase> buildSource() async {
     final cacheBuffer = await VidNativeCache.ins.getCache(url);

+ 4 - 0
lib/data_channel/channel_stub.dart

@@ -1,3 +1,5 @@
+import 'dart:typed_data';
+
 import 'package:fis_vid/async_vid/vid_data.dart';
 
 import 'channel.dart';
@@ -5,6 +7,8 @@ import 'channel.dart';
 class VidDataChannelImpl extends VidDataChannel {
   VidDataChannelImpl(String url) : super(url);
 
+  static void receiveChunk(String id, Uint8List chunk) {}
+
   @override
   Future<AsyncVidImageDataBase> buildSource() {
     // TODO: implement buildSource

+ 8 - 0
lib/data_channel/channel_web.dart

@@ -1,3 +1,5 @@
+import 'dart:typed_data';
+
 import 'package:fis_common/env/env.dart';
 import 'package:fis_vid/async_vid/http/vid_data.dart';
 import 'package:fis_vid/async_vid/shell/vid_data.dart';
@@ -8,6 +10,12 @@ import 'channel.dart';
 class VidDataChannelImpl extends VidDataChannel {
   VidDataChannelImpl(String url) : super(url);
 
+  static void receiveChunk(String id, Uint8List chunk) {
+    if (FPlatform.isPureWeb == false) {
+      AsyncShellVidImageData.receiveChunk(id, chunk);
+    }
+  }
+
   @override
   Future<AsyncVidImageDataBase> buildSource() async {
     if (FPlatform.isPureWeb) {