// Copyright 2019 The MediaPipe Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // Declares CalculatorGraph, which links Calculators into a directed acyclic // graph, and allows its evaluation. #ifndef MEDIAPIPE_FRAMEWORK_CALCULATOR_GRAPH_H_ #define MEDIAPIPE_FRAMEWORK_CALCULATOR_GRAPH_H_ #include <atomic> #include <functional> #include <map> #include <memory> #include <string> #include <utility> #include <vector> #include "absl/base/attributes.h" #include "absl/base/thread_annotations.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/calculator.pb.h" #include "mediapipe/framework/calculator_base.h" #include "mediapipe/framework/calculator_node.h" #include "mediapipe/framework/counter_factory.h" #include "mediapipe/framework/executor.h" #include "mediapipe/framework/graph_output_stream.h" #include "mediapipe/framework/graph_service.h" #include "mediapipe/framework/graph_service_manager.h" #include "mediapipe/framework/mediapipe_profiling.h" #include "mediapipe/framework/output_side_packet_impl.h" #include "mediapipe/framework/output_stream_manager.h" #include "mediapipe/framework/output_stream_poller.h" #include "mediapipe/framework/output_stream_shard.h" #include "mediapipe/framework/packet.h" #include "mediapipe/framework/packet_generator_graph.h" #include "mediapipe/framework/scheduler.h" #include "mediapipe/framework/scheduler_shared.h" #include "mediapipe/framework/subgraph.h" #include "mediapipe/framework/thread_pool_executor.pb.h" #include "mediapipe/framework/timestamp.h" #include "mediapipe/framework/validated_graph_config.h" namespace mediapipe { #if !MEDIAPIPE_DISABLE_GPU class GpuResources; struct GpuSharedData; #endif // !MEDIAPIPE_DISABLE_GPU StatusOrPoller; // The class representing a DAG of calculator nodes. // // CalculatorGraph is the primary API for the MediaPipe Framework. // In general, CalculatorGraph should be used if the only thing you need // to do is run the graph (without pushing data in or extracting it as // the graph runs). // // Example: // // Build dependency "//mediapipe/framework:calculator_framework". // // #include "mediapipe/framework/calculator_framework.h" // // mediapipe::CalculatorGraphConfig config; // MP_RETURN_IF_ERROR(mediapipe::tool::ParseGraphFromString(kGraphStr, // &config)); mediapipe::CalculatorGraph graph; // MP_RETURN_IF_ERROR(graph.Initialize(config)); // // std::map<std::string, mediapipe::Packet> extra_side_packets; // extra_side_packets["video_id"] = mediapipe::MakePacket<std::string>( // "3edb9503834e9b42"); // MP_RETURN_IF_ERROR(graph.Run(extra_side_packets)); // // // Run again (demonstrating the more concise initializer list syntax). // MP_RETURN_IF_ERROR(graph.Run( // {{"video_id", mediapipe::MakePacket<std::string>("Ex-uGhDzue4")}})); // // See mediapipe/framework/graph_runner.h for an interface // // to insert and extract packets from a graph as it runs. // // Once it is done using the graph, close its streams and wait till done. // MP_RETURN_IF_ERROR(graph->CloseAllInputStreams()); // MP_RETURN_IF_ERROR(graph->WaitUntilDone()); class CalculatorGraph { … }; } // namespace mediapipe #endif // MEDIAPIPE_FRAMEWORK_CALCULATOR_GRAPH_H_