Project import generated by Copybara.

GitOrigin-RevId: 796203faee20d7aae2876aac8ca5a1827dee4fe3
This commit is contained in:
MediaPipe Team
2019-09-30 11:26:36 -07:00
committed by jqtang
parent 412ab42d1f
commit a2a63e3876
122 changed files with 7330 additions and 2016 deletions
+7
View File
@@ -116,6 +116,13 @@ typedef NS_ENUM(int, MPPPacketType) {
/// @param name The name of the input side packet.
- (void)setSidePacket:(const mediapipe::Packet&)packet named:(const std::string&)name;
/// Sets a service packet. If it was already set, it is overwritten.
/// Must be called before the graph is started.
/// @param packet The packet to be associated with the service.
/// @param service.
- (void)setServicePacket:(mediapipe::Packet&)packet
forService:(const mediapipe::GraphServiceBase&)service;
/// Adds input side packets from a map. Any inputs that were already set are
/// left unchanged.
/// Must be called before the graph is started.
+33 -8
View File
@@ -22,6 +22,7 @@
#include "absl/memory/memory.h"
#include "mediapipe/framework/calculator_framework.h"
#include "mediapipe/framework/formats/image_frame.h"
#include "mediapipe/framework/graph_service.h"
#include "mediapipe/gpu/MPPGraphGPUData.h"
#include "mediapipe/gpu/gl_base.h"
#include "mediapipe/gpu/gpu_shared_data_internal.h"
@@ -38,6 +39,8 @@
std::map<std::string, mediapipe::Packet> _inputSidePackets;
/// Packet headers that will be added to the graph when it is started.
std::map<std::string, mediapipe::Packet> _streamHeaders;
/// Service packets to be added to the graph when it is started.
std::map<const mediapipe::GraphServiceBase*, mediapipe::Packet> _servicePackets;
/// Number of frames currently being processed by the graph.
std::atomic<int32_t> _framesInFlight;
@@ -199,6 +202,13 @@ void CallFrameDelegate(void* wrapperVoid, const std::string& streamName,
_inputSidePackets[name] = packet;
}
- (void)setServicePacket:(mediapipe::Packet&)packet
forService:(const mediapipe::GraphServiceBase&)service {
_GTMDevAssert(!_started, @"%@ must be called before the graph is started",
NSStringFromSelector(_cmd));
_servicePackets[&service] = std::move(packet);
}
- (void)addSidePackets:(const std::map<std::string, mediapipe::Packet>&)extraSidePackets {
_GTMDevAssert(!_started, @"%@ must be called before the graph is started",
NSStringFromSelector(_cmd));
@@ -206,18 +216,33 @@ void CallFrameDelegate(void* wrapperVoid, const std::string& streamName,
}
- (BOOL)startWithError:(NSError**)error {
::mediapipe::Status status = [self performStart];
if (!status.ok()) {
if (error) {
*error = [NSError gus_errorWithStatus:status];
}
return NO;
}
_started = YES;
return YES;
}
- (::mediapipe::Status)performStart {
::mediapipe::Status status = _graph->Initialize(_config);
if (status.ok()) {
status = _graph->StartRun(_inputSidePackets, _streamHeaders);
if (status.ok()) {
_started = YES;
return YES;
if (!status.ok()) {
return status;
}
for (const auto& service_packet : _servicePackets) {
status = _graph->SetServicePacket(*service_packet.first, service_packet.second);
if (!status.ok()) {
return status;
}
}
if (error) {
*error = [NSError gus_errorWithStatus:status];
status = _graph->StartRun(_inputSidePackets, _streamHeaders);
if (!status.ok()) {
return status;
}
return NO;
return status;
}
- (void)cancel {
+3
View File
@@ -61,6 +61,9 @@
/// Loads an image from the test bundle.
- (UIImage*)testImageNamed:(NSString*)name extension:(NSString*)extension;
/// Returns a URL for a file.extension in the test bundle.
- (NSURL*)URLForTestFile:(NSString*)file extension:(NSString*)extension;
/// Loads an image from the test bundle in subpath.
- (UIImage*)testImageNamed:(NSString*)name
extension:(NSString*)extension
+6 -2
View File
@@ -43,9 +43,13 @@ static void EnsureOutputDirFor(NSString *outputFile) {
@implementation MPPGraphTestBase
- (NSData*)testDataNamed:(NSString*)name extension:(NSString*)extension {
- (NSURL*)URLForTestFile:(NSString*)file extension:(NSString*)extension {
NSBundle* testBundle = [NSBundle bundleForClass:[self class]];
NSURL* resourceURL = [testBundle URLForResource:name withExtension:extension];
return [testBundle URLForResource:file withExtension:extension];
}
- (NSData*)testDataNamed:(NSString*)name extension:(NSString*)extension {
NSURL* resourceURL = [self URLForTestFile:name extension:extension];
XCTAssertNotNil(resourceURL,
@"Unable to find data with name: %@. Did you add it to your resources?", name);
NSError* error;