Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native Memory Helpers, take 2 #19

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flutter-mediapipe-root
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Used to normalize the paths of commands.
// The contents of this file do not matter.
36 changes: 36 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Main Branch CI

# Declare default permissions as read only.
permissions: read-all

on:
push:
branches: [main]
pull_request:
branches: [main, ffi-wrapper, ffi-wrapper-core-pkg]
workflow_dispatch:
schedule:
- cron: "0 0 * * *" # Every day at midnight

defaults:
run:
shell: bash

jobs:
flutter-tests:
name: Test mediapipe_core against ${{ matrix.flutter_version }}
runs-on: ${{ matrix.os }}
# Skip running job on forks
if: github.repository == 'google/flutter-mediapipe'
strategy:
fail-fast: false
matrix:
flutter_version: [stable, beta, master]
# TODO(craiglabenz): Add `ubuntu-latest` and `windows-latest` when those artifacts exist
os: [macos-latest]
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
channel: ${{ matrix.flutter_version }}
- run: ./tool/mediapipe_ci_script_${{ matrix.flutter_version }}.sh
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Runs the utility to pull in all header files from `google/mediapipe`
headers:
cd packages/build_cmd && dart bin/main.dart headers

# Runs `ffigen` for all packages
generate: generate_core generate_text

# Runs `ffigen` for all packages, compiles the faked C artifacts, and runs all tests
test: generate_text test_text generate_core test_core

# Runs `ffigen` for all packages and all tests for all packages
test_only: test_core test_text

# Runs `sdks_finder` to update manifest files
sdks:
dart tool/builder/bin/main.dart sdks

# Core ---

# Runs `ffigen` for `mediapipe_core`
generate_core:
cd packages/mediapipe-core && dart run ffigen --config=ffigen.yaml

# Runs unit tests for `mediapipe_core`
test_core:
cd packages/mediapipe-core && dart test

# Text ---

# Runs `ffigen` for `mediapipe_text`
generate_text:
cd packages/mediapipe-task-text && dart run ffigen --config=ffigen.yaml

# Compiles the faked C artifacts for testing
compile_fake_text:
# Builds standalone executable
cd packages/mediapipe-task-text/test/c && gcc fake_text_classifier.c -o fake_text_classifier
# Builds what Flutter needs
cd packages/mediapipe-task-text/test/c && gcc -static -c -fPIC *.c -o fake_text_classifier.o
cd packages/mediapipe-task-text/test/c && gcc -shared -o fake_text_classifier.dylib fake_text_classifier.o

# Runs `ffigen` for `mediapipe_text` and all text tests
test_text: compile_fake_text test_text_only

# Runs all text tests
test_text_only:
cd packages/mediapipe-task-text && flutter test
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Flutter-MediaPipe

This repository will be home to the source code for the mediapipe_task_vision, mediapipe_task_audio, and mediapipe_task_text plugins for Flutter.

## Releasing

### Updating MediaPipe SDKs

Anytime MediaPipe releases new versions of their SDKs, this package will need to be updated to incorporate those latest builds. SDK versions are pinned in the `sdk_downloads.json` files in each package, which are updated by running the following command from the root of the repository:

```
$ make sdks
```

The Google Cloud Storage bucket in question only gives read-list access to a specific list of Googlers' accounts, so this command must be run from such a Googler's corp machines.

After this, create and merge a PR with the changes and then proceed to `Releasing to pub.dev`.

### Releasing to pub.dev

TODO
6 changes: 6 additions & 0 deletions packages/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include: package:lints/recommended.yaml

linter:
rules:
- public_member_api_docs # see https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#documentation-dartdocs-javadocs-etc

7 changes: 7 additions & 0 deletions packages/mediapipe-core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
3 changes: 3 additions & 0 deletions packages/mediapipe-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

- Initial version.
27 changes: 27 additions & 0 deletions packages/mediapipe-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# MediaPipe Core for Flutter

