Skip to content

Commit b1005dc

Browse files
committed
updates to inference and example
1 parent e3d7c67 commit b1005dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2858
-1280
lines changed

packages/mediapipe-core/lib/src/interface/task_options.dart

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import 'dart:typed_data';
66

77
import 'package:equatable/equatable.dart';
88

9-
/// {@template TaskOptions}
9+
/// {@template BaseOptions}
1010
/// Root class for options classes for MediaPipe tasks.
11-
///
11+
/// {@endtemplate}
12+
abstract class Options extends Equatable {}
13+
14+
/// {@template TaskOptions}
1215
/// Implementing classes will contain two [BaseInnerTaskOptions] subclasses,
1316
/// including a descendent of the universal options struct, [BaseBaseOptions].
1417
/// The second field will be task-specific.
@@ -17,7 +20,7 @@ import 'package:equatable/equatable.dart';
1720
/// This implementation is not immutable to track whether `dispose` has been
1821
/// called. All values used by pkg:equatable are in fact immutable.
1922
// ignore: must_be_immutable
20-
abstract class BaseTaskOptions extends Equatable {
23+
abstract class BaseTaskOptions extends Options {
2124
/// {@macro TaskOptions}
2225
BaseTaskOptions();
2326

packages/mediapipe-core/lib/src/io/ffi_utils.dart

+6-5
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ extension DartAwareChars on Pointer<Char> {
6969
///
7070
/// See also:
7171
/// * [toDartStrings]
72-
String toDartString({int? length}) {
72+
String toDartString({int? length, bool copy = false}) {
7373
if (isNullPointer) {
7474
throw Exception('Unexpectedly called `toDartString` on nullptr');
7575
}
76-
return cast<Utf8>().toDartString(length: length);
76+
final value = cast<Utf8>().toDartString(length: length);
77+
return copy ? String.fromCharCodes(List<int>.from(value.codeUnits)) : value;
7778
}
7879

7980
/// Releases all native memory.
@@ -90,14 +91,14 @@ extension DartAwarePointerChars on Pointer<Pointer<Char>> {
9091
///
9192
/// See also:
9293
/// * [toDartString], for a non-list equivalent.
93-
List<String?> toDartStrings(int length) {
94+
List<String> toDartStrings(int length, {bool copy = false}) {
9495
if (isNullPointer) {
9596
throw Exception('Unexpectedly called `toDartStrings` on nullptr');
9697
}
97-
final dartStrings = <String?>[];
98+
final dartStrings = <String>[];
9899
int counter = 0;
99100
while (counter < length) {
100-
dartStrings.add(this[counter].toDartString());
101+
dartStrings.add(this[counter].toDartString(copy: copy));
101102
counter++;
102103
}
103104
return dartStrings;

packages/mediapipe-core/lib/src/io/task_options.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'third_party/mediapipe/generated/mediapipe_common_bindings.dart'
1515
/// should manage their [InnerTaskOptions] fields. The two suggested methods are
1616
/// [copyToNative] and [dispose].
1717
/// {@endtemplate}
18-
mixin TaskOptions<T extends Struct> on BaseTaskOptions {
18+
mixin TaskOptions<T extends Struct> on Options {
1919
/// {@template TaskOptions.copyToNative}
2020
/// Copies these task options into native memory. Any fields of type
2121
/// [InnerTaskOptions] should have their `assignToStruct` method called.

packages/mediapipe-core/test/io/task_options_test.dart

+6-2
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,17 @@ void main() {
8686
expect(ptr.ref.score_threshold, lessThan(0.90001));
8787
expect(ptr.ref.category_allowlist_count, 3);
8888
expect(
89-
ptr.ref.category_allowlist.toDartStrings(3),
89+
ptr.ref.category_allowlist.toDartStrings(
90+
3,
91+
),
9092
['good', 'great', 'best'],
9193
);
9294

9395
expect(ptr.ref.category_denylist_count, 4);
9496
expect(
95-
ptr.ref.category_denylist.toDartStrings(4),
97+
ptr.ref.category_denylist.toDartStrings(
98+
4,
99+
),
96100
['bad', 'terrible', 'worst', 'honestly come on'],
97101
);
98102
});

0 commit comments

Comments
 (0)