|
@@ -1,5 +1,8 @@
|
|
|
|
+import 'dart:convert';
|
|
import 'dart:typed_data';
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
+import 'package:fis_common/env/env.dart';
|
|
|
|
+import 'package:fis_common/web/shell_api_hepler.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:vid/us/vid_us_data_http_reader.dart';
|
|
import 'package:vid/us/vid_us_data_http_reader.dart';
|
|
import 'package:vid/us/vid_us_data_reader.dart';
|
|
import 'package:vid/us/vid_us_data_reader.dart';
|
|
@@ -8,6 +11,7 @@ import 'package:vid/us/vid_us_image_data.dart';
|
|
import 'package:vid/us/vid_us_probe.dart';
|
|
import 'package:vid/us/vid_us_probe.dart';
|
|
|
|
|
|
import 'reader.dart';
|
|
import 'reader.dart';
|
|
|
|
+import 'shell/reader.dart';
|
|
|
|
|
|
abstract class AsyncVidImageDataBase {
|
|
abstract class AsyncVidImageDataBase {
|
|
late AsyncVidDataReaderBase _reader;
|
|
late AsyncVidDataReaderBase _reader;
|
|
@@ -76,21 +80,35 @@ abstract class AsyncVidImageDataBase {
|
|
///Initialize the HttpVidUsImageData, must be called firstly.
|
|
///Initialize the HttpVidUsImageData, must be called firstly.
|
|
Future<bool> initialize() async {
|
|
Future<bool> initialize() async {
|
|
if (!_initialized) {
|
|
if (!_initialized) {
|
|
- var header = await _readHeader();
|
|
|
|
|
|
+ String header;
|
|
|
|
+ if (_reader.isVrd) {
|
|
|
|
+ header = vid_header;
|
|
|
|
+ } else {
|
|
|
|
+ header = await _readHeader();
|
|
|
|
+ }
|
|
if (header != vid_header) {
|
|
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
|
|
|
|
- _probe = await _readProbe();
|
|
|
|
- _imageFormat = await _readImageFormat();
|
|
|
|
- _extendedData = await _readExtendedData();
|
|
|
|
- _imagePositionList = [];
|
|
|
|
- var imagePositionListData = await _readImagePositionListData();
|
|
|
|
- _imageCount = imagePositionListData.length ~/ 8;
|
|
|
|
- var imagePositionReader = VidUsDataReader(imagePositionListData);
|
|
|
|
- for (var i = 0; i < _imageCount; i++) {
|
|
|
|
- _imagePositionList.add(imagePositionReader.readInt64V2());
|
|
|
|
|
|
+ if (_reader.isVrd) {
|
|
|
|
+ _version = await _getVersion();
|
|
|
|
+ _probe = await _getProbe();
|
|
|
|
+ _imageFormat = await _getImageFormat();
|
|
|
|
+ _extendedData = await _getExtendedData();
|
|
|
|
+ _imageCount = await _getImageCount();
|
|
|
|
+ print('_imageCount:$_imageCount');
|
|
|
|
+ } else {
|
|
|
|
+ _version = await _readVersion();
|
|
|
|
+ //Get probe info
|
|
|
|
+ _probe = await _readProbe();
|
|
|
|
+ _imageFormat = await _readImageFormat();
|
|
|
|
+ _extendedData = await _readExtendedData();
|
|
|
|
+ _imagePositionList = [];
|
|
|
|
+ var imagePositionListData = await _readImagePositionListData();
|
|
|
|
+ _imageCount = imagePositionListData.length ~/ 8;
|
|
|
|
+ var imagePositionReader = VidUsDataReader(imagePositionListData);
|
|
|
|
+ for (var i = 0; i < _imageCount; i++) {
|
|
|
|
+ _imagePositionList.add(imagePositionReader.readInt64V2());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
_initialized = true;
|
|
_initialized = true;
|
|
}
|
|
}
|
|
@@ -245,9 +263,21 @@ abstract class AsyncVidImageDataBase {
|
|
var timeout = 0;
|
|
var timeout = 0;
|
|
while (!_closed) {
|
|
while (!_closed) {
|
|
try {
|
|
try {
|
|
- var imageData = _reader.readBytes(_imagePositionList[index]);
|
|
|
|
|
|
+ print('_reader.readBytes $index');
|
|
|
|
+ Uint8List imageData;
|
|
|
|
+ if (_reader.isVrd) {
|
|
|
|
+ imageData = _reader.getImageBytes(index);
|
|
|
|
+ if (imageData.isEmpty) {
|
|
|
|
+ _reader.skipToFrame(index);
|
|
|
|
+ throw Exception("Can not find image Data");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ imageData = _reader.readBytes(_imagePositionList[index]);
|
|
|
|
+ }
|
|
|
|
+ print('_reader.readBytes $index done');
|
|
return VidUsImage.fromBytes(imageData);
|
|
return VidUsImage.fromBytes(imageData);
|
|
} catch (ex) {
|
|
} catch (ex) {
|
|
|
|
+ print('_reader.readBytes $index ex:$ex');
|
|
if (ex is NotReadyException) {
|
|
if (ex is NotReadyException) {
|
|
if (timeout >= _readImageTimeout) {
|
|
if (timeout >= _readImageTimeout) {
|
|
throw ReadTimeoutException();
|
|
throw ReadTimeoutException();
|
|
@@ -261,4 +291,59 @@ abstract class AsyncVidImageDataBase {
|
|
}
|
|
}
|
|
throw AlreadyClosedException();
|
|
throw AlreadyClosedException();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ Future<int> _getVersion() async {
|
|
|
|
+ final result = await ShellApiHelper.call(
|
|
|
|
+ 'getVersion',
|
|
|
|
+ {
|
|
|
|
+ 'Url': _reader.url,
|
|
|
|
+ },
|
|
|
|
+ );
|
|
|
|
+ print('_getVersion:$result');
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Future<VidUsProbe> _getProbe() async {
|
|
|
|
+ final result = await ShellApiHelper.call(
|
|
|
|
+ 'getVinnoProbe',
|
|
|
|
+ {
|
|
|
|
+ 'Url': _reader.url,
|
|
|
|
+ },
|
|
|
|
+ );
|
|
|
|
+ var probe = base64Decode(result);
|
|
|
|
+ var probeResult = VidUsProbe.fromBytes(probe);
|
|
|
|
+ print("probe : ${probeResult.name} ${probeResult.type}");
|
|
|
|
+ return probeResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Future<VidUsImageFormat> _getImageFormat() async {
|
|
|
|
+ final result = await ShellApiHelper.call(
|
|
|
|
+ 'getImageFormat',
|
|
|
|
+ {
|
|
|
|
+ 'Url': _reader.url,
|
|
|
|
+ },
|
|
|
|
+ );
|
|
|
|
+ return VidUsImageFormat.values
|
|
|
|
+ .firstWhere((element) => element.index == result);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Future<Uint8List> _getExtendedData() async {
|
|
|
|
+ final result = await ShellApiHelper.call(
|
|
|
|
+ 'getExtendedData',
|
|
|
|
+ {
|
|
|
|
+ 'Url': _reader.url,
|
|
|
|
+ },
|
|
|
|
+ );
|
|
|
|
+ return base64Decode(result);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Future<int> _getImageCount() async {
|
|
|
|
+ final result = await ShellApiHelper.call(
|
|
|
|
+ 'getImageCount',
|
|
|
|
+ {
|
|
|
|
+ 'Url': _reader.url,
|
|
|
|
+ },
|
|
|
|
+ );
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
}
|
|
}
|