mp_core

Shared types, model configuration, and runtime primitives for MP tasks.

Use mp_core directly when building a custom task adapter, or transitively through mp_vision, mp_text, mp_audio, or mp_genai.

What it provides

  • Model assets, image and audio containers, result types, errors, and task lifecycle
  • Immutable image, audio, landmark, classification, detection, embedding, and segmentation containers.
  • Models loaded from bytes, local paths, or absolute URIs.
  • Optional SHA-256 verification for remotely loaded models.
  • CPU, GPU, Edge TPU NNAPI, and LiteRT delegate configuration.
  • Task lifecycle, status errors, timestamp validation, and injectable runtimes.
  • Generated FFI bindings for the public MediaPipe Tasks C headers.
  • Shared browser module and model-asset helpers.

Model assets

Models are application data, not SDK configuration. Supply one as bytes, a local path, or an absolute HTTPS URI, and pin remote models with a SHA-256 digest:

final local = ModelAsset.path('models/gesture_recognizer.task');
final memory = ModelAsset.bytes(Uint8List.fromList(modelBytes));
final remote = ModelAsset.uri(
  Uri.parse('https://cdn.example.com/models/gesture_recognizer.task'),
  sha256: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
);

The SDK never chooses or downloads a model without an explicit ModelAsset. Publish immutable, versioned model URLs and always provide a digest for production clients.

Combine a model with a delegate:

final options = BaseOptions(modelAsset: local, delegate: MpDelegate.cpu);

Ownership

Every created task implements MpTask. Call close() when inference is no longer needed. Closing twice is safe, and invoking a closed task fails immediately with MpTaskClosedError.

final detector = await ObjectDetector.create(options);
try {
  final result = await detector.detect(image);
  // Use the result.
} finally {
  await detector.close();
}

Long-lived tasks belong near the owning feature boundary, not inside a per-frame callback. A task serializes its native calls, so handles are never entered concurrently.

Failure contract

Unsupported API and platform combinations fail explicitly with MpException(MpStatus.unimplemented, …) rather than silently returning empty results. Check MpStatus before treating a failure as a model or input problem.

Where to go next

MP is independent software. MediaPipe is a trademark of Google LLC; this project is not affiliated with or endorsed by Google.

Libraries

mp_core
Shared, platform-neutral primitives for MediaPipe Tasks.
native
Low-level generated bindings for the MediaPipe Tasks C API.
web
Browser-only support used by MP task runtimes.