mediapipe/mediapipe/framework/api2
MediaPipe Team 280bd320b4 Fix more OSS warnings and build errors
-Wc++98-compat-extra-semi
* in type_map.h

-Winconsistent-missing-override
* in gl_texture_buffer.h

-Wdeprecated-declarations
* usage of (absl) Status in
  * status_util.cc
  * api2/packet.h
  * output_stream_shard.cc

-Wimplicit-const-int-float-conversion
* Adds a static_cast to handle the precision loss when converting from large ints to floating point

ANNOTATE_THREAD_NAME
* explicitly uses ABSL_ANNOTATE_THREAD_NAME instead. This is useful in Chromium's build where there are multiple ANNOTATE_THREAD_NAME symbols

Also ran clang-format over all of each edited file

PiperOrigin-RevId: 537351290
2023-06-02 10:46:42 -07:00
..
BUILD Support proto3 node_option in api2 graph_builder 2023-04-11 20:49:35 -07:00
builder_test.cc Support proto3 node_option in api2 graph_builder 2023-04-11 20:49:35 -07:00
builder.h Internal Change 2023-04-30 23:10:21 -07:00
const_str.h Project import generated by Copybara. 2022-03-21 12:12:39 -07:00
contract_test.cc Project import generated by Copybara. 2021-02-27 03:30:05 -05:00
contract.h Change object detector learning rate decay to cosine decay. 2023-04-26 12:13:17 -07:00
node_test.cc Internal change 2023-04-19 11:01:13 -07:00
node.cc Project import generated by Copybara. 2020-12-16 00:05:25 -05:00
node.h Add location info in registry (debug mode only) 2023-02-10 16:58:44 -08:00
packet_nc.cc Project import generated by Copybara. 2022-05-05 19:57:20 +00:00
packet_test.cc Rollback: Add PacketSharingOwnership, a safer replacement for PointToForeign. 2023-02-05 08:59:09 -08:00
packet.cc Project import generated by Copybara. 2021-02-27 03:30:05 -05:00
packet.h Fix more OSS warnings and build errors 2023-06-02 10:46:42 -07:00
port_test.cc Internal change 2023-04-06 22:13:38 -07:00
port.h Internal change 2023-04-21 13:12:47 -07:00
README.md Fix typo in README 2023-05-01 10:25:05 -07:00
subgraph_test.cc Project import generated by Copybara. 2021-12-13 15:56:02 -08:00
tag_test.cc Project import generated by Copybara. 2022-03-21 12:12:39 -07:00
tag.h Project import generated by Copybara. 2022-03-22 17:48:17 -07:00
test_contracts.h Project import generated by Copybara. 2020-12-16 00:05:25 -05:00
tuple_test.cc Project import generated by Copybara. 2020-12-16 00:05:25 -05:00
tuple.h Project import generated by Copybara. 2021-12-13 15:56:02 -08:00
type_list_test.cc Project import generated by Copybara. 2020-12-16 00:05:25 -05:00
type_list.h Project import generated by Copybara. 2020-12-16 00:05:25 -05:00

New MediaPipe APIs

This directory defines new APIs for MediaPipe:

  • Node API, an update to the Calculator API for defining MediaPipe components.
  • Builder API, for assembling CalculatorGraphConfigs with C++, as an alternative to using the proto API directly.

The new APIs interoperate fully with the existing framework code, and we are adopting them in our calculators. We are still making improvements, and the placement of this code under the mediapipe::api2 namespace is not final.

Developers are welcome to try out these APIs as early adopters, but there may be breaking changes.

Node API

This API can be used to define calculators. It is designed to be more type-safe and less verbose than the original API.

Input/output ports (streams and side packets) can now be declared as typed constants, instead of using plain strings for access.

For example, instead of

constexpr char kSelectTag[] = "SELECT";
if (cc->Inputs().HasTag(kSelectTag)) {
  cc->Inputs().Tag(kSelectTag).Set<int>();
}

you can write

static constexpr Input<int>::Optional kSelect{"SELECT"};

Instead of setting up the contract procedurally in GetContract, add ports to the contract declaratively, as follows:

MEDIAPIPE_NODE_CONTRACT(kInput, kOutput);

To access an input in Process, instead of

int select = cc->Inputs().Tag(kSelectTag).Get<int>();

write

int select = kSelect(cc).Get();  // alternative: *kSelect(cc)

Sets of multiple ports can be declared with ::Multiple. Note, also, that a tag string must always be provided when declaring a port; use "" for untagged ports. For example:

for (int i = 0; i < cc->Inputs().NumEntries(); ++i) {
  cc->Inputs().Index(i).SetAny();
}

becomes

static constexpr Input<AnyType>::Multiple kIn{""};

For output ports, the payload can be passed directly to the Send method. For example, instead of

cc->Outputs().Index(0).Add(
    new std::pair<Packet, Packet>(cc->Inputs().Index(0).Value(),
                                  cc->Inputs().Index(1).Value()),
    cc->InputTimestamp());

you can write

kPair(cc).Send({kIn(cc)[0].packet(), kIn(cc)[1].packet()});

The input timestamp is propagated to the outputs by default. If your calculator wants to alter timestamps, it must add a TimestampChange entry to its contract declaration. For example:

MEDIAPIPE_NODE_CONTRACT(kMain, kLoop, kPrevLoop,
                        StreamHandler("ImmediateInputStreamHandler"),
                        TimestampChange::Arbitrary());

Several calculators in calculators/core and calculators/tensor have been updated to use this API. Reference them for more examples.

More complete documentation will be provided in the future.

Builder API

Documentation will be provided in the future.