├── .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 | [![Discord](https://img.shields.io/discord/871618277258960896?color=7289DA&label=%20&logo=discord&logoColor=white)](https://go.vignetteapp.org/discord) ![NuGet](https://img.shields.io/nuget/v/MediaPipe.NET.Runtime.CPU) ![NuGet](https://img.shields.io/nuget/v/MediaPipe.NET.Runtime.GPU) ![Deploy workflow](https://github.com/vignetteapp/MediaPipe.NET.Runtime/actions/workflows/deploy-all.yml/badge.svg) ![CI workflow](https://github.com/vignetteapp/MediaPipe.NET.Runtime/actions/workflows/ci.yml/badge.svg) 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 11 | #include 12 | #include 13 | 14 | #include "mediapipe/framework/calculator_graph.h" 15 | #include "mediapipe_api/common.h" 16 | #include "mediapipe_api/external/absl/status.h" 17 | #include "mediapipe_api/external/absl/statusor.h" 18 | #include "mediapipe_api/external/protobuf.h" 19 | #include "mediapipe_api/framework/packet.h" 20 | 21 | #ifndef MEDIAPIPE_DISABLE_GPU 22 | #include "mediapipe/gpu/gl_calculator_helper.h" 23 | #include "mediapipe/gpu/gpu_shared_data_internal.h" 24 | #endif // !defined(MEDIAPIPE_DISABLE_GPU) 25 | 26 | extern "C" { 27 | 28 | typedef std::map SidePackets; 29 | typedef mp_api::StatusArgs NativePacketCallback(mediapipe::CalculatorGraph* graph, int stream_id, const mediapipe::Packet&); 30 | 31 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__(mediapipe::CalculatorGraph** graph_out); 32 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__PKc_i(const char* serialized_config, int size, mediapipe::CalculatorGraph** graph_out); 33 | MP_CAPI(void) mp_CalculatorGraph__delete(mediapipe::CalculatorGraph* graph); 34 | 35 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__Initialize__PKc_i(mediapipe::CalculatorGraph* graph, const char* serialized_config, int size, 36 | absl::Status** status_out); 37 | 38 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__Initialize__PKc_i_Rsp(mediapipe::CalculatorGraph* graph, const char* serialized_config, int size, 39 | SidePackets* side_packets, absl::Status** status_out); 40 | 41 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__Config(mediapipe::CalculatorGraph* graph, mp_api::SerializedProto* config_out); 42 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__ObserveOutputStream__PKc_PF_b(mediapipe::CalculatorGraph* graph, const char* stream_name, int stream_id, 43 | NativePacketCallback* packet_callback, bool observe_timestamp_bounds, 44 | absl::Status** status_out); 45 | 46 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__AddOutputStreamPoller__PKc_b(mediapipe::CalculatorGraph* graph, const char* stream_name, 47 | bool observe_timestamp_bounds, mediapipe::StatusOrPoller** status_or_poller_out); 48 | 49 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__Run__Rsp(mediapipe::CalculatorGraph* graph, SidePackets* side_packets, absl::Status** status_out); 50 | 51 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__StartRun__Rsp(mediapipe::CalculatorGraph* graph, SidePackets* side_packets, absl::Status** status_out); 52 | 53 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__WaitUntilIdle(mediapipe::CalculatorGraph* graph, absl::Status** status_out); 54 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__WaitUntilDone(mediapipe::CalculatorGraph* graph, absl::Status** status_out); 55 | MP_CAPI(bool) mp_CalculatorGraph__HasError(mediapipe::CalculatorGraph* graph); 56 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__AddPacketToInputStream__PKc_Ppacket(mediapipe::CalculatorGraph* graph, const char* stream_name, 57 | mediapipe::Packet* packet, absl::Status** status_out); 58 | 59 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__SetInputStreamMaxQueueSize__PKc_i(mediapipe::CalculatorGraph* graph, const char* stream_name, int max_queue_size, 60 | absl::Status** status_out); 61 | 62 | MP_CAPI(bool) mp_CalculatorGraph__HasInputStream__PKc(mediapipe::CalculatorGraph* graph, const char* name); 63 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__CloseInputStream__PKc(mediapipe::CalculatorGraph* graph, const char* stream_name, absl::Status** status_out); 64 | 65 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__CloseAllPacketSources(mediapipe::CalculatorGraph* graph, absl::Status** status_out); 66 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__Cancel(mediapipe::CalculatorGraph* graph); 67 | MP_CAPI(bool) mp_CalculatorGraph__GraphInputStreamsClosed(mediapipe::CalculatorGraph* graph); 68 | MP_CAPI(bool) mp_CalculatorGraph__IsNodeThrottled__i(mediapipe::CalculatorGraph* graph, int node_id); 69 | MP_CAPI(bool) mp_CalculatorGraph__UnthrottleSources(mediapipe::CalculatorGraph* graph); 70 | 71 | #ifndef MEDIAPIPE_DISABLE_GPU 72 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__GetGpuResources(mediapipe::CalculatorGraph* graph, std::shared_ptr** gpu_resources_out); 73 | 74 | MP_CAPI(MpReturnCode) mp_CalculatorGraph__SetGpuResources__SPgpu(mediapipe::CalculatorGraph* graph, std::shared_ptr* gpu_resources, 75 | absl::Status** status_out); 76 | #endif // !defined(MEDIAPIPE_DISABLE_GPU) 77 | 78 | } // extern "C" 79 | 80 | #endif // MEDIAPIPE_API_FRAMEWORK_CALCULATOR_GRAPH_H_ 81 | -------------------------------------------------------------------------------- /mediapipe_api/framework/formats/annotation/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 | ":rasterization_cs", 16 | ":locus_cs", 17 | ], 18 | prefix = "Framework/Formats/Annotation", 19 | ) 20 | 21 | csharp_proto_src( 22 | name = "rasterization_cs", 23 | proto_src = "mediapipe/framework/formats/annotation/rasterization.proto", 24 | deps = [ 25 | "@com_google_mediapipe//mediapipe/framework/formats/annotation:protos_src", 26 | ], 27 | ) 28 | 29 | csharp_proto_src( 30 | name = "locus_cs", 31 | proto_src = "mediapipe/framework/formats/annotation/locus.proto", 32 | deps = [ 33 | "@com_google_mediapipe//mediapipe/framework/formats/annotation:protos_src", 34 | ], 35 | ) 36 | -------------------------------------------------------------------------------- /mediapipe_api/framework/formats/classification.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/formats/classification.h" 8 | 9 | MpReturnCode mp_Packet__GetClassificationList(mediapipe::Packet* packet, mp_api::SerializedProto* value_out) { 10 | return mp_Packet__GetSerializedProto(packet, value_out); 11 | } 12 | 13 | MpReturnCode mp_Packet__GetClassificationListVector(mediapipe::Packet* packet, mp_api::StructArray* value_out) { 14 | return mp_Packet__GetSerializedProtoVector(packet, value_out); 15 | } 16 | -------------------------------------------------------------------------------- /mediapipe_api/framework/formats/classification.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_FORMATS_CLASSIFICATION_H_ 8 | #define MEDIAPIPE_API_FRAMEWORK_FORMATS_CLASSIFICATION_H_ 9 | 10 | #include "mediapipe/framework/formats/classification.pb.h" 11 | #include "mediapipe_api/common.h" 12 | #include "mediapipe_api/external/protobuf.h" 13 | #include "mediapipe_api/framework/packet.h" 14 | 15 | extern "C" { 16 | 17 | MP_CAPI(MpReturnCode) mp_Packet__GetClassificationList(mediapipe::Packet* packet, mp_api::SerializedProto* value_out); 18 | MP_CAPI(MpReturnCode) mp_Packet__GetClassificationListVector(mediapipe::Packet* packet, mp_api::StructArray* value_out); 19 | 20 | } // extern "C" 21 | 22 | #endif // MEDIAPIPE_API_FRAMEWORK_FORMATS_CLASSIFICATION_H_ 23 | -------------------------------------------------------------------------------- /mediapipe_api/framework/formats/detection.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/formats/detection.h" 8 | 9 | MpReturnCode mp_Packet__GetDetection(mediapipe::Packet* packet, mp_api::SerializedProto* value_out) { 10 | return mp_Packet__GetSerializedProto(packet, value_out); 11 | } 12 | 13 | MpReturnCode mp_Packet__GetDetectionVector(mediapipe::Packet* packet, mp_api::StructArray* value_out) { 14 | return mp_Packet__GetSerializedProtoVector(packet, value_out); 15 | } 16 | -------------------------------------------------------------------------------- /mediapipe_api/framework/formats/detection.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_FORMATS_DETECTION_H_ 8 | #define MEDIAPIPE_API_FRAMEWORK_FORMATS_DETECTION_H_ 9 | 10 | #include "mediapipe/framework/formats/detection.pb.h" 11 | #include "mediapipe_api/common.h" 12 | #include "mediapipe_api/external/protobuf.h" 13 | #include "mediapipe_api/framework/packet.h" 14 | 15 | extern "C" { 16 | 17 | MP_CAPI(MpReturnCode) mp_Packet__GetDetection(mediapipe::Packet* packet, mp_api::SerializedProto* value_out); 18 | MP_CAPI(MpReturnCode) mp_Packet__GetDetectionVector(mediapipe::Packet* packet, mp_api::StructArray* value_out); 19 | 20 | } // extern "C" 21 | 22 | #endif // MEDIAPIPE_API_FRAMEWORK_FORMATS_DETECTION_H_ 23 | -------------------------------------------------------------------------------- /mediapipe_api/framework/formats/image_frame.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_FORMATS_IMAGE_FRAME_H_ 8 | #define MEDIAPIPE_API_FRAMEWORK_FORMATS_IMAGE_FRAME_H_ 9 | 10 | #include 11 | #include 12 | 13 | #include "mediapipe/framework/formats/image_frame.h" 14 | #include "mediapipe_api/common.h" 15 | #include "mediapipe_api/external/absl/status.h" 16 | #include "mediapipe_api/external/absl/statusor.h" 17 | #include "mediapipe_api/framework/packet.h" 18 | 19 | extern "C" { 20 | 21 | typedef absl::StatusOr StatusOrImageFrame; 22 | typedef void(Deleter)(uint8*); 23 | 24 | MP_CAPI(MpReturnCode) mp_ImageFrame__(mediapipe::ImageFrame** image_frame_out); 25 | MP_CAPI(MpReturnCode) mp_ImageFrame__ui_i_i_ui(mediapipe::ImageFormat::Format format, int width, int height, uint32 alignment_boundary, 26 | mediapipe::ImageFrame** image_frame_out); 27 | MP_CAPI(MpReturnCode) mp_ImageFrame__ui_i_i_i_Pui8_PF(mediapipe::ImageFormat::Format format, int width, int height, int width_step, uint8* pixel_data, 28 | Deleter* deleter, mediapipe::ImageFrame** image_frame_out); 29 | MP_CAPI(void) mp_ImageFrame__delete(mediapipe::ImageFrame* image_frame); 30 | MP_CAPI(bool) mp_ImageFrame__IsEmpty(mediapipe::ImageFrame* image_frame); 31 | MP_CAPI(MpReturnCode) mp_ImageFrame__SetToZero(mediapipe::ImageFrame* image_frame); 32 | MP_CAPI(MpReturnCode) mp_ImageFrame__SetAlignmentPaddingAreas(mediapipe::ImageFrame* image_frame); 33 | MP_CAPI(bool) mp_ImageFrame__IsContiguous(mediapipe::ImageFrame* image_frame); 34 | MP_CAPI(MpReturnCode) mp_ImageFrame__IsAligned__ui(mediapipe::ImageFrame* image_frame, uint32 alignment_boundary, bool* value_out); 35 | MP_CAPI(mediapipe::ImageFormat::Format) mp_ImageFrame__Format(mediapipe::ImageFrame* image_frame); 36 | MP_CAPI(int) mp_ImageFrame__Width(mediapipe::ImageFrame* image_frame); 37 | MP_CAPI(int) mp_ImageFrame__Height(mediapipe::ImageFrame* image_frame); 38 | MP_CAPI(int) mp_ImageFrame__WidthStep(mediapipe::ImageFrame* image_frame); 39 | MP_CAPI(uint8*) mp_ImageFrame__MutablePixelData(mediapipe::ImageFrame* image_frame); 40 | MP_CAPI(MpReturnCode) mp_ImageFrame__CopyToBuffer__Pui8_i(mediapipe::ImageFrame* image_frame, uint8* buffer, int buffer_size); 41 | MP_CAPI(MpReturnCode) mp_ImageFrame__CopyToBuffer__Pui16_i(mediapipe::ImageFrame* image_frame, uint16* buffer, int buffer_size); 42 | MP_CAPI(MpReturnCode) mp_ImageFrame__CopyToBuffer__Pf_i(mediapipe::ImageFrame* image_frame, float* buffer, int buffer_size); 43 | 44 | // StatusOr API 45 | MP_CAPI(void) mp_StatusOrImageFrame__delete(StatusOrImageFrame* status_or_image_frame); 46 | MP_CAPI(bool) mp_StatusOrImageFrame__ok(StatusOrImageFrame* status_or_image_frame); 47 | MP_CAPI(MpReturnCode) mp_StatusOrImageFrame__status(StatusOrImageFrame* status_or_image_frame, absl::Status** status_out); 48 | MP_CAPI(MpReturnCode) mp_StatusOrImageFrame__value(StatusOrImageFrame* status_or_image_frame, mediapipe::ImageFrame** value_out); 49 | 50 | // Packet API 51 | MP_CAPI(MpReturnCode) mp__MakeImageFramePacket__Pif(mediapipe::ImageFrame* image_frame, mediapipe::Packet** packet_out); 52 | MP_CAPI(MpReturnCode) mp__MakeImageFramePacket_At__Pif_Rt(mediapipe::ImageFrame* image_frame, mediapipe::Timestamp* timestamp, mediapipe::Packet** packet_out); 53 | MP_CAPI(MpReturnCode) mp_Packet__ConsumeImageFrame(mediapipe::Packet* packet, StatusOrImageFrame** value_out); 54 | MP_CAPI(MpReturnCode) mp_Packet__GetImageFrame(mediapipe::Packet* packet, const mediapipe::ImageFrame** value_out); 55 | MP_CAPI(MpReturnCode) mp_Packet__ValidateAsImageFrame(mediapipe::Packet* packet, absl::Status** status_out); 56 | 57 | } // extern "C" 58 | 59 | #endif // MEDIAPIPE_API_FRAMEWORK_FORMATS_IMAGE_FRAME_H_ 60 | -------------------------------------------------------------------------------- /mediapipe_api/framework/formats/landmark.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/formats/landmark.h" 8 | 9 | MpReturnCode mp_Packet__GetLandmarkList(mediapipe::Packet* packet, mp_api::SerializedProto* value_out) { 10 | return mp_Packet__GetSerializedProto(packet, value_out); 11 | } 12 | 13 | MpReturnCode mp_Packet__GetLandmarkListVector(mediapipe::Packet* packet, mp_api::StructArray* value_out) { 14 | return mp_Packet__GetSerializedProtoVector(packet, value_out); 15 | } 16 | 17 | MpReturnCode mp_Packet__GetNormalizedLandmarkList(mediapipe::Packet* packet, mp_api::SerializedProto* value_out) { 18 | return mp_Packet__GetSerializedProto(packet, value_out); 19 | } 20 | 21 | MpReturnCode mp_Packet__GetNormalizedLandmarkListVector(mediapipe::Packet* packet, mp_api::StructArray* value_out) { 22 | return mp_Packet__GetSerializedProtoVector(packet, value_out); 23 | } 24 | -------------------------------------------------------------------------------- /mediapipe_api/framework/formats/landmark.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_FORMATS_LANDMARK_H_ 8 | #define MEDIAPIPE_API_FRAMEWORK_FORMATS_LANDMARK_H_ 9 | 10 | #include "mediapipe/framework/formats/landmark.pb.h" 11 | #include "mediapipe_api/common.h" 12 | #include "mediapipe_api/external/protobuf.h" 13 | #include "mediapipe_api/framework/packet.h" 14 | 15 | extern "C" { 16 | 17 | MP_CAPI(MpReturnCode) mp_Packet__GetLandmarkList(mediapipe::Packet* packet, mp_api::SerializedProto* value_out); 18 | MP_CAPI(MpReturnCode) mp_Packet__GetLandmarkListVector(mediapipe::Packet* packet, mp_api::StructArray* value_out); 19 | MP_CAPI(MpReturnCode) mp_Packet__GetNormalizedLandmarkList(mediapipe::Packet* packet, mp_api::SerializedProto* value_out); 20 | MP_CAPI(MpReturnCode) mp_Packet__GetNormalizedLandmarkListVector(mediapipe::Packet* packet, mp_api::StructArray* value_out); 21 | 22 | } // extern "C" 23 | 24 | #endif // MEDIAPIPE_API_FRAMEWORK_FORMATS_LANDMARK_H_ 25 | -------------------------------------------------------------------------------- /mediapipe_api/framework/formats/matrix_data.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/formats/matrix_data.h" 8 | 9 | MpReturnCode mp__MakeMatrixPacket__PKc_i(const char* serialized_matrix_data, int size, mediapipe::Packet** packet_out) { 10 | TRY 11 | auto matrix_data = ParseFromStringAsProto(serialized_matrix_data, size); 12 | 13 | mediapipe::Matrix matrix; 14 | mediapipe::MatrixFromMatrixDataProto(matrix_data, &matrix); 15 | 16 | *packet_out = new mediapipe::Packet{mediapipe::MakePacket(matrix)}; 17 | RETURN_CODE(MpReturnCode::Success); 18 | CATCH_EXCEPTION 19 | } 20 | 21 | MpReturnCode mp__MakeMatrixPacket_At__PKc_i_Rt(const char* serialized_matrix_data, int size, mediapipe::Timestamp* timestamp, mediapipe::Packet** packet_out) { 22 | TRY 23 | auto matrix_data = ParseFromStringAsProto(serialized_matrix_data, size); 24 | 25 | mediapipe::Matrix matrix; 26 | mediapipe::MatrixFromMatrixDataProto(matrix_data, &matrix); 27 | 28 | *packet_out = new mediapipe::Packet{mediapipe::MakePacket(matrix).At(*timestamp)}; 29 | RETURN_CODE(MpReturnCode::Success); 30 | CATCH_EXCEPTION 31 | } 32 | 33 | MP_CAPI(MpReturnCode) mp_Packet__GetMatrix(mediapipe::Packet* packet, mp_api::SerializedProto* value_out) { 34 | TRY 35 | mediapipe::MatrixData matrix_data; 36 | auto matrix = packet->Get(); 37 | mediapipe::MatrixDataProtoFromMatrix(matrix, &matrix_data); 38 | 39 | SerializeProto(matrix_data, value_out); 40 | 41 | RETURN_CODE(MpReturnCode::Success); 42 | CATCH_EXCEPTION 43 | } 44 | 45 | MP_CAPI(MpReturnCode) mp_Packet__ValidateAsMatrix(mediapipe::Packet* packet, absl::Status** status_out) { 46 | TRY 47 | *status_out = new absl::Status{packet->ValidateAsType()}; 48 | RETURN_CODE(MpReturnCode::Success); 49 | CATCH_EXCEPTION 50 | } 51 | -------------------------------------------------------------------------------- /mediapipe_api/framework/formats/matrix_data.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_FORMATS_MATRIX_DATA_H_ 8 | #define MEDIAPIPE_API_FRAMEWORK_FORMATS_MATRIX_DATA_H_ 9 | 10 | #include "mediapipe/framework/formats/matrix.h" 11 | #include "mediapipe_api/common.h" 12 | #include "mediapipe_api/external/protobuf.h" 13 | #include "mediapipe_api/framework/packet.h" 14 | 15 | extern "C" { 16 | 17 | MP_CAPI(MpReturnCode) mp__MakeMatrixPacket__PKc_i(const char* matrix_data_serialized, int size, mediapipe::Packet** packet_out); 18 | MP_CAPI(MpReturnCode) mp__MakeMatrixPacket_At__PKc_i_Rt(const char* matrix_data_serialized, int size, mediapipe::Timestamp* timestamp, 19 | mediapipe::Packet** packet_out); 20 | MP_CAPI(MpReturnCode) mp_Packet__GetMatrix(mediapipe::Packet* packet, mp_api::SerializedProto* value_out); 21 | MP_CAPI(MpReturnCode) mp_Packet__ValidateAsMatrix(mediapipe::Packet* packet, absl::Status** status_out); 22 | 23 | } // extern "C" 24 | 25 | #endif // MEDIAPIPE_API_FRAMEWORK_FORMATS_MATRIX_DATA_H_ 26 | -------------------------------------------------------------------------------- /mediapipe_api/framework/formats/motion/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 | ":optical_flow_field_data_cs", 16 | ], 17 | prefix = "Framework/Formats/Motion", 18 | ) 19 | 20 | csharp_proto_src( 21 | name = "optical_flow_field_data_cs", 22 | proto_src = "mediapipe/framework/formats/motion/optical_flow_field_data.proto", 23 | deps = [ 24 | "@com_google_mediapipe//mediapipe/framework/formats/motion:protos_src", 25 | ], 26 | ) 27 | -------------------------------------------------------------------------------- /mediapipe_api/framework/formats/object_detection/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 | ":anchor_cs", 16 | ], 17 | prefix = "Framework/Formats/ObjectDetection", 18 | ) 19 | 20 | csharp_proto_src( 21 | name = "anchor_cs", 22 | proto_src = "mediapipe/framework/formats/object_detection/anchor.proto", 23 | deps = [ 24 | "@com_google_mediapipe//mediapipe/framework/formats/object_detection:protos_src", 25 | ], 26 | ) 27 | -------------------------------------------------------------------------------- /mediapipe_api/framework/formats/rect.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/formats/rect.h" 8 | 9 | MpReturnCode mp_Packet__GetRect(mediapipe::Packet* packet, mp_api::SerializedProto* value_out) { 10 | return mp_Packet__GetSerializedProto(packet, value_out); 11 | } 12 | 13 | MpReturnCode mp_Packet__GetRectVector(mediapipe::Packet* packet, mp_api::StructArray* value_out) { 14 | return mp_Packet__GetSerializedProtoVector(packet, value_out); 15 | } 16 | 17 | MpReturnCode mp_Packet__GetNormalizedRect(mediapipe::Packet* packet, mp_api::SerializedProto* value_out) { 18 | return mp_Packet__GetSerializedProto(packet, value_out); 19 | } 20 | 21 | MpReturnCode mp_Packet__GetNormalizedRectVector(mediapipe::Packet* packet, mp_api::StructArray* value_out) { 22 | return mp_Packet__GetSerializedProtoVector(packet, value_out); 23 | } 24 | -------------------------------------------------------------------------------- /mediapipe_api/framework/formats/rect.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_FORMATS_RECT_H_ 8 | #define MEDIAPIPE_API_FRAMEWORK_FORMATS_RECT_H_ 9 | 10 | #include "mediapipe/framework/formats/rect.pb.h" 11 | #include "mediapipe_api/common.h" 12 | #include "mediapipe_api/external/protobuf.h" 13 | #include "mediapipe_api/framework/packet.h" 14 | 15 | extern "C" { 16 | 17 | MP_CAPI(MpReturnCode) mp_Packet__GetRect(mediapipe::Packet* packet, mp_api::SerializedProto* value_out); 18 | MP_CAPI(MpReturnCode) mp_Packet__GetRectVector(mediapipe::Packet* packet, mp_api::StructArray* value_out); 19 | MP_CAPI(MpReturnCode) mp_Packet__GetNormalizedRect(mediapipe::Packet* packet, mp_api::SerializedProto* value_out); 20 | MP_CAPI(MpReturnCode) mp_Packet__GetNormalizedRectVector(mediapipe::Packet* packet, mp_api::StructArray* value_out); 21 | 22 | } // extern "C" 23 | 24 | #endif // MEDIAPIPE_API_FRAMEWORK_FORMATS_RECT_H_ 25 | -------------------------------------------------------------------------------- /mediapipe_api/framework/output_stream_poller.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/output_stream_poller.h" 8 | 9 | #include "mediapipe_api/external/absl/statusor.h" 10 | 11 | void mp_OutputStreamPoller__delete(mediapipe::OutputStreamPoller* poller) { delete poller; } 12 | 13 | MpReturnCode mp_OutputStreamPoller__Reset(mediapipe::OutputStreamPoller* poller) { 14 | TRY_ALL 15 | poller->Reset(); 16 | RETURN_CODE(MpReturnCode::Success); 17 | CATCH_ALL 18 | } 19 | 20 | MpReturnCode mp_OutputStreamPoller__Next_Ppacket(mediapipe::OutputStreamPoller* poller, mediapipe::Packet* packet, bool* result_out) { 21 | TRY_ALL 22 | *result_out = poller->Next(packet); 23 | RETURN_CODE(MpReturnCode::Success); 24 | CATCH_ALL 25 | } 26 | 27 | MpReturnCode mp_OutputStreamPoller__SetMaxQueueSize(mediapipe::OutputStreamPoller* poller, int queue_size) { 28 | TRY_ALL 29 | poller->SetMaxQueueSize(queue_size); 30 | RETURN_CODE(MpReturnCode::Success); 31 | CATCH_ALL 32 | } 33 | 34 | MpReturnCode mp_OutputStreamPoller__QueueSize(mediapipe::OutputStreamPoller* poller, int* queue_size_out) { 35 | TRY_ALL 36 | *queue_size_out = poller->QueueSize(); 37 | RETURN_CODE(MpReturnCode::Success); 38 | CATCH_ALL 39 | } 40 | 41 | void mp_StatusOrPoller__delete(mediapipe::StatusOrPoller* status_or_poller) { delete status_or_poller; } 42 | 43 | bool mp_StatusOrPoller__ok(mediapipe::StatusOrPoller* status_or_poller) { return absl_StatusOr__ok(status_or_poller); } 44 | 45 | MpReturnCode mp_StatusOrPoller__status(mediapipe::StatusOrPoller* status_or_poller, absl::Status** status_out) { 46 | return absl_StatusOr__status(status_or_poller, status_out); 47 | } 48 | 49 | MpReturnCode mp_StatusOrPoller__value(mediapipe::StatusOrPoller* poller, mediapipe::OutputStreamPoller** poller_out) { 50 | return absl_StatusOr__value(poller, poller_out); 51 | } 52 | -------------------------------------------------------------------------------- /mediapipe_api/framework/output_stream_poller.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_OUTPUT_STREAM_POLLER_H_ 8 | #define MEDIAPIPE_API_FRAMEWORK_OUTPUT_STREAM_POLLER_H_ 9 | 10 | #include "mediapipe/framework/calculator_graph.h" 11 | #include "mediapipe_api/common.h" 12 | 13 | extern "C" { 14 | 15 | MP_CAPI(void) mp_OutputStreamPoller__delete(mediapipe::OutputStreamPoller* poller); 16 | MP_CAPI(MpReturnCode) mp_OutputStreamPoller__Reset(mediapipe::OutputStreamPoller* poller); 17 | MP_CAPI(MpReturnCode) mp_OutputStreamPoller__Next_Ppacket(mediapipe::OutputStreamPoller* poller, mediapipe::Packet* packet, bool* result_out); 18 | MP_CAPI(MpReturnCode) mp_OutputStreamPoller__SetMaxQueueSize(mediapipe::OutputStreamPoller* poller, int queue_size); 19 | MP_CAPI(MpReturnCode) mp_OutputStreamPoller__QueueSize(mediapipe::OutputStreamPoller* poller, int* queue_size_out); 20 | 21 | MP_CAPI(void) mp_StatusOrPoller__delete(mediapipe::StatusOrPoller* poller); 22 | MP_CAPI(bool) mp_StatusOrPoller__ok(mediapipe::StatusOrPoller* poller); 23 | MP_CAPI(MpReturnCode) mp_StatusOrPoller__status(mediapipe::StatusOrPoller* poller, absl::Status** status_out); 24 | MP_CAPI(MpReturnCode) mp_StatusOrPoller__value(mediapipe::StatusOrPoller* poller, mediapipe::OutputStreamPoller** poller_out); 25 | 26 | } // extern "C" 27 | 28 | #endif // MEDIAPIPE_API_FRAMEWORK_OUTPUT_STREAM_POLLER_H_ 29 | -------------------------------------------------------------------------------- /mediapipe_api/framework/port/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 = "logging", 13 | srcs = ["logging.cc"], 14 | hdrs = ["logging.h"], 15 | deps = [ 16 | "//mediapipe_api:common", 17 | "@com_google_mediapipe//mediapipe/framework/port:logging", 18 | ], 19 | alwayslink = True, 20 | ) 21 | -------------------------------------------------------------------------------- /mediapipe_api/framework/port/logging.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/port/logging.h" 8 | 9 | namespace { 10 | const char* argv; 11 | } 12 | 13 | MpReturnCode google_InitGoogleLogging__PKc(const char* name) { 14 | TRY_ALL 15 | argv = strcpy_to_heap(name); 16 | google::InitGoogleLogging(argv); 17 | RETURN_CODE(MpReturnCode::Success); 18 | CATCH_ALL 19 | } 20 | 21 | MpReturnCode google_ShutdownGoogleLogging() { 22 | TRY_ALL 23 | google::ShutdownGoogleLogging(); 24 | delete[] argv; 25 | RETURN_CODE(MpReturnCode::Success); 26 | CATCH_ALL 27 | } 28 | -------------------------------------------------------------------------------- /mediapipe_api/framework/port/logging.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_PORT_LOGGING_H_ 8 | #define MEDIAPIPE_API_FRAMEWORK_PORT_LOGGING_H_ 9 | 10 | #include "mediapipe/framework/port/logging.h" 11 | #include "mediapipe_api/common.h" 12 | 13 | extern "C" { 14 | 15 | MP_CAPI(MpReturnCode) google_InitGoogleLogging__PKc(const char* name); 16 | MP_CAPI(MpReturnCode) google_ShutdownGoogleLogging(); 17 | 18 | } // extern "C" 19 | 20 | #endif // MEDIAPIPE_API_FRAMEWORK_PORT_LOGGING_H_ 21 | -------------------------------------------------------------------------------- /mediapipe_api/framework/timestamp.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/timestamp.h" 8 | 9 | MpReturnCode mp_Timestamp__l(int64 timestamp, mediapipe::Timestamp** timestamp_out) { 10 | TRY 11 | *timestamp_out = new mediapipe::Timestamp(timestamp); 12 | RETURN_CODE(MpReturnCode::Success); 13 | CATCH_EXCEPTION 14 | } 15 | 16 | void mp_Timestamp__delete(mediapipe::Timestamp* timestamp) { delete timestamp; } 17 | 18 | int64 mp_Timestamp__Value(mediapipe::Timestamp* timestamp) { return timestamp->Value(); } 19 | 20 | double mp_Timestamp__Seconds(mediapipe::Timestamp* timestamp) { return timestamp->Seconds(); } 21 | 22 | int64 mp_Timestamp__Microseconds(mediapipe::Timestamp* timestamp) { return timestamp->Microseconds(); } 23 | 24 | MpReturnCode mp_Timestamp__DebugString(mediapipe::Timestamp* timestamp, const char** str_out) { 25 | TRY 26 | *str_out = strcpy_to_heap(timestamp->DebugString()); 27 | RETURN_CODE(MpReturnCode::Success); 28 | CATCH_EXCEPTION 29 | } 30 | 31 | bool mp_Timestamp__IsSpecialValue(mediapipe::Timestamp* timestamp) { return timestamp->IsSpecialValue(); } 32 | 33 | bool mp_Timestamp__IsRangeValue(mediapipe::Timestamp* timestamp) { return timestamp->IsRangeValue(); } 34 | 35 | bool mp_Timestamp__IsAllowedInStream(mediapipe::Timestamp* timestamp) { return timestamp->IsAllowedInStream(); } 36 | 37 | MpReturnCode mp_Timestamp__NextAllowedInStream(mediapipe::Timestamp* timestamp, mediapipe::Timestamp** timestamp_out) { 38 | TRY 39 | *timestamp_out = new mediapipe::Timestamp{timestamp->NextAllowedInStream()}; 40 | RETURN_CODE(MpReturnCode::Success); 41 | CATCH_EXCEPTION 42 | } 43 | 44 | MpReturnCode mp_Timestamp__PreviousAllowedInStream(mediapipe::Timestamp* timestamp, mediapipe::Timestamp** timestamp_out) { 45 | TRY 46 | *timestamp_out = new mediapipe::Timestamp{timestamp->PreviousAllowedInStream()}; 47 | RETURN_CODE(MpReturnCode::Success); 48 | CATCH_EXCEPTION 49 | } 50 | 51 | MpReturnCode mp_Timestamp_FromSeconds__d(double seconds, mediapipe::Timestamp** timestamp_out) { 52 | TRY 53 | *timestamp_out = new mediapipe::Timestamp{mediapipe::Timestamp::FromSeconds(seconds)}; 54 | RETURN_CODE(MpReturnCode::Success); 55 | CATCH_EXCEPTION 56 | } 57 | 58 | MpReturnCode mp_Timestamp_Unset(mediapipe::Timestamp** timestamp_out) { 59 | TRY 60 | *timestamp_out = new mediapipe::Timestamp{mediapipe::Timestamp::Unset()}; 61 | RETURN_CODE(MpReturnCode::Success); 62 | CATCH_EXCEPTION 63 | } 64 | 65 | MpReturnCode mp_Timestamp_Unstarted(mediapipe::Timestamp** timestamp_out) { 66 | TRY 67 | *timestamp_out = new mediapipe::Timestamp{mediapipe::Timestamp::Unstarted()}; 68 | RETURN_CODE(MpReturnCode::Success); 69 | CATCH_EXCEPTION 70 | } 71 | 72 | MpReturnCode mp_Timestamp_PreStream(mediapipe::Timestamp** timestamp_out) { 73 | TRY 74 | *timestamp_out = new mediapipe::Timestamp{mediapipe::Timestamp::PreStream()}; 75 | RETURN_CODE(MpReturnCode::Success); 76 | CATCH_EXCEPTION 77 | } 78 | 79 | MpReturnCode mp_Timestamp_Min(mediapipe::Timestamp** timestamp_out) { 80 | TRY 81 | *timestamp_out = new mediapipe::Timestamp{mediapipe::Timestamp::Min()}; 82 | RETURN_CODE(MpReturnCode::Success); 83 | CATCH_EXCEPTION 84 | } 85 | 86 | MpReturnCode mp_Timestamp_Max(mediapipe::Timestamp** timestamp_out) { 87 | TRY 88 | *timestamp_out = new mediapipe::Timestamp{mediapipe::Timestamp::Max()}; 89 | RETURN_CODE(MpReturnCode::Success); 90 | CATCH_EXCEPTION 91 | } 92 | 93 | MpReturnCode mp_Timestamp_PostStream(mediapipe::Timestamp** timestamp_out) { 94 | TRY 95 | *timestamp_out = new mediapipe::Timestamp{mediapipe::Timestamp::PostStream()}; 96 | RETURN_CODE(MpReturnCode::Success); 97 | CATCH_EXCEPTION 98 | } 99 | 100 | MpReturnCode mp_Timestamp_OneOverPostStream(mediapipe::Timestamp** timestamp_out) { 101 | TRY 102 | *timestamp_out = new mediapipe::Timestamp{mediapipe::Timestamp::OneOverPostStream()}; 103 | RETURN_CODE(MpReturnCode::Success); 104 | CATCH_EXCEPTION 105 | } 106 | 107 | MpReturnCode mp_Timestamp_Done(mediapipe::Timestamp** timestamp_out) { 108 | TRY 109 | *timestamp_out = new mediapipe::Timestamp{mediapipe::Timestamp::Done()}; 110 | RETURN_CODE(MpReturnCode::Success); 111 | CATCH_EXCEPTION 112 | } 113 | -------------------------------------------------------------------------------- /mediapipe_api/framework/timestamp.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_TIMESTAMP_H_ 8 | #define MEDIAPIPE_API_FRAMEWORK_TIMESTAMP_H_ 9 | 10 | #include "mediapipe/framework/timestamp.h" 11 | #include "mediapipe_api/common.h" 12 | 13 | extern "C" { 14 | 15 | MP_CAPI(MpReturnCode) mp_Timestamp__l(int64 timestamp, mediapipe::Timestamp** timestamp_out); 16 | MP_CAPI(void) mp_Timestamp__delete(mediapipe::Timestamp* timestamp); 17 | MP_CAPI(int64) mp_Timestamp__Value(mediapipe::Timestamp* timestamp); 18 | MP_CAPI(double) mp_Timestamp__Seconds(mediapipe::Timestamp* timestamp); 19 | MP_CAPI(int64) mp_Timestamp__Microseconds(mediapipe::Timestamp* timestamp); 20 | MP_CAPI(MpReturnCode) mp_Timestamp__DebugString(mediapipe::Timestamp* timestamp, const char** str_out); 21 | MP_CAPI(bool) mp_Timestamp__IsSpecialValue(mediapipe::Timestamp* timestamp); 22 | MP_CAPI(bool) mp_Timestamp__IsRangeValue(mediapipe::Timestamp* timestamp); 23 | MP_CAPI(bool) mp_Timestamp__IsAllowedInStream(mediapipe::Timestamp* timestamp); 24 | MP_CAPI(MpReturnCode) mp_Timestamp__NextAllowedInStream(mediapipe::Timestamp* timestamp, mediapipe::Timestamp** timestamp_out); 25 | MP_CAPI(MpReturnCode) mp_Timestamp__PreviousAllowedInStream(mediapipe::Timestamp* timestamp, mediapipe::Timestamp** timestamp_out); 26 | 27 | MP_CAPI(MpReturnCode) mp_Timestamp_FromSeconds__d(double seconds, mediapipe::Timestamp** timestamp_out); 28 | MP_CAPI(MpReturnCode) mp_Timestamp_Unset(mediapipe::Timestamp** timestamp_out); 29 | MP_CAPI(MpReturnCode) mp_Timestamp_Unstarted(mediapipe::Timestamp** timestamp_out); 30 | MP_CAPI(MpReturnCode) mp_Timestamp_PreStream(mediapipe::Timestamp** timestamp_out); 31 | MP_CAPI(MpReturnCode) mp_Timestamp_Min(mediapipe::Timestamp** timestamp_out); 32 | MP_CAPI(MpReturnCode) mp_Timestamp_Max(mediapipe::Timestamp** timestamp_out); 33 | MP_CAPI(MpReturnCode) mp_Timestamp_PostStream(mediapipe::Timestamp** timestamp_out); 34 | MP_CAPI(MpReturnCode) mp_Timestamp_OneOverPostStream(mediapipe::Timestamp** timestamp_out); 35 | MP_CAPI(MpReturnCode) mp_Timestamp_Done(mediapipe::Timestamp** timestamp_out); 36 | 37 | } // extern "C" 38 | 39 | #endif // MEDIAPIPE_API_FRAMEWORK_TIMESTAMP_H_ 40 | -------------------------------------------------------------------------------- /mediapipe_api/framework/validated_graph_config.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_VALIDATED_GRAPH_CONFIG_H_ 8 | #define MEDIAPIPE_API_FRAMEWORK_VALIDATED_GRAPH_CONFIG_H_ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "mediapipe/framework/validated_graph_config.h" 15 | #include "mediapipe_api/common.h" 16 | #include "mediapipe_api/external/protobuf.h" 17 | 18 | namespace mp_api { 19 | 20 | typedef struct EdgeInfo { 21 | int upstream; 22 | mediapipe::NodeTypeInfo::NodeRef parent_node; 23 | const char* name; 24 | bool back_edge; 25 | }; 26 | 27 | inline void CopyEdgeInfo(const mediapipe::EdgeInfo& src, mp_api::EdgeInfo* dst) { 28 | dst->upstream = src.upstream; 29 | dst->parent_node = src.parent_node; 30 | dst->name = strcpy_to_heap(src.name); 31 | dst->back_edge = src.back_edge; 32 | } 33 | 34 | inline void CopyEdgeInfoVector(const std::vector& src, mp_api::StructArray* dst) { 35 | auto vec_size = src.size(); 36 | auto data = new mp_api::EdgeInfo[vec_size]; 37 | 38 | auto it = src.begin(); 39 | auto p = data; 40 | 41 | for (; it != src.end(); ++it, ++p) { 42 | CopyEdgeInfo(*it, p); 43 | } 44 | dst->data = data; 45 | dst->size = static_cast(vec_size); 46 | } 47 | 48 | } // namespace mp_api 49 | 50 | extern "C" { 51 | 52 | typedef std::map SidePackets; 53 | 54 | MP_CAPI(MpReturnCode) mp_ValidatedGraphConfig__(mediapipe::ValidatedGraphConfig** config_out); 55 | MP_CAPI(void) mp_ValidatedGraphConfig__delete(mediapipe::ValidatedGraphConfig* config); 56 | 57 | MP_CAPI(MpReturnCode) mp_ValidatedGraphConfig__Initialize__Rcgc(mediapipe::ValidatedGraphConfig* config, const char* serialized_config, int size, 58 | absl::Status** status_out); 59 | MP_CAPI(MpReturnCode) mp_ValidatedGraphConfig__Initialize__PKc(mediapipe::ValidatedGraphConfig* config, const char* graph_type, absl::Status** status_out); 60 | 61 | MP_CAPI(bool) mp_ValidatedGraphConfig__Initialized(mediapipe::ValidatedGraphConfig* config); 62 | MP_CAPI(MpReturnCode) mp_ValidatedGraphConfig__ValidateRequiredSidePackets__Rsp(mediapipe::ValidatedGraphConfig* config, SidePackets* side_packets, 63 | absl::Status** status_out); 64 | 65 | MP_CAPI(MpReturnCode) mp_ValidatedGraphConfig__Config(mediapipe::ValidatedGraphConfig* config, mp_api::SerializedProto* value_out); 66 | 67 | MP_CAPI(MpReturnCode) mp_ValidatedGraphConfig__InputStreamInfos(mediapipe::ValidatedGraphConfig* config, mp_api::StructArray* value_out); 68 | MP_CAPI(MpReturnCode) mp_ValidatedGraphConfig__OutputStreamInfos(mediapipe::ValidatedGraphConfig* config, mp_api::StructArray* value_out); 69 | MP_CAPI(MpReturnCode) mp_ValidatedGraphConfig__InputSidePacketInfos(mediapipe::ValidatedGraphConfig* config, mp_api::StructArray* value_out); 70 | MP_CAPI(MpReturnCode) mp_ValidatedGraphConfig__OutputSidePacketInfos(mediapipe::ValidatedGraphConfig* config, mp_api::StructArray* value_out); 71 | 72 | MP_CAPI(int) mp_ValidatedGraphConfig__OutputStreamIndex__PKc(mediapipe::ValidatedGraphConfig* config, const char* name); 73 | MP_CAPI(int) mp_ValidatedGraphConfig__OutputSidePacketIndex__PKc(mediapipe::ValidatedGraphConfig* config, const char* name); 74 | MP_CAPI(int) mp_ValidatedGraphConfig__OutputStreamToNode__PKc(mediapipe::ValidatedGraphConfig* config, const char* name); 75 | 76 | MP_CAPI(MpReturnCode) mp_ValidatedGraphConfig__RegisteredSidePacketTypeName(mediapipe::ValidatedGraphConfig* config, const char* name, 77 | absl::StatusOr** status_or_string_out); 78 | MP_CAPI(MpReturnCode) mp_ValidatedGraphConfig__RegisteredStreamTypeName(mediapipe::ValidatedGraphConfig* config, const char* name, 79 | absl::StatusOr** status_or_string_out); 80 | 81 | MP_CAPI(MpReturnCode) mp_ValidatedGraphConfig__Package(mediapipe::ValidatedGraphConfig* config, const char** str_out); 82 | 83 | MP_CAPI(bool) mp_ValidatedGraphConfig_IsReservedExecutorName(const char* name); 84 | MP_CAPI(bool) mp_ValidatedGraphConfig__IsExternalSidePacket__PKc(mediapipe::ValidatedGraphConfig* config, const char* name); 85 | 86 | MP_CAPI(void) mp_api_EdgeInfoArray__delete(mp_api::EdgeInfo* edge_info_vector_data, int size); 87 | 88 | } // extern "C" 89 | 90 | #endif // MEDIAPIPE_API_FRAMEWORK_VALIDATED_GRAPH_CONFIG_H_ 91 | -------------------------------------------------------------------------------- /mediapipe_api/gpu/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 | cc_library( 15 | name = "gl_base", 16 | hdrs = ["gl_base.h"], 17 | deps = [ 18 | "//mediapipe_api:common", 19 | "@com_google_mediapipe//mediapipe/gpu:gl_base", 20 | ], 21 | alwayslink = True, 22 | ) 23 | 24 | cc_library( 25 | name = "gl_calculator_helper", 26 | srcs = ["gl_calculator_helper.cc"], 27 | hdrs = ["gl_calculator_helper.h"], 28 | copts = [ 29 | "-Wno-return-type-c-linkage", 30 | ], 31 | deps = [ 32 | "//mediapipe_api:common", 33 | "//mediapipe_api/external/absl:status", 34 | "@com_google_mediapipe//mediapipe/gpu:gl_calculator_helper", 35 | ], 36 | alwayslink = True, 37 | ) 38 | 39 | cc_library( 40 | name = "gl_context", 41 | srcs = ["gl_context.cc"], 42 | hdrs = ["gl_context.h"], 43 | deps = [ 44 | "//mediapipe_api:common", 45 | "//mediapipe_api/external/absl:statusor", 46 | "@com_google_mediapipe//mediapipe/gpu:gl_context", 47 | ], 48 | alwayslink = True, 49 | ) 50 | 51 | cc_library( 52 | name = "gl_texture_buffer", 53 | srcs = ["gl_texture_buffer.cc"], 54 | hdrs = ["gl_texture_buffer.h"], 55 | copts = [ 56 | "-Wno-return-type-c-linkage", 57 | ], 58 | deps = [ 59 | ":gl_context", 60 | "//mediapipe_api:common", 61 | "@com_google_mediapipe//mediapipe/gpu:gl_texture_buffer", 62 | ], 63 | alwayslink = True, 64 | ) 65 | 66 | cc_library( 67 | name = "gpu_buffer", 68 | srcs = ["gpu_buffer.cc"], 69 | hdrs = ["gpu_buffer.h"], 70 | copts = [ 71 | "-Wno-return-type-c-linkage", 72 | ], 73 | deps = [ 74 | ":gl_texture_buffer", 75 | "//mediapipe_api:common", 76 | "//mediapipe_api/external/absl:status", 77 | "//mediapipe_api/external/absl:statusor", 78 | "//mediapipe_api/framework:packet", 79 | "@com_google_mediapipe//mediapipe/gpu:gpu_buffer", 80 | ], 81 | alwayslink = True, 82 | ) 83 | 84 | cc_library( 85 | name = "gpu_buffer_format", 86 | srcs = ["gpu_buffer_format.cc"], 87 | hdrs = ["gpu_buffer_format.h"], 88 | deps = [ 89 | "//mediapipe_api:common", 90 | "@com_google_mediapipe//mediapipe/gpu:gpu_buffer_format", 91 | ], 92 | alwayslink = True, 93 | ) 94 | 95 | cc_library( 96 | name = "gpu_shared_data_internal", 97 | srcs = ["gpu_shared_data_internal.cc"], 98 | hdrs = ["gpu_shared_data_internal.h"], 99 | deps = [ 100 | ":gl_context", 101 | "//mediapipe_api:common", 102 | "//mediapipe_api/external/absl:status", 103 | "//mediapipe_api/external/absl:statusor", 104 | "@com_google_mediapipe//mediapipe/gpu:gpu_shared_data_internal", 105 | ], 106 | alwayslink = True, 107 | ) 108 | 109 | pkg_files( 110 | name = "proto_srcs", 111 | srcs = [ 112 | ":gpu_origin_cs", 113 | ":scale_mode_cs", 114 | ":gl_scaler_calculator_cs", 115 | ":gl_surface_sink_calculator_cs", 116 | ":copy_calculator_cs", 117 | ":gl_context_options_cs", 118 | ], 119 | prefix = "Gpu", 120 | ) 121 | 122 | csharp_proto_src( 123 | name = "gpu_origin_cs", 124 | proto_src = "mediapipe/gpu/gpu_origin.proto", 125 | deps = [ 126 | "@com_google_mediapipe//mediapipe/gpu:protos_src", 127 | ], 128 | ) 129 | 130 | csharp_proto_src( 131 | name = "scale_mode_cs", 132 | proto_src = "mediapipe/gpu/scale_mode.proto", 133 | deps = [ 134 | "@com_google_mediapipe//mediapipe/gpu:protos_src", 135 | ], 136 | ) 137 | 138 | csharp_proto_src( 139 | name = "gl_scaler_calculator_cs", 140 | proto_src = "mediapipe/gpu/gl_scaler_calculator.proto", 141 | deps = [ 142 | "@com_google_mediapipe//mediapipe/gpu:protos_src", 143 | "@com_google_mediapipe//mediapipe/framework:protos_src", 144 | ], 145 | ) 146 | 147 | csharp_proto_src( 148 | name = "gl_surface_sink_calculator_cs", 149 | proto_src = "mediapipe/gpu/gl_surface_sink_calculator.proto", 150 | deps = [ 151 | "@com_google_mediapipe//mediapipe/gpu:protos_src", 152 | "@com_google_mediapipe//mediapipe/framework:protos_src", 153 | ], 154 | ) 155 | 156 | csharp_proto_src( 157 | name = "copy_calculator_cs", 158 | proto_src = "mediapipe/gpu/copy_calculator.proto", 159 | deps = [ 160 | "@com_google_mediapipe//mediapipe/gpu:protos_src", 161 | "@com_google_mediapipe//mediapipe/framework:protos_src", 162 | ], 163 | ) 164 | 165 | csharp_proto_src( 166 | name = "gl_context_options_cs", 167 | proto_src = "mediapipe/gpu/gl_context_options.proto", 168 | deps = [ 169 | "@com_google_mediapipe//mediapipe/gpu:protos_src", 170 | "@com_google_mediapipe//mediapipe/framework:protos_src", 171 | ], 172 | ) 173 | -------------------------------------------------------------------------------- /mediapipe_api/gpu/gl_base.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_GPU_GL_BASE_H_ 8 | #define MEDIAPIPE_API_GPU_GL_BASE_H_ 9 | 10 | #include "mediapipe/gpu/gl_base.h" 11 | #include "mediapipe_api/common.h" 12 | 13 | extern "C" { 14 | 15 | MP_CAPI(void) glFlush(); 16 | MP_CAPI(void) glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum gl_format, GLenum gl_type, uint8_t* pixels); 17 | 18 | #if HAS_EGL 19 | MP_CAPI(EGLContext) eglGetCurrentContext(); 20 | #endif // HAS_EGL 21 | 22 | } // extern "C" 23 | 24 | #endif // MEDIAPIPE_API_GPU_GL_BASE_H_ 25 | -------------------------------------------------------------------------------- /mediapipe_api/gpu/gl_calculator_helper.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_GPU_GL_CALCULATOR_HELPER_H_ 8 | #define MEDIAPIPE_API_GPU_GL_CALCULATOR_HELPER_H_ 9 | 10 | #include 11 | 12 | #include "mediapipe/gpu/gl_calculator_helper.h" 13 | #include "mediapipe_api/common.h" 14 | #include "mediapipe_api/external/absl/status.h" 15 | 16 | extern "C" { 17 | 18 | typedef mp_api::StatusArgs NativeGlStatusFunction(); 19 | 20 | /** GlCalculatorHelper API */ 21 | MP_CAPI(MpReturnCode) mp_GlCalculatorHelper__(mediapipe::GlCalculatorHelper** gl_calculator_helper_out); 22 | MP_CAPI(void) mp_GlCalculatorHelper__delete(mediapipe::GlCalculatorHelper* gl_calculator_helper); 23 | MP_CAPI(MpReturnCode) mp_GlCalculatorHelper__InitializeForTest__Pgr(mediapipe::GlCalculatorHelper* gl_calculator_helper, 24 | mediapipe::GpuResources* gpu_resources); 25 | MP_CAPI(MpReturnCode) mp_GlCalculatorHelper__RunInGlContext__PF(mediapipe::GlCalculatorHelper* gl_calculator_helper, NativeGlStatusFunction* gl_func, 26 | absl::Status** status_out); 27 | 28 | MP_CAPI(MpReturnCode) mp_GlCalculatorHelper__CreateSourceTexture__Rif(mediapipe::GlCalculatorHelper* gl_calculator_helper, mediapipe::ImageFrame* image_frame, 29 | mediapipe::GlTexture** gl_texture_out); 30 | MP_CAPI(MpReturnCode) mp_GlCalculatorHelper__CreateSourceTexture__Rgb(mediapipe::GlCalculatorHelper* gl_calculator_helper, mediapipe::GpuBuffer* gpu_buffer, 31 | mediapipe::GlTexture** gl_texture_out); 32 | 33 | #ifdef __APPLE__ 34 | MP_CAPI(MpReturnCode) mp_GlCalculatorHelper__CreateSourceTexture__Rgb_i(mediapipe::GlCalculatorHelper* gl_calculator_helper, mediapipe::GpuBuffer* gpu_buffer, 35 | int plane, mediapipe::GlTexture** gl_texture_out); 36 | #endif // __APPLE__ 37 | 38 | MP_CAPI(MpReturnCode) mp_GlCalculatorHelper__CreateDestinationTexture__i_i_ui(mediapipe::GlCalculatorHelper* gl_calculator_helper, int output_width, 39 | int output_height, mediapipe::GpuBufferFormat format, 40 | mediapipe::GlTexture** gl_texture_out); 41 | MP_CAPI(MpReturnCode) mp_GlCalculatorHelper__CreateDestinationTexture__Rgb(mediapipe::GlCalculatorHelper* gl_calculator_helper, 42 | mediapipe::GpuBuffer* gpu_buffer, mediapipe::GlTexture** gl_texture_out); 43 | MP_CAPI(GLuint) mp_GlCalculatorHelper__framebuffer(mediapipe::GlCalculatorHelper* gl_calculator_helper); 44 | MP_CAPI(MpReturnCode) mp_GlCalculatorHelper__BindFrameBuffer__Rtexture(mediapipe::GlCalculatorHelper* gl_calculator_helper, mediapipe::GlTexture* gl_texture); 45 | MP_CAPI(mediapipe::GlContext&) mp_GlCalculatorHelper__GetGlContext(mediapipe::GlCalculatorHelper* gl_calculator_helper); 46 | MP_CAPI(bool) mp_GlCalculatorHelper__Initialized(mediapipe::GlCalculatorHelper* gl_calculator_helper); 47 | 48 | /** GlTexture API */ 49 | MP_CAPI(MpReturnCode) mp_GlTexture__(mediapipe::GlTexture** gl_texture_out); 50 | MP_CAPI(void) mp_GlTexture__delete(mediapipe::GlTexture* gl_texture); 51 | MP_CAPI(int) mp_GlTexture__width(mediapipe::GlTexture* gl_texture); 52 | MP_CAPI(int) mp_GlTexture__height(mediapipe::GlTexture* gl_texture); 53 | MP_CAPI(GLenum) mp_GlTexture__target(mediapipe::GlTexture* gl_texture); 54 | MP_CAPI(GLuint) mp_GlTexture__name(mediapipe::GlTexture* gl_texture); 55 | MP_CAPI(MpReturnCode) mp_GlTexture__Release(mediapipe::GlTexture* gl_texture); 56 | MP_CAPI(MpReturnCode) mp_GlTexture__GetGpuBufferFrame(mediapipe::GlTexture* gl_texture, mediapipe::GpuBuffer** gpu_buffer_out); 57 | 58 | } // extern "C" 59 | 60 | #endif // MEDIAPIPE_API_GPU_GL_CALCULATOR_HELPER_H_ 61 | -------------------------------------------------------------------------------- /mediapipe_api/gpu/gl_context.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/gpu/gl_context.h" 8 | 9 | void mp_SharedGlContext__delete(SharedGlContext* shared_gl_context) { delete shared_gl_context; } 10 | 11 | mediapipe::GlContext* mp_SharedGlContext__get(SharedGlContext* shared_gl_context) { return shared_gl_context->get(); } 12 | 13 | void mp_SharedGlContext__reset(SharedGlContext* shared_gl_context) { shared_gl_context->reset(); } 14 | 15 | MpReturnCode mp_GlContext_GetCurrent(SharedGlContext** shared_gl_context_out) { 16 | TRY 17 | auto gl_context = mediapipe::GlContext::GetCurrent(); 18 | 19 | if (gl_context.get() == nullptr) { 20 | *shared_gl_context_out = nullptr; 21 | } else { 22 | *shared_gl_context_out = new SharedGlContext{gl_context}; 23 | } 24 | RETURN_CODE(MpReturnCode::Success); 25 | CATCH_EXCEPTION 26 | } 27 | 28 | MpReturnCode mp_GlContext_Create__P_b(bool create_thread, StatusOrSharedGlContext** status_or_shared_gl_context_out) { 29 | TRY 30 | *status_or_shared_gl_context_out = new StatusOrSharedGlContext{mediapipe::GlContext::Create(nullptr, create_thread)}; 31 | RETURN_CODE(MpReturnCode::Success); 32 | CATCH_EXCEPTION 33 | } 34 | 35 | MpReturnCode mp_GlContext_Create__Rgc_b(mediapipe::GlContext* share_context, bool create_thread, StatusOrSharedGlContext** status_or_shared_gl_context_out) { 36 | TRY 37 | *status_or_shared_gl_context_out = new StatusOrSharedGlContext{mediapipe::GlContext::Create(*share_context, create_thread)}; 38 | RETURN_CODE(MpReturnCode::Success); 39 | CATCH_EXCEPTION 40 | } 41 | 42 | MpReturnCode mp_GlContext_Create__ui_b(mediapipe::PlatformGlContext share_context, bool create_thread, 43 | StatusOrSharedGlContext** status_or_shared_gl_context_out) { 44 | TRY 45 | *status_or_shared_gl_context_out = new StatusOrSharedGlContext{mediapipe::GlContext::Create(share_context, create_thread)}; 46 | RETURN_CODE(MpReturnCode::Success); 47 | CATCH_EXCEPTION 48 | } 49 | 50 | #if HAS_EAGL 51 | MpReturnCode mp_GlContext_Create__Pes_b(EAGLSharegroup* sharegroup, bool create_thread, StatusOrSharedGlContext** status_or_shared_gl_context_out) { 52 | TRY 53 | *status_or_shared_gl_context_out = new StatusOrSharedGlContext{mediapipe::GlContext::Create(sharegroup, create_thread)}; 54 | RETURN_CODE(MpReturnCode::Success); 55 | CATCH_EXCEPTION 56 | } 57 | #endif // HAS_EAGL 58 | 59 | #if defined(__EMSCRIPTEN__) 60 | #elif HAS_EGL 61 | EGLDisplay mp_GlContext__egl_display(mediapipe::GlContext* gl_context) { return gl_context->egl_display(); } 62 | 63 | EGLConfig mp_GlContext__egl_config(mediapipe::GlContext* gl_context) { return gl_context->egl_config(); } 64 | 65 | EGLContext mp_GlContext__egl_context(mediapipe::GlContext* gl_context) { return gl_context->egl_context(); } 66 | #elif HAS_EAGL 67 | EAGLContext* mp_GlContext__eagl_context(mediapipe::GlContext* gl_context) { return gl_context->eagl_context(); } 68 | #elif HAS_NSGL 69 | NSOpenGLContext* mp_GlContext__nsgl_context(mediapipe::GlContext* gl_context) { return gl_context->nsgl_context(); } 70 | 71 | NSOpenGLPixelFormat* mp_GlContext__nsgl_pixel_format(mediapipe::GlContext* gl_context) { return gl_context->nsgl_pixel_format(); } 72 | #endif // defined(__EMSCRIPTEN__) 73 | 74 | bool mp_GlContext__IsCurrent(mediapipe::GlContext* gl_context) { return gl_context->IsCurrent(); } 75 | 76 | GLint mp_GlContext__gl_major_version(mediapipe::GlContext* gl_context) { return gl_context->gl_major_version(); } 77 | 78 | GLint mp_GlContext__gl_minor_version(mediapipe::GlContext* gl_context) { return gl_context->gl_minor_version(); } 79 | 80 | int64_t mp_GlContext__gl_finish_count(mediapipe::GlContext* gl_context) { return gl_context->gl_finish_count(); } 81 | 82 | // GlSyncToken API 83 | void mp_GlSyncToken__delete(mediapipe::GlSyncToken* gl_sync_token) { delete gl_sync_token; } 84 | 85 | mediapipe::GlSyncPoint* mp_GlSyncToken__get(mediapipe::GlSyncToken* gl_sync_token) { return gl_sync_token->get(); } 86 | 87 | void mp_GlSyncToken__reset(mediapipe::GlSyncToken* gl_sync_token) { gl_sync_token->reset(); } 88 | 89 | MpReturnCode mp_GlSyncPoint__Wait(mediapipe::GlSyncPoint* gl_sync_point) { 90 | TRY 91 | gl_sync_point->Wait(); 92 | RETURN_CODE(MpReturnCode::Success); 93 | CATCH_EXCEPTION 94 | } 95 | 96 | MpReturnCode mp_GlSyncPoint__WaitOnGpu(mediapipe::GlSyncPoint* gl_sync_point) { 97 | TRY 98 | gl_sync_point->WaitOnGpu(); 99 | RETURN_CODE(MpReturnCode::Success); 100 | CATCH_EXCEPTION 101 | } 102 | 103 | MpReturnCode mp_GlSyncPoint__IsReady(mediapipe::GlSyncPoint* gl_sync_point, bool* value_out) { 104 | TRY 105 | *value_out = gl_sync_point->IsReady(); 106 | RETURN_CODE(MpReturnCode::Success); 107 | CATCH_EXCEPTION 108 | } 109 | 110 | MpReturnCode mp_GlSyncPoint__GetContext(mediapipe::GlSyncPoint* gl_sync_point, SharedGlContext** shared_gl_context_out) { 111 | TRY 112 | *shared_gl_context_out = new SharedGlContext{gl_sync_point->GetContext()}; 113 | RETURN_CODE(MpReturnCode::Success); 114 | CATCH_EXCEPTION 115 | } 116 | -------------------------------------------------------------------------------- /mediapipe_api/gpu/gl_context.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_GPU_GL_CONTEXT_H_ 8 | #define MEDIAPIPE_API_GPU_GL_CONTEXT_H_ 9 | 10 | #include 11 | #include 12 | 13 | #include "mediapipe/gpu/gl_context.h" 14 | #include "mediapipe_api/common.h" 15 | #include "mediapipe_api/external/absl/statusor.h" 16 | 17 | extern "C" { 18 | 19 | typedef std::shared_ptr SharedGlContext; 20 | typedef absl::StatusOr StatusOrSharedGlContext; 21 | 22 | MP_CAPI(void) mp_SharedGlContext__delete(SharedGlContext* shared_gl_context); 23 | MP_CAPI(mediapipe::GlContext*) mp_SharedGlContext__get(SharedGlContext* shared_gl_context); 24 | MP_CAPI(void) mp_SharedGlContext__reset(SharedGlContext* shared_gl_context); 25 | 26 | MP_CAPI(MpReturnCode) mp_GlContext_GetCurrent(SharedGlContext** shared_gl_context_out); 27 | MP_CAPI(MpReturnCode) mp_GlContext_Create__P_b(bool create_thread, StatusOrSharedGlContext** status_or_shared_gl_context_out); 28 | MP_CAPI(MpReturnCode) mp_GlContext_Create__Rgc_b(mediapipe::GlContext* share_context, bool create_thread, 29 | StatusOrSharedGlContext** status_or_shared_gl_context_out); 30 | MP_CAPI(MpReturnCode) mp_GlContext_Create__ui_b(mediapipe::PlatformGlContext share_context, bool create_thread, 31 | StatusOrSharedGlContext** status_or_shared_gl_context_out); 32 | #if HAS_EAGL 33 | MP_CAPI(MpReturnCode) mp_GlContext_Create__Pes_b(EAGLSharegroup* sharegroup, bool create_thread, StatusOrSharedGlContext** status_or_shared_gl_context_out); 34 | #endif // HAS_EAGL 35 | 36 | #if defined(__EMSCRIPTEN__) 37 | #elif HAS_EGL 38 | MP_CAPI(EGLDisplay) mp_GlContext__egl_display(mediapipe::GlContext* gl_context); 39 | MP_CAPI(EGLConfig) mp_GlContext__egl_config(mediapipe::GlContext* gl_context); 40 | MP_CAPI(EGLContext) mp_GlContext__egl_context(mediapipe::GlContext* gl_context); 41 | #elif HAS_EAGL 42 | MP_CAPI(EAGLContext*) mp_GlContext__eagl_context(mediapipe::GlContext* gl_context); 43 | // TODO: cv_texture_cache 44 | #elif HAS_NSGL 45 | MP_CAPI(NSOpenGLContext*) mp_GlContext__nsgl_context(mediapipe::GlContext* gl_context); 46 | MP_CAPI(NSOpenGLPixelFormat*) mp_GlContext__nsgl_pixel_format(mediapipe::GlContext* gl_context); 47 | // TODO: cv_texture_cache 48 | #endif // defined(__EMSCRIPTEN__) 49 | 50 | MP_CAPI(bool) mp_GlContext__IsCurrent(mediapipe::GlContext* gl_context); 51 | MP_CAPI(GLint) mp_GlContext__gl_major_version(mediapipe::GlContext* gl_context); 52 | MP_CAPI(GLint) mp_GlContext__gl_minor_version(mediapipe::GlContext* gl_context); 53 | MP_CAPI(int64_t) mp_GlContext__gl_finish_count(mediapipe::GlContext* gl_context); 54 | 55 | // GlSyncToken API 56 | MP_CAPI(void) mp_GlSyncToken__delete(mediapipe::GlSyncToken* gl_sync_token); 57 | MP_CAPI(mediapipe::GlSyncPoint*) mp_GlSyncToken__get(mediapipe::GlSyncToken* gl_sync_token); 58 | MP_CAPI(void) mp_GlSyncToken__reset(mediapipe::GlSyncToken* gl_sync_token); 59 | 60 | MP_CAPI(MpReturnCode) mp_GlSyncPoint__Wait(mediapipe::GlSyncPoint* gl_sync_point); 61 | MP_CAPI(MpReturnCode) mp_GlSyncPoint__WaitOnGpu(mediapipe::GlSyncPoint* gl_sync_point); 62 | MP_CAPI(MpReturnCode) mp_GlSyncPoint__IsReady(mediapipe::GlSyncPoint* gl_sync_point, bool* value_out); 63 | MP_CAPI(MpReturnCode) mp_GlSyncPoint__GetContext(mediapipe::GlSyncPoint* gl_sync_point, SharedGlContext** shared_gl_context_out); 64 | 65 | } // extern "C" 66 | 67 | #endif // MEDIAPIPE_API_GPU_GL_CONTEXT_H_ 68 | -------------------------------------------------------------------------------- /mediapipe_api/gpu/gl_texture_buffer.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/gpu/gl_texture_buffer.h" 8 | 9 | void mp_SharedGlTextureBuffer__delete(SharedGlTextureBuffer* gl_texture_buffer) { delete gl_texture_buffer; } 10 | 11 | mediapipe::GlTextureBuffer* mp_SharedGlTextureBuffer__get(SharedGlTextureBuffer* gl_texture_buffer) { return gl_texture_buffer->get(); } 12 | 13 | void mp_SharedGlTextureBuffer__reset(SharedGlTextureBuffer* gl_texture_buffer) { gl_texture_buffer->reset(); } 14 | 15 | MpReturnCode mp_SharedGlTextureBuffer__ui_ui_i_i_ui_PF_PSgc(GLenum target, GLuint name, int width, int height, mediapipe::GpuBufferFormat format, 16 | GlTextureBufferDeletionCallback* deletion_callback, 17 | std::shared_ptr* producer_context, 18 | SharedGlTextureBuffer** gl_texture_buffer_out) { 19 | TRY 20 | auto callback = [name, deletion_callback](mediapipe::GlSyncToken token) -> void { 21 | deletion_callback(name, new mediapipe::GlSyncToken{token}); 22 | }; 23 | *gl_texture_buffer_out = new SharedGlTextureBuffer{new mediapipe::GlTextureBuffer{ 24 | GL_TEXTURE_2D, 25 | name, 26 | width, 27 | height, 28 | format, 29 | callback, 30 | *producer_context, 31 | }}; 32 | RETURN_CODE(MpReturnCode::Success); 33 | CATCH_EXCEPTION 34 | } 35 | 36 | GLuint mp_GlTextureBuffer__name(mediapipe::GlTextureBuffer* gl_texture_buffer) { return gl_texture_buffer->name(); } 37 | 38 | GLenum mp_GlTextureBuffer__target(mediapipe::GlTextureBuffer* gl_texture_buffer) { return gl_texture_buffer->target(); } 39 | 40 | int mp_GlTextureBuffer__width(mediapipe::GlTextureBuffer* gl_texture_buffer) { return gl_texture_buffer->width(); } 41 | 42 | int mp_GlTextureBuffer__height(mediapipe::GlTextureBuffer* gl_texture_buffer) { return gl_texture_buffer->height(); } 43 | 44 | mediapipe::GpuBufferFormat mp_GlTextureBuffer__format(mediapipe::GlTextureBuffer* gl_texture_buffer) { return gl_texture_buffer->format(); } 45 | 46 | MpReturnCode mp_GlTextureBuffer__WaitUntilComplete(mediapipe::GlTextureBuffer* gl_texture_buffer) { 47 | TRY_ALL 48 | gl_texture_buffer->WaitUntilComplete(); 49 | RETURN_CODE(MpReturnCode::Success); 50 | CATCH_ALL 51 | } 52 | 53 | MpReturnCode mp_GlTextureBuffer__WaitOnGpu(mediapipe::GlTextureBuffer* gl_texture_buffer) { 54 | TRY_ALL 55 | gl_texture_buffer->WaitOnGpu(); 56 | RETURN_CODE(MpReturnCode::Success); 57 | CATCH_ALL 58 | } 59 | 60 | MpReturnCode mp_GlTextureBuffer__Reuse(mediapipe::GlTextureBuffer* gl_texture_buffer) { 61 | TRY_ALL 62 | gl_texture_buffer->Reuse(); 63 | RETURN_CODE(MpReturnCode::Success); 64 | CATCH_ALL 65 | } 66 | 67 | MpReturnCode mp_GlTextureBuffer__Updated__Pgst(mediapipe::GlTextureBuffer* gl_texture_buffer, mediapipe::GlSyncToken* prod_token) { 68 | TRY_ALL 69 | gl_texture_buffer->Updated(*prod_token); 70 | RETURN_CODE(MpReturnCode::Success); 71 | CATCH_ALL 72 | } 73 | 74 | MpReturnCode mp_GlTextureBuffer__DidRead__Pgst(mediapipe::GlTextureBuffer* gl_texture_buffer, mediapipe::GlSyncToken* cons_token) { 75 | TRY_ALL 76 | gl_texture_buffer->DidRead(*cons_token); 77 | RETURN_CODE(MpReturnCode::Success); 78 | CATCH_ALL 79 | } 80 | 81 | MpReturnCode mp_GlTextureBuffer__WaitForConsumers(mediapipe::GlTextureBuffer* gl_texture_buffer) { 82 | TRY_ALL 83 | gl_texture_buffer->WaitForConsumers(); 84 | RETURN_CODE(MpReturnCode::Success); 85 | CATCH_ALL 86 | } 87 | 88 | MpReturnCode mp_GlTextureBuffer__WaitForConsumersOnGpu(mediapipe::GlTextureBuffer* gl_texture_buffer) { 89 | TRY_ALL 90 | gl_texture_buffer->WaitForConsumersOnGpu(); 91 | RETURN_CODE(MpReturnCode::Success); 92 | CATCH_ALL 93 | } 94 | 95 | const SharedGlContext& mp_GlTextureBuffer__GetProducerContext(mediapipe::GlTextureBuffer* gl_texture_buffer) { return gl_texture_buffer->GetProducerContext(); } 96 | -------------------------------------------------------------------------------- /mediapipe_api/gpu/gl_texture_buffer.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_GPU_GL_TEXTURE_BUFFER_H_ 8 | #define MEDIAPIPE_API_GPU_GL_TEXTURE_BUFFER_H_ 9 | 10 | #include 11 | #include 12 | 13 | #include "mediapipe/gpu/gl_texture_buffer.h" 14 | #include "mediapipe_api/common.h" 15 | #include "mediapipe_api/gpu/gl_context.h" 16 | 17 | extern "C" { 18 | 19 | typedef std::shared_ptr SharedGlTextureBuffer; 20 | typedef void GlTextureBufferDeletionCallback(GLuint name, std::shared_ptr* sync_token); 21 | 22 | MP_CAPI(void) mp_SharedGlTextureBuffer__delete(SharedGlTextureBuffer* gl_texture_buffer); 23 | MP_CAPI(mediapipe::GlTextureBuffer*) mp_SharedGlTextureBuffer__get(SharedGlTextureBuffer* gl_texture_buffer); 24 | MP_CAPI(void) mp_SharedGlTextureBuffer__reset(SharedGlTextureBuffer* gl_texture_buffer); 25 | 26 | MP_CAPI(MpReturnCode) mp_SharedGlTextureBuffer__ui_ui_i_i_ui_PF_PSgc(GLenum target, GLuint name, int width, int height, mediapipe::GpuBufferFormat format, 27 | GlTextureBufferDeletionCallback* deletion_callback, 28 | std::shared_ptr* producer_context, 29 | SharedGlTextureBuffer** gl_texture_buffer_out); 30 | 31 | MP_CAPI(GLuint) mp_GlTextureBuffer__name(mediapipe::GlTextureBuffer* gl_texture_buffer); 32 | MP_CAPI(GLenum) mp_GlTextureBuffer__target(mediapipe::GlTextureBuffer* gl_texture_buffer); 33 | MP_CAPI(int) mp_GlTextureBuffer__width(mediapipe::GlTextureBuffer* gl_texture_buffer); 34 | MP_CAPI(int) mp_GlTextureBuffer__height(mediapipe::GlTextureBuffer* gl_texture_buffer); 35 | MP_CAPI(mediapipe::GpuBufferFormat) mp_GlTextureBuffer__format(mediapipe::GlTextureBuffer* gl_texture_buffer); 36 | 37 | MP_CAPI(MpReturnCode) mp_GlTextureBuffer__WaitUntilComplete(mediapipe::GlTextureBuffer* gl_texture_buffer); 38 | MP_CAPI(MpReturnCode) mp_GlTextureBuffer__WaitOnGpu(mediapipe::GlTextureBuffer* gl_texture_buffer); 39 | MP_CAPI(MpReturnCode) mp_GlTextureBuffer__Reuse(mediapipe::GlTextureBuffer* gl_texture_buffer); 40 | MP_CAPI(MpReturnCode) mp_GlTextureBuffer__Updated__Pgst(mediapipe::GlTextureBuffer* gl_texture_buffer, mediapipe::GlSyncToken* prod_token); 41 | MP_CAPI(MpReturnCode) mp_GlTextureBuffer__DidRead__Pgst(mediapipe::GlTextureBuffer* gl_texture_buffer, mediapipe::GlSyncToken* cons_token); 42 | MP_CAPI(MpReturnCode) mp_GlTextureBuffer__WaitForConsumers(mediapipe::GlTextureBuffer* gl_texture_buffer); 43 | MP_CAPI(MpReturnCode) mp_GlTextureBuffer__WaitForConsumersOnGpu(mediapipe::GlTextureBuffer* gl_texture_buffer); 44 | MP_CAPI(const SharedGlContext&) mp_GlTextureBuffer__GetProducerContext(mediapipe::GlTextureBuffer* gl_texture_buffer); 45 | 46 | } // extern "C" 47 | 48 | #endif // MEDIAPIPE_API_GPU_GL_TEXTURE_BUFFER_H_ 49 | -------------------------------------------------------------------------------- /mediapipe_api/gpu/gpu_buffer.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/gpu/gpu_buffer.h" 8 | 9 | #include 10 | 11 | void mp_GpuBuffer__delete(mediapipe::GpuBuffer* gpu_buffer) { delete gpu_buffer; } 12 | 13 | #if MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER 14 | #else 15 | MpReturnCode mp_GpuBuffer__PSgtb(SharedGlTextureBuffer* gl_texture_buffer, mediapipe::GpuBuffer** gpu_buffer_out) { 16 | TRY 17 | *gpu_buffer_out = new mediapipe::GpuBuffer{*gl_texture_buffer}; 18 | RETURN_CODE(MpReturnCode::Success); 19 | CATCH_EXCEPTION 20 | } 21 | #endif // MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER 22 | 23 | int mp_GpuBuffer__width(mediapipe::GpuBuffer* gpu_buffer) { return gpu_buffer->width(); } 24 | 25 | int mp_GpuBuffer__height(mediapipe::GpuBuffer* gpu_buffer) { return gpu_buffer->height(); } 26 | 27 | mediapipe::GpuBufferFormat mp_GpuBuffer__format(mediapipe::GpuBuffer* gpu_buffer) { return gpu_buffer->format(); } 28 | 29 | void mp_StatusOrGpuBuffer__delete(StatusOrGpuBuffer* status_or_gpu_buffer) { delete status_or_gpu_buffer; } 30 | 31 | bool mp_StatusOrGpuBuffer__ok(StatusOrGpuBuffer* status_or_gpu_buffer) { return absl_StatusOr__ok(status_or_gpu_buffer); } 32 | 33 | MpReturnCode mp_StatusOrGpuBuffer__status(StatusOrGpuBuffer* status_or_gpu_buffer, absl::Status** status_out) { 34 | return absl_StatusOr__status(status_or_gpu_buffer, status_out); 35 | } 36 | 37 | MpReturnCode mp_StatusOrGpuBuffer__value(StatusOrGpuBuffer* status_or_gpu_buffer, mediapipe::GpuBuffer** value_out) { 38 | return absl_StatusOr__value(status_or_gpu_buffer, value_out); 39 | } 40 | 41 | MpReturnCode mp__MakeGpuBufferPacket__Rgb(mediapipe::GpuBuffer* gpu_buffer, mediapipe::Packet** packet_out) { 42 | TRY 43 | *packet_out = new mediapipe::Packet{mediapipe::MakePacket(std::move(*gpu_buffer))}; 44 | RETURN_CODE(MpReturnCode::Success); 45 | CATCH_EXCEPTION 46 | } 47 | 48 | MpReturnCode mp__MakeGpuBufferPacket_At__Rgb_Rts(mediapipe::GpuBuffer* gpu_buffer, mediapipe::Timestamp* timestamp, mediapipe::Packet** packet_out) { 49 | TRY 50 | *packet_out = new mediapipe::Packet{mediapipe::MakePacket(std::move(*gpu_buffer)).At(*timestamp)}; 51 | RETURN_CODE(MpReturnCode::Success); 52 | CATCH_EXCEPTION 53 | } 54 | 55 | MpReturnCode mp_Packet__ConsumeGpuBuffer(mediapipe::Packet* packet, StatusOrGpuBuffer** status_or_value_out) { 56 | return mp_Packet__Consume(packet, status_or_value_out); 57 | } 58 | 59 | MpReturnCode mp_Packet__GetGpuBuffer(mediapipe::Packet* packet, const mediapipe::GpuBuffer** value_out) { return mp_Packet__Get(packet, value_out); } 60 | 61 | MpReturnCode mp_Packet__ValidateAsGpuBuffer(mediapipe::Packet* packet, absl::Status** status_out) { 62 | TRY 63 | *status_out = new absl::Status{packet->ValidateAsType()}; 64 | RETURN_CODE(MpReturnCode::Success); 65 | CATCH_EXCEPTION 66 | } 67 | -------------------------------------------------------------------------------- /mediapipe_api/gpu/gpu_buffer.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_GPU_GPU_BUFFER_H_ 8 | #define MEDIAPIPE_API_GPU_GPU_BUFFER_H_ 9 | 10 | #include 11 | 12 | #include "mediapipe/gpu/gpu_buffer.h" 13 | #include "mediapipe_api/common.h" 14 | #include "mediapipe_api/external/absl/status.h" 15 | #include "mediapipe_api/external/absl/statusor.h" 16 | #include "mediapipe_api/framework/packet.h" 17 | #include "mediapipe_api/gpu/gl_texture_buffer.h" 18 | 19 | extern "C" { 20 | 21 | typedef absl::StatusOr StatusOrGpuBuffer; 22 | 23 | MP_CAPI(void) mp_GpuBuffer__delete(mediapipe::GpuBuffer* gpu_buffer); 24 | 25 | #if MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER 26 | // TODO 27 | #else 28 | MP_CAPI(MpReturnCode) mp_GpuBuffer__PSgtb(SharedGlTextureBuffer* gl_texture_buffer, mediapipe::GpuBuffer** gpu_buffer_out); 29 | #endif // MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER 30 | 31 | MP_CAPI(int) mp_GpuBuffer__width(mediapipe::GpuBuffer* gpu_buffer); 32 | MP_CAPI(int) mp_GpuBuffer__height(mediapipe::GpuBuffer* gpu_buffer); 33 | MP_CAPI(mediapipe::GpuBufferFormat) mp_GpuBuffer__format(mediapipe::GpuBuffer* gpu_buffer); 34 | 35 | MP_CAPI(void) mp_StatusOrGpuBuffer__delete(StatusOrGpuBuffer* status_or_gpu_buffer); 36 | MP_CAPI(bool) mp_StatusOrGpuBuffer__ok(StatusOrGpuBuffer* status_or_gpu_buffer); 37 | MP_CAPI(MpReturnCode) mp_StatusOrGpuBuffer__status(StatusOrGpuBuffer* status_or_gpu_buffer, absl::Status** status_out); 38 | MP_CAPI(MpReturnCode) mp_StatusOrGpuBuffer__value(StatusOrGpuBuffer* status_or_gpu_buffer, mediapipe::GpuBuffer** value_out); 39 | 40 | MP_CAPI(MpReturnCode) mp__MakeGpuBufferPacket__Rgb(mediapipe::GpuBuffer* gpu_buffer, mediapipe::Packet** packet_out); 41 | MP_CAPI(MpReturnCode) mp__MakeGpuBufferPacket_At__Rgb_Rts(mediapipe::GpuBuffer* gpu_buffer, mediapipe::Timestamp* timestamp, mediapipe::Packet** packet_out); 42 | MP_CAPI(MpReturnCode) mp_Packet__ConsumeGpuBuffer(mediapipe::Packet* packet, StatusOrGpuBuffer** status_or_value_out); 43 | MP_CAPI(MpReturnCode) mp_Packet__GetGpuBuffer(mediapipe::Packet* packet, const mediapipe::GpuBuffer** value_out); 44 | MP_CAPI(MpReturnCode) mp_Packet__ValidateAsGpuBuffer(mediapipe::Packet* packet, absl::Status** status_out); 45 | 46 | } // extern "C" 47 | 48 | #endif // MEDIAPIPE_API_GPU_GPU_BUFFER_H_ 49 | -------------------------------------------------------------------------------- /mediapipe_api/gpu/gpu_buffer_format.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/gpu/gpu_buffer_format.h" 8 | 9 | mediapipe::ImageFormat::Format mp__ImageFormatForGpuBufferFormat__ui(mediapipe::GpuBufferFormat format) { 10 | return mediapipe::ImageFormatForGpuBufferFormat(format); 11 | } 12 | 13 | mediapipe::GpuBufferFormat mp__GpuBufferFormatForImageFormat__ui(mediapipe::ImageFormat::Format format) { 14 | return mediapipe::GpuBufferFormatForImageFormat(format); 15 | } 16 | 17 | MpReturnCode mp__GlTextureInfoForGpuBufferFormat__ui_i_ui(mediapipe::GpuBufferFormat format, int plane, mediapipe::GlVersion gl_version, 18 | mediapipe::GlTextureInfo* gl_texture_info_out) { 19 | TRY 20 | *gl_texture_info_out = mediapipe::GlTextureInfoForGpuBufferFormat(format, plane, gl_version); 21 | RETURN_CODE(MpReturnCode::Success); 22 | CATCH_EXCEPTION 23 | } 24 | -------------------------------------------------------------------------------- /mediapipe_api/gpu/gpu_buffer_format.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_GPU_GPU_BUFFER_FORMAT_H_ 8 | #define MEDIAPIPE_API_GPU_GPU_BUFFER_FORMAT_H_ 9 | 10 | #include "mediapipe/gpu/gpu_buffer_format.h" 11 | #include "mediapipe_api/common.h" 12 | 13 | extern "C" { 14 | 15 | MP_CAPI(mediapipe::ImageFormat::Format) mp__ImageFormatForGpuBufferFormat__ui(mediapipe::GpuBufferFormat format); 16 | MP_CAPI(mediapipe::GpuBufferFormat) mp__GpuBufferFormatForImageFormat__ui(mediapipe::ImageFormat::Format format); 17 | MP_CAPI(MpReturnCode) mp__GlTextureInfoForGpuBufferFormat__ui_i_ui(mediapipe::GpuBufferFormat format, int plane, mediapipe::GlVersion gl_version, 18 | mediapipe::GlTextureInfo* gl_texture_info_out); 19 | 20 | } // extern "C" 21 | 22 | #endif // MEDIAPIPE_API_GPU_GPU_BUFFER_FORMAT_H_ 23 | -------------------------------------------------------------------------------- /mediapipe_api/gpu/gpu_shared_data_internal.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/gpu/gpu_shared_data_internal.h" 8 | 9 | void mp_SharedGpuResources__delete(SharedGpuResources* gpu_resources) { delete gpu_resources; } 10 | 11 | mediapipe::GpuResources* mp_SharedGpuResources__get(SharedGpuResources* gpu_resources) { return gpu_resources->get(); } 12 | 13 | void mp_SharedGpuResources__reset(SharedGpuResources* gpu_resources) { gpu_resources->reset(); } 14 | 15 | MpReturnCode mp_GpuResources_Create(absl::StatusOr** status_or_gpu_resources_out) { 16 | TRY 17 | *status_or_gpu_resources_out = new absl::StatusOr{mediapipe::GpuResources::Create()}; 18 | RETURN_CODE(MpReturnCode::Success); 19 | CATCH_EXCEPTION 20 | } 21 | 22 | MP_CAPI(MpReturnCode) mp_GpuResources_Create__Pv(mediapipe::PlatformGlContext external_context, 23 | absl::StatusOr** status_or_gpu_resources_out) { 24 | TRY 25 | *status_or_gpu_resources_out = new absl::StatusOr{mediapipe::GpuResources::Create(external_context)}; 26 | RETURN_CODE(MpReturnCode::Success); 27 | CATCH_EXCEPTION 28 | } 29 | 30 | void mp_StatusOrGpuResources__delete(absl::StatusOr* status_or_gpu_resources) { delete status_or_gpu_resources; } 31 | 32 | bool mp_StatusOrGpuResources__ok(absl::StatusOr* status_or_gpu_resources) { return absl_StatusOr__ok(status_or_gpu_resources); } 33 | 34 | MpReturnCode mp_StatusOrGpuResources__status(absl::StatusOr* status_or_gpu_resources, absl::Status** status_out) { 35 | return absl_StatusOr__status(status_or_gpu_resources, status_out); 36 | } 37 | 38 | MpReturnCode mp_StatusOrGpuResources__value(absl::StatusOr* status_or_gpu_resources, SharedGpuResources** value_out) { 39 | return absl_StatusOr__value(status_or_gpu_resources, value_out); 40 | } 41 | -------------------------------------------------------------------------------- /mediapipe_api/gpu/gpu_shared_data_internal.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_GPU_GPU_SHARED_DATA_INTERNAL_H_ 8 | #define MEDIAPIPE_API_GPU_GPU_SHARED_DATA_INTERNAL_H_ 9 | 10 | #include 11 | #include 12 | 13 | #include "mediapipe/gpu/gpu_shared_data_internal.h" 14 | #include "mediapipe_api/common.h" 15 | #include "mediapipe_api/external/absl/statusor.h" 16 | 17 | extern "C" { 18 | 19 | typedef std::shared_ptr SharedGpuResources; 20 | 21 | MP_CAPI(void) mp_SharedGpuResources__delete(SharedGpuResources* gpu_resources); 22 | MP_CAPI(mediapipe::GpuResources*) mp_SharedGpuResources__get(SharedGpuResources* gpu_resources); 23 | MP_CAPI(void) mp_SharedGpuResources__reset(SharedGpuResources* gpu_resources); 24 | 25 | MP_CAPI(MpReturnCode) mp_GpuResources_Create(absl::StatusOr** status_or_gpu_resources_out); 26 | MP_CAPI(MpReturnCode) mp_GpuResources_Create__Pv(mediapipe::PlatformGlContext external_context, 27 | absl::StatusOr** status_or_gpu_resources_out); 28 | 29 | MP_CAPI(void) mp_StatusOrGpuResources__delete(absl::StatusOr* status_or_gpu_resources); 30 | MP_CAPI(bool) mp_StatusOrGpuResources__ok(absl::StatusOr* status_or_gpu_resources); 31 | MP_CAPI(MpReturnCode) mp_StatusOrGpuResources__status(absl::StatusOr* status_or_gpu_resources, absl::Status** status_out); 32 | MP_CAPI(MpReturnCode) mp_StatusOrGpuResources__value(absl::StatusOr* status_or_gpu_resources, SharedGpuResources** value_out); 33 | 34 | } // extern "C" 35 | 36 | #endif // MEDIAPIPE_API_GPU_GPU_SHARED_DATA_INTERNAL_H_ 37 | -------------------------------------------------------------------------------- /mediapipe_api/graphs/instant_motion_tracking/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 | genrule( 12 | name = "asset3d", 13 | srcs = ["@com_google_mediapipe//mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets:robot/robot.obj.uuu.zip"], 14 | outs = ["robot/robot.obj.uuu"], 15 | cmd = "unzip -p $< > $@", 16 | ) 17 | 18 | filegroup( 19 | name = "assets", 20 | srcs = [ 21 | ":asset3d", 22 | "@com_google_mediapipe//mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets:robot/robot_texture.jpg", 23 | ], 24 | ) 25 | -------------------------------------------------------------------------------- /mediapipe_api/graphs/instant_motion_tracking/calculators/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 | cc_library( 15 | name = "transformations", 16 | srcs = ["transformations.cc"], 17 | hdrs = ["transformations.h"], 18 | deps = [ 19 | "//mediapipe_api:common", 20 | "//mediapipe_api/external:protobuf", 21 | "//mediapipe_api/framework:packet", 22 | "@com_google_mediapipe//mediapipe/graphs/instant_motion_tracking/calculators:tracked_anchor_manager_calculator", 23 | ], 24 | alwayslink = True, 25 | ) 26 | 27 | pkg_files( 28 | name = "proto_srcs", 29 | srcs = [ 30 | ":sticker_buffer_cs", 31 | ], 32 | prefix = "Graphs/InstantMotionTracking/Calculators", 33 | ) 34 | 35 | csharp_proto_src( 36 | name = "sticker_buffer_cs", 37 | proto_src = "mediapipe/graphs/instant_motion_tracking/calculators/sticker_buffer.proto", 38 | deps = [ 39 | "@com_google_mediapipe//mediapipe/graphs/instant_motion_tracking/calculators:protos_src", 40 | ], 41 | ) 42 | -------------------------------------------------------------------------------- /mediapipe_api/graphs/instant_motion_tracking/calculators/transformations.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/graphs/instant_motion_tracking/calculators/transformations.h" 8 | 9 | #include 10 | 11 | MpReturnCode mp__MakeAnchor3dVectorPacket__PA_i(const mediapipe::Anchor3d* value, int size, mediapipe::Packet** packet_out) { 12 | TRY 13 | std::vector vector{}; 14 | for (auto i = 0; i < size; ++i) { 15 | vector.push_back(value[i]); 16 | } 17 | *packet_out = new mediapipe::Packet{mediapipe::MakePacket>(vector)}; 18 | RETURN_CODE(MpReturnCode::Success); 19 | CATCH_EXCEPTION 20 | } 21 | 22 | MpReturnCode mp__MakeAnchor3dVectorPacket_At__PA_i_Rt(const mediapipe::Anchor3d* value, int size, mediapipe::Timestamp* timestamp, 23 | mediapipe::Packet** packet_out) { 24 | TRY 25 | std::vector vector{}; 26 | for (auto i = 0; i < size; ++i) { 27 | vector.push_back(value[i]); 28 | } 29 | *packet_out = new mediapipe::Packet{mediapipe::MakePacket>(vector).At(*timestamp)}; 30 | RETURN_CODE(MpReturnCode::Success); 31 | CATCH_EXCEPTION 32 | } 33 | 34 | MpReturnCode mp_Packet__GetAnchor3dVector(mediapipe::Packet* packet, mp_api::StructArray* value_out) { 35 | return mp_Packet__GetStructVector(packet, value_out); 36 | } 37 | 38 | void mp_Anchor3dArray__delete(mediapipe::Anchor3d* anchor_vector_data) { delete[] anchor_vector_data; } 39 | -------------------------------------------------------------------------------- /mediapipe_api/graphs/instant_motion_tracking/calculators/transformations.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_GRAPHS_INSTANT_MOTION_TRACKING_CALCULATORS_TRANSFORMATIONS_H_ 8 | #define MEDIAPIPE_API_GRAPHS_INSTANT_MOTION_TRACKING_CALCULATORS_TRANSFORMATIONS_H_ 9 | 10 | #include "mediapipe/graphs/instant_motion_tracking/calculators/transformations.h" 11 | #include "mediapipe_api/common.h" 12 | #include "mediapipe_api/framework/packet.h" 13 | 14 | extern "C" { 15 | 16 | MP_CAPI(MpReturnCode) mp__MakeAnchor3dVectorPacket__PA_i(const mediapipe::Anchor3d* value, int size, mediapipe::Packet** packet_out); 17 | MP_CAPI(MpReturnCode) mp__MakeAnchor3dVectorPacket_At__PA_i_Rt(const mediapipe::Anchor3d* value, int size, mediapipe::Timestamp* timestamp, 18 | mediapipe::Packet** packet_out); 19 | MP_CAPI(MpReturnCode) mp_Packet__GetAnchor3dVector(mediapipe::Packet* packet, mp_api::StructArray* value_out); 20 | MP_CAPI(void) mp_Anchor3dArray__delete(mediapipe::Anchor3d* anchor_vector_data); 21 | 22 | } // extern "C" 23 | 24 | #endif // MEDIAPIPE_API_GRAPHS_INSTANT_MOTION_TRACKING_CALCULATORS_TRANSFORMATIONS_H_ 25 | -------------------------------------------------------------------------------- /mediapipe_api/graphs/instant_motion_tracking/subgraphs/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( 8 | "@com_google_mediapipe//mediapipe/framework/tool:mediapipe_graph.bzl", 9 | "mediapipe_simple_subgraph", 10 | ) 11 | 12 | package(default_visibility = ["//visibility:public"]) 13 | 14 | mediapipe_simple_subgraph( 15 | name = "region_tracking_cpu", 16 | graph = "region_tracking_cpu.pbtxt", 17 | register_as = "RegionTrackingSubgraphCpu", 18 | deps = [ 19 | "@com_google_mediapipe//mediapipe/graphs/instant_motion_tracking/calculators:tracked_anchor_manager_calculator", 20 | "@com_google_mediapipe//mediapipe/graphs/tracking/subgraphs:box_tracking_cpu", 21 | ], 22 | ) 23 | -------------------------------------------------------------------------------- /mediapipe_api/graphs/instant_motion_tracking/subgraphs/region_tracking_cpu.pbtxt: -------------------------------------------------------------------------------- 1 | # MediaPipe graph that performs region tracking on initial anchor positions 2 | # provided by the application 3 | 4 | # Images in/out of graph with tracked and scaled normalized anchor data 5 | type: "RegionTrackingSubgraphCpu" 6 | input_stream: "VIDEO:input_video" 7 | input_stream: "SENTINEL:sticker_sentinel" 8 | input_stream: "ANCHORS:initial_anchor_data" 9 | output_stream: "ANCHORS:tracked_scaled_anchor_data" 10 | 11 | # Manages the anchors and tracking if user changes/adds/deletes anchors 12 | node { 13 | calculator: "TrackedAnchorManagerCalculator" 14 | input_stream: "SENTINEL:sticker_sentinel" 15 | input_stream: "ANCHORS:initial_anchor_data" 16 | input_stream: "BOXES:boxes" 17 | input_stream_info: { 18 | tag_index: 'BOXES' 19 | back_edge: true 20 | } 21 | output_stream: "START_POS:start_pos" 22 | output_stream: "CANCEL_ID:cancel_object_id" 23 | output_stream: "ANCHORS:tracked_scaled_anchor_data" 24 | } 25 | 26 | # Subgraph performs anchor placement and tracking 27 | node { 28 | calculator: "BoxTrackingSubgraphCpu" 29 | input_stream: "VIDEO:input_video" 30 | input_stream: "BOXES:start_pos" 31 | input_stream: "CANCEL_ID:cancel_object_id" 32 | output_stream: "BOXES:boxes" 33 | } 34 | -------------------------------------------------------------------------------- /mediapipe_api/graphs/object_detection_3d/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("//mediapipe_api:import_model.bzl", "copy_file") 8 | 9 | package( 10 | default_visibility = ["//visibility:public"], 11 | ) 12 | 13 | copy_file( 14 | name = "camera_texture", 15 | src = "@com_google_mediapipe//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/camera:texture.jpg", 16 | out = "camera_texture.jpg", 17 | ) 18 | 19 | copy_file( 20 | name = "chair_texture", 21 | src = "@com_google_mediapipe//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair:texture.jpg", 22 | out = "chair_texture.jpg", 23 | ) 24 | 25 | copy_file( 26 | name = "cup_texture", 27 | src = "@com_google_mediapipe//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/cup:texture.jpg", 28 | out = "cup_texture.jpg", 29 | ) 30 | 31 | copy_file( 32 | name = "sneaker_texture", 33 | src = "@com_google_mediapipe//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker:texture.jpg", 34 | out = "sneaker_texture.jpg", 35 | ) 36 | 37 | copy_file( 38 | name = "camera_mesh", 39 | src = "@com_google_mediapipe//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/camera:model.obj.uuu", 40 | out = "camera.obj.uuu", 41 | ) 42 | 43 | copy_file( 44 | name = "chair_mesh", 45 | src = "@com_google_mediapipe//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair:model.obj.uuu", 46 | out = "chair.obj.uuu", 47 | ) 48 | 49 | copy_file( 50 | name = "cup_mesh", 51 | src = "@com_google_mediapipe//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/cup:model.obj.uuu", 52 | out = "cup.obj.uuu", 53 | ) 54 | 55 | copy_file( 56 | name = "sneaker_mesh", 57 | src = "@com_google_mediapipe//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker:model.obj.uuu", 58 | out = "sneaker.obj.uuu", 59 | ) 60 | 61 | filegroup( 62 | name = "assets", 63 | srcs = [ 64 | ":camera_mesh", 65 | ":camera_texture", 66 | ":chair_mesh", 67 | ":chair_texture", 68 | ":cup_mesh", 69 | ":cup_texture", 70 | ":sneaker_mesh", 71 | ":sneaker_texture", 72 | "@com_google_mediapipe//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets:box.obj.uuu", 73 | "@com_google_mediapipe//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets:classic_colors.png", 74 | ], 75 | ) 76 | -------------------------------------------------------------------------------- /mediapipe_api/graphs/object_detection_3d/calculators/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 | cc_library( 15 | name = "model_matrix", 16 | srcs = ["model_matrix.cc"], 17 | hdrs = ["model_matrix.h"], 18 | deps = [ 19 | "//mediapipe_api:common", 20 | "//mediapipe_api/external:protobuf", 21 | "//mediapipe_api/framework:packet", 22 | "@com_google_mediapipe//mediapipe/graphs/object_detection_3d/calculators:model_matrix_cc_proto", 23 | ], 24 | alwayslink = True, 25 | ) 26 | 27 | pkg_files( 28 | name = "proto_srcs", 29 | srcs = [ 30 | ":model_matrix_cs", 31 | ], 32 | prefix = "Graphs/ObjectDetection3d/Calculators", 33 | ) 34 | 35 | csharp_proto_src( 36 | name = "model_matrix_cs", 37 | proto_src = "mediapipe/graphs/object_detection_3d/calculators/model_matrix.proto", 38 | deps = [ 39 | "@com_google_mediapipe//mediapipe/graphs/object_detection_3d/calculators:protos_src", 40 | ], 41 | ) 42 | -------------------------------------------------------------------------------- /mediapipe_api/graphs/object_detection_3d/calculators/model_matrix.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/graphs/object_detection_3d/calculators/model_matrix.h" 8 | 9 | MpReturnCode mp_Packet__GetTimedModelMatrixProtoList(mediapipe::Packet* packet, mp_api::SerializedProto* value_out) { 10 | return mp_Packet__GetSerializedProto(packet, value_out); 11 | } 12 | -------------------------------------------------------------------------------- /mediapipe_api/graphs/object_detection_3d/calculators/model_matrix.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_GRAPHS_OBJECT_DETECTION_3D_CALCULATORS_MODEL_MATRIX_H_ 8 | #define MEDIAPIPE_API_GRAPHS_OBJECT_DETECTION_3D_CALCULATORS_MODEL_MATRIX_H_ 9 | 10 | #include "mediapipe/graphs/object_detection_3d/calculators/model_matrix.pb.h" 11 | #include "mediapipe_api/common.h" 12 | #include "mediapipe_api/external/protobuf.h" 13 | #include "mediapipe_api/framework/packet.h" 14 | 15 | extern "C" { 16 | 17 | MP_CAPI(MpReturnCode) mp_Packet__GetTimedModelMatrixProtoList(mediapipe::Packet* packet, mp_api::SerializedProto* value_out); 18 | 19 | } // extern "C" 20 | 21 | #endif // MEDIAPIPE_API_GRAPHS_OBJECT_DETECTION_3D_CALCULATORS_MODEL_MATRIX_H_ 22 | -------------------------------------------------------------------------------- /mediapipe_api/import_model.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 | """Asset Packager 8 | 9 | Macros to zip dependent assets (e.g. *.tflite) in a format compatible with Unity. 10 | """ 11 | 12 | load("@rules_pkg//:pkg.bzl", "pkg_zip") 13 | 14 | def copy_file(name, src, out): 15 | native.genrule( 16 | name = name, 17 | srcs = [src], 18 | outs = [out], 19 | cmd = "cp $< $@", 20 | ) 21 | 22 | def pkg_asset(name, srcs = [], **kwargs): 23 | """Package MediaPipe assets 24 | 25 | This task renames asset files so that they can be added to an AssetBundle (e.g. x.tflte -> x.bytes) and zip them. 26 | 27 | Args: 28 | name: the name of the output zip file 29 | srcs: files to be packaged 30 | **kwargs: other arguments for pkg_zip 31 | """ 32 | 33 | rename_target = "normalize_%s_exts" % name 34 | _normalize_exts(name = rename_target, srcs = srcs) 35 | 36 | pkg_zip( 37 | name = name, 38 | srcs = [":" + rename_target], 39 | **kwargs 40 | ) 41 | 42 | def _normalize_exts_impl(ctx): 43 | output_files = [] 44 | 45 | for src in ctx.files.srcs: 46 | ext = "bytes" if src.extension in ctx.attr.bytes_exts else ("txt" if src.extension in ctx.attr.txt_exts else src.extension) 47 | 48 | if ext == src.extension: 49 | output_files.append(src) 50 | else: 51 | dest = ctx.actions.declare_file(src.path[:-1 * len(src.extension)] + ext) 52 | ctx.actions.run_shell( 53 | inputs = [src], 54 | outputs = [dest], 55 | arguments = [src.path, dest.path], 56 | command = "test $1 != $2 && cp $1 $2", 57 | progress_message = "Copying {} to {}...".format(src.path, dest.path), 58 | ) 59 | output_files.append(dest) 60 | 61 | return [ 62 | DefaultInfo(files = depset(output_files)), 63 | ] 64 | 65 | _normalize_exts = rule( 66 | implementation = _normalize_exts_impl, 67 | attrs = { 68 | "srcs": attr.label_list(allow_files = True), 69 | "bytes_exts": attr.string_list(default = ["binarypb", "jpg", "png", "tflite", "uuu"]), 70 | "txt_exts": attr.string_list(default = ["pbtxt"]), 71 | }, 72 | ) 73 | -------------------------------------------------------------------------------- /mediapipe_api/java/com/github/homuler/mediapipe/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("//mediapipe_api/java/com/google/mediapipe:mediapipe_aar.bzl", "mediapipe_aar") 8 | 9 | # A sample aar to extend UnityPlayerActivity 10 | mediapipe_aar( 11 | name = "mediapipe_android", 12 | srcs = [], 13 | assets = [ 14 | # If preferable, model files can be included to aar 15 | ], 16 | jni_deps = [ 17 | "//mediapipe_api:mediapipe_c", 18 | ], 19 | deps = [ 20 | "@opencv", 21 | ], 22 | ) 23 | -------------------------------------------------------------------------------- /mediapipe_api/java/com/github/homuler/mediapipe/MediaPipeUnityPlayerActivity.java: -------------------------------------------------------------------------------- 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 com.github.homuler.mediapipe; 8 | 9 | import android.os.Bundle; 10 | import android.util.Log; 11 | import com.google.mediapipe.framework.AndroidAssetUtil; 12 | import com.unity3d.player.UnityPlayerActivity; 13 | 14 | public class MediaPipeUnityPlayerActivity extends UnityPlayerActivity { 15 | static { 16 | // Load all native libraries needed by the app. 17 | System.loadLibrary("mediapipe_jni"); 18 | } 19 | 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | 23 | // Initialize asset manager so that MediaPipe native libraries can access the 24 | // app assets, e.g., binary graphs. 25 | boolean res = AndroidAssetUtil.initializeNativeAssetManager(this); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mediapipe_api/java/com/google/mediapipe/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 | licenses(["notice"]) 8 | -------------------------------------------------------------------------------- /mediapipe_api/java/com/google/mediapipe/mediapipe_aar.bzl: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019 Adam Michael 2 | # Copyright (c) 2021 homuler 3 | # 4 | # Use of this source code is governed by an MIT-style 5 | # license that can be found in the LICENSE file or at 6 | # https://opensource.org/licenses/MIT. 7 | 8 | # Based on https://github.com/aj-michael/aar_with_jni/blob/b284343108b1e4cbfdbbf155bbcfa0b06e878f79/aar_with_jni.bzl 9 | 10 | """AAR Generator 11 | 12 | Macro to generate AAR, including libmediapipe_jni.so 13 | """ 14 | 15 | load("@build_bazel_rules_android//android:rules.bzl", "android_binary", "android_library") 16 | 17 | def mediapipe_aar(name, package = "com.github.homuler.mediapipe", srcs = [], deps = [], jni_deps = [], assets = [], assets_dir = "", target_sdk_version = 27, min_sdk_version = 21): 18 | """Generate MediaPipeUnityPlugin AAR. 19 | 20 | Args: 21 | package: package name 22 | name: the name of the AAR 23 | srcs: java source files 24 | deps: aar's dependencies (e.g. .so files) 25 | jni_deps: additional dependencies that will be linked to libmediapipe_jni.so 26 | assets: additional assets to be included into the archive. 27 | assets_dir: path where the assets will the packaged 28 | target_sdk_version: AAR's target SDK version 29 | min_sdk_version: AAR's min SDK version 30 | """ 31 | native.cc_binary( 32 | name = "libmediapipe_jni.so", 33 | linkshared = 1, 34 | linkstatic = 1, 35 | deps = jni_deps, 36 | ) 37 | 38 | native.cc_library( 39 | name = name + "_mediapipe_jni_lib", 40 | srcs = [":libmediapipe_jni.so"], 41 | alwayslink = 1, 42 | ) 43 | 44 | native.genrule( 45 | name = name + "_aar_manifest_generator", 46 | outs = ["AndroidManifest.xml"], 47 | cmd = """ 48 | cat > $(OUTS) < 50 | 52 | 55 | 56 | 57 | EOF 58 | """.format(package, min_sdk_version, target_sdk_version), 59 | ) 60 | 61 | android_library( 62 | name = name + "_android_lib", 63 | srcs = srcs, 64 | manifest = "AndroidManifest.xml", 65 | deps = [ 66 | ":" + name + "_mediapipe_jni_lib", 67 | ] + deps, 68 | assets = assets, 69 | assets_dir = assets_dir, 70 | ) 71 | 72 | _aar_with_jni(name, name + "_android_lib") 73 | 74 | def _aar_with_jni(name, android_library): 75 | # Generate dummy AndroidManifest.xml for dummy apk usage 76 | # (dummy apk is generated by _dummy_app target below) 77 | native.genrule( 78 | name = name + "_binary_manifest_generator", 79 | outs = [name + "_generated_AndroidManifest.xml"], 80 | cmd = """ 81 | cat > $(OUTS) < 85 | 86 | 87 | EOF 88 | """, 89 | ) 90 | 91 | # Generate dummy apk including .so files. 92 | # We extract out .so files and throw away the apk. 93 | android_binary( 94 | name = name + "_dummy_app", 95 | manifest = name + "_generated_AndroidManifest.xml", 96 | custom_package = "dummy.package.for.so", 97 | deps = [android_library], 98 | ) 99 | 100 | native.genrule( 101 | name = name, 102 | srcs = [android_library + ".aar", name + "_dummy_app_unsigned.apk"], 103 | outs = [name + ".aar"], 104 | tags = ["manual"], 105 | cmd = """ 106 | cp $(location {}.aar) $(location :{}.aar) 107 | chmod +w $(location :{}.aar) 108 | origdir=$$PWD 109 | cd $$(mktemp -d) 110 | unzip $$origdir/$(location :{}_dummy_app_unsigned.apk) "lib/**" 111 | cp -r lib jni 112 | zip -r $$origdir/$(location :{}.aar) jni/*/*.so 113 | """.format(android_library, name, name, name, name), 114 | ) 115 | -------------------------------------------------------------------------------- /mediapipe_api/modules/face_detection/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 | ":face_detection_cs", 16 | ], 17 | prefix = "Modules/FaceDetection", 18 | ) 19 | 20 | csharp_proto_src( 21 | name = "face_detection_cs", 22 | proto_src = "mediapipe/modules/face_detection/face_detection.proto", 23 | deps = [ 24 | "@com_google_mediapipe//mediapipe/modules/face_detection:protos_src", 25 | "@com_google_mediapipe//mediapipe/calculators/tensor:protos_src", 26 | "@com_google_mediapipe//mediapipe/framework:protos_src", 27 | "@com_google_mediapipe//mediapipe/gpu:protos_src", 28 | ], 29 | ) 30 | -------------------------------------------------------------------------------- /mediapipe_api/modules/face_geometry/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 | ":effect_renderer_calculator_cs", 16 | ":env_generator_calculator_cs", 17 | ":geometry_pipeline_calculator_cs", 18 | ], 19 | prefix = "Modules/FaceGeometry", 20 | ) 21 | 22 | csharp_proto_src( 23 | name = "effect_renderer_calculator_cs", 24 | proto_src = "mediapipe/modules/face_geometry/effect_renderer_calculator.proto", 25 | deps = [ 26 | "@com_google_mediapipe//mediapipe/modules/face_geometry:protos_src", 27 | "@com_google_mediapipe//mediapipe/framework:protos_src", 28 | ], 29 | ) 30 | 31 | csharp_proto_src( 32 | name = "env_generator_calculator_cs", 33 | proto_src = "mediapipe/modules/face_geometry/env_generator_calculator.proto", 34 | deps = [ 35 | "@com_google_mediapipe//mediapipe/modules/face_geometry:protos_src", 36 | "@com_google_mediapipe//mediapipe/modules/face_geometry/protos:protos_src", 37 | "@com_google_mediapipe//mediapipe/framework:protos_src", 38 | ], 39 | ) 40 | 41 | csharp_proto_src( 42 | name = "geometry_pipeline_calculator_cs", 43 | proto_src = "mediapipe/modules/face_geometry/geometry_pipeline_calculator.proto", 44 | deps = [ 45 | "@com_google_mediapipe//mediapipe/modules/face_geometry:protos_src", 46 | "@com_google_mediapipe//mediapipe/framework:protos_src", 47 | ], 48 | ) 49 | 50 | -------------------------------------------------------------------------------- /mediapipe_api/modules/face_geometry/protos/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 | cc_library( 13 | name = "face_geometry", 14 | srcs = ["face_geometry.cc"], 15 | hdrs = ["face_geometry.h"], 16 | deps = [ 17 | "//mediapipe_api:common", 18 | "//mediapipe_api/external:protobuf", 19 | "//mediapipe_api/framework:packet", 20 | "@com_google_mediapipe//mediapipe/modules/face_geometry/protos:face_geometry_cc_proto", 21 | ], 22 | alwayslink = True, 23 | ) 24 | 25 | pkg_files( 26 | name = "proto_srcs", 27 | srcs = [ 28 | ":environment_cs", 29 | ":face_geometry_cs", 30 | ":geometry_pipeline_metadata_cs", 31 | ":mesh_3d_cs", 32 | ], 33 | prefix = "Modules/FaceGeometry/Protos", 34 | ) 35 | 36 | csharp_proto_src( 37 | name = "environment_cs", 38 | proto_src = "mediapipe/modules/face_geometry/protos/environment.proto", 39 | deps = [ 40 | "@com_google_mediapipe//mediapipe/modules/face_geometry/protos:protos_src", 41 | ], 42 | ) 43 | 44 | csharp_proto_src( 45 | name = "face_geometry_cs", 46 | proto_src = "mediapipe/modules/face_geometry/protos/face_geometry.proto", 47 | deps = [ 48 | "@com_google_mediapipe//mediapipe/framework/formats:protos_src", 49 | "@com_google_mediapipe//mediapipe/modules/face_geometry/protos:protos_src", 50 | ], 51 | ) 52 | 53 | csharp_proto_src( 54 | name = "geometry_pipeline_metadata_cs", 55 | proto_src = "mediapipe/modules/face_geometry/protos/geometry_pipeline_metadata.proto", 56 | deps = [ 57 | "@com_google_mediapipe//mediapipe/modules/face_geometry/protos:protos_src", 58 | ], 59 | ) 60 | 61 | csharp_proto_src( 62 | name = "mesh_3d_cs", 63 | proto_src = "mediapipe/modules/face_geometry/protos/mesh_3d.proto", 64 | deps = [ 65 | "@com_google_mediapipe//mediapipe/modules/face_geometry/protos:protos_src", 66 | ], 67 | ) 68 | -------------------------------------------------------------------------------- /mediapipe_api/modules/face_geometry/protos/face_geometry.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/modules/face_geometry/protos/face_geometry.h" 8 | 9 | MpReturnCode mp_Packet__GetFaceGeometry(mediapipe::Packet* packet, mp_api::SerializedProto* value_out) { 10 | return mp_Packet__GetSerializedProto(packet, value_out); 11 | } 12 | 13 | MpReturnCode mp_Packet__GetFaceGeometryVector(mediapipe::Packet* packet, mp_api::StructArray* value_out) { 14 | return mp_Packet__GetSerializedProtoVector(packet, value_out); 15 | } 16 | -------------------------------------------------------------------------------- /mediapipe_api/modules/face_geometry/protos/face_geometry.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_MODULES_FACE_GEOMETRY_PROTOS_FACE_GEOMETRY_H_ 8 | #define MEDIAPIPE_API_MODULES_FACE_GEOMETRY_PROTOS_FACE_GEOMETRY_H_ 9 | 10 | #include "mediapipe/modules/face_geometry/protos/face_geometry.pb.h" 11 | #include "mediapipe_api/common.h" 12 | #include "mediapipe_api/external/protobuf.h" 13 | #include "mediapipe_api/framework/packet.h" 14 | 15 | extern "C" { 16 | 17 | MP_CAPI(MpReturnCode) mp_Packet__GetFaceGeometry(mediapipe::Packet* packet, mp_api::SerializedProto* value_out); 18 | MP_CAPI(MpReturnCode) mp_Packet__GetFaceGeometryVector(mediapipe::Packet* packet, mp_api::StructArray* value_out); 19 | 20 | } // extern "C" 21 | 22 | #endif // MEDIAPIPE_API_MODULES_FACE_GEOMETRY_PROTOS_FACE_GEOMETRY_H_ 23 | -------------------------------------------------------------------------------- /mediapipe_api/modules/holistic_landmark/calculators/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 | ":roi_tracking_calculator_cs", 16 | ], 17 | prefix = "Modules/HolisticLandmark/Calculators", 18 | ) 19 | 20 | csharp_proto_src( 21 | name = "roi_tracking_calculator_cs", 22 | proto_src = "mediapipe/modules/holistic_landmark/calculators/roi_tracking_calculator.proto", 23 | deps = [ 24 | "@com_google_mediapipe//mediapipe/modules/holistic_landmark/calculators:protos_src", 25 | "@com_google_mediapipe//mediapipe/framework:protos_src", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /mediapipe_api/modules/iris_landmark/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( 8 | "@com_google_mediapipe//mediapipe/framework/tool:mediapipe_graph.bzl", 9 | "mediapipe_simple_subgraph", 10 | ) 11 | 12 | package(default_visibility = ["//visibility:public"]) 13 | 14 | mediapipe_simple_subgraph( 15 | name = "iris_landmarks_from_face_landmarks_gpu", 16 | graph = "iris_landmarks_from_face_landmarks_gpu.pbtxt", 17 | register_as = "IrisLandmarksFromFaceLandmarksGpu", 18 | deps = [ 19 | "@com_google_mediapipe//mediapipe/calculators/core:concatenate_proto_list_calculator", 20 | "@com_google_mediapipe//mediapipe/calculators/core:split_proto_list_calculator", 21 | "@com_google_mediapipe//mediapipe/graphs/iris_tracking/calculators:update_face_landmarks_calculator", 22 | "@com_google_mediapipe//mediapipe/modules/iris_landmark:iris_landmark_left_and_right_gpu", 23 | ], 24 | ) 25 | 26 | mediapipe_simple_subgraph( 27 | name = "iris_landmarks_from_face_landmarks_cpu", 28 | graph = "iris_landmarks_from_face_landmarks_cpu.pbtxt", 29 | register_as = "IrisLandmarksFromFaceLandmarksCpu", 30 | deps = [ 31 | "@com_google_mediapipe//mediapipe/calculators/core:concatenate_proto_list_calculator", 32 | "@com_google_mediapipe//mediapipe/calculators/core:split_proto_list_calculator", 33 | "@com_google_mediapipe//mediapipe/graphs/iris_tracking/calculators:update_face_landmarks_calculator", 34 | "@com_google_mediapipe//mediapipe/modules/iris_landmark:iris_landmark_left_and_right_cpu", 35 | ], 36 | ) 37 | -------------------------------------------------------------------------------- /mediapipe_api/modules/iris_landmark/iris_landmarks_from_face_landmarks_cpu.pbtxt: -------------------------------------------------------------------------------- 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 | # Detects iris landmarks, eye contour landmarks, and corresponding rect (ROI) from face landmarks. 8 | 9 | type: "IrisLandmarkLeftAndRightFromFaceLandmarksCpu" 10 | 11 | # CPU image. (ImageFrame) 12 | input_stream: "IMAGE:image" 13 | # Face landmarks. (NormalizedLandmarkList) 14 | input_stream: "FACE_LANDMARKS:face_landmarks" 15 | 16 | # Refined face landmarks. (NormalizedLandmarkList) 17 | output_stream: "UPDATED_FACE_LANDMARKS:refined_face_landmarks" 18 | 19 | # 71 normalized eye contour landmarks. (NormalizedLandmarkList) 20 | output_stream: "LEFT_EYE_CONTOUR_LANDMARKS:left_eye_contour_landmarks" 21 | # 5 normalized iris landmarks. (NormalizedLandmarkList) 22 | output_stream: "LEFT_EYE_IRIS_LANDMARKS:left_iris_landmarks" 23 | # Region of interest used to do calculations for the left eye. (NormalizedRect) 24 | output_stream: "LEFT_EYE_ROI:left_eye_rect_from_landmarks" 25 | 26 | # 71 normalized eye contour landmarks. (NormalizedLandmarkList) 27 | output_stream: "RIGHT_EYE_CONTOUR_LANDMARKS:right_eye_contour_landmarks" 28 | # 5 normalized iris landmarks. (NormalizedLandmarkList) 29 | output_stream: "RIGHT_EYE_IRIS_LANDMARKS:right_iris_landmarks" 30 | # Region of interest used to do calculations for the right eye. (NormalizedRect) 31 | output_stream: "RIGHT_EYE_ROI:right_eye_rect_from_landmarks" 32 | 33 | 34 | # Gets two landmarks which define left eye boundary. 35 | node { 36 | calculator: "SplitNormalizedLandmarkListCalculator" 37 | input_stream: "face_landmarks" 38 | output_stream: "left_eye_boundary_landmarks" 39 | node_options: { 40 | [type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] { 41 | ranges: { begin: 33 end: 34 } 42 | ranges: { begin: 133 end: 134 } 43 | combine_outputs: true 44 | } 45 | } 46 | } 47 | 48 | # Gets two landmarks which define right eye boundary. 49 | node { 50 | calculator: "SplitNormalizedLandmarkListCalculator" 51 | input_stream: "face_landmarks" 52 | output_stream: "right_eye_boundary_landmarks" 53 | node_options: { 54 | [type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] { 55 | ranges: { begin: 362 end: 363 } 56 | ranges: { begin: 263 end: 264 } 57 | combine_outputs: true 58 | } 59 | } 60 | } 61 | 62 | # Detects iris landmarks, eye contour landmarks, and corresponding rect (ROI). 63 | node { 64 | calculator: "IrisLandmarkLeftAndRightCpu" 65 | input_stream: "IMAGE:image" 66 | input_stream: "LEFT_EYE_BOUNDARY_LANDMARKS:left_eye_boundary_landmarks" 67 | input_stream: "RIGHT_EYE_BOUNDARY_LANDMARKS:right_eye_boundary_landmarks" 68 | output_stream: "LEFT_EYE_CONTOUR_LANDMARKS:left_eye_contour_landmarks" 69 | output_stream: "LEFT_EYE_IRIS_LANDMARKS:left_iris_landmarks" 70 | output_stream: "LEFT_EYE_ROI:left_eye_rect_from_landmarks" 71 | output_stream: "RIGHT_EYE_CONTOUR_LANDMARKS:right_eye_contour_landmarks" 72 | output_stream: "RIGHT_EYE_IRIS_LANDMARKS:right_iris_landmarks" 73 | output_stream: "RIGHT_EYE_ROI:right_eye_rect_from_landmarks" 74 | } 75 | 76 | node { 77 | calculator: "ConcatenateNormalizedLandmarkListCalculator" 78 | input_stream: "left_eye_contour_landmarks" 79 | input_stream: "right_eye_contour_landmarks" 80 | output_stream: "refined_eye_landmarks" 81 | } 82 | 83 | node { 84 | calculator: "UpdateFaceLandmarksCalculator" 85 | input_stream: "NEW_EYE_LANDMARKS:refined_eye_landmarks" 86 | input_stream: "FACE_LANDMARKS:face_landmarks" 87 | output_stream: "UPDATED_FACE_LANDMARKS:refined_face_landmarks" 88 | } 89 | -------------------------------------------------------------------------------- /mediapipe_api/modules/iris_landmark/iris_landmarks_from_face_landmarks_gpu.pbtxt: -------------------------------------------------------------------------------- 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 | # Detects iris landmarks, eye contour landmarks, and corresponding rect (ROI) from face landmarks. 8 | 9 | type: "IrisLandmarksFromFaceLandmarksGpu" 10 | 11 | # GPU image. (GpuBuffer) 12 | input_stream: "IMAGE:image" 13 | # Face landmarks. (NormalizedLandmarkList) 14 | input_stream: "FACE_LANDMARKS:face_landmarks" 15 | 16 | # Refined face landmarks. (NormalizedLandmarkList) 17 | output_stream: "UPDATED_FACE_LANDMARKS:refined_face_landmarks" 18 | 19 | # 71 normalized eye contour landmarks. (NormalizedLandmarkList) 20 | output_stream: "LEFT_EYE_CONTOUR_LANDMARKS:left_eye_contour_landmarks" 21 | # 5 normalized iris landmarks. (NormalizedLandmarkList) 22 | output_stream: "LEFT_EYE_IRIS_LANDMARKS:left_iris_landmarks" 23 | # Region of interest used to do calculations for the left eye. (NormalizedRect) 24 | output_stream: "LEFT_EYE_ROI:left_eye_rect_from_landmarks" 25 | 26 | # 71 normalized eye contour landmarks. (NormalizedLandmarkList) 27 | output_stream: "RIGHT_EYE_CONTOUR_LANDMARKS:right_eye_contour_landmarks" 28 | # 5 normalized iris landmarks. (NormalizedLandmarkList) 29 | output_stream: "RIGHT_EYE_IRIS_LANDMARKS:right_iris_landmarks" 30 | # Region of interest used to do calculations for the right eye. (NormalizedRect) 31 | output_stream: "RIGHT_EYE_ROI:right_eye_rect_from_landmarks" 32 | 33 | # Gets two landmarks which define left eye boundary. 34 | node { 35 | calculator: "SplitNormalizedLandmarkListCalculator" 36 | input_stream: "face_landmarks" 37 | output_stream: "left_eye_boundary_landmarks" 38 | node_options: { 39 | [type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] { 40 | ranges: { begin: 33 end: 34 } 41 | ranges: { begin: 133 end: 134 } 42 | combine_outputs: true 43 | } 44 | } 45 | } 46 | 47 | # Gets two landmarks which define right eye boundary. 48 | node { 49 | calculator: "SplitNormalizedLandmarkListCalculator" 50 | input_stream: "face_landmarks" 51 | output_stream: "right_eye_boundary_landmarks" 52 | node_options: { 53 | [type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] { 54 | ranges: { begin: 362 end: 363 } 55 | ranges: { begin: 263 end: 264 } 56 | combine_outputs: true 57 | } 58 | } 59 | } 60 | 61 | # Detects iris landmarks, eye contour landmarks, and corresponding rect (ROI). 62 | node { 63 | calculator: "IrisLandmarkLeftAndRightGpu" 64 | input_stream: "IMAGE:image" 65 | input_stream: "LEFT_EYE_BOUNDARY_LANDMARKS:left_eye_boundary_landmarks" 66 | input_stream: "RIGHT_EYE_BOUNDARY_LANDMARKS:right_eye_boundary_landmarks" 67 | output_stream: "LEFT_EYE_CONTOUR_LANDMARKS:left_eye_contour_landmarks" 68 | output_stream: "LEFT_EYE_IRIS_LANDMARKS:left_iris_landmarks" 69 | output_stream: "LEFT_EYE_ROI:left_eye_rect_from_landmarks" 70 | output_stream: "RIGHT_EYE_CONTOUR_LANDMARKS:right_eye_contour_landmarks" 71 | output_stream: "RIGHT_EYE_IRIS_LANDMARKS:right_iris_landmarks" 72 | output_stream: "RIGHT_EYE_ROI:right_eye_rect_from_landmarks" 73 | } 74 | 75 | node { 76 | calculator: "ConcatenateNormalizedLandmarkListCalculator" 77 | input_stream: "left_eye_contour_landmarks" 78 | input_stream: "right_eye_contour_landmarks" 79 | output_stream: "refined_eye_landmarks" 80 | } 81 | 82 | node { 83 | calculator: "UpdateFaceLandmarksCalculator" 84 | input_stream: "NEW_EYE_LANDMARKS:refined_eye_landmarks" 85 | input_stream: "FACE_LANDMARKS:face_landmarks" 86 | output_stream: "UPDATED_FACE_LANDMARKS:refined_face_landmarks" 87 | } 88 | -------------------------------------------------------------------------------- /mediapipe_api/modules/objectron/calculators/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 | cc_library( 13 | name = "annotation", 14 | srcs = ["annotation_data.cc"], 15 | hdrs = ["annotation_data.h"], 16 | deps = [ 17 | "//mediapipe_api:common", 18 | "//mediapipe_api/external:protobuf", 19 | "//mediapipe_api/framework:packet", 20 | "@com_google_mediapipe//mediapipe/modules/objectron/calculators:annotation_cc_proto", 21 | ], 22 | alwayslink = True, 23 | ) 24 | 25 | pkg_files( 26 | name = "proto_srcs", 27 | srcs = [ 28 | ":object_cs", 29 | ":a_r_capture_metadata_cs", 30 | ":annotation_data_cs", 31 | ":camera_parameters_cs", 32 | ":frame_annotation_tracker_calculator_cs", 33 | ":belief_decoder_config_cs", 34 | ":tflite_tensors_to_objects_calculator_cs", 35 | ":tensors_to_objects_calculator_cs", 36 | ":lift_2d_frame_annotation_to_3d_calculator_cs", 37 | ":frame_annotation_to_rect_calculator_cs", 38 | ":filter_detection_calculator_cs", 39 | ], 40 | prefix = "Modules/Objectron/Calculators", 41 | ) 42 | 43 | 44 | csharp_proto_src( 45 | name = "object_cs", 46 | proto_src = "mediapipe/modules/objectron/calculators/object.proto", 47 | deps = [ 48 | "@com_google_mediapipe//mediapipe/modules/objectron/calculators:protos_src", 49 | ], 50 | ) 51 | 52 | csharp_proto_src( 53 | name = "a_r_capture_metadata_cs", 54 | proto_src = "mediapipe/modules/objectron/calculators/a_r_capture_metadata.proto", 55 | deps = [ 56 | "@com_google_mediapipe//mediapipe/modules/objectron/calculators:protos_src", 57 | ], 58 | ) 59 | 60 | csharp_proto_src( 61 | name = "annotation_data_cs", 62 | proto_src = "mediapipe/modules/objectron/calculators/annotation_data.proto", 63 | deps = [ 64 | "@com_google_mediapipe//mediapipe/modules/objectron/calculators:protos_src", 65 | ], 66 | ) 67 | 68 | csharp_proto_src( 69 | name = "camera_parameters_cs", 70 | proto_src = "mediapipe/modules/objectron/calculators/camera_parameters.proto", 71 | deps = [ 72 | "@com_google_mediapipe//mediapipe/modules/objectron/calculators:protos_src", 73 | ], 74 | ) 75 | 76 | csharp_proto_src( 77 | name = "frame_annotation_tracker_calculator_cs", 78 | proto_src = "mediapipe/modules/objectron/calculators/frame_annotation_tracker_calculator.proto", 79 | deps = [ 80 | "@com_google_mediapipe//mediapipe/modules/objectron/calculators:protos_src", 81 | "@com_google_mediapipe//mediapipe/framework:protos_src", 82 | ], 83 | ) 84 | 85 | csharp_proto_src( 86 | name = "belief_decoder_config_cs", 87 | proto_src = "mediapipe/modules/objectron/calculators/belief_decoder_config.proto", 88 | deps = [ 89 | "@com_google_mediapipe//mediapipe/modules/objectron/calculators:protos_src", 90 | ], 91 | ) 92 | 93 | csharp_proto_src( 94 | name = "tflite_tensors_to_objects_calculator_cs", 95 | proto_src = "mediapipe/modules/objectron/calculators/tflite_tensors_to_objects_calculator.proto", 96 | deps = [ 97 | "@com_google_mediapipe//mediapipe/modules/objectron/calculators:protos_src", 98 | "@com_google_mediapipe//mediapipe/framework:protos_src", 99 | ], 100 | ) 101 | 102 | csharp_proto_src( 103 | name = "tensors_to_objects_calculator_cs", 104 | proto_src = "mediapipe/modules/objectron/calculators/tensors_to_objects_calculator.proto", 105 | deps = [ 106 | "@com_google_mediapipe//mediapipe/modules/objectron/calculators:protos_src", 107 | "@com_google_mediapipe//mediapipe/framework:protos_src", 108 | ], 109 | ) 110 | 111 | csharp_proto_src( 112 | name = "lift_2d_frame_annotation_to_3d_calculator_cs", 113 | proto_src = "mediapipe/modules/objectron/calculators/lift_2d_frame_annotation_to_3d_calculator.proto", 114 | deps = [ 115 | "@com_google_mediapipe//mediapipe/modules/objectron/calculators:protos_src", 116 | "@com_google_mediapipe//mediapipe/framework:protos_src", 117 | ], 118 | ) 119 | 120 | csharp_proto_src( 121 | name = "frame_annotation_to_rect_calculator_cs", 122 | proto_src = "mediapipe/modules/objectron/calculators/frame_annotation_to_rect_calculator.proto", 123 | deps = [ 124 | "@com_google_mediapipe//mediapipe/modules/objectron/calculators:protos_src", 125 | "@com_google_mediapipe//mediapipe/framework:protos_src", 126 | ], 127 | ) 128 | 129 | csharp_proto_src( 130 | name = "filter_detection_calculator_cs", 131 | proto_src = "mediapipe/modules/objectron/calculators/filter_detection_calculator.proto", 132 | deps = [ 133 | "@com_google_mediapipe//mediapipe/modules/objectron/calculators:protos_src", 134 | "@com_google_mediapipe//mediapipe/framework:protos_src", 135 | ], 136 | ) 137 | -------------------------------------------------------------------------------- /mediapipe_api/modules/objectron/calculators/annotation_data.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/modules/objectron/calculators/annotation_data.h" 8 | 9 | MpReturnCode mp_Packet__GetFrameAnnotation(mediapipe::Packet* packet, mp_api::SerializedProto* value_out) { 10 | return mp_Packet__GetSerializedProto(packet, value_out); 11 | } 12 | -------------------------------------------------------------------------------- /mediapipe_api/modules/objectron/calculators/annotation_data.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_MODULES_OBJECTRON_CALCULATORS_ANNOTATION_DATA_H_ 8 | #define MEDIAPIPE_API_MODULES_OBJECTRON_CALCULATORS_ANNOTATION_DATA_H_ 9 | 10 | #include "mediapipe/modules/objectron/calculators/annotation_data.pb.h" 11 | #include "mediapipe_api/common.h" 12 | #include "mediapipe_api/external/protobuf.h" 13 | #include "mediapipe_api/framework/packet.h" 14 | 15 | extern "C" { 16 | 17 | MP_CAPI(MpReturnCode) mp_Packet__GetFrameAnnotation(mediapipe::Packet* packet, mp_api::SerializedProto* value_out); 18 | 19 | } // extern "C" 20 | 21 | #endif // MEDIAPIPE_API_MODULES_OBJECTRON_CALCULATORS_ANNOTATION_DATA_H_ 22 | -------------------------------------------------------------------------------- /mediapipe_api/objc/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("@build_bazel_rules_apple//apple:ios.bzl", "ios_framework") 8 | 9 | objc_library( 10 | name = "mediapipe_c_ios", 11 | sdk_frameworks = [ 12 | "Accelerate", 13 | "AVFoundation", 14 | "CoreVideo", 15 | "CoreGraphics", 16 | "CoreMedia", 17 | "GLKit", 18 | "OpenGLES", 19 | "QuartzCore", 20 | ], 21 | deps = [ 22 | "//mediapipe_api:mediapipe_c", 23 | "@ios_opencv//:OpencvFramework", 24 | ], 25 | ) 26 | 27 | ios_framework( 28 | name = "MediaPipeUnity", 29 | bundle_id = "PLEASE_SET_YOUR_BUNDLE_ID_HERE", 30 | families = [ 31 | "iphone", 32 | "ipad", 33 | ], 34 | infoplists = ["Info.plist"], 35 | minimum_os_version = "11.0", 36 | visibility = ["//visibility:public"], 37 | deps = [ 38 | ":mediapipe_c_ios", 39 | ], 40 | ) 41 | -------------------------------------------------------------------------------- /mediapipe_api/objc/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /mediapipe_api/util/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 | cc_library( 15 | name = "resource_util", 16 | srcs = ["resource_util_custom.cc"], 17 | hdrs = ["resource_util_custom.h"], 18 | deps = [ 19 | "//mediapipe_api:common", 20 | "@com_google_absl//absl/strings", 21 | "@com_google_mediapipe//mediapipe/framework/port:ret_check", 22 | "@com_google_mediapipe//mediapipe/framework/port:status", 23 | "@com_google_mediapipe//mediapipe/util:resource_util", 24 | ], 25 | alwayslink = True, 26 | ) 27 | 28 | pkg_files( 29 | name = "proto_srcs", 30 | srcs = [ 31 | ":audio_decoder_cs", 32 | ":color_cs", 33 | ":label_map_cs", 34 | ":render_data_cs", 35 | ], 36 | prefix = "Util", 37 | ) 38 | 39 | csharp_proto_src( 40 | name = "audio_decoder_cs", 41 | proto_src = "mediapipe/util/audio_decoder.proto", 42 | deps = [ 43 | "@com_google_mediapipe//mediapipe/util:protos_src", 44 | "@com_google_mediapipe//mediapipe/framework:protos_src", 45 | ], 46 | ) 47 | 48 | csharp_proto_src( 49 | name = "color_cs", 50 | proto_src = "mediapipe/util/color.proto", 51 | deps = [ 52 | "@com_google_mediapipe//mediapipe/util:protos_src", 53 | ], 54 | ) 55 | 56 | csharp_proto_src( 57 | name = "label_map_cs", 58 | proto_src = "mediapipe/util/label_map.proto", 59 | deps = [ 60 | "@com_google_mediapipe//mediapipe/util:protos_src", 61 | ], 62 | ) 63 | 64 | csharp_proto_src( 65 | name = "render_data_cs", 66 | proto_src = "mediapipe/util/render_data.proto", 67 | deps = [ 68 | "@com_google_mediapipe//mediapipe/util:protos_src", 69 | ], 70 | ) 71 | -------------------------------------------------------------------------------- /mediapipe_api/util/resource_util_custom.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/util/resource_util_custom.h" 8 | 9 | #include "absl/strings/str_cat.h" 10 | #include "mediapipe/framework/port/ret_check.h" 11 | 12 | void mp__SetCustomGlobalResourceProvider__P(ResourceProvider* resource_provider) { 13 | mediapipe::SetCustomGlobalResourceProvider([resource_provider](const std::string& path, std::string* output) -> ::absl::Status { 14 | if (resource_provider(path.c_str(), output)) { 15 | return absl::OkStatus(); 16 | } 17 | return absl::FailedPreconditionError(absl::StrCat("Failed to read ", path)); 18 | }); 19 | } 20 | 21 | void mp__SetCustomGlobalPathResolver__P(PathResolver* path_resolver) { 22 | mediapipe::SetCustomGlobalPathResolver([path_resolver](const std::string& path) -> ::absl::StatusOr { 23 | auto resolved_path = path_resolver(path.c_str()); 24 | 25 | RET_CHECK_NE(resolved_path, nullptr); 26 | return std::string(resolved_path); 27 | }); 28 | } 29 | -------------------------------------------------------------------------------- /mediapipe_api/util/resource_util_custom.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_UTIL_RESOURCE_UTIL_CUSTOM_H_ 8 | #define MEDIAPIPE_API_UTIL_RESOURCE_UTIL_CUSTOM_H_ 9 | 10 | #include 11 | 12 | #include "mediapipe/util/resource_util_custom.h" 13 | #include "mediapipe_api/common.h" 14 | 15 | extern "C" { 16 | 17 | typedef bool ResourceProvider(const char* path, std::string* output); 18 | typedef const char* PathResolver(const char* path); 19 | 20 | MP_CAPI(void) mp__SetCustomGlobalResourceProvider__P(ResourceProvider* resource_provider); 21 | MP_CAPI(void) mp__SetCustomGlobalPathResolver__P(PathResolver* path_resolver); 22 | 23 | } // extern "C" 24 | 25 | #endif // MEDIAPIPE_API_UTIL_RESOURCE_UTIL_CUSTOM_H_ 26 | -------------------------------------------------------------------------------- /mediapipe_api/util/tracking/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 | ":tone_models_cs", 16 | ":tone_estimation_cs", 17 | ":region_flow_computation_cs", 18 | ":motion_saliency_cs", 19 | ":motion_estimation_cs", 20 | ":motion_analysis_cs", 21 | ":region_flow_cs", 22 | ":motion_models_cs", 23 | ":camera_motion_cs", 24 | ":push_pull_filtering_cs", 25 | ":frame_selection_solution_evaluator_cs", 26 | ":frame_selection_cs", 27 | ":flow_packager_cs", 28 | ":tracking_cs", 29 | ":box_tracker_cs", 30 | ":tracked_detection_manager_config_cs", 31 | ":box_detector_cs", 32 | ], 33 | prefix = "Util", 34 | ) 35 | 36 | csharp_proto_src( 37 | name = "tone_models_cs", 38 | proto_src = "mediapipe/util/tracking/tone_models.proto", 39 | deps = [ 40 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 41 | ], 42 | ) 43 | 44 | csharp_proto_src( 45 | name = "tone_estimation_cs", 46 | proto_src = "mediapipe/util/tracking/tone_estimation.proto", 47 | deps = [ 48 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 49 | ], 50 | ) 51 | 52 | csharp_proto_src( 53 | name = "region_flow_computation_cs", 54 | proto_src = "mediapipe/util/tracking/region_flow_computation.proto", 55 | deps = [ 56 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 57 | ], 58 | ) 59 | 60 | csharp_proto_src( 61 | name = "motion_saliency_cs", 62 | proto_src = "mediapipe/util/tracking/motion_saliency.proto", 63 | deps = [ 64 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 65 | ], 66 | ) 67 | 68 | csharp_proto_src( 69 | name = "motion_estimation_cs", 70 | proto_src = "mediapipe/util/tracking/motion_estimation.proto", 71 | deps = [ 72 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 73 | ], 74 | ) 75 | 76 | csharp_proto_src( 77 | name = "motion_analysis_cs", 78 | proto_src = "mediapipe/util/tracking/motion_analysis.proto", 79 | deps = [ 80 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 81 | ], 82 | ) 83 | 84 | csharp_proto_src( 85 | name = "region_flow_cs", 86 | proto_src = "mediapipe/util/tracking/region_flow.proto", 87 | deps = [ 88 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 89 | ], 90 | ) 91 | 92 | csharp_proto_src( 93 | name = "motion_models_cs", 94 | proto_src = "mediapipe/util/tracking/motion_models.proto", 95 | deps = [ 96 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 97 | ], 98 | ) 99 | 100 | csharp_proto_src( 101 | name = "camera_motion_cs", 102 | proto_src = "mediapipe/util/tracking/camera_motion.proto", 103 | deps = [ 104 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 105 | ], 106 | ) 107 | 108 | csharp_proto_src( 109 | name = "push_pull_filtering_cs", 110 | proto_src = "mediapipe/util/tracking/push_pull_filtering.proto", 111 | deps = [ 112 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 113 | ], 114 | ) 115 | 116 | csharp_proto_src( 117 | name = "frame_selection_solution_evaluator_cs", 118 | proto_src = "mediapipe/util/tracking/frame_selection_solution_evaluator.proto", 119 | deps = [ 120 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 121 | ], 122 | ) 123 | 124 | csharp_proto_src( 125 | name = "frame_selection_cs", 126 | proto_src = "mediapipe/util/tracking/frame_selection.proto", 127 | deps = [ 128 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 129 | ], 130 | ) 131 | 132 | csharp_proto_src( 133 | name = "flow_packager_cs", 134 | proto_src = "mediapipe/util/tracking/flow_packager.proto", 135 | deps = [ 136 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 137 | ], 138 | ) 139 | 140 | csharp_proto_src( 141 | name = "tracking_cs", 142 | proto_src = "mediapipe/util/tracking/tracking.proto", 143 | deps = [ 144 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 145 | ], 146 | ) 147 | 148 | csharp_proto_src( 149 | name = "box_tracker_cs", 150 | proto_src = "mediapipe/util/tracking/box_tracker.proto", 151 | deps = [ 152 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 153 | ], 154 | ) 155 | 156 | csharp_proto_src( 157 | name = "tracked_detection_manager_config_cs", 158 | proto_src = "mediapipe/util/tracking/tracked_detection_manager_config.proto", 159 | deps = [ 160 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 161 | ], 162 | ) 163 | 164 | csharp_proto_src( 165 | name = "box_detector_cs", 166 | proto_src = "mediapipe/util/tracking/box_detector.proto", 167 | deps = [ 168 | "@com_google_mediapipe//mediapipe/util/tracking:protos_src", 169 | ], 170 | ) 171 | -------------------------------------------------------------------------------- /third_party/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The MediaPipe Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | licenses(["notice"]) # Apache License 2.0 16 | 17 | package(default_visibility = ["//visibility:public"]) 18 | 19 | exports_files(["LICENSE"]) 20 | 21 | cc_library( 22 | name = "glog", 23 | visibility = ["//visibility:public"], 24 | deps = select({ 25 | "@com_google_mediapipe//mediapipe:android_x86": [ 26 | "@com_github_glog_glog_no_gflags//:glog", 27 | ], 28 | "@com_google_mediapipe//mediapipe:android_x86_64": [ 29 | "@com_github_glog_glog_no_gflags//:glog", 30 | ], 31 | "@com_google_mediapipe//mediapipe:android_armeabi": [ 32 | "@com_github_glog_glog_no_gflags//:glog", 33 | ], 34 | "@com_google_mediapipe//mediapipe:android_arm": [ 35 | "@com_github_glog_glog_no_gflags//:glog", 36 | ], 37 | "@com_google_mediapipe//mediapipe:android_arm64": [ 38 | "@com_github_glog_glog_no_gflags//:glog", 39 | ], 40 | "@com_google_mediapipe//mediapipe:ios": [ 41 | "@com_github_glog_glog_no_gflags//:glog", 42 | ], 43 | "@com_google_mediapipe//mediapipe:macos": [ 44 | "@com_github_glog_glog//:glog", 45 | ], 46 | "@com_google_mediapipe//mediapipe:windows": [ 47 | "@com_github_glog_glog//:glog", 48 | ], 49 | "//conditions:default": [ 50 | "@com_github_glog_glog//:glog", 51 | ], 52 | }), 53 | ) 54 | 55 | cc_library( 56 | name = "libffmpeg", 57 | visibility = ["//visibility:public"], 58 | deps = select({ 59 | "@com_google_mediapipe//mediapipe:android_x86": [], 60 | "@com_google_mediapipe//mediapipe:android_x86_64": [], 61 | "@com_google_mediapipe//mediapipe:android_armeabi": [], 62 | "@com_google_mediapipe//mediapipe:android_arm": [], 63 | "@com_google_mediapipe//mediapipe:android_arm64": [], 64 | "@com_google_mediapipe//mediapipe:ios": [], 65 | "@com_google_mediapipe//mediapipe:macos": [ 66 | "@macos_ffmpeg//:libffmpeg", 67 | ], 68 | "//conditions:default": [ 69 | "@linux_ffmpeg//:libffmpeg", 70 | ], 71 | }), 72 | ) 73 | -------------------------------------------------------------------------------- /third_party/android_configure.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2019 gRPC authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Copyright 2016 The TensorFlow Authors. All Rights Reserved. 16 | # Licensed under the Apache License, Version 2.0 (the "License"); 17 | # you may not use this file except in compliance with the License. 18 | # You may obtain a copy of the License at 19 | # http://www.apache.org/licenses/LICENSE-2.0 20 | # Unless required by applicable law or agreed to in writing, software 21 | # distributed under the License is distributed on an "AS IS" BASIS, 22 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | # See the License for the specific language governing permissions and 24 | # limitations under the License. 25 | 26 | # Based on https://github.com/gnossen/grpc/blob/19fe1e777c9de7cfa42b04bbe764856f265b6110/third_party/android/android_configure.bzl 27 | # and https://github.com/tensorflow/tensorflow/blob/c858694b46eb777087b57a721f0cbb7e271e4b9e/third_party/android/android_configure.bzl 28 | 29 | # Changes 30 | # - determine ANDROID_NDK_API_LEVEL dynamically 31 | # - not to set `path` explicitly 32 | 33 | """Repository rule for Android SDK and NDK autoconfiguration. 34 | This rule is a no-op unless the required android environment variables are set. 35 | """ 36 | 37 | # Workaround for https://github.com/bazelbuild/bazel/issues/14260 38 | 39 | _ANDROID_NDK_HOME = "ANDROID_NDK_HOME" 40 | _ANDROID_NDK_API_LEVEL = "ANDROID_NDK_API_LEVEL" 41 | _ANDROID_SDK_HOME = "ANDROID_HOME" 42 | 43 | def _android_autoconf_impl(repository_ctx): 44 | sdk_home = repository_ctx.os.environ.get(_ANDROID_SDK_HOME) 45 | ndk_home = repository_ctx.os.environ.get(_ANDROID_NDK_HOME) 46 | ndk_api_level = repository_ctx.os.environ.get(_ANDROID_NDK_API_LEVEL) 47 | 48 | # version 31.0.0 won't work https://stackoverflow.com/a/68036845 49 | sdk_rule = "" 50 | if sdk_home: 51 | sdk_rule = """native.android_sdk_repository(name="androidsdk")""" 52 | 53 | # Note that Bazel does not support NDK 22 yet. 54 | ndk_rule = "" 55 | if ndk_home: 56 | if not ndk_api_level: 57 | ndk_rule = """native.android_ndk_repository(name="androidndk")""" 58 | else: 59 | ndk_rule = """ 60 | native.android_ndk_repository( 61 | name="androidndk", 62 | api_level={}, 63 | ) 64 | """.format(ndk_api_level) 65 | 66 | if ndk_rule == "" and sdk_rule == "": 67 | sdk_rule = "pass" 68 | 69 | repository_ctx.file("BUILD.bazel", "") 70 | repository_ctx.file("android_configure.bzl", """ 71 | def android_workspace(): 72 | {} 73 | {} 74 | """.format(sdk_rule, ndk_rule)) 75 | 76 | android_configure = repository_rule( 77 | implementation = _android_autoconf_impl, 78 | environ = [ 79 | _ANDROID_NDK_HOME, 80 | _ANDROID_NDK_API_LEVEL, 81 | _ANDROID_SDK_HOME, 82 | ], 83 | ) 84 | -------------------------------------------------------------------------------- /third_party/bazel_android_fixes.diff: -------------------------------------------------------------------------------- 1 | diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/android_ndk_cc_toolchain_template.txt b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/android_ndk_cc_toolchain_template.txt 2 | index 6e6c5c9592..e201f38565 100644 3 | --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/android_ndk_cc_toolchain_template.txt 4 | +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/android_ndk_cc_toolchain_template.txt 5 | @@ -14,7 +14,7 @@ cc_toolchain( 6 | objcopy_files = ":%toolchainName%-all_files", 7 | static_runtime_lib = ":%staticRuntimeLibs%", 8 | strip_files = ":%toolchainName%-all_files", 9 | - supports_param_files = 0, 10 | + supports_param_files = 1, 11 | toolchain_identifier = "%toolchainName%", 12 | toolchain_config = ":%toolchainName%-config", 13 | ) 14 | diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java 15 | index 5140b4afdd..3c207997ef 100644 16 | --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java 17 | +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java 18 | @@ -31,7 +31,7 @@ public final class CppFileTypes { 19 | // supported with clang. Bazel is not officially supporting these targets, and the extensions are 20 | // listed only as long as they work with the existing C++ actions. 21 | public static final FileType CPP_SOURCE = 22 | - FileType.of(".cc", ".cpp", ".cxx", ".c++", ".C", ".cu", ".cl"); 23 | + FileType.of(".cc", ".cpp", ".cxx", ".c++", ".cu", ".cl"); 24 | public static final FileType C_SOURCE = FileType.of(".c"); 25 | public static final FileType OBJC_SOURCE = FileType.of(".m"); 26 | public static final FileType OBJCPP_SOURCE = FileType.of(".mm"); 27 | @@ -91,15 +91,46 @@ public final class CppFileTypes { 28 | } 29 | }; 30 | 31 | - public static final FileType ASSEMBLER_WITH_C_PREPROCESSOR = FileType.of(".S"); 32 | - public static final FileType PIC_ASSEMBLER = FileType.of(".pic.s"); 33 | + // FileType is extended to use case-sensitive comparison also on Windows 34 | + public static final FileType ASSEMBLER_WITH_C_PREPROCESSOR = 35 | + new FileType() { 36 | + final String ext = ".S"; 37 | + 38 | + @Override 39 | + public boolean apply(String path) { 40 | + return path.endsWith(ext); 41 | + } 42 | + 43 | + @Override 44 | + public ImmutableList getExtensions() { 45 | + return ImmutableList.of(ext); 46 | + } 47 | + }; 48 | + 49 | + // FileType is extended to use case-sensitive comparison also on Windows 50 | + public static final FileType PIC_ASSEMBLER = 51 | + new FileType() { 52 | + final String ext = ".pic.s"; 53 | + 54 | + @Override 55 | + public boolean apply(String path) { 56 | + return OS.endsWith(path, ext) && path.endsWith(".s"); 57 | + } 58 | + 59 | + @Override 60 | + public ImmutableList getExtensions() { 61 | + return ImmutableList.of(ext); 62 | + } 63 | + }; 64 | + 65 | + // FileType is extended to use case-sensitive comparison also on Windows 66 | public static final FileType ASSEMBLER = 67 | new FileType() { 68 | final String ext = ".s"; 69 | 70 | @Override 71 | public boolean apply(String path) { 72 | - return (OS.endsWith(path, ext) && !PIC_ASSEMBLER.matches(path)) 73 | + return (path.endsWith(ext) && !PIC_ASSEMBLER.matches(path)) 74 | || OS.endsWith(path, ".asm"); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /third_party/build_bazel_apple_support_transitions.diff: -------------------------------------------------------------------------------- 1 | diff --git a/lib/transitions.bzl b/lib/transitions.bzl 2 | index f07e628..1e48a26 100644 3 | --- a/lib/transitions.bzl 4 | +++ b/lib/transitions.bzl 5 | @@ -18,7 +18,7 @@ def _macos_universal_transition_impl(settings, _attr): 6 | # Create a split transition from any macOS cpu to a list of all macOS cpus 7 | if settings["//command_line_option:cpu"].startswith("darwin"): 8 | return [ 9 | - {"//command_line_option:cpu": "darwin_x86_64"}, 10 | + {"//command_line_option:cpu": "darwin"}, 11 | {"//command_line_option:cpu": "darwin_arm64"}, 12 | ] 13 | else: 14 | -------------------------------------------------------------------------------- /third_party/build_bazel_rules_apple_validation.diff: -------------------------------------------------------------------------------- 1 | diff --git a/apple/internal/entitlements_support.bzl b/apple/internal/entitlements_support.bzl 2 | index 83b1bad0..fe77c687 100644 3 | --- a/apple/internal/entitlements_support.bzl 4 | +++ b/apple/internal/entitlements_support.bzl 5 | @@ -389,4 +389,5 @@ def _process_entitlements( 6 | 7 | entitlements_support = struct( 8 | process_entitlements = _process_entitlements, 9 | + validate_bundle_id = _validate_bundle_id, 10 | ) 11 | diff --git a/apple/internal/ios_rules.bzl b/apple/internal/ios_rules.bzl 12 | index 23e00090..9428e1a6 100644 13 | --- a/apple/internal/ios_rules.bzl 14 | +++ b/apple/internal/ios_rules.bzl 15 | @@ -684,6 +684,7 @@ def _ios_framework_impl(ctx): 16 | apple_xplat_toolchain_info = ctx.attr._xplat_toolchain[AppleXPlatToolsToolchainInfo] 17 | bin_root_path = ctx.bin_dir.path 18 | bundle_id = ctx.attr.bundle_id 19 | + entitlements_support.validate_bundle_id(bundle_id) 20 | bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) 21 | executable_name = bundling_support.executable_name(ctx) 22 | features = features_support.compute_enabled_features( 23 | -------------------------------------------------------------------------------- /third_party/com_github_glog_glog_no_gflags_fixes.diff: -------------------------------------------------------------------------------- 1 | diff --git a/bazel/glog.bzl b/bazel/glog.bzl 2 | index a46e2d1..f9f9a03 100644 3 | --- a/bazel/glog.bzl 4 | +++ b/bazel/glog.bzl 5 | @@ -107,12 +107,12 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs): 6 | "src/utilities.h", 7 | "src/vlog_is_on.cc", 8 | ] + select({ 9 | - "@bazel_tools//src/conditions:windows": windows_only_srcs, 10 | + "@com_google_mediapipe//mediapipe:windows": windows_only_srcs, 11 | "//conditions:default": [":config_h"], 12 | }), 13 | copts = 14 | select({ 15 | - "@bazel_tools//src/conditions:windows": common_copts + windows_only_copts, 16 | + "@com_google_mediapipe//mediapipe:windows": common_copts + windows_only_copts, 17 | "@bazel_tools//src/conditions:darwin": common_copts + linux_or_darwin_copts + darwin_only_copts, 18 | "@bazel_tools//src/conditions:freebsd": common_copts + linux_or_darwin_copts + freebsd_only_copts, 19 | ":wasm": common_copts + wasm_copts, 20 | @@ -128,7 +128,7 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs): 21 | native.cc_library( 22 | name = "glog_headers", 23 | deps = select({ 24 | - "@bazel_tools//src/conditions:windows": [":windows_glog_headers"], 25 | + "@com_google_mediapipe//mediapipe:windows": [":windows_glog_headers"], 26 | "//conditions:default": [":default_glog_headers"], 27 | }), 28 | ) 29 | diff --git a/src/logging.cc b/src/logging.cc 30 | index ddcf910..c7e7578 100644 31 | --- a/src/logging.cc 32 | +++ b/src/logging.cc 33 | @@ -73,6 +73,10 @@ 34 | # include "stacktrace.h" 35 | #endif 36 | 37 | +#ifdef __ANDROID__ 38 | +#include 39 | +#endif 40 | + 41 | using std::string; 42 | using std::vector; 43 | using std::setw; 44 | @@ -1485,6 +1489,23 @@ ostream& LogMessage::stream() { 45 | return data_->stream_; 46 | } 47 | 48 | +namespace { 49 | +#if defined(__ANDROID__) 50 | +int AndroidLogLevel(const int severity) { 51 | + switch (severity) { 52 | + case 3: 53 | + return ANDROID_LOG_FATAL; 54 | + case 2: 55 | + return ANDROID_LOG_ERROR; 56 | + case 1: 57 | + return ANDROID_LOG_WARN; 58 | + default: 59 | + return ANDROID_LOG_INFO; 60 | + } 61 | +} 62 | +#endif // defined(__ANDROID__) 63 | +} // namespace 64 | + 65 | // Flush buffered message, called by the destructor, or any other function 66 | // that needs to synchronize the log. 67 | void LogMessage::Flush() { 68 | @@ -1519,6 +1540,12 @@ void LogMessage::Flush() { 69 | } 70 | LogDestination::WaitForSinks(data_); 71 | 72 | +#if defined(__ANDROID__) 73 | + const int level = AndroidLogLevel((int)data_->severity_); 74 | + const std::string text = std::string(data_->message_text_); 75 | + __android_log_write(level, "native", text.substr(0,data_->num_chars_to_log_).c_str()); 76 | +#endif // defined(__ANDROID__) 77 | + 78 | if (append_newline) { 79 | // Fix the ostrstream back how it was before we screwed with it. 80 | // It's 99.44% certain that we don't need to worry about doing this. 81 | -------------------------------------------------------------------------------- /third_party/emscripten_extract_archive_fixes.diff: -------------------------------------------------------------------------------- 1 | diff --git a/emscripten/tools/building.py b/emscripten/tools/building.py 2 | index 2720abdb1..56b8e2a9a 100644 3 | --- a/emscripten/tools/building.py 4 | +++ b/emscripten/tools/building.py 5 | @@ -80,10 +80,10 @@ def warn_if_duplicate_entries(archive_contents, archive_filename): 6 | def extract_archive_contents(archive_files): 7 | archive_results = shared.run_multiple_processes([[LLVM_AR, 't', a] for a in archive_files], pipe_stdout=True) 8 | 9 | - unpack_temp_dir = tempfile.mkdtemp('_archive_contents', 'emscripten_temp_') 10 | + unpack_temp_dir_root = tempfile.mkdtemp('_archive_contents', 'emscripten_temp_') 11 | 12 | def clean_at_exit(): 13 | - try_delete(unpack_temp_dir) 14 | + try_delete(unpack_temp_dir_root) 15 | shared.atexit.register(clean_at_exit) 16 | 17 | archive_contents = [] 18 | @@ -102,12 +102,14 @@ def extract_archive_contents(archive_files): 19 | 20 | warn_if_duplicate_entries(contents, a) 21 | 22 | + unpack_temp_dir = os.path.join(unpack_temp_dir_root, str(i)) 23 | + os.mkdir(unpack_temp_dir) 24 | archive_contents += [{ 25 | 'archive_name': archive_files[i], 26 | 'o_files': [os.path.join(unpack_temp_dir, c) for c in contents] 27 | }] 28 | 29 | - shared.run_multiple_processes([[LLVM_AR, 'xo', a] for a in archive_files], cwd=unpack_temp_dir) 30 | + shared.run_process([LLVM_AR, 'xo', archive_files[i]], cwd=unpack_temp_dir) 31 | 32 | # check that all files were created 33 | for a in archive_contents: 34 | -------------------------------------------------------------------------------- /third_party/ffmpeg_linux.BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The MediaPipe Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | licenses(["notice"]) # LGPL 16 | 17 | exports_files(["LICENSE"]) 18 | 19 | cc_library( 20 | name = "libffmpeg", 21 | srcs = [ 22 | "lib/libavcodec.so", 23 | "lib/libavformat.so", 24 | "lib/libavresample.so", 25 | "lib/libavutil.so", 26 | "lib/libswscale.so", 27 | ], 28 | hdrs = glob( 29 | [ 30 | "include/libavcodec/*.h", 31 | "include/libavformat/*.h", 32 | "include/libavutil/*.h", 33 | "include/libswscale/*.h", 34 | "include/libavresample/*.h", 35 | ], 36 | ), 37 | includes = ["include"], 38 | linkopts = [ 39 | "-lavcodec", 40 | "-lavformat", 41 | "-lavutil", 42 | "-lswscale", 43 | "-lavresample", 44 | ], 45 | linkstatic = 1, 46 | visibility = ["//visibility:public"], 47 | ) 48 | -------------------------------------------------------------------------------- /third_party/ffmpeg_macos.BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The MediaPipe Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | licenses(["notice"]) # LGPL 16 | 17 | exports_files(["LICENSE"]) 18 | 19 | cc_library( 20 | name = "libffmpeg", 21 | srcs = [ 22 | "lib/libavcodec.dylib", 23 | "lib/libavformat.dylib", 24 | "lib/libavresample.dylib", 25 | "lib/libavutil.dylib", 26 | "lib/libswscale.dylib", 27 | ], 28 | hdrs = glob( 29 | [ 30 | "include/libavcodec/*.h", 31 | "include/libavformat/*.h", 32 | "include/libavutil/*.h", 33 | "include/libswscale/*.h", 34 | "include/libavresample/*.h", 35 | ], 36 | ), 37 | includes = ["include"], 38 | linkopts = [ 39 | "-lavcodec", 40 | "-lavformat", 41 | "-lavutil", 42 | "-lswscale", 43 | "-lavresample", 44 | ], 45 | linkstatic = 1, 46 | visibility = ["//visibility:public"], 47 | ) 48 | -------------------------------------------------------------------------------- /third_party/opencv_linux.BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The MediaPipe Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Description: 16 | # OpenCV libraries for video/image processing on Linux 17 | 18 | licenses(["notice"]) # BSD license 19 | 20 | exports_files(["LICENSE"]) 21 | 22 | # The following build rule assumes that OpenCV is installed by 23 | # 'apt-get install libopencv-core-dev libopencv-highgui-dev \' 24 | # ' libopencv-calib3d-dev libopencv-features2d-dev \' 25 | # ' libopencv-imgproc-dev libopencv-video-dev' 26 | # on Debian buster/Ubuntu 18.04. 27 | # If you install OpenCV separately, please modify the build rule accordingly. 28 | cc_library( 29 | name = "opencv", 30 | srcs = glob( 31 | [ 32 | "lib/libopencv_core.so", 33 | "lib/libopencv_calib3d.so", 34 | "lib/libopencv_features2d.so", 35 | "lib/libopencv_highgui.so", 36 | "lib/libopencv_imgcodecs.so", 37 | "lib/libopencv_imgproc.so", 38 | "lib/libopencv_video.so", 39 | "lib/libopencv_videoio.so", 40 | ], 41 | ), 42 | hdrs = glob([ 43 | # For OpenCV 3.x 44 | "include/opencv2/**/*.h*", 45 | # For OpenCV 4.x 46 | # "include/opencv4/opencv2/**/*.h*", 47 | ]), 48 | includes = [ 49 | # For OpenCV 3.x 50 | "include/", 51 | # For OpenCV 4.x 52 | # "include/opencv4/", 53 | ], 54 | linkstatic = 1, 55 | visibility = ["//visibility:public"], 56 | ) 57 | -------------------------------------------------------------------------------- /third_party/opencv_wasm.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 | # Description: 8 | # OpenCV libraries for WASM (LLVM IR bitcode) 9 | 10 | licenses(["notice"]) # BSD license 11 | 12 | exports_files(["LICENSE"]) 13 | 14 | # OpenCV needs to be built manually. 15 | # cf. https://docs.opencv.org/3.4/d4/da1/tutorial_js_setup.html 16 | # 17 | # Note that the output must be LLVM IR bitcode, not WASM. 18 | # emcmake python ./platforms/js/build_js.py build_js --build_flags="-emit-llvm -s USE_WEBGL2=1 -flto --oformat=object -s SIDE_MODULE=1" 19 | cc_library( 20 | name = "opencv", 21 | srcs = [ 22 | "lib/libopencv_video.a", 23 | "lib/libopencv_imgproc.a", 24 | "lib/libopencv_features2d.a", 25 | "lib/libopencv_calib3d.a", 26 | "lib/libopencv_core.a", 27 | ], 28 | hdrs = glob([ 29 | # For OpenCV 3.x 30 | "include/opencv2/**/*.h*", 31 | # For OpenCV 4.x 32 | # "include/opencv4/opencv2/**/*.h*", 33 | ]), 34 | includes = [ 35 | # For OpenCV 3.x 36 | "include/", 37 | # For OpenCV 4.x 38 | # "include/opencv4/", 39 | ], 40 | linkstatic = 1, 41 | visibility = ["//visibility:public"], 42 | ) 43 | -------------------------------------------------------------------------------- /third_party/opencv_windows.BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The MediaPipe Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Description: 16 | # OpenCV libraries for video/image processing on Windows 17 | 18 | licenses(["notice"]) # BSD license 19 | 20 | exports_files(["LICENSE"]) 21 | 22 | OPENCV_VERSION = "3416" # 3.4.16 23 | 24 | # The following build rule assumes that the executable "opencv-3.4.16-vc14_vc15.exe" 25 | # is downloaded and the files are extracted to local. 26 | # If you install OpenCV separately, please modify the build rule accordingly. 27 | cc_library( 28 | name = "opencv", 29 | srcs = [ 30 | "x64/vc15/lib/opencv_world" + OPENCV_VERSION + ".lib", 31 | "x64/vc15/bin/opencv_world" + OPENCV_VERSION + ".dll", 32 | ], 33 | hdrs = glob(["include/opencv2/**/*.h*"]), 34 | includes = ["include/"], 35 | linkstatic = 1, 36 | visibility = ["//visibility:public"], 37 | ) 38 | 39 | filegroup( 40 | name = "opencv_world_dll", 41 | srcs = [ 42 | "x64/vc15/bin/opencv_world" + OPENCV_VERSION + ".dll", 43 | ], 44 | visibility = ["//visibility:public"], 45 | ) 46 | -------------------------------------------------------------------------------- /third_party/tensorflow_xnnpack_emscripten_fixes.diff: -------------------------------------------------------------------------------- 1 | diff --git a/tensorflow/workspace2.bzl b/tensorflow/workspace2.bzl 2 | index b999e94ef26..d3c48f2f23a 100644 3 | --- a/tensorflow/workspace2.bzl 4 | +++ b/tensorflow/workspace2.bzl 5 | @@ -135,6 +135,7 @@ def _tf_repositories(): 6 | # LINT.IfChange 7 | tf_http_archive( 8 | name = "XNNPACK", 9 | + patch_file = ["//third_party:xnnpack_emscripten_fix.patch"], 10 | sha256 = "7077e61fe8d766dd0887d53d86680e552c2275920eb8b4e21de772e9a24bca74", 11 | strip_prefix = "XNNPACK-a0ec971de0dc82e0bf8784393cb8c4a56c171045", 12 | urls = tf_mirror_urls("https://github.com/google/XNNPACK/archive/a0ec971de0dc82e0bf8784393cb8c4a56c171045.zip"), 13 | diff --git a/third_party/xnnpack_emscripten_fix.patch b/third_party/xnnpack_emscripten_fix.patch 14 | new file mode 100644 15 | index 00000000000..857d956675c 16 | --- /dev/null 17 | +++ b/third_party/xnnpack_emscripten_fix.patch 18 | @@ -0,0 +1,23 @@ 19 | +diff --git a/BUILD.bazel b/BUILD.bazel 20 | +index d8b8f2b61..2bf84146f 100644 21 | +--- a/BUILD.bazel 22 | ++++ b/BUILD.bazel 23 | +@@ -8926,15 +8926,15 @@ xnnpack_aggregate_library( 24 | + ], 25 | + wasm_deps = [ 26 | + ":wasm_prod_microkernels", 27 | +- ":asm_microkernels", 28 | ++ # ":asm_microkernels", 29 | + ], 30 | + wasmrelaxedsimd_deps = [ 31 | + ":wasm_prod_microkernels", 32 | +- ":asm_microkernels", 33 | ++ # ":asm_microkernels", 34 | + ], 35 | + wasmsimd_deps = [ 36 | + ":wasm_prod_microkernels", 37 | +- ":asm_microkernels", 38 | ++ # ":asm_microkernels", 39 | + ], 40 | + x86_deps = [ 41 | + ":sse2_prod_microkernels", 42 | -------------------------------------------------------------------------------- /third_party/unity.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 | licenses(["notice"]) # BSD license 8 | 9 | exports_files(["LICENSE"]) 10 | 11 | java_import( 12 | name = "classes.jar", 13 | jars = [ 14 | "Editor/Data/PlaybackEngines/AndroidPlayer/Variations/mono/Release/Classes/classes.jar", 15 | ], 16 | neverlink = True, 17 | visibility = ["//visibility:public"], 18 | ) 19 | 20 | android_library( 21 | name = "activity", 22 | srcs = glob( 23 | ["Editor/Data/PlaybackEngines/AndroidPlayer/Source/**/*.java"], 24 | ), 25 | visibility = ["//visibility:public"], 26 | deps = [ 27 | ":classes.jar", 28 | ], 29 | ) 30 | --------------------------------------------------------------------------------