MEDIAPIPE_NODE/SUBGRAPH_IMPLEMENTATION to use common define for registration

PiperOrigin-RevId: 547669538
This commit is contained in:
MediaPipe Team 2023-07-12 20:06:12 -07:00 committed by Copybara-Service
parent cc2aa4f4cc
commit 450c933cb5
2 changed files with 16 additions and 11 deletions

View File

@ -224,11 +224,10 @@ class SubgraphImpl : public Subgraph, public Intf {
// This macro is used to register a calculator that does not use automatic // This macro is used to register a calculator that does not use automatic
// registration. Deprecated. // registration. Deprecated.
#define MEDIAPIPE_NODE_IMPLEMENTATION(Impl) \ #define MEDIAPIPE_NODE_IMPLEMENTATION(Impl) \
static mediapipe::NoDestructor<mediapipe::RegistrationToken> \ MEDIAPIPE_REGISTER_FACTORY_FUNCTION_QUALIFIED( \
REGISTRY_STATIC_VAR(calculator_registration, \ mediapipe::CalculatorBaseRegistry, calculator_registration, \
__LINE__)(mediapipe::CalculatorBaseRegistry::Register( \
Impl::kCalculatorName, \ Impl::kCalculatorName, \
absl::make_unique<mediapipe::internal::CalculatorBaseFactoryFor<Impl>>)) absl::make_unique<mediapipe::internal::CalculatorBaseFactoryFor<Impl>>)
// This macro is used to register a non-split-contract calculator. Deprecated. // This macro is used to register a non-split-contract calculator. Deprecated.
#define MEDIAPIPE_REGISTER_NODE(name) REGISTER_CALCULATOR(name) #define MEDIAPIPE_REGISTER_NODE(name) REGISTER_CALCULATOR(name)
@ -236,10 +235,9 @@ class SubgraphImpl : public Subgraph, public Intf {
// This macro is used to define a subgraph that does not use automatic // This macro is used to define a subgraph that does not use automatic
// registration. Deprecated. // registration. Deprecated.
#define MEDIAPIPE_SUBGRAPH_IMPLEMENTATION(Impl) \ #define MEDIAPIPE_SUBGRAPH_IMPLEMENTATION(Impl) \
static mediapipe::NoDestructor<mediapipe::RegistrationToken> \ MEDIAPIPE_REGISTER_FACTORY_FUNCTION_QUALIFIED( \
REGISTRY_STATIC_VAR(subgraph_registration, \ mediapipe::SubgraphRegistry, subgraph_registration, \
__LINE__)(mediapipe::SubgraphRegistry::Register( \ Impl::kCalculatorName, absl::make_unique<Impl>)
Impl::kCalculatorName, absl::make_unique<Impl>))
} // namespace api2 } // namespace api2
} // namespace mediapipe } // namespace mediapipe

View File

@ -396,6 +396,13 @@ class GlobalFactoryRegistry {
new mediapipe::RegistrationToken( \ new mediapipe::RegistrationToken( \
RegistryType::Register(#name, __VA_ARGS__)) RegistryType::Register(#name, __VA_ARGS__))
#define MEDIAPIPE_REGISTER_FACTORY_FUNCTION_QUALIFIED(RegistryType, var_name, \
name, ...) \
static auto* REGISTRY_STATIC_VAR(var_name, __LINE__) = \
new mediapipe::RegistrationToken( \
RegistryType::Register(name, __VA_ARGS__))
// TODO: migrate to the above.
#define REGISTER_FACTORY_FUNCTION_QUALIFIED(RegistryType, var_name, name, ...) \ #define REGISTER_FACTORY_FUNCTION_QUALIFIED(RegistryType, var_name, name, ...) \
static auto* REGISTRY_STATIC_VAR(var_name, __LINE__) = \ static auto* REGISTRY_STATIC_VAR(var_name, __LINE__) = \
new mediapipe::RegistrationToken( \ new mediapipe::RegistrationToken( \