![pub package](https://img.shields.io/pub/v/mediapipe_core)

A Flutter plugin to use the MediaPipe Core API, which enables multiple Mediapipe tasks.

To learn more about MediaPipe, please visit the [MediaPipe website](https://developers.google.com/mediapipe)

## Getting Started

To get started with MediaPipe, please [see the documentation](https://developers.google.com/mediapipe/solutions/guide).

<!-- ASPIRATIONAL
## Usage

To use this plugin, please visit the [Core Usage documentation](https://github.com/google/flutter-mediapipe#Usage)
-->

## Issues and feedback

Please file Flutter-MediaPipe specific issues, bugs, or feature requests in our [issue tracker](https://github.com/google/flutter-mediapipe/issues/new).

Issues that are specific to Flutter can be filed in the [Flutter issue tracker](https://github.com/flutter/flutter/issues/new).

To contribute a change to this plugin,
please review our [contribution guide](https://github.com/google/flutter-mediapipe/blob/master/CONTRIBUTING.md)
and open a [pull request](https://github.com/google/flutter-mediapipe/pulls).
5 changes: 5 additions & 0 deletions packages/mediapipe-core/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include: ../analysis_options.yaml

analyzer:
exclude:
- "**/mediapipe_common_bindings.dart"
26 changes: 26 additions & 0 deletions packages/mediapipe-core/ffigen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "MediaPipeCommonBindings"
description: "Bindings for shared MediaPipe structs common across many tasks"
output:
bindings: "lib/src/third_party/mediapipe/generated/mediapipe_common_bindings.dart"
symbol-file:
output: "package:mediapipe_core/generated/core_symbols.yaml"
import-path: "package:mediapipe_core/src/third_party/mediapipe/generated/mediapipe_common_bindings.dart"
headers:
entry-points:
- "third_party/mediapipe/tasks/c/**"
preamble: |
/* Copyright 2023 The MediaPipe Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
ffi-native:
38 changes: 38 additions & 0 deletions packages/mediapipe-core/lib/generated/core_symbols.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
format_version: 1.0.0
files:
package:mediapipe_core/src/third_party/mediapipe/generated/mediapipe_common_bindings.dart:
used-config:
ffi-native: false
symbols:
c:@S@BaseOptions:
name: BaseOptions
c:@S@Category:
name: Category
c:@S@ClassificationResult:
name: ClassificationResult
c:@S@Classifications:
name: Classifications
c:@S@ClassifierOptions:
name: ClassifierOptions
c:@S@__darwin_pthread_handler_rec:
name: __darwin_pthread_handler_rec
c:@S@_opaque_pthread_attr_t:
name: _opaque_pthread_attr_t
c:@S@_opaque_pthread_cond_t:
name: _opaque_pthread_cond_t
c:@S@_opaque_pthread_condattr_t:
name: _opaque_pthread_condattr_t
c:@S@_opaque_pthread_mutex_t:
name: _opaque_pthread_mutex_t
c:@S@_opaque_pthread_mutexattr_t:
name: _opaque_pthread_mutexattr_t
c:@S@_opaque_pthread_once_t:
name: _opaque_pthread_once_t
c:@S@_opaque_pthread_rwlock_t:
name: _opaque_pthread_rwlock_t
c:@S@_opaque_pthread_rwlockattr_t:
name: _opaque_pthread_rwlockattr_t
c:@S@_opaque_pthread_t:
name: _opaque_pthread_t
c:@UA@__mbstate_t:
name: __mbstate_t
11 changes: 11 additions & 0 deletions packages/mediapipe-core/lib/mediapipe_core.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// Package containing core dependencies for MediaPipe's text, vision, and
/// audio-based tasks.
library;

export 'src/containers.dart' show Category, Classifications;
export 'src/ffi_utils.dart';
export 'src/task_options.dart' show BaseOptions, ClassifierOptions;