Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/http_frontend/http_graph_executor_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#pragma GCC diagnostic pop
#pragma warning(pop)

#include "../logging.hpp"
#include "../mediapipe_internal/mediapipegraphexecutor.hpp"
#include "../mediapipe_internal/mediapipe_utils.hpp"

Expand Down Expand Up @@ -92,6 +93,16 @@ Status onPacketReadySerializeImpl(
const mediapipe_packet_type_enum packetType,
const ::mediapipe::Packet& packet,
std::string& response) {
if (packet.IsEmpty()) {
SPDLOG_DEBUG("Received empty packet for output stream: {}", packetName);
response.clear();
return StatusCode::OK;
}
if (!packet.ValidateAsType<std::string>().ok()) {
SPDLOG_ERROR("Packet type mismatch for stream: {}. Expected std::string but received: {}",
packetName, packet.DebugTypeName());
return Status(StatusCode::MEDIAPIPE_EXECUTION_ERROR, "Invalid packet payload type for HTTP output");
}
response = packet.Get<std::string>();
return StatusCode::OK;
}
Expand Down
37 changes: 37 additions & 0 deletions src/test/mediapipeflow_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

#include "../config.hpp"
#include "../grpcservermodule.hpp"
#include "../http_frontend/http_graph_executor_impl.hpp"
#include "../http_rest_api_handler.hpp"
#include "../kfs_frontend/kfs_graph_executor_impl.hpp"
#include "../kfs_frontend/kfs_grpc_inference_service.hpp"
Expand Down Expand Up @@ -4484,3 +4485,39 @@ TEST(MediapipeIdleUnloadGuard, CreateDefinitionLazyLoadRejectsDuplicate) {
auto status2 = factory.createDefinition("dupGraph", mgc, metrics, manager, true);
ASSERT_EQ(status2, ovms::StatusCode::PIPELINE_DEFINITION_ALREADY_EXIST);
}

TEST(HttpMediapipeSerialization, ValidStringPacket) {
std::string expected = "sample_response_data";
::mediapipe::Packet packet = ::mediapipe::MakePacket<std::string>(expected);
std::string response;
auto status = ovms::onPacketReadySerializeImpl(
"1", "test_graph", "1", "out",
ovms::mediapipe_packet_type_enum::UNKNOWN,
packet,
response);
ASSERT_EQ(status, ovms::StatusCode::OK);
EXPECT_EQ(response, expected);
}

TEST(HttpMediapipeSerialization, EmptyPacketHandledGracefully) {
::mediapipe::Packet emptyPacket;
std::string response = "previous_value";
auto status = ovms::onPacketReadySerializeImpl(
"1", "test_graph", "1", "out",
ovms::mediapipe_packet_type_enum::UNKNOWN,
emptyPacket,
response);
ASSERT_EQ(status, ovms::StatusCode::OK);
EXPECT_TRUE(response.empty());
}

TEST(HttpMediapipeSerialization, NonStringPacketReturnsErrorWithoutCrash) {
::mediapipe::Packet intPacket = ::mediapipe::MakePacket<int>(42);
std::string response;
auto status = ovms::onPacketReadySerializeImpl(
"1", "test_graph", "1", "out",
ovms::mediapipe_packet_type_enum::OVTENSOR,
intPacket,
response);
ASSERT_EQ(status, ovms::StatusCode::MEDIAPIPE_EXECUTION_ERROR);
}