mediapipe/mediapipe/framework/api2
MediaPipe Team 2c82f67097 Add location info in registry (debug mode only)
PiperOrigin-RevId: 508786558
2023-02-10 16:58:44 -08:00
..
BUILD Remove unused includes. 2022-10-12 14:38:04 -07:00
builder_test.cc Update test to reflect the recommended graph construction style: 2023-01-25 17:13:17 -08:00
builder.h Stream/SidePacket == and != operators 2023-01-23 16:43:23 -08: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 Project import generated by Copybara. 2021-02-27 03:30:05 -05:00
node_test.cc Project import generated by Copybara. 2021-12-13 15:56:02 -08: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 Rollback: Add PacketSharingOwnership, a safer replacement for PointToForeign. 2023-02-05 08:59:09 -08:00
port_test.cc Project import generated by Copybara. 2022-06-28 12:11:05 +00:00
port.h Internal change 2022-12-14 18:14:55 -08:00
README.md Project import generated by Copybara. 2021-06-03 17:04:35 -04: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 = kSelectTag(cc).Get();  // alternative: *kSelectTag(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.