chromium/third_party/mediapipe/README.chromium

Name: MediaPipe
Short Name: mediapipe
URL: https://github.com/google/mediapipe
Version: 905eade19971467bca916bbb80da6936a994095f
Revision: 7c625938d8074b77e6cefcc29beabd995c613e2b
Date: 2024-08-27
License: Apache 2.0
License File: LICENSE
Security Critical: Yes
Shipped: yes
CPEPrefix: unknown

Description:
MediaPipe Tasks provides the core programming interface of the MediaPipe
Solutions suite, including a set of libraries for deploying innovative ML
solutions onto devices with a minimum of code. It supports multiple platforms,
including Android, Web / JavaScript, Python, and support for iOS is coming soon.

To update this library
======================

1) Change the `Version` and `Date` lines above.

2) Run the `update.sh` script in this directory.

3) Fix the build and get everything compiling and `components_unittests`
  passing with the gn arg `build_with_mediapipe_lib = true` and optionally with
  `mediapipe_build_with_gpu_support = true`.


To make a new patch file
========================

1) Make changes in //third_party/mediapipe/src/

2) `git commit` those changes.

  Note: This works best when you are only making a single patch in your git
  branch.

3) Run this command (or one like it):

  ```
  git format-patch origin/main third_party/mediapipe/src/ -o third_party/mediapipe/patches
  ```

  Note: git format-patch takes arguments in the same style as git diff. See the
  man page for git-format-patch for help.

4) Rename the added patch file and change the subject line as needed.


Patches which can be low-friction upstreamed
============================================
* set-executable-bit-for-files-with-shebang.patch - `chmod +x` on all files that
have a shebang, per Chromium presubmit checks.

* remove-mediapipe-op-resolver-default-value.patch - Removes the
MediaPipeOpResolver from being always constructed in base_options.h. Chromium
does not use it anyways, and building all those ops is not necessary.

* use-re2-instead-of-std-regex.patch - Uses RE2 instead of std::regex per
Chromium binary size requirements.

* unnecessary-const.patch - Removes an unnecessary "const".


Patches which need to be upstreamed differently than they are patched
=====================================================================
* remove-usage-of-absl-flags.patch - Completely removes any `ABSL_FLAG`
declaration and replaces it with non-functionality. None of these code paths are
used by Chromium. In order to upstream this patch, each flag would need to be
moved to a separate .cc file containing nothing but the flag declaration. Then,
Chromium could use a good default value given by upstream or write our own logic
to determine the best flag value.

* remove-xnnpack-from-cpu-delegate.patch - Removes references to XNNPACK from
the CPU inference delegate. Not sure why this is here, but it is not needed in
Chromium because we conditionally add the XNNPACK delegate when the platform
supports it.

* remove-resource_util_windows.cc-functionality.patch - Getting resources as
runfiles or through command line flags is not needed in Chromium, so it's either
to simply remove all that code than add bazel's runfiles lib and support the
ABSL_FLAG.

* compile-with-gpu-on-windows.patch - MediaPipe uses pthreads internally when
built with GPU support enabled - for Windows build, most of the functionality
can be replaced by std::threads, with an exception that MediaPipe also relies on
running a callback on thread destruction. This is not something that is allowed
in Chromium, so it would potentially need to be a more complex change in
MediaPipe (i.e. we need a replacement for `EnsureEglThreadRelease()` in
gl_context_egl.cc).

* no-consume.patch - MediaPipe still uses shared_ptr::unique() but only in code that Chrome does not exercise. This needs to actually be fixed properly upstream.

Other patches
=============
* update-any-usage.patch - Renames usage of the proto google.protobuf.Any to
google.protobuf.AnyLite as well as checking in generated source for these
protos (in shims/protobuf). The checked in source is required as protoc
special cases google.protobuf.Any, and mediapipe can not use that name as
protobuf already uses that name and chrome has the full implementation
checked into the repo. To use the same name would result in ODR violations. The
souce was generated using normal protoc and the special functions added for Any
were copied over (specifically variants of PackFrom, UnpackTo and Is).
Here's the set of functions that were added to the generated file:
  template <typename T>
  bool PackFrom(const T& message) {
    internal::AnyMetadata any_metadata(&type_url_, &value_);
    return any_metadata.PackFrom(GetArena(), message);
  }
  template <typename T>
  bool UnpackTo(T* message) const {
    internal::AnyMetadata any_metadata(&(const_cast<AnyLite*>(this)->type_url_),
                                       &(const_cast<AnyLite*>(this)->value_));
    return any_metadata.UnpackTo(message);
  }
  template<typename T> bool Is() const {
    internal::AnyMetadata any_metadata(&(const_cast<AnyLite*>(this)->type_url_),
                                       &(const_cast<AnyLite*>(this)->value_));
    return any_metadata.Is<T>();
  }

* dont-use-dedicated-context-for-some-calculators.patch - temporary patch that
is only needed when unit-testing with GPU support (not yet official). Will be
removed after MediaPipe w/ GPU is taught how to use Chromium's GL thread and
GL context instead of creating its own.
TODO(https://crbug.com/1492217): remove this patch once it is no longer needed.