mockingbird_platform_interface 0.1.0 copy "mockingbird_platform_interface: ^0.1.0" to clipboard
mockingbird_platform_interface: ^0.1.0 copied to clipboard

The platform interface of the mockingbird plugin: plain data records, the engine contract, and the shared dart:ffi implementation for native platforms.

mockingbird_platform_interface #

The platform interface for the mockingbird plugin: the MockingbirdPlatform contract every platform package implements, the plain data records that cross it, and a shared dart:ffi implementation for the platforms that link the engine natively.

App code does not depend on this package. Depend on mockingbird, which pulls in the platform packages for Android, iOS, macOS and web.

The contract #

MockingbirdPlatform exposes the engine's operations with plain Dart types and the C ABI's status codes as integers; the mockingbird package turns codes into exceptions and records into its typed API:

abstract class MockingbirdPlatform extends PlatformInterface {
  Future<void> initialize();
  String version();
  String statusName(int status);
  MockingbirdCreateResult create(MockingbirdNativeConfig config);
  void destroy(MockingbirdEngineHandle handle);
  int start(MockingbirdEngineHandle handle);
  int stop(MockingbirdEngineHandle handle);
  int pushPcm(MockingbirdEngineHandle handle, Int16List samples, int captureTsUs);
  MockingbirdPcmResult readPcm(MockingbirdEngineHandle handle, int maxSamples);
  MockingbirdEventResult pollEvent(MockingbirdEngineHandle handle);
  MockingbirdPacketResult drainPacket(MockingbirdEngineHandle handle);
  MockingbirdStatsResult stats(MockingbirdEngineHandle handle);
  int updateConfig(MockingbirdEngineHandle handle, MockingbirdNativeConfig config);
}

MockingbirdNativeConfig, MockingbirdNativeEvent, MockingbirdNativePacket and MockingbirdNativeStats mirror the C structs field for field, with no dart:ffi types, so the main library compiles on every platform including the web.

The FFI implementation #

package:mockingbird_platform_interface/ffi.dart holds MockingbirdFfiPlatform, a complete implementation over the generated bindings. A platform package that links the engine natively only supplies the library:

class MockingbirdMacOS extends MockingbirdFfiPlatform {
  static void registerWith() => MockingbirdPlatform.instance = MockingbirdMacOS();

  @override
  ffi.DynamicLibrary get nativeLibrary => ffi.DynamicLibrary.process();
}

The web package implements MockingbirdPlatform directly over a WebAssembly module. Import ffi.dart only from code that never runs on the web.

Regenerating the bindings #

The bindings are generated from include/mockingbird/mockingbird.h in the engine repository with ffigen:

dart run ffigen --config ffigen.yaml

Run it after any change to the header, then re-run the tests of mockingbird.

0
likes
160
points
229
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

The platform interface of the mockingbird plugin: plain data records, the engine contract, and the shared dart:ffi implementation for native platforms.

Repository (GitHub)
View/report issues

Topics

#audio #ffi #platform-interface

License

MIT (license)

Dependencies

ffi, flutter, plugin_platform_interface

More

Packages that depend on mockingbird_platform_interface