├── .bazelrc
├── .bazelversion
├── .clang-format
├── .github
└── workflows
│ ├── ci.yml
│ └── deploy-all.yml
├── .gitignore
├── .vscode
└── settings.json
├── LICENSE
├── MediaPipe.NET.Runtime.sln
├── Mediapipe.Net.Framework.Protobuf
└── Mediapipe.Net.Framework.Protobuf.csproj
├── Mediapipe.Net.Runtime.CPU
├── Mediapipe.Net.Runtime.CPU.csproj
└── _._
├── Mediapipe.Net.Runtime.GPU
├── Mediapipe.Net.Runtime.GPU.csproj
└── _._
├── Readme.md
├── Third Party Notices.md
├── WORKSPACE
├── build.py
├── mediapipe_api
├── BUILD
├── calculators
│ ├── audio
│ │ └── BUILD
│ ├── core
│ │ └── BUILD
│ ├── image
│ │ └── BUILD
│ ├── tensor
│ │ └── BUILD
│ ├── tflite
│ │ └── BUILD
│ ├── util
│ │ └── BUILD
│ └── video
│ │ └── BUILD
├── common.cc
├── common.h
├── csharp_proto_src.bzl
├── external
│ ├── BUILD
│ ├── absl
│ │ ├── BUILD
│ │ ├── status.cc
│ │ ├── status.h
│ │ └── statusor.h
│ ├── glog.cc
│ ├── glog.h
│ ├── protobuf.cc
│ ├── protobuf.h
│ ├── stdlib.cc
│ ├── stdlib.h
│ ├── wasm_patch.cc
│ └── wasm_patch.h
├── framework
│ ├── BUILD
│ ├── calculator.cc
│ ├── calculator.h
│ ├── calculator_graph.cc
│ ├── calculator_graph.h
│ ├── formats
│ │ ├── BUILD
│ │ ├── annotation
│ │ │ └── BUILD
│ │ ├── classification.cc
│ │ ├── classification.h
│ │ ├── detection.cc
│ │ ├── detection.h
│ │ ├── image_frame.cc
│ │ ├── image_frame.h
│ │ ├── landmark.cc
│ │ ├── landmark.h
│ │ ├── matrix_data.cc
│ │ ├── matrix_data.h
│ │ ├── motion
│ │ │ └── BUILD
│ │ ├── object_detection
│ │ │ └── BUILD
│ │ ├── rect.cc
│ │ └── rect.h
│ ├── output_stream_poller.cc
│ ├── output_stream_poller.h
│ ├── packet.cc
│ ├── packet.h
│ ├── port
│ │ ├── BUILD
│ │ ├── logging.cc
│ │ └── logging.h
│ ├── timestamp.cc
│ ├── timestamp.h
│ ├── validated_graph_config.cc
│ └── validated_graph_config.h
├── gpu
│ ├── BUILD
│ ├── gl_base.h
│ ├── gl_calculator_helper.cc
│ ├── gl_calculator_helper.h
│ ├── gl_context.cc
│ ├── gl_context.h
│ ├── gl_texture_buffer.cc
│ ├── gl_texture_buffer.h
│ ├── gpu_buffer.cc
│ ├── gpu_buffer.h
│ ├── gpu_buffer_format.cc
│ ├── gpu_buffer_format.h
│ ├── gpu_shared_data_internal.cc
│ └── gpu_shared_data_internal.h
├── graphs
│ ├── instant_motion_tracking
│ │ ├── BUILD
│ │ ├── calculators
│ │ │ ├── BUILD
│ │ │ ├── transformations.cc
│ │ │ └── transformations.h
│ │ └── subgraphs
│ │ │ ├── BUILD
│ │ │ └── region_tracking_cpu.pbtxt
│ └── object_detection_3d
│ │ ├── BUILD
│ │ └── calculators
│ │ ├── BUILD
│ │ ├── model_matrix.cc
│ │ └── model_matrix.h
├── import_model.bzl
├── java
│ └── com
│ │ ├── github
│ │ └── homuler
│ │ │ └── mediapipe
│ │ │ ├── BUILD
│ │ │ └── MediaPipeUnityPlayerActivity.java
│ │ └── google
│ │ └── mediapipe
│ │ ├── BUILD
│ │ └── mediapipe_aar.bzl
├── modules
│ ├── face_detection
│ │ └── BUILD
│ ├── face_geometry
│ │ ├── BUILD
│ │ └── protos
│ │ │ ├── BUILD
│ │ │ ├── face_geometry.cc
│ │ │ └── face_geometry.h
│ ├── holistic_landmark
│ │ └── calculators
│ │ │ └── BUILD
│ ├── iris_landmark
│ │ ├── BUILD
│ │ ├── iris_landmarks_from_face_landmarks_cpu.pbtxt
│ │ └── iris_landmarks_from_face_landmarks_gpu.pbtxt
│ └── objectron
│ │ └── calculators
│ │ ├── BUILD
│ │ ├── annotation_data.cc
│ │ └── annotation_data.h
├── objc
│ ├── BUILD
│ └── Info.plist
└── util
│ ├── BUILD
│ ├── resource_util_custom.cc
│ ├── resource_util_custom.h
│ └── tracking
│ └── BUILD
└── third_party
├── BUILD
├── android_configure.bzl
├── bazel_android_fixes.diff
├── build_bazel_apple_support_transitions.diff
├── build_bazel_rules_apple_validation.diff
├── com_github_glog_glog_no_gflags_fixes.diff
├── emscripten_extract_archive_fixes.diff
├── emsdk_bitcode_support.diff
├── ffmpeg_linux.BUILD
├── ffmpeg_macos.BUILD
├── mediapipe_emscripten_patch.diff
├── mediapipe_extension.diff
├── mediapipe_model_path.diff
├── mediapipe_opencv.diff
├── mediapipe_visibility.diff
├── mediapipe_workaround.diff
├── opencv.BUILD
├── opencv_linux.BUILD
├── opencv_wasm.BUILD
├── opencv_windows.BUILD
├── proto_namespace.diff
├── tensorflow_xnnpack_emscripten_fixes.diff
└── unity.BUILD
/.bazelrc:
--------------------------------------------------------------------------------
1 | # Tensorflow needs remote repo
2 | common --experimental_repo_remote_exec
3 |
4 | # Basic build settings
5 | build --jobs 128
6 | build --define='absl=1'
7 | build --features=compiler_param_file
8 | build --enable_platform_specific_config
9 |
10 | # Linux
11 | build:linux --cxxopt=-std=c++17
12 | build:linux --host_cxxopt=-std=c++17
13 | build:linux --copt=-w
14 |
15 | # windows
16 | build:windows --cxxopt=/std:c++17
17 | build:windows --host_cxxopt=/std:c++17
18 | build:windows --copt=/w
19 | # For using M_* math constants on Windows with MSVC.
20 | build:windows --copt=/D_USE_MATH_DEFINES
21 | build:windows --host_copt=/D_USE_MATH_DEFINES
22 |
23 | # macOS
24 | build:macos --cxxopt=-std=c++17
25 | build:macos --host_cxxopt=-std=c++17
26 | build:macos --copt=-w
27 |
28 | # Sets the default Apple platform to macOS.
29 | build --apple_platform_type=macos
30 |
31 | # Compile ObjC++ files with C++17
32 | build --per_file_copt=.*\.mm\$@-std=c++17
33 |
34 | # Allow debugging with XCODE
35 | build --apple_generate_dsym
36 |
37 | # Android configs.
38 | # Note: the documentation tells us to use @androidndk//:default_crosstool, but
39 | # the automatic configuration transition uses //external:android/crosstool.
40 | # Using it here works and spares us from having two different config_settings
41 | # for Android.
42 | build:android --crosstool_top=//external:android/crosstool
43 | build:android --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
44 | build:android --cxxopt=-std=c++17
45 | build:android --copt=-w
46 | build:android --linkopt=-landroid
47 | build:android --linkopt=-ldl
48 | build:android --linkopt=-llog
49 | build:android --linkopt=-lm
50 | build:android --linkopt=-Wl,--gc-sections
51 |
52 | build:android_armv7 --config=android
53 | build:android_armv7 --cpu=armeabi-v7a
54 | build:android_armv7 --fat_apk_cpu=armeabi-v7a
55 |
56 | build:android_arm64 --config=android
57 | build:android_arm64 --cpu=arm64-v8a
58 | build:android_arm64 --fat_apk_cpu=arm64-v8a
59 |
60 | build:android_fat --config=android
61 | # specify dummy cpu to avoid an error: "Illegal ambiguous match on configurable attribute "linkopts" in @XNNPACK//:xnnpack_for_tflite:"
62 | build:android_fat --cpu=arm64-v8a
63 | build:android_fat --fat_apk_cpu=armeabi-v7a,arm64-v8a
64 |
65 | build:ios --apple_platform_type=ios
66 | build:ios --copt=-fno-aligned-allocation
67 |
68 | build:ios_i386 --config=ios
69 | build:ios_i386 --cpu=ios_i386
70 | build:ios_i386 --watchos_cpus=i386
71 |
72 | build:ios_x86_64 --config=ios
73 | build:ios_x86_64 --cpu=ios_x86_64
74 | build:ios_x86_64 --watchos_cpus=i386
75 |
76 | build:ios_armv7 --config=ios
77 | build:ios_armv7 --cpu=ios_armv7
78 | build:ios_armv7 --watchos_cpus=armv7k
79 |
80 | build:ios_arm64 --config=ios
81 | build:ios_arm64 --cpu=ios_arm64
82 | build:ios_arm64 --watchos_cpus=armv7k
83 |
84 | build:ios_arm64e --config=ios
85 | build:ios_arm64e --cpu=ios_arm64e
86 | build:ios_arm64e --watchos_cpus=armv7k
87 |
88 | build:ios_fat --config=ios
89 | build:ios_fat --ios_multi_cpus=armv7,arm64
90 | build:ios_fat --watchos_cpus=armv7k
91 |
92 | build:darwin_x86_64 --apple_platform_type=macos
93 | build:darwin_x86_64 --macos_minimum_os=10.12
94 | build:darwin_x86_64 --cpu=darwin_x86_64
95 |
96 | build:darwin_arm64 --apple_platform_type=macos
97 | build:darwin_arm64 --macos_minimum_os=10.16
98 | build:darwin_arm64 --cpu=darwin_arm64
99 |
100 | build:wasm --crosstool_top=@emsdk//emscripten_toolchain:everything
101 | build:wasm --cpu=wasm
102 | build:wasm --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
103 | build:wasm --copt=-emit-llvm
104 | build:wasm --cxxopt=-emit-llvm
--------------------------------------------------------------------------------
/.bazelversion:
--------------------------------------------------------------------------------
1 | 5.2.0
2 |
--------------------------------------------------------------------------------
/.clang-format:
--------------------------------------------------------------------------------
1 | ---
2 | Language: Cpp
3 | BasedOnStyle: Google
4 | ColumnLimit: 160
5 | IndentWidth: 2
6 | AllowShortLambdasOnASingleLine: Empty
7 | MacroBlockBegin: "^TRY$|^TRY_ALL$"
8 | MacroBlockEnd: "^CATCH_EXCEPTION$|^CATCH_ALL$"
9 | TypenameMacros: ['MP_CAPI']
10 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "bsv.bazel.buildFlags": ["-c", "opt", "--define", "MEDIAPIPE_DISABLE_GPU=1"],
3 | "bsv.cc.compdb.targets": [
4 | "//mediapipe_api/framework/...",
5 | "//mediapipe_api/graphs/...",
6 | "//mediapipe_api/modules/...",
7 | "//mediapipe_api/util/...",
8 | "//mediapipe_api:calculators",
9 | "//mediapipe_api:common",
10 | "//mediapipe_api:mediapipe_c",
11 | ]
12 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2022, homuler and Vignette
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/MediaPipe.NET.Runtime.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.4.33213.308
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mediapipe.Net.Framework.Protobuf", "Mediapipe.Net.Framework.Protobuf\Mediapipe.Net.Framework.Protobuf.csproj", "{65DCAF1A-62F7-4230-89B6-FC8E35D9AE24}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BB426371-FEFE-4260-8162-DC594EC9A612}"
9 | ProjectSection(SolutionItems) = preProject
10 | Mediapipe.Net.Runtime.CPU\Mediapipe.Net.Runtime.CPU.csproj = Mediapipe.Net.Runtime.CPU\Mediapipe.Net.Runtime.CPU.csproj
11 | Mediapipe.Net.Runtime.GPU\Mediapipe.Net.Runtime.GPU.csproj = Mediapipe.Net.Runtime.GPU\Mediapipe.Net.Runtime.GPU.csproj
12 | EndProjectSection
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Release|Any CPU = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {65DCAF1A-62F7-4230-89B6-FC8E35D9AE24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {65DCAF1A-62F7-4230-89B6-FC8E35D9AE24}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {65DCAF1A-62F7-4230-89B6-FC8E35D9AE24}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {65DCAF1A-62F7-4230-89B6-FC8E35D9AE24}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(NestedProjects) = preSolution
29 | {65DCAF1A-62F7-4230-89B6-FC8E35D9AE24} = {BB426371-FEFE-4260-8162-DC594EC9A612}
30 | EndGlobalSection
31 | GlobalSection(ExtensibilityGlobals) = postSolution
32 | SolutionGuid = {AE021919-43F5-46E0-B041-0B4D56A52BCA}
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/Mediapipe.Net.Framework.Protobuf/Mediapipe.Net.Framework.Protobuf.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0;netstandard2.1
5 | Library
6 | Mediapipe.Net.Framework.Protobuf
7 | Mediapipe.Net.Framework.Protobuf
8 |
9 |
10 |
11 | Mediapipe.Net.Framework.Protobuf
12 | 0.9.1
13 | Vignette
14 | Google;MediaPipe;Protobuf;
15 | Mediapipe.Net.Framework.Protobuf
16 | Auto-generated protobuf files for MediaPipe.NET. (MediaPipe v0.8.10)
17 | 2022 homuler and Vignette
18 | https://github.com/vignetteapp/MediaPipe.NET.Runtime
19 | LICENSE
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Mediapipe.Net.Runtime.CPU/Mediapipe.Net.Runtime.CPU.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.1
5 | Library
6 | Mediapipe.Net.Runtime.CPU
7 | Mediapipe.Net.Runtime.CPU
8 |
9 |
10 |
11 | true
12 | Mediapipe.Net.Runtime.CPU
13 | 0.9.1
14 | homuler;Vignette
15 | Google;Mediapipe;Tracking;Media Analysis
16 | Mediapipe.Net.Runtime.CPU
17 | Native runtime libraries for MediaPipe.NET (CPU) (MediaPipe v0.8.10)
18 | 2022 homuler and Vignette
19 | https://github.com/vignetteapp/MediaPipe.NET.Runtime
20 | https://github.com/vignetteapp/MediaPipe.NET.Runtime
21 | LICENSE
22 | false
23 |
24 |
25 |
26 |
27 | if not exist "$(MSBuildProjectDirectory)\runtimes\win-x64\native\mediapipe_c.dll" (
28 | cd $(MSBuildProjectDirectory)\..\
29 | python3 build.py build --desktop cpu --opencv cmake -vv
30 | )
31 |
32 |
33 | if [ ! -f $(MSBuildProjectDirectory)/runtimes/linux-x64/native/libmediapipe_c.so ]; then
34 | cd $(MSBuildProjectDirectory)/../
35 | python3 build.py build --desktop cpu --opencv cmake -vv
36 | fi
37 |
38 |
39 | if [ ! -f $(MSBuildProjectDirectory)/runtimes/osx-x64/native/libmediapipe_c.dylib ]; then
40 | cd $(MSBuildProjectDirectory)/../
41 | python3 build.py build --desktop cpu --opencv cmake -vv
42 | fi
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
54 | true
55 | lib\$(TargetFramework)
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/Mediapipe.Net.Runtime.CPU/_._:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosyneco/MediaPipe.NET.Runtime/d99960ad6148093e2eb3021f75947b50b8b6fa40/Mediapipe.Net.Runtime.CPU/_._
--------------------------------------------------------------------------------
/Mediapipe.Net.Runtime.GPU/Mediapipe.Net.Runtime.GPU.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.1
5 | Library
6 | Mediapipe.Net.Runtime.GPU
7 | Mediapipe.Net.Runtime.GPU
8 |
9 |
10 |
11 | true
12 | Mediapipe.Net.Runtime.GPU
13 | 0.9.1
14 | homuler;Vignette
15 | Google;Mediapipe;Tracking;Media Analysis
16 | Mediapipe.Net.Runtime.GPU
17 | Native runtime libraries for MediaPipe.NET (GPU) (MediaPipe v0.8.10)
18 | 2022 homuler and Vignette
19 | https://github.com/vignetteapp/MediaPipe.NET.Runtime
20 | https://github.com/vignetteapp/MediaPipe.NET.Runtime
21 | LICENSE
22 | false
23 |
24 |
25 |
26 |
27 |
28 | if [ ! -f $(MSBuildProjectDirectory)/runtimes/linux-x64/native/libmediapipe_c.so ]; then
29 | cd $(MSBuildProjectDirectory)/../
30 | python3 build.py build --desktop gpu --opencv cmake -vv
31 | fi
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
43 | true
44 | lib\$(TargetFramework)
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/Mediapipe.Net.Runtime.GPU/_._:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosyneco/MediaPipe.NET.Runtime/d99960ad6148093e2eb3021f75947b50b8b6fa40/Mediapipe.Net.Runtime.GPU/_._
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | # MediaPipe.NET.Runtime
2 |
3 | > Native library package for MediaPipe.NET.
4 |
5 | [](https://go.vignetteapp.org/discord)    
6 |
7 | This is the first half of the port of [MediaPipeUnityPlugin](https://github.com/homuler/MediaPipeUnityPlugin/), in order to use MediaPipe on the latest .NET environment. The goal is to separate the actual C# bindings from the native library into 2 different workflows to increase productivity and efficiency. We think it will drastically improve maintainability as we'll be able to take better advantage of CI and other things like GitHub releases.
8 |
9 | We take homuler's Mediapipe C API and building utilities almost completely as-is, use them to build a native Mediapipe library, and ship all libraries for different OSes into one Nuget native runtime package: `Mediapipe.Net.Runtime`.
10 |
11 | Since the workflow also generated C# Protobuf sources, we decided to also bundle them in their own Nuget package. This helps separating the source code from an auto-generated one, and also makes more sense when it comes to package releases.
12 |
13 | A few key points to note:
14 | - The namespace where all C# Protobuf sources belong is `Mediapipe.Net.Framework.Protobuf`, to match our MediaPipe.NET namespaces.
15 | - On Windows, the name of the native library is `mediapipe_c.dll` rather than `libmediapipe_c.dll` as it makes more sense on Windows and helps avoiding confusion when making bindings to it.
16 | - Since the native library can be shipped in CPU and GPU version, we ship both in their individual Nuget package: `Mediapipe.Net.Runtime.CPU` and `Mediapipe.Net.Runtime.GPU`. Since Mediapipe only supports GPU computation on Linux as of now, it also means that `Mediapipe.Net.Runtime.GPU` only bundles a Linux native library.
17 | - We considerably changed the `build.py` script to adapt for this workflow. For example, some things are not downloaded as they are only relevant in Unity, and options such as `--protobuf` and `--install` have been added to better control the build process.
18 |
19 | ## Build instructions
20 |
21 | Coming soon!
22 |
23 | While waiting, you can look at the [MediaPipeUnityPlugin installation guide](https://github.com/homuler/MediaPipeUnityPlugin/wiki/Installation-Guide), as it already gives a very good indication on how to build the native libraries. Most if not every command there will also work here.
24 |
25 | You can also check [some of our CI files](https://github.com/vignetteapp/MediaPipe.NET.Runtime/blob/ci/.github/workflows/ci.yml) and look at the commands used for something more accurate but less commented.
26 |
27 | ### Generating new patchfiles for `third_party`
28 |
29 | To generate new patches for `third_party` (especially when dealing with Protobuf namespaces), you must clone the mediapipe repository that corresponds to the version being tagged.
30 |
31 | ```sh
32 | # for example we will be cloning 0.9.1
33 | $ git clone https://github.com/google/mediapipe -b 0.9.1
34 | ```
35 | Then cd to the `mediapipe` folder and make your changes. Once satisfied, generate your patchfile using `git` like so:
36 |
37 | ```sh
38 | $ git diff -p --output=patch.diff
39 | ```
40 | Keep in mind patches must be limited to the area they're supposed to modify. Follow the format in `third_party` if possible.
41 |
42 | If you're editing an existing patch, just replace the file like so, however, if you're making a new patch for use in MP.NET, make sure you add it to the `WORKSPACE` file under `patches`.
43 |
44 | ## License
45 |
46 | This repository is licensed under the MIT license. See [LICENSE](LICENSE) for details.
47 |
--------------------------------------------------------------------------------
/mediapipe_api/calculators/audio/BUILD:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2021 homuler
2 | #
3 | # Use of this source code is governed by an MIT-style
4 | # license that can be found in the LICENSE file or at
5 | # https://opensource.org/licenses/MIT.
6 |
7 | load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
8 | load("//mediapipe_api:csharp_proto_src.bzl", "csharp_proto_src")
9 |
10 | package(default_visibility = ["//visibility:public"])
11 |
12 | pkg_files(
13 | name = "proto_srcs",
14 | srcs = [
15 | ":mfcc_mel_calculators_cs",
16 | ":rational_factor_resample_calculator_cs",
17 | ":spectrogram_calculator_cs",
18 | ":stabilized_log_calculator_cs",
19 | ":time_series_framer_calculator_cs",
20 | ],
21 | prefix = "Calculators/Audio",
22 | )
23 |
24 | csharp_proto_src(
25 | name = "mfcc_mel_calculators_cs",
26 | proto_src = "mediapipe/calculators/audio/mfcc_mel_calculators.proto",
27 | deps = [
28 | "@com_google_mediapipe//mediapipe/calculators/audio:protos_src",
29 | "@com_google_mediapipe//mediapipe/framework:protos_src",
30 | ],
31 | )
32 |
33 | csharp_proto_src(
34 | name = "rational_factor_resample_calculator_cs",
35 | proto_src = "mediapipe/calculators/audio/rational_factor_resample_calculator.proto",
36 | deps = [
37 | "@com_google_mediapipe//mediapipe/calculators/audio:protos_src",
38 | "@com_google_mediapipe//mediapipe/framework:protos_src",
39 | ],
40 | )
41 |
42 | csharp_proto_src(
43 | name = "spectrogram_calculator_cs",
44 | proto_src = "mediapipe/calculators/audio/spectrogram_calculator.proto",
45 | deps = [
46 | "@com_google_mediapipe//mediapipe/calculators/audio:protos_src",
47 | "@com_google_mediapipe//mediapipe/framework:protos_src",
48 | ],
49 | )
50 |
51 | csharp_proto_src(
52 | name = "stabilized_log_calculator_cs",
53 | proto_src = "mediapipe/calculators/audio/stabilized_log_calculator.proto",
54 | deps = [
55 | "@com_google_mediapipe//mediapipe/calculators/audio:protos_src",
56 | "@com_google_mediapipe//mediapipe/framework:protos_src",
57 | ],
58 | )
59 |
60 | csharp_proto_src(
61 | name = "time_series_framer_calculator_cs",
62 | proto_src = "mediapipe/calculators/audio/time_series_framer_calculator.proto",
63 | deps = [
64 | "@com_google_mediapipe//mediapipe/calculators/audio:protos_src",
65 | "@com_google_mediapipe//mediapipe/framework:protos_src",
66 | ],
67 | )
68 |
--------------------------------------------------------------------------------
/mediapipe_api/calculators/tensor/BUILD:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2021 homuler
2 | #
3 | # Use of this source code is governed by an MIT-style
4 | # license that can be found in the LICENSE file or at
5 | # https://opensource.org/licenses/MIT.
6 |
7 | load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
8 | load("//mediapipe_api:csharp_proto_src.bzl", "csharp_proto_src")
9 |
10 | package(
11 | default_visibility = ["//visibility:public"],
12 | )
13 |
14 | pkg_files(
15 | name = "proto_srcs",
16 | srcs = [
17 | ":image_to_tensor_calculator_cs",
18 | ":inference_calculator_cs",
19 | ":landmarks_to_tensor_calculator_cs",
20 | ":tensor_converter_calculator_cs",
21 | ":tensors_to_classification_calculator_cs",
22 | ":tensors_to_detections_calculator_cs",
23 | ":tensors_to_floats_calculator_cs",
24 | ":tensors_to_landmarks_calculator_cs",
25 | ":tensors_to_segmentation_calculator_cs",
26 | ],
27 | prefix = "Calculators/Tensor",
28 | )
29 |
30 | csharp_proto_src(
31 | name = "inference_calculator_cs",
32 | proto_src = "mediapipe/calculators/tensor/inference_calculator.proto",
33 | deps = [
34 | "@com_google_mediapipe//mediapipe/calculators/tensor:protos_src",
35 | "@com_google_mediapipe//mediapipe/framework:protos_src",
36 | ],
37 | )
38 |
39 | csharp_proto_src(
40 | name = "tensor_converter_calculator_cs",
41 | proto_src = "mediapipe/calculators/tensor/tensor_converter_calculator.proto",
42 | deps = [
43 | "@com_google_mediapipe//mediapipe/calculators/tensor:protos_src",
44 | "@com_google_mediapipe//mediapipe/framework:protos_src",
45 | ],
46 | )
47 |
48 | csharp_proto_src(
49 | name = "tensors_to_detections_calculator_cs",
50 | proto_src = "mediapipe/calculators/tensor/tensors_to_detections_calculator.proto",
51 | deps = [
52 | "@com_google_mediapipe//mediapipe/calculators/tensor:protos_src",
53 | "@com_google_mediapipe//mediapipe/framework:protos_src",
54 | ],
55 | )
56 |
57 | csharp_proto_src(
58 | name = "tensors_to_landmarks_calculator_cs",
59 | proto_src = "mediapipe/calculators/tensor/tensors_to_landmarks_calculator.proto",
60 | deps = [
61 | "@com_google_mediapipe//mediapipe/calculators/tensor:protos_src",
62 | "@com_google_mediapipe//mediapipe/framework:protos_src",
63 | ],
64 | )
65 |
66 | csharp_proto_src(
67 | name = "landmarks_to_tensor_calculator_cs",
68 | proto_src = "mediapipe/calculators/tensor/landmarks_to_tensor_calculator.proto",
69 | deps = [
70 | "@com_google_mediapipe//mediapipe/calculators/tensor:protos_src",
71 | "@com_google_mediapipe//mediapipe/framework:protos_src",
72 | ],
73 | )
74 |
75 | csharp_proto_src(
76 | name = "tensors_to_floats_calculator_cs",
77 | proto_src = "mediapipe/calculators/tensor/tensors_to_floats_calculator.proto",
78 | deps = [
79 | "@com_google_mediapipe//mediapipe/calculators/tensor:protos_src",
80 | "@com_google_mediapipe//mediapipe/framework:protos_src",
81 | ],
82 | )
83 |
84 | csharp_proto_src(
85 | name = "tensors_to_classification_calculator_cs",
86 | proto_src = "mediapipe/calculators/tensor/tensors_to_classification_calculator.proto",
87 | deps = [
88 | "@com_google_mediapipe//mediapipe/calculators/tensor:protos_src",
89 | "@com_google_mediapipe//mediapipe/framework:protos_src",
90 | "@com_google_mediapipe//mediapipe/util:protos_src",
91 | ],
92 | )
93 |
94 | csharp_proto_src(
95 | name = "image_to_tensor_calculator_cs",
96 | proto_src = "mediapipe/calculators/tensor/image_to_tensor_calculator.proto",
97 | deps = [
98 | "@com_google_mediapipe//mediapipe/calculators/tensor:protos_src",
99 | "@com_google_mediapipe//mediapipe/framework:protos_src",
100 | "@com_google_mediapipe//mediapipe/gpu:protos_src",
101 | ],
102 | )
103 |
104 | csharp_proto_src(
105 | name = "tensors_to_segmentation_calculator_cs",
106 | proto_src = "mediapipe/calculators/tensor/tensors_to_segmentation_calculator.proto",
107 | deps = [
108 | "@com_google_mediapipe//mediapipe/calculators/tensor:protos_src",
109 | "@com_google_mediapipe//mediapipe/framework:protos_src",
110 | "@com_google_mediapipe//mediapipe/gpu:protos_src",
111 | ],
112 | )
113 |
--------------------------------------------------------------------------------
/mediapipe_api/calculators/tflite/BUILD:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2021 homuler
2 | #
3 | # Use of this source code is governed by an MIT-style
4 | # license that can be found in the LICENSE file or at
5 | # https://opensource.org/licenses/MIT.
6 |
7 | load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
8 | load("//mediapipe_api:csharp_proto_src.bzl", "csharp_proto_src")
9 |
10 | package(default_visibility = ["//visibility:public"])
11 |
12 | pkg_files(
13 | name = "proto_srcs",
14 | srcs = [
15 | ":ssd_anchors_calculator_cs",
16 | ":tflite_custom_op_resolver_calculator_cs",
17 | ":tflite_inference_calculator_cs",
18 | ":tflite_converter_calculator_cs",
19 | ":tflite_tensors_to_segmentation_calculator_cs",
20 | ":tflite_tensors_to_detections_calculator_cs",
21 | ":tflite_tensors_to_classification_calculator_cs",
22 | ":tflite_tensors_to_landmarks_calculator_cs",
23 | ],
24 | prefix = "Calculators/Tflite",
25 | )
26 |
27 | csharp_proto_src(
28 | name = "ssd_anchors_calculator_cs",
29 | proto_src = "mediapipe/calculators/tflite/ssd_anchors_calculator.proto",
30 | deps = [
31 | "@com_google_mediapipe//mediapipe/calculators/tflite:protos_src",
32 | "@com_google_mediapipe//mediapipe/framework:protos_src",
33 | ],
34 | )
35 |
36 | csharp_proto_src(
37 | name = "tflite_custom_op_resolver_calculator_cs",
38 | proto_src = "mediapipe/calculators/tflite/tflite_custom_op_resolver_calculator.proto",
39 | deps = [
40 | "@com_google_mediapipe//mediapipe/calculators/tflite:protos_src",
41 | "@com_google_mediapipe//mediapipe/framework:protos_src",
42 | ],
43 | )
44 |
45 | csharp_proto_src(
46 | name = "tflite_inference_calculator_cs",
47 | proto_src = "mediapipe/calculators/tflite/tflite_inference_calculator.proto",
48 | deps = [
49 | "@com_google_mediapipe//mediapipe/calculators/tflite:protos_src",
50 | "@com_google_mediapipe//mediapipe/framework:protos_src",
51 | ],
52 | )
53 |
54 | csharp_proto_src(
55 | name = "tflite_converter_calculator_cs",
56 | proto_src = "mediapipe/calculators/tflite/tflite_converter_calculator.proto",
57 | deps = [
58 | "@com_google_mediapipe//mediapipe/calculators/tflite:protos_src",
59 | "@com_google_mediapipe//mediapipe/framework:protos_src",
60 | ],
61 | )
62 |
63 | csharp_proto_src(
64 | name = "tflite_tensors_to_segmentation_calculator_cs",
65 | proto_src = "mediapipe/calculators/tflite/tflite_tensors_to_segmentation_calculator.proto",
66 | deps = [
67 | "@com_google_mediapipe//mediapipe/calculators/tflite:protos_src",
68 | "@com_google_mediapipe//mediapipe/framework:protos_src",
69 | ],
70 | )
71 |
72 | csharp_proto_src(
73 | name = "tflite_tensors_to_detections_calculator_cs",
74 | proto_src = "mediapipe/calculators/tflite/tflite_tensors_to_detections_calculator.proto",
75 | deps = [
76 | "@com_google_mediapipe//mediapipe/calculators/tflite:protos_src",
77 | "@com_google_mediapipe//mediapipe/framework:protos_src",
78 | ],
79 | )
80 |
81 | csharp_proto_src(
82 | name = "tflite_tensors_to_classification_calculator_cs",
83 | proto_src = "mediapipe/calculators/tflite/tflite_tensors_to_classification_calculator.proto",
84 | deps = [
85 | "@com_google_mediapipe//mediapipe/calculators/tflite:protos_src",
86 | "@com_google_mediapipe//mediapipe/framework:protos_src",
87 | ],
88 | )
89 |
90 | csharp_proto_src(
91 | name = "tflite_tensors_to_landmarks_calculator_cs",
92 | proto_src = "mediapipe/calculators/tflite/tflite_tensors_to_landmarks_calculator.proto",
93 | deps = [
94 | "@com_google_mediapipe//mediapipe/calculators/tflite:protos_src",
95 | "@com_google_mediapipe//mediapipe/framework:protos_src",
96 | ],
97 | )
98 |
--------------------------------------------------------------------------------
/mediapipe_api/calculators/video/BUILD:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2021 homuler
2 | #
3 | # Use of this source code is governed by an MIT-style
4 | # license that can be found in the LICENSE file or at
5 | # https://opensource.org/licenses/MIT.
6 |
7 | load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
8 | load("//mediapipe_api:csharp_proto_src.bzl", "csharp_proto_src")
9 |
10 | package(default_visibility = ["//visibility:public"])
11 |
12 | pkg_files(
13 | name = "proto_srcs",
14 | srcs = [
15 | ":flow_to_image_calculator_cs",
16 | ":opencv_video_encoder_calculator_cs",
17 | ":motion_analysis_calculator_cs",
18 | ":flow_packager_calculator_cs",
19 | ":box_tracker_calculator_cs",
20 | ":tracked_detection_manager_calculator_cs",
21 | ":box_detector_calculator_cs",
22 | ":video_pre_stream_calculator_cs",
23 | ],
24 | prefix = "Calculators/Video",
25 | )
26 |
27 | csharp_proto_src(
28 | name = "flow_to_image_calculator_cs",
29 | proto_src = "mediapipe/calculators/video/flow_to_image_calculator.proto",
30 | deps = [
31 | "@com_google_mediapipe//mediapipe/calculators/video:protos_src",
32 | "@com_google_mediapipe//mediapipe/framework:protos_src",
33 | ],
34 | )
35 |
36 | csharp_proto_src(
37 | name = "opencv_video_encoder_calculator_cs",
38 | proto_src = "mediapipe/calculators/video/opencv_video_encoder_calculator.proto",
39 | deps = [
40 | "@com_google_mediapipe//mediapipe/calculators/video:protos_src",
41 | "@com_google_mediapipe//mediapipe/framework:protos_src",
42 | ],
43 | )
44 |
45 | csharp_proto_src(
46 | name = "motion_analysis_calculator_cs",
47 | proto_src = "mediapipe/calculators/video/motion_analysis_calculator.proto",
48 | deps = [
49 | "@com_google_mediapipe//mediapipe/calculators/video:protos_src",
50 | "@com_google_mediapipe//mediapipe/framework:protos_src",
51 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src",
52 | ],
53 | )
54 |
55 | csharp_proto_src(
56 | name = "flow_packager_calculator_cs",
57 | proto_src = "mediapipe/calculators/video/flow_packager_calculator.proto",
58 | deps = [
59 | "@com_google_mediapipe//mediapipe/calculators/video:protos_src",
60 | "@com_google_mediapipe//mediapipe/framework:protos_src",
61 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src",
62 | ],
63 | )
64 |
65 | csharp_proto_src(
66 | name = "box_tracker_calculator_cs",
67 | proto_src = "mediapipe/calculators/video/box_tracker_calculator.proto",
68 | deps = [
69 | "@com_google_mediapipe//mediapipe/calculators/video:protos_src",
70 | "@com_google_mediapipe//mediapipe/framework:protos_src",
71 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src",
72 | ],
73 | )
74 |
75 | csharp_proto_src(
76 | name = "tracked_detection_manager_calculator_cs",
77 | proto_src = "mediapipe/calculators/video/tracked_detection_manager_calculator.proto",
78 | deps = [
79 | "@com_google_mediapipe//mediapipe/calculators/video:protos_src",
80 | "@com_google_mediapipe//mediapipe/framework:protos_src",
81 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src",
82 | ],
83 | )
84 |
85 | csharp_proto_src(
86 | name = "box_detector_calculator_cs",
87 | proto_src = "mediapipe/calculators/video/box_detector_calculator.proto",
88 | deps = [
89 | "@com_google_mediapipe//mediapipe/calculators/video:protos_src",
90 | "@com_google_mediapipe//mediapipe/framework:protos_src",
91 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src",
92 | ],
93 | )
94 |
95 | csharp_proto_src(
96 | name = "video_pre_stream_calculator_cs",
97 | proto_src = "mediapipe/calculators/video/video_pre_stream_calculator.proto",
98 | deps = [
99 | "@com_google_mediapipe//mediapipe/calculators/video:protos_src",
100 | "@com_google_mediapipe//mediapipe/framework:protos_src",
101 | ],
102 | )
103 |
--------------------------------------------------------------------------------
/mediapipe_api/common.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #include "mediapipe_api/common.h"
8 |
9 | #ifndef MEDIAPIPE_DISABLE_SIGABRT_HANDLER
10 | thread_local struct sigaction mp_api::orig_act;
11 | thread_local sigjmp_buf mp_api::abrt_jbuf;
12 |
13 | void mp_api::sigabrt_handler(int sig) { siglongjmp(abrt_jbuf, 1); }
14 | #endif
15 |
16 | namespace mp_api {
17 | FreeHGlobal* freeHGlobal;
18 | }
19 |
20 | void mp_api__SetFreeHGlobal(mp_api::FreeHGlobal* freeHGlobal) {
21 | mp_api::freeHGlobal = freeHGlobal;
22 | }
23 |
--------------------------------------------------------------------------------
/mediapipe_api/common.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #ifndef MEDIAPIPE_API_COMMON_H_
8 | #define MEDIAPIPE_API_COMMON_H_
9 |
10 | #ifdef _WIN32
11 | #define MP_CAPI_EXPORT __declspec(dllexport)
12 | #else
13 | #define MP_CAPI_EXPORT
14 | #endif
15 |
16 | #include
17 | #include
18 | #include
19 |
20 | #include "mediapipe/framework/port/logging.h"
21 |
22 | extern inline const char* strcpy_to_heap(const std::string& str) {
23 | if (str.empty()) {
24 | return nullptr;
25 | }
26 |
27 | auto str_ptr = new char[str.length() + 1];
28 | snprintf(str_ptr, str.length() + 1, str.c_str());
29 |
30 | return str_ptr;
31 | }
32 |
33 | enum class MpReturnCode : int {
34 | Success = 0,
35 | StandardError = 1,
36 | UnknownError = 70,
37 | Unset = 128,
38 | Aborted = 134,
39 | };
40 |
41 | namespace mp_api {
42 |
43 | template
44 | struct StructArray {
45 | T* data;
46 | int size;
47 | };
48 |
49 | typedef void FreeHGlobal(void* hglobal);
50 |
51 | extern FreeHGlobal* freeHGlobal;
52 |
53 | #if defined(_WIN32) || defined(__EMSCRIPTEN__)
54 | #define MEDIAPIPE_DISABLE_SIGABRT_HANDLER
55 | #endif
56 |
57 | #if defined(__EMSCRIPTEN__)
58 | #define MEDIAPIPE_IGNORE_EXCEPTION
59 | #endif
60 |
61 | #ifndef MEDIAPIPE_DISABLE_SIGABRT_HANDLER
62 | extern thread_local struct sigaction orig_act;
63 | extern thread_local sigjmp_buf abrt_jbuf;
64 |
65 | extern void sigabrt_handler(int sig);
66 | #endif
67 |
68 | } // namespace mp_api
69 |
70 | // TODO: make code more readable
71 | #ifdef MEDIAPIPE_IGNORE_EXCEPTION
72 | #define TRY \
73 | auto volatile _mp_return_code = MpReturnCode::Unset; \
74 | {
75 | #else
76 | #define TRY \
77 | auto volatile _mp_return_code = MpReturnCode::Unset; \
78 | try {
79 | #endif // MEDIAPIPE_IGNORE_EXCEPTION
80 |
81 | #ifdef MEDIAPIPE_IGNORE_EXCEPTION
82 | #define CATCH_EXCEPTION \
83 | } \
84 | return _mp_return_code;
85 | #else
86 | #define CATCH_EXCEPTION \
87 | } \
88 | catch (std::exception & e) { \
89 | LOG(ERROR) << e.what(); \
90 | google::FlushLogFiles(google::GLOG_ERROR); \
91 | _mp_return_code = MpReturnCode::StandardError; \
92 | } \
93 | catch (...) { \
94 | LOG(ERROR) << "Unknown exception occured"; \
95 | google::FlushLogFiles(google::GLOG_ERROR); \
96 | _mp_return_code = MpReturnCode::UnknownError; \
97 | } \
98 | return _mp_return_code;
99 | #endif
100 |
101 | #ifdef MEDIAPIPE_DISABLE_SIGABRT_HANDLER
102 | #define TRY_ALL TRY
103 | #define CATCH_ALL CATCH_EXCEPTION
104 | #else
105 | #define TRY_ALL \
106 | TRY \
107 | struct sigaction act; \
108 | sigemptyset(&act.sa_mask); \
109 | act.sa_flags = 0; \
110 | act.sa_handler = mp_api::sigabrt_handler; \
111 | sigaction(SIGABRT, &act, &mp_api::orig_act); \
112 | if (sigsetjmp(mp_api::abrt_jbuf, 1) == 0) {
113 | #define CATCH_ALL \
114 | } \
115 | else { \
116 | LOG(ERROR) << "Aborted"; \
117 | google::FlushLogFiles(google::GLOG_ERROR); \
118 | _mp_return_code = MpReturnCode::Aborted; \
119 | } \
120 | sigaction(SIGABRT, &mp_api::orig_act, nullptr); \
121 | CATCH_EXCEPTION
122 | #endif // MEDIAPIPE_DISABLE_SIGABRT_HANDLER
123 |
124 | #define RETURN_CODE(code) _mp_return_code = code
125 |
126 | #ifdef _WIN32
127 | #define CDECL __cdecl
128 | #else
129 | #define CDECL
130 | #endif // _WIN32
131 |
132 | #define MP_CAPI(rettype) MP_CAPI_EXPORT extern rettype CDECL
133 |
134 | extern "C" {
135 |
136 | MP_CAPI(void) mp_api__SetFreeHGlobal(mp_api::FreeHGlobal* freeHGlobal);
137 |
138 | } // extern "C"
139 |
140 | #endif // MEDIAPIPE_API_COMMON_H_
141 |
--------------------------------------------------------------------------------
/mediapipe_api/csharp_proto_src.bzl:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2021 homuler
2 | #
3 | # Use of this source code is governed by an MIT-style
4 | # license that can be found in the LICENSE file or at
5 | # https://opensource.org/licenses/MIT.
6 |
7 | """Proto compiler
8 |
9 | Macro for generating C# source files corresponding to .proto files
10 | """
11 |
12 | def csharp_proto_src(name, proto_src, deps):
13 | """Generate C# source code for *.proto
14 |
15 | Args:
16 | name: target name
17 | deps: label list of dependent targets
18 | proto_src: target .proto file path
19 | """
20 |
21 | base_name = proto_src.split("/")[-1]
22 | csharp_out = _camelize(base_name.split(".")[0]) + ".cs"
23 | outdir = "$(GENDIR)"
24 |
25 | native.genrule(
26 | name = name,
27 | srcs = deps + [
28 | "@com_google_protobuf//:well_known_protos",
29 | ],
30 | outs = [csharp_out],
31 | cmd = """
32 | mkdir -p {outdir}
33 | $(location @com_google_protobuf//:protoc) \
34 | --proto_path=. \
35 | --proto_path={outdir} \
36 | --proto_path=$$(pwd)/external/com_google_protobuf/src \
37 | --proto_path=$$(pwd)/external/com_google_mediapipe \
38 | --csharp_out={outdir} {}
39 | mv {outdir}/{outfile} $$(dirname $(location {outfile}))
40 | """.format(proto_src, outdir = outdir, outfile = csharp_out),
41 | tools = [
42 | "@com_google_protobuf//:protoc",
43 | ],
44 | )
45 |
46 | def _camelize(str):
47 | res = ""
48 | need_capitalize = True
49 |
50 | for s in str.elems():
51 | if not s.isalnum():
52 | need_capitalize = True
53 | continue
54 |
55 | if need_capitalize:
56 | res += s.capitalize()
57 | else:
58 | res += s
59 |
60 | need_capitalize = s.isdigit()
61 |
62 | return res
63 |
64 | def _replace_suffix(string, old, new):
65 | """Returns a string with an old suffix replaced by a new suffix."""
66 | return string.endswith(old) and string[:-len(old)] + new or string
67 |
--------------------------------------------------------------------------------
/mediapipe_api/external/BUILD:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2021 homuler
2 | #
3 | # Use of this source code is governed by an MIT-style
4 | # license that can be found in the LICENSE file or at
5 | # https://opensource.org/licenses/MIT.
6 |
7 | cc_library(
8 | name = "glog",
9 | srcs = ["glog.cc"],
10 | hdrs = ["glog.h"],
11 | visibility = ["//visibility:public"],
12 | deps = [
13 | "//mediapipe_api:common",
14 | ],
15 | alwayslink = True,
16 | )
17 |
18 | cc_library(
19 | name = "protobuf",
20 | srcs = ["protobuf.cc"],
21 | hdrs = ["protobuf.h"],
22 | visibility = ["//visibility:public"],
23 | deps = [
24 | "//mediapipe_api:common",
25 | "@com_google_mediapipe//mediapipe/framework/port:parse_text_proto",
26 | "@com_google_protobuf//:protobuf",
27 | ],
28 | alwayslink = True,
29 | )
30 |
31 | cc_library(
32 | name = "stdlib",
33 | srcs = ["stdlib.cc"],
34 | hdrs = ["stdlib.h"],
35 | visibility = ["//visibility:public"],
36 | deps = [
37 | "//mediapipe_api:common",
38 | "//mediapipe_api/external/absl:statusor",
39 | ],
40 | alwayslink = True,
41 | )
42 |
43 | cc_library(
44 | name = "wasm_patch",
45 | srcs = ["wasm_patch.cc"],
46 | hdrs = ["wasm_patch.h"],
47 | visibility = ["//visibility:public"],
48 | deps = [
49 | "//mediapipe_api:common",
50 | ],
51 | alwayslink = True,
52 | )
53 |
--------------------------------------------------------------------------------
/mediapipe_api/external/absl/BUILD:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2021 homuler
2 | #
3 | # Use of this source code is governed by an MIT-style
4 | # license that can be found in the LICENSE file or at
5 | # https://opensource.org/licenses/MIT.
6 |
7 | package(
8 | default_visibility = ["//visibility:public"],
9 | )
10 |
11 | cc_library(
12 | name = "status",
13 | srcs = ["status.cc"],
14 | hdrs = ["status.h"],
15 | deps = [
16 | "//mediapipe_api:common",
17 | "@com_google_absl//absl/status",
18 | ],
19 | alwayslink = True,
20 | )
21 |
22 | cc_library(
23 | name = "statusor",
24 | hdrs = ["statusor.h"],
25 | deps = [
26 | "//mediapipe_api:common",
27 | "@com_google_absl//absl/status:statusor",
28 | ],
29 | alwayslink = True,
30 | )
31 |
--------------------------------------------------------------------------------
/mediapipe_api/external/absl/status.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #include "mediapipe_api/external/absl/status.h"
8 |
9 | MpReturnCode absl_Status__i_PKc(int code, const char* message, absl::Status** status_out) {
10 | TRY
11 | auto status_code = static_cast(code);
12 | *status_out = new absl::Status{status_code, message};
13 | RETURN_CODE(MpReturnCode::Success);
14 | CATCH_EXCEPTION
15 | }
16 |
17 | void absl_Status__delete(absl::Status* status) { delete status; }
18 |
19 | MpReturnCode absl_Status__ToString(absl::Status* status, const char** str_out) {
20 | TRY
21 | *str_out = strcpy_to_heap(status->ToString());
22 | RETURN_CODE(MpReturnCode::Success);
23 | CATCH_EXCEPTION
24 | }
25 |
26 | bool absl_Status__ok(absl::Status* status) { return status->ok(); }
27 |
28 | int absl_Status__raw_code(absl::Status* status) { return status->raw_code(); }
29 |
--------------------------------------------------------------------------------
/mediapipe_api/external/absl/status.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #ifndef MEDIAPIPE_API_EXTERNAL_ABSL_STATUS_H_
8 | #define MEDIAPIPE_API_EXTERNAL_ABSL_STATUS_H_
9 |
10 | #include "absl/status/status.h"
11 | #include "mediapipe_api/common.h"
12 |
13 | namespace mp_api {
14 |
15 | typedef struct StatusArgs {
16 | absl::StatusCode code;
17 | void* message;
18 | };
19 |
20 | } // namespace mp_api
21 |
22 | extern "C" {
23 |
24 | MP_CAPI(MpReturnCode) absl_Status__i_PKc(int code, const char* message, absl::Status** status_out);
25 | MP_CAPI(void) absl_Status__delete(absl::Status* status);
26 |
27 | MP_CAPI(MpReturnCode) absl_Status__ToString(absl::Status* status, const char** str_out);
28 | MP_CAPI(bool) absl_Status__ok(absl::Status* status);
29 | MP_CAPI(int) absl_Status__raw_code(absl::Status* status);
30 |
31 | } // extern "C"
32 |
33 | #endif // MEDIAPIPE_API_EXTERNAL_ABSL_STATUS_H_
34 |
--------------------------------------------------------------------------------
/mediapipe_api/external/absl/statusor.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #ifndef MEDIAPIPE_API_EXTERNAL_ABSL_STATUSOR_H_
8 | #define MEDIAPIPE_API_EXTERNAL_ABSL_STATUSOR_H_
9 |
10 | #include
11 |
12 | #include "absl/status/statusor.h"
13 | #include "mediapipe_api/common.h"
14 |
15 | template
16 | inline bool absl_StatusOr__ok(absl::StatusOr* status_or) {
17 | return status_or->ok();
18 | }
19 |
20 | template
21 | inline MpReturnCode absl_StatusOr__status(absl::StatusOr* status_or, absl::Status** status_out) {
22 | TRY
23 | *status_out = new absl::Status{status_or->status()};
24 | RETURN_CODE(MpReturnCode::Success);
25 | CATCH_EXCEPTION
26 | }
27 |
28 | template
29 | inline MpReturnCode absl_StatusOr__value(absl::StatusOr* status_or, T* value_out) {
30 | TRY_ALL
31 | *value_out = std::move(*status_or).value();
32 | RETURN_CODE(MpReturnCode::Success);
33 | CATCH_ALL
34 | }
35 |
36 | template
37 | inline MpReturnCode absl_StatusOr__value(absl::StatusOr* status_or, T** value_out) {
38 | TRY_ALL
39 | *value_out = new T{std::move(*status_or).value()};
40 | RETURN_CODE(MpReturnCode::Success);
41 | CATCH_ALL
42 | }
43 |
44 | #endif // MEDIAPIPE_API_EXTERNAL_ABSL_STATUSOR_H_
45 |
--------------------------------------------------------------------------------
/mediapipe_api/external/glog.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #include "mediapipe_api/external/glog.h"
8 |
9 | void glog_FLAGS_logtostderr(bool flag) { FLAGS_logtostderr = flag; }
10 |
11 | void glog_FLAGS_stderrthreshold(int threshold) { FLAGS_stderrthreshold = threshold; }
12 |
13 | void glog_FLAGS_minloglevel(int level) { FLAGS_minloglevel = level; }
14 |
15 | void glog_FLAGS_log_dir(const char* dir) { FLAGS_log_dir = dir; }
16 |
17 | void glog_FLAGS_v(int v) { FLAGS_v = v; }
18 |
19 | void glog_LOG_INFO__PKc(const char* str) { LOG(INFO) << str; }
20 |
21 | void glog_LOG_WARNING__PKc(const char* str) { LOG(WARNING) << str; }
22 |
23 | void glog_LOG_ERROR__PKc(const char* str) { LOG(ERROR) << str; }
24 |
25 | void glog_LOG_FATAL__PKc(const char* str) { LOG(FATAL) << str; }
26 |
27 | void google_FlushLogFiles(google::LogSeverity severity) { google::FlushLogFiles(severity); }
28 |
--------------------------------------------------------------------------------
/mediapipe_api/external/glog.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #ifndef MEDIAPIPE_API_EXTERNAL_GLOG_H_
8 | #define MEDIAPIPE_API_EXTERNAL_GLOG_H_
9 |
10 | #include
11 |
12 | #include "mediapipe_api/common.h"
13 |
14 | extern "C" {
15 |
16 | MP_CAPI(void) glog_FLAGS_logtostderr(bool flag);
17 | MP_CAPI(void) glog_FLAGS_stderrthreshold(int threshold);
18 | MP_CAPI(void) glog_FLAGS_minloglevel(int level);
19 | MP_CAPI(void) glog_FLAGS_log_dir(const char* dir);
20 | MP_CAPI(void) glog_FLAGS_v(int v);
21 | MP_CAPI(void) glog_LOG_INFO__PKc(const char* str);
22 | MP_CAPI(void) glog_LOG_WARNING__PKc(const char* str);
23 | MP_CAPI(void) glog_LOG_ERROR__PKc(const char* str);
24 | MP_CAPI(void) glog_LOG_FATAL__PKc(const char* str);
25 |
26 | MP_CAPI(void) google_FlushLogFiles(google::LogSeverity severity);
27 |
28 | } // extern "C"
29 |
30 | #endif // MEDIAPIPE_API_EXTERNAL_GLOG_H_
31 |
--------------------------------------------------------------------------------
/mediapipe_api/external/protobuf.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #include "mediapipe_api/external/protobuf.h"
8 |
9 | #include
10 | #include
11 |
12 | #include "google/protobuf/stubs/logging.h"
13 |
14 | using google::protobuf::LogLevel;
15 |
16 | namespace {
17 | LogHandler* logHandler;
18 | google::protobuf::LogHandler* defaultLogHandler;
19 | }
20 |
21 | void HandleProtobufLog(LogLevel level, const char* filename, int line, const std::string& message) { logHandler(level, filename, line, message.c_str()); }
22 |
23 | MpReturnCode google_protobuf__SetLogHandler__PF(LogHandler* handler) {
24 | TRY
25 | logHandler = handler;
26 | auto prevLogHandler = google::protobuf::SetLogHandler(&HandleProtobufLog);
27 |
28 | if (defaultLogHandler == nullptr) {
29 | defaultLogHandler = prevLogHandler;
30 | }
31 | RETURN_CODE(MpReturnCode::Success);
32 | CATCH_EXCEPTION
33 | }
34 |
35 | MpReturnCode google_protobuf__ResetLogHandler() {
36 | TRY
37 | if (logHandler) {
38 | google::protobuf::SetLogHandler(defaultLogHandler);
39 | }
40 | logHandler = nullptr;
41 | RETURN_CODE(MpReturnCode::Success);
42 | CATCH_EXCEPTION
43 | }
44 |
45 | void mp_api_SerializedProtoArray__delete(mp_api::SerializedProto* serialized_proto_vector_data, int size) {
46 | auto serialized_proto = serialized_proto_vector_data;
47 | for (auto i = 0; i < size; ++i) {
48 | delete (serialized_proto++)->str;
49 | }
50 | delete[] serialized_proto_vector_data;
51 | }
52 |
--------------------------------------------------------------------------------
/mediapipe_api/external/protobuf.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #ifndef MEDIAPIPE_API_EXTERNAL_PROTOBUF_H_
8 | #define MEDIAPIPE_API_EXTERNAL_PROTOBUF_H_
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | #include "mediapipe/framework/port/parse_text_proto.h"
15 | #include "mediapipe_api/common.h"
16 |
17 | namespace mp_api {
18 |
19 | typedef struct SerializedProto {
20 | const char* str;
21 | int length;
22 | };
23 |
24 | } // namespace mp_api
25 |
26 | template
27 | inline void SerializeProto(const T& proto, mp_api::SerializedProto* serialized_proto) {
28 | auto str = proto.SerializeAsString();
29 | auto size = str.size();
30 | auto bytes = new char[size + 1];
31 | memcpy(bytes, str.c_str(), size);
32 |
33 | serialized_proto->str = bytes;
34 | serialized_proto->length = static_cast(size);
35 | }
36 |
37 | template
38 | inline void SerializeProtoVector(const std::vector& proto_vec, mp_api::StructArray* serialized_proto_vector) {
39 | auto vec_size = proto_vec.size();
40 | auto data = new mp_api::SerializedProto[vec_size];
41 |
42 | for (auto i = 0; i < vec_size; ++i) {
43 | SerializeProto(proto_vec[i], &data[i]);
44 | }
45 | serialized_proto_vector->data = data;
46 | serialized_proto_vector->size = static_cast(vec_size);
47 | }
48 |
49 | template
50 | inline T ParseFromStringAsProto(const char* serialized_data, int size) {
51 | T proto;
52 | CHECK(proto.ParseFromString(std::string(serialized_data, size)));
53 |
54 | return proto;
55 | }
56 |
57 | template
58 | inline bool ConvertFromTextFormat(const char* str, mp_api::SerializedProto* output) {
59 | T proto;
60 | auto result = google::protobuf::TextFormat::ParseFromString(str, &proto);
61 |
62 | if (result) {
63 | SerializeProto(proto, output);
64 | }
65 | return result;
66 | }
67 |
68 | extern "C" {
69 |
70 | typedef void LogHandler(int level, const char* filename, int line, const char* message);
71 |
72 | MP_CAPI(MpReturnCode) google_protobuf__SetLogHandler__PF(LogHandler* handler);
73 |
74 | MP_CAPI(MpReturnCode) google_protobuf__ResetLogHandler();
75 |
76 | MP_CAPI(void) mp_api_SerializedProtoArray__delete(mp_api::SerializedProto* serialized_proto_vector_data, int size);
77 |
78 | } // extern "C"
79 |
80 | #endif // MEDIAPIPE_API_EXTERNAL_PROTOBUF_H_
81 |
--------------------------------------------------------------------------------
/mediapipe_api/external/stdlib.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #include "mediapipe_api/external/stdlib.h"
8 |
9 | void delete_array__PKc(const char* str) { delete[] str; }
10 |
11 | void delete_array__Pf(float* f) { delete[] f; }
12 |
13 | void std_string__delete(std::string* str) { delete str; }
14 |
15 | MpReturnCode std_string__PKc_i(const char* src, int size, std::string** str_out) {
16 | TRY
17 | *str_out = new std::string(src, size);
18 | RETURN_CODE(MpReturnCode::Success);
19 | CATCH_EXCEPTION
20 | }
21 |
22 | void std_string__swap__Rstr(std::string* src, std::string* dst) { src->swap(*dst); }
23 |
24 | void mp_StatusOrString__delete(absl::StatusOr* status_or_string) { delete status_or_string; }
25 |
26 | bool mp_StatusOrString__ok(absl::StatusOr* status_or_string) { return status_or_string->ok(); }
27 |
28 | MpReturnCode mp_StatusOrString__status(absl::StatusOr* status_or_string, absl::Status** status_out) {
29 | return absl_StatusOr__status(status_or_string, status_out);
30 | }
31 |
32 | MpReturnCode mp_StatusOrString__value(absl::StatusOr* status_or_string, const char** value_out) {
33 | TRY_ALL
34 | auto str = std::move(*status_or_string).value();
35 | *value_out = strcpy_to_heap(str);
36 | RETURN_CODE(MpReturnCode::Success);
37 | CATCH_ALL
38 | }
39 |
40 | MpReturnCode mp_StatusOrString__bytearray(absl::StatusOr* status_or_string, const char** value_out, int* size_out) {
41 | TRY_ALL
42 | auto str = std::move(*status_or_string).value();
43 | auto length = str.size();
44 | auto bytes = new char[length];
45 | memcpy(bytes, str.c_str(), length);
46 |
47 | *value_out = bytes;
48 | *size_out = length;
49 | RETURN_CODE(MpReturnCode::Success);
50 | CATCH_ALL
51 | }
52 |
--------------------------------------------------------------------------------
/mediapipe_api/external/stdlib.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #ifndef MEDIAPIPE_API_EXTERNAL_STDLIB_H_
8 | #define MEDIAPIPE_API_EXTERNAL_STDLIB_H_
9 |
10 | #include
11 |
12 | #include "mediapipe_api/common.h"
13 | #include "mediapipe_api/external/absl/statusor.h"
14 |
15 | extern "C" {
16 |
17 | MP_CAPI(void) delete_array__PKc(const char* str);
18 | MP_CAPI(void) delete_array__Pf(float* f);
19 |
20 | // string API
21 | MP_CAPI(void) std_string__delete(std::string* str);
22 | MP_CAPI(MpReturnCode) std_string__PKc_i(const char* src, int size, std::string** str_out);
23 | MP_CAPI(void) std_string__swap__Rstr(std::string* src, std::string* dst);
24 |
25 | // StatusOr API
26 | MP_CAPI(void) mp_StatusOrString__delete(absl::StatusOr* status_or_string);
27 | MP_CAPI(bool) mp_StatusOrString__ok(absl::StatusOr* status_or_string);
28 | MP_CAPI(MpReturnCode) mp_StatusOrString__status(absl::StatusOr* status_or_string, absl::Status** status_out);
29 | MP_CAPI(MpReturnCode) mp_StatusOrString__value(absl::StatusOr* status_or_string, const char** value_out);
30 | MP_CAPI(MpReturnCode) mp_StatusOrString__bytearray(absl::StatusOr* status_or_string, const char** value_out, int* size_out);
31 |
32 | } // extern "C"
33 |
34 | #endif // MEDIAPIPE_API_EXTERNAL_STDLIB_H_
35 |
--------------------------------------------------------------------------------
/mediapipe_api/external/wasm_patch.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #include "mediapipe_api/external/wasm_patch.h"
8 |
9 | FILE* popen(const char *command, const char *type) {
10 | LOG(ERROR) << "popen is not supported on Web";
11 | return nullptr;
12 | }
13 |
--------------------------------------------------------------------------------
/mediapipe_api/external/wasm_patch.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #ifndef MEDIAPIPE_API_EXTERNAL_WASM_PATCH_H_
8 | #define MEDIAPIPE_API_EXTERNAL_WASM_PATCH_H_
9 |
10 | #include "mediapipe_api/common.h"
11 |
12 | #ifdef __EMSCRIPTEN__
13 |
14 | #ifdef __cplusplus
15 | extern "C" {
16 | #endif // __cplusplus
17 |
18 | MP_CAPI(FILE*) popen(const char* command, const char* type);
19 |
20 | #ifdef __cplusplus
21 | } // extern "C"
22 | #endif // __cplusplus
23 |
24 | #endif // __EMSCRIPTEN__
25 |
26 | #endif // MEDIAPIPE_API_EXTERNAL_WASM_PATCH_H_
27 |
--------------------------------------------------------------------------------
/mediapipe_api/framework/calculator.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #include "mediapipe_api/framework/calculator.h"
8 |
9 | #include "mediapipe/framework/calculator.pb.h"
10 |
11 | bool mp_api__ConvertFromCalculatorGraphConfigTextFormat(const char* config_text, mp_api::SerializedProto* value_out) {
12 | return ConvertFromTextFormat(config_text, value_out);
13 | }
14 |
--------------------------------------------------------------------------------
/mediapipe_api/framework/calculator.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #ifndef MEDIAPIPE_API_FRAMEWORK_CALCULATOR_H_
8 | #define MEDIAPIPE_API_FRAMEWORK_CALCULATOR_H_
9 |
10 | #include
11 | #include
12 |
13 | #include "mediapipe_api/common.h"
14 | #include "mediapipe_api/external/protobuf.h"
15 |
16 | extern "C" {
17 |
18 | MP_CAPI(bool) mp_api__ConvertFromCalculatorGraphConfigTextFormat(const char* config_text, mp_api::SerializedProto* value_out);
19 |
20 | } // extern "C"
21 |
22 | #endif // MEDIAPIPE_API_FRAMEWORK_CALCULATOR_H_
23 |
--------------------------------------------------------------------------------
/mediapipe_api/framework/calculator_graph.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 homuler
2 | //
3 | // Use of this source code is governed by an MIT-style
4 | // license that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | #ifndef MEDIAPIPE_API_FRAMEWORK_CALCULATOR_GRAPH_H_
8 | #define MEDIAPIPE_API_FRAMEWORK_CALCULATOR_GRAPH_H_
9 |
10 | #include